I need help making a circle using only ASCII characters in a bidimensional array.
Thanks in advance
I need help making a circle using only ASCII characters in a bidimensional array.
Thanks in advance
What sort of help?
- defining a 2D array?
- printing it
- putting some symbol at specific positions in the grid
- the function for the perimeter of a circle?
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
I have everything working except the function for the perimeter of the circle.
x = r * cos( theta );
y = r * sin( theta );
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
oooooooooooXXXXXX
ooooooooooXooooooX
oooooooooXooooooooX
oooooooooXooooooooX
oooooooooXooooooooX
oooooooooXooooooooX
oooooooooXooooooooX
oooooooooXooooooooX
ooooooooooXooooooX
oooooooooooXXXXXX
I used those and I got this. It is a circle but some time ago I saw an other way to get a better circle(don't remember where). Is there any algorithm to make a better circle?
Thanks for the help anyway
Last edited by Johanson; 04-03-2006 at 10:16 AM.
Post your code, that seems rather too octagonal.
Use [code][/code] tags when posting code (and your fixed-width output).
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
Code:void TestCircle(DRAWING draw,int a,int b,int r) /* DRAWING is a type of bidemensional arrays of the type char */ { int x,y; double theta=0; for(;theta!=360.0 ;theta+=1) { x = a + r * cos( theta ); y = b + r * sin( theta ); des[x][y]='X'; } }
Just some cleanups
I was bored. Again.Code:void TestCircle(DRAWING draw,int a,int b,int r) /* DRAWING is a type of bidemensional arrays of the type char */ { int x,y; /* put nothing on the same line as a brace */ double theta=0; for(;theta!=360.0 ;theta++) /* ++ is the same as += 1 */ { x = a + r * cos( theta ); y = b + r * sin( theta ); des[x][y]='X'; } }
EDIT: And you have a space button for a reason. Jeeeeeesus.
Last edited by cboard_member; 04-03-2006 at 12:27 PM.
Good class architecture is not like a Swiss Army Knife; it should be more like a well balanced throwing knife.
- Mike McShaffry
The problem is probably that you are outputting the circle on a console screen where the height of a character is about double the length of the width so you need to change that 2:1 ratio to 1:1 to get a circle instead of an oval.
> for(;theta!=360.0 ;theta+=1)
Additionally, the math trigonometry functions take radians, not degrees.
There are 2PI radians in a full circle, which means you go round about 60 times more than necessary.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
@ahluka:
using operator++() on double theta is not really a good idea.
You might want to do (theta < 2*PI; theta += 0.1) to get some accuracy.
Console screen text is typically 8x4 pixels per character. One quick fix would be to create des[][] with half the width, then double it later. This wold however create a possibly-annoying "twin character syndrome".
#define PI 3.14159
#define DEGTORAD(x) ( (x) * (PI) / (180.0) )
Just for fun, here's an easy way to draw circles, adapted from "8088 Macro Assembler Programming" by Dan Rollins. Could be shortened/optimized a bit:
Code:void circle(int x, int y, int r) { int target = 0; int a = r; int b = 0; int dec, count; while(a > b) { b = (r * r - a * a); count = 0; dec = 1; while(b >= 0) { b -= dec; dec += 2; count++; } b = count; SWAP(target, b); while(b < target) { plot(x + a, y + b); plot(x - a, y + b); plot(x - a, y - b); plot(x + a, y - b); plot(x + b, y + a); plot(x - b, y + a); plot(x - b, y - a); plot(x + b, y - a); b++; } a--; } }
Thans a lot. This is exactly what I wantedOriginally Posted by joed
Edit:
The only problem is that when the radius=2, it won't work correctly. It shows this:
ooXoo
ooooo
XoooX
ooooo
ooXoo
Last edited by Johanson; 04-08-2006 at 07:07 AM.
dwk
Seek and ye shall find. quaere et invenies.
"Simplicity does not precede complexity, but follows it." -- Alan Perlis
"Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
"The only real mistake is the one from which we learn nothing." -- John Powell
Other boards: DaniWeb, TPS
Unofficial Wiki FAQ: cpwiki.sf.net
My website: http://dwks.theprogrammingsite.com/
Projects: codeform, xuni, atlantis, nort, etc.