How to draw a polyhedron and dedocahedron in turbo c ?
any one has any idea?
This is a discussion on How to ... within the Game Programming forums, part of the General Programming Boards category; How to draw a polyhedron and dedocahedron in turbo c ? any one has any idea?...
How to draw a polyhedron and dedocahedron in turbo c ?
any one has any idea?
AbHHinaay
Sure.
void DrawPolyhedron() and DrawDedocahedron() should do the trick. Do your own homework. Post questions to specific problems you're having with *your* code.
Code:int main(void){srand(time(0));for(double l=rand(),l0=0,l00=0;;l0+=0.1){for(double l000=0;l000 <1;l000+=.001,l+=((double)rand()/RAND_MAX)/0x64,l00+=((sin(l*0x8*atan(l0)*l000-(l0*0x8*atan (l)))*0.5)+0.5)){l00-=floor(l00);for(size_t l0000=0,l00000=(size_t)(0x50*(l00));l0000<l00000;++l0000 )putchar(0x20);putchar(0x61+(int)((double)rand()/RAND_MAX*0x1a));putchar('\n');}}return 0;}
Just abstract the problem. You need to draw lines. So write a function:
void DrawLine(int start_x, int start_y, int end_x, int end_y);
You'll need a function that translates lengths and angles into variables you can pass into the drawing function.
void CalcLine(double theta, int length, int * start_x, int * start_y, int * end_x, int * end_y);
...etc, etc.
Break it up into smaller pieces, make them work, and then reassemble. Presto.
Code:int main(void){srand(time(0));for(double l=rand(),l0=0,l00=0;;l0+=0.1){for(double l000=0;l000 <1;l000+=.001,l+=((double)rand()/RAND_MAX)/0x64,l00+=((sin(l*0x8*atan(l0)*l000-(l0*0x8*atan (l)))*0.5)+0.5)){l00-=floor(l00);for(size_t l0000=0,l00000=(size_t)(0x50*(l00));l0000<l00000;++l0000 )putchar(0x20);putchar(0x61+(int)((double)rand()/RAND_MAX*0x1a));putchar('\n');}}return 0;}
This does not show how to draw a line nor does it show how to create the figure. I leave that as an exercise for you to figure out.Code:struct ipoint2D { int x; int y; }; void Draw(ipoint2D *points, int numpoints) { for (int i=0;i<numpoints;i++) { int x1=points[i].x; int y1=points[i].y; int x2=points[i+1].x; int y2=points[i+1].y; DrawLine (x1,y1,x2,y2); } int x1=points[0].x; int y1=points[0].y; int x2=points[numpoints].x; int y2=points[numpoints].y; DrawLine(x1,y1,x2,y2); }
One hint though - if you want 20 sides to the figure you would divide 360 by 20 and increment the angle by that much each time you draw a 'side'
Arrogance breeds bad code