Q1b. draw a co-ordinate axis at the center of the screen. #include #include #include void main() { int gd=DETECT,gm; int midx,midy; initgraph(&gd,&gm,"\\TURBOC3\\bgi"); cleardevice(); midx=getmaxx()/2; midy=getmaxy()/2; line(1,midy,640,midy); line(midx,1,midx,480); outtextxy(150,150,"nikita"); getch(); } Q2a. divide your screen into four region, draw a circle, ractangle, elipse and half ellipse in each region with appropriate message. # include #include #include void main() { int gd=DETECT,gm; int midx,midy; initgraph(&gd,&gm,"c:\\TURBOC3\\bgi"); cleardevice(); midx=getmaxx()/2; midy=getmaxy()/2; line(1,midy,640,midy); line(midx,1,midx,480); setcolor(RED); circle(midx+(-150),midy-(100),midx+(200),midy-(150)); printf("t\tIt's a circle"); setcolor(GREEN); rectangle(midx+(100),midy-(100),midx+(200),midy-(150)); printf("\t\t\t\t this is Rectangle \n\n\n\n\n"); setcolor(BLUE); elipse(midx+(-150),midy-(-100),0,360,midx+(-250),midy-(200)); printf("/n/n/n/n/n/n/n/n/n/n/n/t wow!! It's an ellipse); setcolor(YELLOW); ellipse(midx+(180),midy-(-100),180,0,midx+(-200),midy-(150)); printf("\t\t\t ohh!! half ellipse! looks like:)"); getch(); } Q2b. draw a simple hut on the screen. #include #include void main() { int gd=DETECT,gm; initgraph(&gd,&gm,"C:\\TURBOC3\\BGI"); setcolor(WHITE); rectangle(150,180,250,300); rectangle(250,180,420,300); rectangle(180,250,220,300); line(200,100,150,180); line(200,100,250,180); line(200,100,370,100); line(370,100,420,180); outtextxy(180,150"nikita"); getch(); closegraph(); } Q2 b colorhuut #include #include void main() { int gd=DETECT,gm; initgraph(&gd,&gm,"C:TURBOC3\\BGI"); setcolor(WHITE); rectangle(150,180,250,300); rectangle(250,180,420,300); rectangle(180,250,220,300); line(200,100,150,180); line(200,100,250,180); line(200,100,370,100); line(370,100,420,180); setfillstyle(SOLID_FILL,BROWN); floodfill(152,182,WHITE); floodfill(252,182,WHITE); setfillstyle(HATCH_FILL,GREEN); floodfill(200,105,WHITE); floodfill(210,105,WHITE); getch(); closegraph(); } Q3 : draw the following basic shapes in the center of the screen. #include #include void main() { int gd=DETECT,gm,left=100,top=100,right=200,bottom=200,x=300,y=150,radius=50; initgraph(&gd,&gm,"C:\\TURBOC3\\BGI"); rectangle(120,150,230,200); circle(x,y,radius); bar(left+300,top,right+300,bottom); line(left-10,top+150,left+410,top+150); ellipse(x,y+200,0,360,80,50); for(radius=25;radius<=100;radius=radius+20) circle(500,350,radius); getch(); closegraph(); } Q4a: devlop the program for DDA line drawing algorithm #include #include #include void main() { floatx,y,x1,y1,x2,y2,dx,dy,pixel; inti,gd,gm; printf("enter the value of x1:"); scanf("%f",&x1); printf("enter the value of y1:"); scanf("%f",&y1); printf("enter the value of x2:"); scanf(%f",&x2); printf("enter the value of y2:"); scanf("%f",&y2); detectgraph(&gd,&gm); initgraph(&gd,&gm,"C:\\TURBOC3\\BGI"); dx=abs(x2-x1); dy=abs(y2-y1); if(dx>=dy) pixel=dx; else pixel=dy; dx=dx/pixel; dy=dy/pixel; x=x1; y=y1; i=1; while(i<=pixel) { putpixel(x,y,1); x=x+dx; y=y+dy; i=i+1; delay(100); } getch(); closegraph(); } OP : 100 200 300 400 Q4b. devlop the proogram for the bresenhams line drawing algorithm #include #include #include void main() { int dx,dy,x,y,p,x1,y1,x2,y2; int gd,gm; clrscr(); printf("\n\n\tEnter the co-ordinates of first point:"); scanf("%d%d",&x1,&y1); printf("\n\n\tEnter the co-ordinates of second point:"); scanf("%d%d",&x2,&y2); dx=(x2-x1); dy=(y2-y1); p=2*(dy)-(dx); x=x1; y=y1; detectgraph(&gd,&gm); initgraph(&gd,&gm,"C:\\turboc3\\bgi"); putpixel(x,y,WHITE); while(x<=x2); { if(p<0) { x=x+1; y=y; p=p+2*(dy); } else { x=x+1; y=y+1; p=p+2*(dy-dx); } putpixel(x,y,WHITE); } getch(); closegraph(); } OP: 100 200 , 300 400 Q5A: devlop the program for the midpoint circle drawing algorithm #include #include #include void pixel(int xc,int yc,intx,int y); void main() { int gd=DETECT,gm,xc,yc,r,x,y,PK; clrscr(); initgraph(&gd,&gm,"C:\\turboc3\\bgi"); printf(*** bresenhams midpoint algorithm of circle***\n"); printf("Enter the value of Xc\t"); scanf("%d",&xc); printf("Enter the value of Yc\t"); scanf("%d",&yc); printf("Enter the radius of \t"); scanf("%d",&r); x=0; y=r; pk=1-r; pixel(xc,yc,x,y); while(x #include #include #include void disp(); float x,y; int xc,yc; void main() { int gd=DETECT,gm; int a,b; float p1,p2; clrscr(); initgraph(&gd,&gm,"c://turboc3//bgi"); printf("Enter xc:\t"); scanf("%d",&xc); printf("Enter yc:\t"); scanf("%d",&yc); printf("Enter a:\t"); scanf("%d",&a); printf(b:\t"); scanf("%d",&b); x=0;y=b; disp(); p1=(b*b)-(a*a*b)+(a*a)/4; while((2.0*b*b*x)<=(2.0*a*a*y)) { x++; if(p1<=0) p1=p1+(2.0*b*b*x)+(b*b); else { y--; p1=p1+(2.0*b*b*x)+(b*b)-(2.0*a*a*y); } disp(); x=-x; } x=a; y=0; disp(); p2=(a*a)+2.0*(b*b*a)+(b*b)/4; while((2.0*b*b*x)>(2.0*a*a*y)) { y++; if(p2>0) p2=p2+(a*a)-(2.0*a*a*y); else { x--; p2=p2+(2.0*b*b*x)-(2.0*a*a*y)+(a*a); } disp(); y=-y; disp(); y=-y; } getch(); closegraph(); } void disp() { putpixel(xc+x,yc+y,10); putpixel(xc-x,yc+y,10); putpixel(xc+x,yc-y,10); putpixel(xc+x,yc-y,10); } OP : 100 200 30 60 Q.6a write a program to implement 2d scalling. #include #include #include void main() { int i; int gd=DETECT,gm; int x2,y2,x1,y1,x,y; initgraph(&gd,&gm,"C:\\TURBOC3\\BGI"); printf("Enter the 2 line end points:x1,y1,x2,y2:\n"); scanf("%d\n%d\n%d\n%d",&x1,&y1,&x2,&y2); line(x1,y1,x2,y2); printf("\nEnter scaling co-ordinates;x\t y\t \n"); scanf("%d%d",&x,&y); x1=(x1*x); y1=(y1*y); x2=(x2*x); y2=(y2*y); printf("Line after scaling"); line(x1,y1,x2,y2); getch(); closegraph(); } OP: 30 40 50 60 5 6 Q.6b write a program to perform 2d translation #include #include #include void main() { int i; int gd=DETECT,gm; int x2,y2,x1,y1,x,y; initgraph(&gd,&gm,"C:\\TURBOC3\\BGI"); printf("Enter the 2 line end points:x1,y1,x2,y2:\n"); scanf("%d\n%d\n%d\n%d",&x1,&y1,&x2,&y2); line(x1,y1,x2,y2); printf("\nEnter scaling co-ordinates;x\t y\t \n"); scanf("%d%d",&x,&y); x1=x1+x; y1=y1+y; x2=x2+x;; y2=y2+y; printf("Line after translation"); line(x1,y1,x2,y2); getch(); closegraph(); } OP: 30 40 50 60 100 200 Q9a: Write a program to fill a circle using flood fill algorithm. #include #include #include #include void floodFill(int x,int y,int oldcolor,int newcolor) { if(getpixel(x,y)==oldcolor) { putpixel(x,y,newcolor); floodFill(x+1,y,oldcolor,newcolor); floodFill(x,y+1,oldcolor,newcolor); floodFill(x-1,y,oldcolor,newcolor); floodFill(x,y-1,oldcolor,newcolor); } } //getpixel(x,y)given the color of specified pixel void main() { int gm,gd=DETECT,radius; int x,y; printf("Enter x and y positions for circle\n"); scanf("%d%d",&x,&y); printf("Enter radius of circle\n"); scanf("%d",&radius); initgraph(&gd,&gm,"C:\\TURBOC3\\BGI"); circle(x,y,radius); floodFill(x,y,6,15); delay(5000); closegraph(); } OP: 100 100 25 Q9B: write a program to fill a circle using boundary fill algorithm. #include #include #include #include void boundaryfill(int x,int y,int f_color,int b_color) { if(getpixel(x,y)!=b_color && getpixel(x,y)!=f_color) { putpixel(x,y,f_color); boundaryfill(x+1,y,f_color,b_color); boundaryfill(x,y+1,f_color,b_color); boundaryfill(x-1,y,f_color,b_color); boundaryfill(x,y-1,f_color,b_color); } } void main() { int gm,gd=DETECT,radius; int x,y; printf("Enter x and y positions for circle\n"); scanf("%d%d",&x,&y); printf("Enter radius of circle\n"); scanf("%d",&radius); initgraph(&gd,&gm,"C:\\TURBOC3\\BGI"); circle(x,y,radius); boundaryfill(x,y,4,15); delay(5000); closegraph(); } OP : 100 100 25 Q10a. Devlop a simple text screen saver using graphics functions. #include #include #include #include void main() { int gd=DETECT,gm,x=600,i; initgraph(&gd,&gm,"C:\\TURBOC3\\BGI"); for(x=0;x<250;x++) { x%=250; setcolor(random(16)); circle(random(635),random(70),50); circle(random(635),random(70),50); circle(random(635),random(70),50); circle(random(635),random(70),50); circle(random(635),random(70),50); clearviewport(); settextstyle(1,0,5); setcolor(RED); outtextxy(50,415-2*x,"World"); setcolor(GREEN); outtextxy(200,415-2*x,"of"); setcolor(YELLOW); settextstyle(3,0,5); outtextxy(350,415-2*x,"graphics"); } getch(); } Q10b. perform smiling face animation using graphic function. #include #include #include void main() { int gd=DETECT,gm; initgraph(&gd,&gm,"C:\\TURBOC3\\BGI"); circle(200,200,30); circle(190,190,5); arc(190,190,50,130,10); circle(210,190,5); arc(210,190,50,130,10); arc(200,210,180,360,10); line(187,210,193,210); line(207,210,213,210); line(198,195,195,200); line(202,195,205,200); line(195,200,200,205); line(205,200,200,205); getch(); closegraph(); } Q10c. draw the moving car on the screen. #include #include #include #include void main() { int gd=DETECT,gm; int i,maxx,midy; initgraph(&gd,&gm,"C:\\TURBOC3\\BGI"); maxx=getmaxx(); midy=getmaxy()/2; for(i=0;i