Practical List Q1.Solve the following: b) Draw a co-ordinate axis at the center of the screen. #include<iostream.h> #include<conio.h> #include<graphics.h> void main() { int gd,gm,a,b; detectgraph(&gd,&gm); initgraph(&gd,&gm,"C:\\Turbo\\BGI "); a=getmaxx(); b=getmaxy(); putpixel(a/2,b/2,10); getch(); } Q2. Solve the following: a) Divide your screen into four regions, draw circle, rectangle, ellipse and half ellipse in each region with appropriate message. #include<iostream.h> #include<conio.h> #include<graphics.h> #include<dos.h> void main() { clrscr(); int gd=DETECT,gm; int x,y,; detectgraph(&gd,&gm); initgraph(&gd,&gm,"C:\\TurboC3\\BGI"); x=getmaxx()/2; y=getmaxy()/2; line(x,0,x,getmaxy()); line(0,y,getmaxx(),y); outtext("Circle"); circle(x/2,y/2,50); rectangle(x+50,y-200,x+200,y-50); ellipse(x/2,y+y/2,0,360,100,50); ellipse(x+x/2,y+y/2,0,180,100,50); getch(); } b) Draw a simple hut on the screen #include<iostream.h> #include<conio.h> #include<graphics.h> void main() { int gd=DETECT,gm; clrscr(); initgraph(&gd,&gm,"C:\\Turboc3\\BGI"); setcolor(RED); rectangle(50,180,150,300); rectangle(150,180,320,300); rectangle(80,250,120,300); line(100,100,50,180); line(100,100,150,180); line(100,100,300,100); line(300,100,320,180); getch(); closegraph(); } Q3 Draw the following basic shapes in the centre of the screen: i-Circle (x,y,Radius) #include<iostream.h> #include<graphics.h> #include<conio.h> int main() { int gd,gm; int x ,y ,radius=80; detectgraph(&gd,&gm); initgraph(&gd,&gm,"C:\\Turboc3\\BGI"); x = getmaxx()/2; y = getmaxy()/2; setcolor(RED); outtextxy(200,300,”circle"); setcolor(RED); circle(20, 30, radius); getch(); closegraph(); return 0; } ii- Rectangle (left,top,right,bottom) #include<iostream.h> #include<graphics.h> #include<conio.h> int main() { int gd,gm; detectgraph(&gd,&gm); initgraph(&gd,&gm, "C:\\Turboc3\\BGI"); outtext("Rectangle"); rectangle(150, 50, 400, 150); getch(); closegraph(); return 0; } IV- Concentric circle #include<iostream.h> #include<graphics.h> #include<conio.h> int main() { int gd = DETECT,gm; int x ,y; initgraph(&gd, &gm, "C:\\TC\\BGI"); /* Initialize center of circle with center of screen */ x = getmaxx()/2; y = getmaxy()/2; outtextxy(240, 50, "Concentric Circles"); setcolor(RED); circle(x, y, 30); setcolor(GREEN); circle(x, y, 50); setcolor(YELLOW); circle(x, y, 70); setcolor(BLUE); circle(x, y, 90); getch(); closegraph(); return 0; } v. Ellipse (x,y,startingangle,endangle,xradius,yradius) #include<iostream-.h> #include<graphics.h> #include<conio.h> int main() { int gd,gm; int x ,y; detectgraph(&gd,&gm); initgraph(&gd, &gm, "C:\\Turboc3\\BGI"); x = getmaxx()/2; y = getmaxy()/2; outtextxy(x-100, 50, "ELLIPSE"); ellipse(x, y, 0, 360, 120, 60); getch(); closegraph(); return 0; } iv- Line (x1,y1,x2,y2) #include<iostream.h> #include <graphics.h> #include <conio.h> void main() { int gd,gm; detectgraph(&gd,&gm); initgraph(&gd, &gm, "C:/TURBOC3/BGI"); outtext("Line"); line(110,210,200,10); getch(); closegraph(); } Q4.Solve the following: a) Develop the program for DDA Line drawing algorithm. #include<iostream.h> #include<conio.h> #include<math.h> #include<dos.h> #include<graphics.h> void main() { clrscr(); int gd,gm,i; float x,y,x1,y1,x2,y2,dx,dy,delx,dely,l; cout<<"\n Enter coordinates:"; cin>>x1; cin>>y1; cin>>x2; cin>>y2; detectgraph(&gd,&gm); initgraph(&gd,&gm,"c:\\Turboc3\\BGI"); dx=x2-x1; dy=y2-y1; if(dx>=dy) l=dx; else l=dy; delx=dx/l; dely=dy/l; x=x1+0.5; y=y1+0.5; i=1; while(i<=l) { putpixel(x,y,WHITE); x=x+delx; y=y+dely; i=i+1; delay(50); } getch(); closegraph(); } b) Develop the program for Breshnam’s Line Algorithm. #include<iostream.h> #include<conio.h> #include<graphics.h> #include<math.h> sign(int,int); void main() { int x,y,x1,x2,y1,y2,s1,s2,dx,dy,temp,err,i,intchg; int gd,gm; cout<<"Enter the end points of a line:"; cin>>x1>>y1>>x2>>y2; detectgraph(&gd,&gm); initgraph(&gd,&gm,"c:\\TurboC3\\BGI"); line(getmaxx()/2,0,getmaxx()/2,getmaxy()); line(0,getmaxy()/2,getmaxx(),getmaxy()/2); x=x1;y=y1; dx=abs(x2-x1); dy=abs(y2-y1); s1=sign(x2,x1); s2=sign(y2,y1); if(dy>dx) { temp=dx; dx=dy; dy=temp; intchg=1; } else intchg=0; err=2*dy-dx; for(i=1;i<=dx;i++) { if((x>=0&&y>=0)||(x>=0&&y<=0)) putpixel(x+getmaxx()/2,getmaxy()/2-y,WHITE) ; else if((x<=0&&y>=0)||(x<=0&&y<=0)) putpixel(getmaxx()/2+x,getmaxy()/2-y,5); while(err>=0) { if(intchg==1) x=x+s1; else y=y+s2; err=err-2*dx; } if(intchg==1) y=y+s2;