/* this is aboutl the 2x2 matrix thing. the other was about something else */ /* It was about building a (ascii) text display screen that would be cross platform h:\tc\whatever loads first */ #include #include #include #include #include #include /* gcc wanted malloc.h here */ #include #include #define PI 3.1415927 struct vector2d {float x; float y; }; int graphdriver; /* The Graphics device driver */ int graphmode; /* The Graphics mode value */ int goodstatus; /* flag for assert */ int myfill(int color); /* ..........................."the constants"......... */ float cs(float th); float sn(float th); float ncs(float th); float nsn(float th); float one(float th); float negone(float th); float zero(float th); /* .........................."the variables".......... */ float (*a)(float th); float (*b)(float th); float (*c)(float th); float (*d)(float th); /* ........................................................ */ int putpoint(struct vector2d *point, int pixcolor); struct vector2d *rowmult(float a11,float a12,float a21,float a22,struct vector2d *w); struct vector2d *to_origin(struct vector2d *w); struct vector2d *from_origin(struct vector2d *w); main() { int testx,testy,index,counter; float theta,r,pi2,loopend; /* int *dummy1,*dummy2; */ struct vector2d *v,*u; u=(struct vector2d *) malloc(sizeof(struct vector2d)); v=(struct vector2d *) malloc(sizeof(struct vector2d)); /* dummy1=(struct int *) malloc(sizeof(struct int)); dummy2=(struct int *) malloc(sizeof(struct int)); */ /*............................................*/ graphdriver = DETECT ; initgraph ( &graphdriver, &graphmode, ""); /*............................................*/ randomize(); pi2=2*PI; goodstatus=1; myfill(13); circle(20,20,10); /* for testing purposes */ /* the test patterns */ /* we are going to build the test patterns */ /* dotgrid */ for(testx=10;testx<200;testx+=10) for(testy=10;testy<200;testy+=10) putpixel(testx,testy,3); /* getch(); */ /*_______________________testing matmult__________ */ /* ................................................ */ a=&cs;b=&nsn;c=&sn;d=&cs; /* these assignments soon superceded by switches */ for(counter=0;counter<100;counter++){ cleardevice(); index=random(7); switch(index) { case 0: a=&cs ;break; case 1: a=&sn ;break; case 2: a=&ncs ;break; case 3: a=&nsn ;break; case 4: a=&one ;break; case 5: a=&negone;break; case 6: a=&zero ;break; default: outtextxy(20,440," default rang in switch "); } index=random(7); switch(index) { case 0: b=&cs ;break; case 1: b=&sn ;break; case 2: b=&ncs ;break; case 3: b=&nsn ;break; case 4: b=&one ;break; case 5: b=&negone;break; case 6: b=&zero ;break; default: outtextxy(20,440," default rang in switch "); }index=random(7); switch(index) { case 0: c=&cs ;break; case 1: c=&sn ;break; case 2: c=&ncs ;break; case 3: c=&nsn ;break; case 4: c=&one ;break; case 5: c=&negone;break; case 6: c=&zero ;break; default: outtextxy(20,440," default rang in switch "); }index=random(7); switch(index) { case 0: d=&cs ;break; case 1: d=&sn ;break; case 2: d=&ncs ;break; case 3: d=&nsn ;break; case 4: d=&one ;break; case 5: d=&negone;break; case 6: d=&zero ;break; default: outtextxy(20,440," default rang in switch "); } myfill(0); loopend=3.0*pi2; for(theta=0.0;thetay=20.0;u->y < 280.0;u->y+=20.0) for (u->x=20.0;u->x < 280.0;u->x+=1.0) { v=to_origin(u); v=rowmult( (*a)(theta), (*b)(theta), (*c)(theta), (*d)(theta), v ); v=from_origin(v); goodstatus=putpoint(v,index); } } } outtextxy(10,380,"Just did the test putpoint(u) loop text."); /* ................................................ */ /*_______________________end testing matmult__________ */ getch(); myfill(2); /* line of dots grid */ for(testx=10;testx<400;testx+=10) for(testy=10;testy<400;testy++) putpixel(testx,testy,4); for(testy=10;testy<400;testy+=10) for(testx=10;testx<400;testx++) putpixel(testx,testy,4); getch(); myfill(0); /* circles (or dots) ----------------------------- */ for(r=10.0;r<150.0;r+=10.0) for(theta=0.0;thetax = w->x - 150; result->y = w->y - 150; return(result); } struct vector2d *from_origin(struct vector2d *w) { struct vector2d *result; result->x = w->x + 150; result->y = w->y + 150; return(result); } struct vector2d *rowmult(float a11,float a12,float a21,float a22,struct vector2d *w) { struct vector2d *result; result->x = a11*w->x + a12*w->y; result->y = a21*w->x + a22*w->y; /* assert(goodstatus); */ if (!goodstatus) goodstatus=goodstatus; return(result); } int putpoint(struct vector2d *point, int pixcolor) { if( (point->x > 5.0) && (point->x < 295.0) && (point->y > 5.0) && (point->y < 295.0) ) {putpixel(180+point->x,20+point->y,pixcolor);return(1);} else return(0); } int myfill(int color) { setfillstyle(SOLID_FILL,color); bar(10,10,590,390); return(1); } float cs(float th){return( 0.7*cos(th));} float sn(float th){return( 0.7*sin(th));} float ncs(float th){return( -0.7*cos(th));} float nsn(float th){return( -0.7*sin(th));} float one(float th){return(1.0);} float negone(float th){return(-1.0);} float zero(float th){return(0.0);}