drawing a circle in C
I need to write a program that draws a grid with different symbols and spaces. The overall shape that is printed on the screen shoudl be a circle that looks like a tire and wheel. There should be different symbols for the hub, the wheel, and then the outer tire and the rest all spaces. The user reads in the circumference of the tire and the program converts it into a radius that is used for the grid to draw the tire. I know I need a for loop to draw the shape, but I am confused as to how to start the drawing from the center of the grid? Can anyone help.
Show us the code you have so far and I'm sure you'll get lots of advice...
Are you trying to draw "graphics" on a console screen, using #+= etc as symbols to represent different aspects (hub, tyre) of your wheel?
How To Ask Questions The Smart Way
Do you want to do this on a graphics window, or a rougher text based window?
Best if you could show us a drawing or picture of what you want. You can attach it with the button down below the editing window "manage attachments", or you can load it to a site like ImageShack, and then post the link for us to see it.
Again, with the ninja-posting!! :p :p
You didn't say anything about spokes so it seems you want a "solid" wheel and everything within the outer circumference will be colored with some symbol. Since you're dealing with a circular shape, every point of the wheel can be defined in terms of its distance from the center. You can do the entire thing with a single pass through the entire grid: first define the center point, then for each point, calculate its distance from the center and based on that distance decide which symbol to write at that point.
There may be more efficient methods (in terms of amount of computation), but I think this approach is probably the easiest to implement.
R.Stiltskin, what you have discribed is exactly what I am trying to do. However, I do not know how to start the loop from the center of the grid. I know how to write the loop to print some symbol based on the column and row the line is in, but I dont know how to start at the center of the grid. I do need the wheel to be solid as well. I am at work right now and can not access my code till this afternoon when I get home. Can you tell me how to set the center of the grid?
Why are you concerned with starting the loop at the center of the grid? It makes no difference where you start the loop -- start at the upper left corner, [0,0] and draw the first row, the second row, ... and so on until the image is complete.
The center of the wheel can be, but isn't necessarily, at the center of the image. You can choose any arbitrary point, let's call it [x0,y0], to be the center of the wheel. Then for each point [x,y] on the grid you calculate its distance from the center:
d = sqrt( (x - x0)^2 + (y - y0)^2 )
and based on the value of d decide which symbol goes at [x,y]. (Create a lookup table that tells which symbol to use for each range of distances.)
Thanks, for all your help. I just got your message. I figured it out using the pathagoen theorem to judge the distance from the center. I used 2 for loops and three if statements to assign the different characters to the graphic. I also read in an inner and outer radius for the wheel and the tire portion. Worked out great! I just had a brain cramp in the beginning.
Do you think I could see your code? I'm trying something similar and I am at a total loss