Drawing a Circle With Asterisks
Hi at that place, I am VERY new to coding and I am having problem amalgam a basic circle with asterisks. I need to practice it using loops but I am struggling. The circumvolve is meant to expect like this:
| |
It would be great for a flake of aid, even if it merely for the first 2 lines so I tin can get a better thought on how to go on. Thank you everyone
I have seen that one, but the fact that information technology prints three stars in the outset line throws me off.
I dont actually understand how I would be able to print a star, two spaces, and then a star using a loop.
I am using the lawmaking in the person's post that prints the kickoff line simply I cant effigy out what to change to go it to look like the circle i want
Last edited on
Sorry I wish I could exist more assistance.. I was just pointing out what I establish. Seems to be an interesting trouble (that I take not yet encountered) and it seems at that place is very simple solutions and very circuitous. Reminds me of when I was looking at random number generation. Information technology seems this is the simpler of the two sides of the complication. promise y'all get a solid solution. And if you do would you exist kind enough to post your solution here?
EDIT: I attempted to deconstruct the problem, and felt lost immediately as well.
Terminal edited on
Thanks for trying, my friend is going to aid me with the solution this afternoon, and I will post it here. I think information technology is i of those issues that is quite like shooting fish in a barrel, I am merely a little clueless with C++ every bit I started my course about vi weeks ago.
Howdy, AdehhRR
If I were going to do this, I would split the logic for defining the circle and the logic for drawing and treat them every bit two unlike problems.
if we have a ii dimensional 7x7 assortment of Boolean values all set to false called shape_elements:
| |
we essentially have a very similar concept to a pixel buffer.
if in our draw_to_screen() code we loop over all of the elements of this array
| |
nosotros have a standardized method for "rendering" the buffer out to the screen.
So the problem becomes populating the array in the start place.
for every "pixel" we want to calculate the distance to the middle of the circle, if this value is less than the circles maximum radius we know that the point is within the circumvolve.
the distance is simply some maths
| |
And so we could create the function for setting all of the elements of the assortment like this:
| |
That would requite us a solid blackness circle, only we want a ring, so we simply add a second radius, for the heart and add that to the check:
| |
That would just be my way of doing it, this code is completely untested but I really hope information technology helps.
Thanks -NGangst
Source: http://www.cplusplus.com/forum/beginner/110133/