#include #include #include #include #include #include #include #include #include int flower_radius=30; int center_radius=8; int center_color=14; /*centers*/ int petal_color=15; /*petals*/ int num_petals=6; void main(void) { void initialize (); void make_pot_of_flowers(int); void draw_the_pot(int); initialize(); draw_the_pot(1); /*draw the back of the pot*/ make_pot_of_flowers(40); draw_the_pot(2); /*draw the front of the pot*/ getch(); cleardevice(); closegraph(); exit(0); } void initialize () { int i,j, errorcode, mode, maxcolor,maxx, maxy; int gdriver = VGA; int gmode = 2; char msg[80]; /* initialize graphics mode */ initgraph(&gdriver, &gmode, ""); /* read result of initialization */ errorcode = graphresult(); /*n error occurred */ if (errorcode != grOk) { printf("Graphics error: %s\n", grapherrormsg(errorcode)); printf("Press any key to halt:"); getch(); /* *terminate with an error code */ exit(1); } mode = getgraphmode(); printf(" %d is the current mode number.\n", mode); printf("%15s is the current graphics mode\n", getmodename(mode)); maxx=getmaxx(); printf("X max = %d\n", maxx); maxy=getmaxy(); printf("Y max = %d\n", maxy); maxcolor=getmaxcolor(); printf("This mode supports colors %d\n", maxcolor); printf("This driver supports modes 0..%d\n", getmaxmode()); printf("Press any key to continue"); getch(); /* loop through the available colors */ cleardevice(); j=0; for (i=0; i<=maxcolor; i++) { setfillstyle(SOLID_FILL,i); j=j+8; if (i==0) setcolor(15); else setcolor(i); sprintf(msg, "<---- Color number %d", i); bar (0,j,20,j+8); outtextxy(30,j, msg); } printf("\n\n\nPress any key to continue"); getch(); cleardevice(); return; } void make_pot_of_flowers(int num_of_flowers) { void make_flower(int, int); int i, rand_hor, rand_vert; int rand_stem, rand_angle; double angle_in_radians; int stem_high, stem_wide; int nowx, nowy; setcolor(15); for (i=1;i<=num_of_flowers;i++) { rand_hor=190+random(20); rand_vert=190+random(20); rand_stem=40+random(100); angle_in_radians=((random(120)+30)* 2.0* 3.14159/360.); stem_high=sin(angle_in_radians)*rand_stem; stem_wide=-1*cos(angle_in_radians)*rand_stem; setcolor(10); line(rand_hor, rand_vert,rand_hor+stem_wide,rand_vert-stem_high); make_flower(rand_hor+stem_wide-flower_radius,rand_vert-stem_high-flower_radius); } return; } void make_flower (int x, int y) { int petal_increment, petal_increment_half, petal_increment_fourth; int starta, enda; int halfway, sa, ea, dist, distinc; int rad, i, j; halfway=center_radius+(flower_radius-center_radius)/2; setcolor(1); circle(x+flower_radius+1,y+flower_radius+1,center_radius);/*draw circle */ setfillstyle(SOLID_FILL,center_color); /*set center_color */ floodfill(x+flower_radius+1,y+flower_radius+1,1); /*fill with color */ petal_increment=360/num_petals; petal_increment_half=360/(num_petals*2); petal_increment_fourth=360/(num_petals*4); starta=petal_increment_fourth; enda=starta+petal_increment_half; setcolor(petal_color); for (i=1; i<=num_petals; i++) { for (rad=center_radius+1;rad<=halfway;rad++) { arc(x+flower_radius+1, y+flower_radius+1,starta,enda,rad); } sa=starta; ea=enda; dist=ea-sa; distinc=dist/(2*(flower_radius-halfway)); for (rad=halfway;rad<=flower_radius;rad++) { arc(x+flower_radius+1, y+flower_radius+1,sa,ea,rad); ea=ea-distinc; sa=sa+distinc; } starta=starta+petal_increment; enda=starta+petal_increment_half; } setcolor(0); circle(x+flower_radius+1,y+flower_radius+1,center_radius); return; } void draw_the_pot(int forb) { int i; setcolor(6); for (i=1;i<=50;i++) { if (forb==1) ellipse(200,200+i,0,180,40,8); /* back of pot */ else ellipse(200,200+i,180,360,40,8); /* font of pot */ } return; }