#include #include #include #include #define XTOL 90 #define YTOL 90 void updateDir( int *rX, int *rY, int update); void drawRect(FILE *out, int x, int y, int size, int fill); void drawCircle(FILE *out, int radius, int angle, int fill); int main(int argc, char *argv[]) { //FILE *out = fopen("PenPlotter.txt","w"); FILE *out = stdout; int rY, rX, x, y, rColor, fill; int rShape, rRadius, rAngle, rSize; int i,loop; struct timeb the_time; ftime(&the_time); srand48(the_time.millitm * the_time.time); /*use time in seconds to set seed */ x = 500; /*starting x coordinate */ y = 333; /*starting y coordinate */ /* initialization parameters */ fprintf(out,"IN;SC0,1000,0,666;PU%d,%d;\n",x,y); loop = lrand48() % 200; for( i = 0; i < loop;i++) { updateDir(&rX,&rY,i==0); x = x+rX; y = y+rY; /*Boundry Conditions*/ if( x < 101 ) x += -2*rX; if( y < 101 ) y += -2*rY; if( x > 899 ) x += -2*rX; if( y > 565 ) y += -2*rY; rColor = lrand48() % 5; rShape = lrand48() % 2; fill = lrand48() % 10; /*Circle Parameters */ rRadius = lrand48() % XTOL/2; rAngle = lrand48() % 20; /*Rectangle Parameter */ rSize = lrand48() % XTOL; /*Square Size */ fprintf(out,"SP%d;PU%d,%d;\n",rColor,x,y); if(rShape) drawRect(out,x,y,rSize,fill == 1); else drawCircle(out,rRadius,rAngle,fill == 1); fprintf(out,"\n\n"); } //fclose(out); return(0); } void updateDir( int *rX, int *rY, int update) { int rDir, x; int rPosNeg; x = lrand48(); printf("%d\n",x); rDir = x % 10; if( rDir == 1 || rDir == 0 || update) { rPosNeg = lrand48() % 2; if( !rPosNeg ) rPosNeg = -1; *rX = (lrand48() % XTOL) * rPosNeg; rPosNeg = lrand48() % 2; if( !rPosNeg ) rPosNeg = -1; *rY = (lrand48() % YTOL) * rPosNeg; } } void drawRect(FILE *out, int x, int y, int size, int fill) { int x1,x2,y1,y2; x1 = x; x2 = x+size; y1 = y; y2 = y+size; fprintf(out, "PD%d,%d,%d,%d,%d,%d,%d,%d;", x2,y1, x2,y2, x1, y2, x1,y1); if(fill) fprintf(out,"FT4,4,45;RA%d,%d;",x2,y2); } void drawCircle(FILE *out, int radius, int angle, int fill) { fprintf(out, "CI%d,%d;",radius,angle); if(fill) fprintf(out,"WG%d,0,360; ",radius); }