Department of Computer Science and
Engineering
Computer Graphics
Lab File
Submitted to: Submitted By: -
Prof. Nidhi Srivastava Payal Jindal
(T114)
Page | 2
Table of Content
S.No. Program Name Page
No.
1. Write a program to study and implementations of graphic functions
and VGA standards. Draw line, circle, ellipse, arc, sector, and bar using
inbuilt functions in switch statement
3
2. Write a Program using inbuilt function for the followings:
1. Display coordinates axes.
2. Display nested circles.
3. Display nested rectangles.
10
3. Write a Program using inbuilt function for the followings:
1. Display different colorful shapes.
2. Display a string “Hello User” in the centre of the screen using
Outtextxy() function.
11
4. Write a Program to make bar chart and pie chart for students for five
subjects
12
5. Write a Program to revolve a coin on a table 15
6. Write a Program to design flying colored balloons 16
7. Write a program to implement scan convert line using DDA Algorithm. 19
8. Write a program to implement scan convert line using Bresenhem
Algorithm.
21
9. Write a Program to scan convert circle using Mid-point algorithm 23
10. Write a program to implement scan convert Circle using Bresenhem
Algorithm.
25
11. Write a Program to scan convert ellipse using Mid-point algorithm 27
12. Write a Program to implement Cohen and Sutherland line clipping
algorithm
28
13. Write a Program to get the Translation vector, Rotation vector and
Scaling vector from the user and translate, rotate and scale the triangle
accordingly
34
Page | 3
1. Write a program to study and implementations of graphic
functions and VGA standards. Draw line, circle, ellipse, arc,
sector, and bar using inbuilt functions in switch statement.
CODE:-
#include<stdio.h>
#include<graphics.h>
#include<dos.h>
#include<stdlib.h>
#include<conio.h>
int main()
{
int gd=DETECT, gm;
int s;
initgraph(&gd,&gm,"C:Turboc3BGI");
printf("ENTER THE NUMBER TO PRINTn");
printf(" 1 FOR LINEn 2 FOR CIRCLEn 3 FOR ELLIPSEn");
printf(" 4 FOR ARCn 5 FOR SECTORn 6 FOR BARnENTER:");
scanf("%d",&s);
switch(s)
{
case 1:
outtextxy(260,150,"****LINE****");
line(150,300,500,300);
break;
case 2:
outtextxy(260,150,"****CIRCLE****");
circle(300,300,100);
break;
case 3:
outtextxy(260,150,"****ELLIPSE****");
ellipse(290,300,0,360,100,50);
break;
case 4:
outtextxy(260,150,"****ARC****");
arc(400,300,120,250,100);
break;
case 5:
outtextxy(260,150,"****SECTOR****");
sector(200,200,30,120,90,85);
break;
Page | 4
case 6:
outtextxy(300,100,"****BAR GRAPH****");
line(100,420,100,250);
line(100,420,400,420);
setfillstyle(LINE_FILL,RED);
bar(150,200,200,419);
setfillstyle(LINE_FILL,GREEN);
bar(225,90,275,419);
setfillstyle(LINE_FILL,BLUE);
bar(300,120,350,419);
setfillstyle(LINE_FILL,YELLOW);
bar(375,180,425,419);
break;
default:
break;
}
getch();
closegraph();
return 0;
}
OUTPUT:-
Page | 5
Page | 6
Page | 7
2.Write a Program using inbuilt function for the followings:
i) Display coordinates axes.
CODE:-
#include<stdio.h>
#include<graphics.h>
#include<math.h>
int main()
{
int gd=DETECT,gm;
//float m;
int midx,midy;
initgraph(&gd,&gm,"C:Turboc3BGI");
midx=getmaxx()/2;
midy=getmaxy()/2;
line(midx,0,midx,getmaxy());
line(0,midy,getmaxx(),midy);
getch();
closegraph();
return 0;
}
OUTPUT:-
Page | 8
ii)Display nested circles.
CODE:-
#include<stdio.h>
#include<graphics.h>
#include<conio.h>
int main()
{
int gd = DETECT,gm;
int x ,y;
initgraph(&gd, &gm, "C:Turboc3BGI");
x = getmaxx()/2;
y = getmaxy()/2;
outtextxy(240, 50, "Concentric Circles");
setcolor(WHITE);
circle(x, y, 30);
setcolor(GREEN);
circle(x, y, 50);
setcolor(RED);
circle(x, y, 70);
setcolor(YELLOW);
circle(x, y, 90);
getch();
closegraph();
return 0;
}
OUTPUT:-
Page | 9
iii) Display nested rectangles.
CODE:-
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<stdlib.h>
#include<direct.h>
int main(void)
{
int gdriver = DETECT, gmode;
initgraph(&gdriver, &gmode, "C:Turboc3BGI");
outtextxy(240, 50, "Nested Rectangles");
setcolor(YELLOW);
rectangle(200,120,400,300);
setcolor(RED);
rectangle(220,140,380,280);
setcolor(WHITE);
rectangle(240,160,360,260);
/* clean up */
getch();
closegraph();
return 0;
}
OUTPUT:-
Page | 10
3. Write a Program using inbuilt function for the followings:
i) Display different colorful shapes.
CODE:-
#include<graphics.h> #include<conio.h>
#include<stdio.h>
int main()
{
int gd=DETECT,gm;
initgraph (&gd,&gm,"c:turboc3BGI");
setbkcolor(BLACK);
setcolor(BLUE);
printf("tttnnLINE");
line(50,40,190,40);
setcolor(GREEN);printf("ttnnnnRECTANGLE");
rectangle(125,115,215,165);
setcolor(WHITE);
printf("tttnnnnnnnARC");
arc(120,200,180,0,30);
setcolor(YELLOW);
printf("tnnnnCIRCLE");
circle(120,270,30);
setcolor(BROWN);
printf("tnnnnECLIPSE");
ellipse(120,350,0,360,30,20);
getch();
closegraph();
return 0;
}
OUTPUT:-
Page | 11
ii) Display a string “Hello User” in the centre of the screen
using Outtextxy() function.
CODE:-
#include <graphics.h>
#include<stdio.h>
#include<conio.h>
int main()
{
int gd = DETECT, gm;initgraph(&gd, &gm, (char*)"C:Turboc3BGI");
outtextxy(200, 150, "Hello User");
getch();
closegraph();
return 0;
}
OUTPUT:-
Page | 12
4. Write a Program to make bar chart and pie chart for students for
five subjects
CODE:-
#include <graphics.h>
#include <conio.h>
#include<stdio.h>
int main()
{
int gd = DETECT, gm;
int s, midx, midy, o,e,c,w;float total,o1,e1,c1,w1, o2,e2,c2,w2;
initgraph(&gd, &gm,"C:Turboc3BGI " );
printf("ENTER THE NUMBER TO PRINTn");
printf(" 1 FOR BARGRAPH:");
printf(" 2 FOR PIE CHART:");
scanf("%d",&s);
switch(s)
{
case 1:
outtextxy(275,0,"BAR GRAPH");
setlinestyle(SOLID_LINE,0,2);
line(90,410,90,50);
line(90,410,590,410);
line(85,60,90,50);
line(95,60,90,50);
line(585,405,590,410);
line(585,415,590,410);
outtextxy(65,60,"Y");
outtextxy(570,420,"X");
outtextxy(70,415,"O");
setfillstyle(XHATCH_FILL, GREEN);
bar(150,80,200,410);
bar(225,100,275,410);
bar(300,120,350,410);
bar(375,170,425,410);
bar(450,135,500,410);
break;
case 2:
midx = getmaxx() / 2;
midy = getmaxy() / 2;
printf("Enter the marks for Operaing System: ");
scanf("%d",&o);
printf("Enterthe marks for E-Commerce: ");
scanf("%d",&e);
Page | 13
printf("Enter the marks for Computer Graphics: ");
scanf("%d",&c);
printf("Enter the marksfor Web Based Programming: ");
scanf("%d",&w);total=o+e+c+w;
o2=(360/total);
e2=(360/total);
c2=(360/total);
w2=(360/total);
o1=o2*o;
e1=e2*e;c1=c2*c;w1=w2*w;
printf("ANGLES ARE: ");
printf("nOS: %f",o1);
printf("tE-COM: %f",e1);
printf("tCG: %f",c1);
printf("tWBP: %f",w1);
setfillstyle(SOLID_FILL, BLUE);
pieslice(midx, midy, 0, o1, 100);
setfillstyle(SOLID_FILL, YELLOW);
pieslice(midx, midy, o1, o1+e1, 100);
setfillstyle(SOLID_FILL, GREEN);
pieslice(midx, midy, o1+e1, o1+e1+c1, 100);
setfillstyle(SOLID_FILL, BROWN);
pieslice(midx, midy, o1+e1+c1, o1+e1+c1+w1,100);
break;
default:
break;
}
getch();
closegraph();
return 0;
}
Page | 14
OUTPUT:-
Page | 15
5. Write a Program to revolve a coin on a table.
CODE:-
#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
int main(void)
{
int gdriver = DETECT, gmode, errorcode;
int midx=250, midy=200;
endangle = 360;int yradius = 50,xradius;
initgraph(&gdriver, &gmode, "C:Turboc3BGI ");
while(!kbhit()){for(xradius=35;xradius<=0;xradius--)
{
ellipse(midx, midy, stangle, endangle,xradius, yradius);
setfillstyle(SOLID_FILL,RED);fillellipse(midx,midy,xradius,yradius);
delay(100);
}
cleardevice();
for(xradius=0;xradius<=35;xradius++)
{
ellipse(midx, midy, stangle, endangle,xradius, yradius);
setfillstyle(SOLID_FILL,RED);
fillellipse(midx,midy,xradius,yradius);
delay(100);
}
}
getch();
closegraph();
return 0;
}
OUTPUT:-
Page | 16
6. Write a Program to design flying colored balloons
CODE:-
#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#include<direct.h>
int main(void)
{
int start_angle,end_angle,xrad,yrad;
int gdriver = DETECT, gmode;/* initialize graphics mode */
initgraph(&gdriver, &gmode, (char *)"C:turboc3BGI");
setfillstyle(SOLID_FILL,BLUE);
fillellipse(100,350,40,60);
ellipse(100,350,start_angle=0,end_angle=360,xrad=40,yrad=60);
line(100,450,100,410);
setfillstyle(SOLID_FILL,WHITE);
fillellipse(300,350,40,60);
ellipse(300,350,start_angle=0,end_angle=360,xrad=40,yrad=60);
line(300,450,300,410);
setfillstyle(SOLID_FILL,BLUE);
fillellipse(500,350,40,60);
ellipse(500,350,start_angle=0,end_angle=360,xrad=40,yrad=60);
line(500,450,500,410);
delay(500);cleardevice();setfillstyle(SOLID_FILL,BLUE);
fillellipse(100,300,40,60);
ellipse(100,300,start_angle=0,end_angle=360,xrad=40,yrad=60);
line(100,400,100,360);setfillstyle(SOLID_FILL,WHITE);
fillellipse(300,300,40,60);
ellipse(300,300,start_angle=0,end_angle=360,xrad=40,yrad=60);
line(300,400,300,360);
setfillstyle(SOLID_FILL,BLUE);
fillellipse(500,300,40,60);
ellipse(500,300,start_angle=0,end_angle=360,xrad=40,yrad=60);
line(500,400,500,360);
delay(500);cleardevice();
{
setfillstyle(SOLID_FILL,BLUE);
fillellipse(100,200,40,60);
ellipse(100,200,start_angle=0,end_angle=360,xrad=40,yrad=60);
line(100,300,100,260);
setfillstyle(SOLID_FILL,WHITE);
fillellipse(300,200,40,60);
ellipse(300,200,start_angle=0,end_angle=360,xrad=40,yrad=60);
Page | 17
line(300,300,300,260);
setfillstyle(SOLID_FILL,BLUE);
fillellipse(500,200,40,60);
ellipse(500,200,start_angle=0,end_angle=360,xrad=40,yrad=60);
line(500,300,500,260);
}
delay(500);
cleardevice();
{
setfillstyle(SOLID_FILL,BLUE);
fillellipse(100,100,40,60);
ellipse(100,100,start_angle=0,end_angle=360,xrad=40,yrad=60);
line(100,200,100,160);
setfillstyle(SOLID_FILL,WHITE);
fillellipse(300,100,40,60);
ellipse(300,100,start_angle=0,end_angle=360,xrad=40,yrad=60);
line(300,200,300,160);
setfillstyle(SOLID_FILL,BLUE);
fillellipse(500,100,40,60);
ellipse(500,100,start_angle=0,end_angle=360,xrad=40,yrad=60);
line(500,200,500,160);
}
/* clean up */
getch();
closegraph();
return 0;
}
Page | 18
OUTPUT:-
Page | 19
7. Write a program to implement scan convert line using DDA
Algorithm.
CODE:-
#include <graphics.h>
#include <conio.h>
#include<stdio.h>
int main(){
int gd=DETECT,gm,i;
float x,y,dx,dy,steps;
int x1,x2,y1,y2;
initgraph(&gd,&gm,"C:Turboc3BGI");
outtextxy(240,90,"DDA LINE DRAWING ALGORITHM");
setbkcolor(BLACK);
x1=100, y1=200, x2=200, y2=300;
dx=(float)(x2-x1);
dy=(float)(y2-y1);
if(dx>=dy)
{steps=dx;}
else{
steps=dy;}
dx=x/steps;
dy=dy/steps;
x=x1;
y=y1;
i=1;
while(i<=steps){
putpixel(x,y,WHITE);
x+=dx;
y+=dy;
i=i+1;}
getch();
closegraph();
return 0; }
Page | 20
OUTPUT:-
Page | 21
8. Write a program to implement scan convert line using
Bresenhem Algorithm.
CODE:-
#include <graphics.h>
#include <conio.h>
#include<stdio.h>
void drawline(int x1, int y1, int x2, int y2)
{
int x,y,dx,dy,p;
dx=x2-x1;
dy=y2-y1;
x=x1;
y=y1;
p=2*dy-dx;
while(x<x2){
if(p>=0){
putpixel(x,y,7);
y=y+1;
p=p+2*dy-2*dx;}
else{
putpixel(x,y,7);
p=p+2*dy;}
x=x+1;} }
int main(){
int gd=DETECT, gm, x1,y1,x2,y2;
int midx, midy;
initgraph(&gd,&gm,"C:Turboc3BGI");
outtextxy(350,50,"BRESENHEM LINE DRAWING ALGORITHM");
midx=getmaxx()/2;
midy=getmaxy()/2;
line(midx,0,midx,getmaxy());
line(0,midy,getmaxx(),midy);
printf("Enter Coordinates of first Point: ");
scanf("%d%d",&x1,&y1);
printf("Enter coordinates of second point: ");
scanf("%d%d",&x2,&y2);
drawline(x1,y1,x2,y2);
getch();
closegraph();
return 0;
}
Page | 22
OUTPUT:-
Page | 23
9. Write a Program to scan convert circle using Mid-point
algorithm
CODE:-
#include<graphics.h>
#include<conio.h>
#include<math.h>
void setPixel(int x, int y, int h, int k)
{
outtextxy(310,150,"****** CIRCLE USING MID POINT ****");
putpixel(x+h, y+k, GREEN);
putpixel(x+h, -y+k, YELLOW);
putpixel(-x+h, -y+k, RED);
putpixel(-x+h, y+k, WHITE);
putpixel(y+h, x+k, GREEN);
putpixel(y+h, -x+k, WHITE);
putpixel(-y+h, -x+k, RED);
putpixel(-y+h, x+k, YELLOW;
)
}
int main()
{
int gd=0, gm,h,k,r;
int x,y,p;
h=200, k=200, r=100;
initgraph(&gd, &gm, (char *)"C:Turboc3BGI");
x=0;y=r;p=1-r;
while(x<=y)
{
setPixel(x,y,h,k);
if(p<0)p=p + 2*x + 3;
else{p=p+2*(x-y)+5;y--;
}
x++;
}
getch();
closegraph();
return 0;
}
Page | 24
OUTPUT:-
Page | 25
10. Write a program to implement scan convert Circle using
Bresenhem Algorithm.
CODE:-
#include<graphics.h>
#include<conio.h>
#include<math.h>
void setPixel(int x, int y, int h, int k)
{
putpixel(x+h, y+k,RED);
putpixel(x+h, -y+k,RED);
putpixel(-x+h, -y+k,WHITE);
putpixel(-x+h, y+k,WHITE);
putpixel(y+h, x+k,YELLOW);
putpixel(y+h, -x+k,GREEN);
putpixel(-y+h, -x+k,GREEN);
putpixel(-y+h, x+k,YELLOW);}
int main(){
int gd=0, gm,h,k,r;
int x,y,d;
h=250,k=250,r=200;
initgraph(&gd,&gm,"C:Turboc3BGI");
outtextxy(400,50,"BRESENHEM CIRCLE DRAWING");
setbkcolor(BLACK);
x=0;
y=r;
d=3-2*r;
while(x<=y){
setPixel(x,y,h,k);
delay(10);
if(d<0)
d=d+4*x-6;
else{
d=d+4*(x-y)+10;
y=y-1;}
x++;
}
getch();
closegraph();
return 0;
}
Page | 26
OUTPUT:-
Page | 27
11. Write a Program to scan convert ellipse using Mid-point algorithm
CODE:-
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<ctype.h>
#include<math.h>
#include<stdlib.h>
void sd_ellipse(int x1,int y1,int rx, int ry);
void plotellipse(int x1, int y1, int x, int y);
void main()
{
int rx,x1,y1,u,v,x,y,ry;
int gdriver=DETECT,gmode;
//float x,y,xinc,yinc,dx,dy;
clrscr();
initgraph(&gdriver,&gmode,"c:turboc3BGI");
u=getmaxx();
v=getmaxy();
printf("ntt ***** MID-POINT ELLIPSE ALGORITHM *****");
printf("nnThe Centre Coordinates are: ");
printf("(%d, %d)",u/2,v/2);
line(0,v/2,u,v/2);
line(u/2,0,u/2,v);
printf("nnEnter the starting coordinates: ");
scanf("%d%d",&x1,&y1);
printf("Enter the Major Axis: ");
scanf("%d",&rx);
printf("Enter the Minor Axis: ");
scanf("%d",&ry);
sd_ellipse(x1,y1,rx,ry);
plotellipse(x1,y1,x,y);
setbkcolor(0);
getch();
closegraph();
return 0;
}
void sd_ellipse(int x1, int y1,int rx,int ry)
{int dx,dy,p1,p2;
int x=0;
int y=ry;
plotellipse(x1,y1,x,y);
p1=(ry*ry)-(rx*rx*ry)+(1/4*rx*rx);
dx=2*ry*ry*x;
Page | 28
dy=2*rx*rx*y;
do{plotellipse(x1,y1,x,y);
if(p1<0){x=x+1;
y=y;
dx=dx+2*ry*ry;
p1=p1+dx+(ry*ry);
}
else
{
x=x+1;
y=y-1;
dx=dx+2*(ry)*ry;
dy=dy-2*(rx)*rx;
p1=p1+dx-dy+(ry*ry);
}}
while(dx<dy);
p2=ry*ry*(x+1/2)*(x+1/2)+rx*rx*(y-1)*(y-1)-rx*rx*ry*ry;
do{plotellipse(x1,y1,x,y);
if(p2>0){x=x;
y=y-1;
dy=dy-2*(rx*rx);
p2=p2-dy+(rx*rx);
}
else{y=y-1;
x=x+1;
dy=dy-2*rx*rx;
dx=dx+2*ry*ry;
p2=p2+dx-dy+(rx*rx);
}
}
while(y>0);
}
void plotellipse(int x1,int y1, int x, int y)
{
putpixel(x1+x,y1+y,15);
putpixel(x1-x,y1+y,15);
putpixel(x1+x,y1-y,15);
putpixel(x1-x,y1-y,15);
}
Page | 29
OUTPUT:-
Page | 30
12. Write a Program to implement Cohen and Sutherland line clipping
algorithm
CODE:-
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<graphics.h>
#include<dos.h>
typedef struct coordinate
{int x,y;char code[4];
}PT;
// typedef struct coordinate PT;
void drawwindow();
void drawline(PT pl, PT p2);
PT setcode(PT p);
PT resetendpt(PT pl, PT p2);
int visibility(PT pl, PT p2);
void main(){int gd = DETECT, v, gm;
PT p1, p2, p3, p4, ptemp;printf("nEnter x1 and y1:n");
scanf("%d %d",&p1.x,&p1.y);
printf("nEnter x2 and y2:n");
scanf("%d %d", &p2.x,&p2.y);
initgraph(&gd,&gm,"c:turboc3BGI");
drawwindow();
delay(500);
drawline(p1, p2);
delay(500);
cleardevice();
delay(500);
p1 = setcode(p1);
p2 = setcode(p2);
v = visibility(p1,p2);
delay(500);
switch(v)
{
case 0: drawwindow();
delay(500);drawline(p1,p2);
break;
case 1: drawwindow();
delay(500);
break;
Page | 31
case 2: p3 = resetendpt(p1, p2);
p4 = resetendpt(p2, p1);
drawwindow();
delay(500);
drawline(p3, p4);
break;
}
delay(5000);
closegraph();
getch();
}
void drawwindow()
{
line(150,100,450,100);
line(450,100,450,350);
line(450,350,150,350);
line(150,350,150,100);
}
void drawline(PT p1, PT p2)
{
line(p1.x, p1.y, p2.x, p2.y);
}
PT setcode(PT p)
{
PT ptemp;
if(p.y < 100)
ptemp.code[0] = '1';
else
ptemp.code[0] = '0';
if(p.y > 350)
ptemp.code[1] = '1';
else
ptemp.code[1] = '0';
if(p.x > 450)
ptemp.code[2] = '1';
else
ptemp.code[2] = '0';
if(p.x < 150)
ptemp.code[3] = '1';
else
ptemp.code[3] = '0';
ptemp.x = p.x;
ptemp.y = p.y;
return(ptemp);
}
Page | 32
int visibility(PT pl, PT p2)
{int i, flag = 0;for(i = 0; i < 4; i++)
{
if((pl.code[i] != '0') || (p2.code[i] != '0'))
flag=1;}
if(flag==0)
return(0);
for(i = 0; i < 4; i++)
{
if((pl.code[i] == p2.code[i]) && (pl.code[i] == '1'))flag='0';}
if(flag==0)return(1);return(2);
}
PT resetendpt(PT p1, PT p2){PT temp;
int x, y, i;float m, k;if(p1.code[3] == '1')x = 150;
if(p1.code[2] == '1')x=450;
if((p1.code[3] == '1') || (p1.code[2] == '1')){m = (float)(p2.y -p1.y) / (p2.x -p1.x);
k = (p1.y + (m * (x -p1.x)));
temp.y = k;
temp.x = x;
for(i = 0; i < 4; i++)
temp.code[i]=p1.code[i];
if(temp.y <= 350 && temp.y >= 100)
return (temp);
}
if(p1.code[0] == '1')
y=100;
if(p1.code[1] == '1')
y=350;
if((p1.code[0] == '1') || (p1.code[1] =='1'))
{
m = (float)(p2.y -p1.y) / (p2.x -p1.x);
k = (float)p1.x + (float)(y -p1.y) / m;
temp.x = k;
temp.y = y;
for(i = 0; i < 4; i++)
temp.code[i] = p1.code[i];
return(temp);
}
else
return(p1);
}
Page | 33
OUTPUT:-
Page | 34
13. Write a Program to get the Translation vector, Rotation vector and
Scaling vector from the user and translate, rotate and scale the triangle
accordingly
CODE:-
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<dos.h>
#include<graphics.h>
#include<process.h>
#include<math.h>
int main(void)
{
int ps,x,y,x1,y1,x2,y2,tx,ty,mx,my,d,x3,y3;
int a1,a2,a3,b1,b2,b3,sa,sb;
double s,c, angle;
int gd=DETECT,gm;
initgraph(&gd,&gm,"C:Turboc3BGI");
printf("ENTER THE COORDINATES");
printf("n Enter first coordinate of the triangle: ");
scanf("%d %d", &x,&y);
printf("n Enter second coordinate of the triangle: ");
scanf("%d %d",&x1,&y1);
printf("nEnter third coordinate of the triangle: ");
scanf("%d %d",&x2,&y2);
printf("ENTER THE NUMBER TO PRINTn");
printf(" 1 To Transition the Triangle n 2 To Rotate the Triangle n 3 To Scale the
Trianglen");
scanf("%d",&ps);
printf("ntt********** TRIANGLE before & after translation ***********");
switch(ps){
case 1:
line(x,y,x1,y1);
line(x1,y1,x2,y2);
line(x2,y2,x,y);
printf("n Now enter the translation vector: ");
scanf("%d%d",&tx,&ty);
setcolor(RED);
ine(x+tx,y+ty,x1+tx,y1+ty);
line(x1+tx,y1+ty,x2+tx,y2+ty);
line(x2+tx,y2+ty,x+tx,y+ty);
break;
case 2:
setcolor(RED);
line(x1,y1,x2,y2);
Page | 35
line(x2,y2, x3,y3);
line(x3, y3, x1, y1);
getch();
printf("Enter rotation angle: ");
scanf("%lf", &angle);
setbkcolor(WHITE);
c = cos(angle *M_PI/180);
s = sin(angle *M_PI/180);
x1 = floor(x1 * c + y1 * s);
y1 = floor(-x1 * s + y1 * c);
x2 = floor(x2 * c + y2 * s);
y2 = floor(-x2 * s + y2 * c);
x3 = floor(x3 * c + y3 * s);
y3 = floor(-x3 * s + y3 * c);
cleardevice();
line(x1, y1 ,x2, y2);
line(x2,y2, x3,y3);
line(x3, y3, x1, y1);
break;
case 3:
line(x1,y1,x2,y2);
line(x2,y2,x3,y3);
line(x3,y3,x1,y1);
printf("Enter the scaling coordinates:");
scanf("%d%d",&sa,&sb);
mx=(x1+x2+x3)/3;
my=(y1+y2+y3)/3;
cleardevice();
a1=mx+(x1-mx)*sa;
b1=my+(y1-my)*sb;
a2=mx+(x2-mx)*sa;
b2=my+(y2-my)*sb;
a3=mx+(x3-mx)*sa;
b3=my+(y3-my)*sb;
line(a1,b1,a2,b2);
line(a2,b2,a3,b3);
line(a3,b3,a1,b1);
default:
break;
}
getch();
closegraph();
return 0;
}
Page | 36
OUTPUT:-
Page | 37

Graphic Design Lab File.docx

  • 1.
    Department of ComputerScience and Engineering Computer Graphics Lab File Submitted to: Submitted By: - Prof. Nidhi Srivastava Payal Jindal (T114)
  • 2.
    Page | 2 Tableof Content S.No. Program Name Page No. 1. Write a program to study and implementations of graphic functions and VGA standards. Draw line, circle, ellipse, arc, sector, and bar using inbuilt functions in switch statement 3 2. Write a Program using inbuilt function for the followings: 1. Display coordinates axes. 2. Display nested circles. 3. Display nested rectangles. 10 3. Write a Program using inbuilt function for the followings: 1. Display different colorful shapes. 2. Display a string “Hello User” in the centre of the screen using Outtextxy() function. 11 4. Write a Program to make bar chart and pie chart for students for five subjects 12 5. Write a Program to revolve a coin on a table 15 6. Write a Program to design flying colored balloons 16 7. Write a program to implement scan convert line using DDA Algorithm. 19 8. Write a program to implement scan convert line using Bresenhem Algorithm. 21 9. Write a Program to scan convert circle using Mid-point algorithm 23 10. Write a program to implement scan convert Circle using Bresenhem Algorithm. 25 11. Write a Program to scan convert ellipse using Mid-point algorithm 27 12. Write a Program to implement Cohen and Sutherland line clipping algorithm 28 13. Write a Program to get the Translation vector, Rotation vector and Scaling vector from the user and translate, rotate and scale the triangle accordingly 34
  • 3.
    Page | 3 1.Write a program to study and implementations of graphic functions and VGA standards. Draw line, circle, ellipse, arc, sector, and bar using inbuilt functions in switch statement. CODE:- #include<stdio.h> #include<graphics.h> #include<dos.h> #include<stdlib.h> #include<conio.h> int main() { int gd=DETECT, gm; int s; initgraph(&gd,&gm,"C:Turboc3BGI"); printf("ENTER THE NUMBER TO PRINTn"); printf(" 1 FOR LINEn 2 FOR CIRCLEn 3 FOR ELLIPSEn"); printf(" 4 FOR ARCn 5 FOR SECTORn 6 FOR BARnENTER:"); scanf("%d",&s); switch(s) { case 1: outtextxy(260,150,"****LINE****"); line(150,300,500,300); break; case 2: outtextxy(260,150,"****CIRCLE****"); circle(300,300,100); break; case 3: outtextxy(260,150,"****ELLIPSE****"); ellipse(290,300,0,360,100,50); break; case 4: outtextxy(260,150,"****ARC****"); arc(400,300,120,250,100); break; case 5: outtextxy(260,150,"****SECTOR****"); sector(200,200,30,120,90,85); break;
  • 4.
    Page | 4 case6: outtextxy(300,100,"****BAR GRAPH****"); line(100,420,100,250); line(100,420,400,420); setfillstyle(LINE_FILL,RED); bar(150,200,200,419); setfillstyle(LINE_FILL,GREEN); bar(225,90,275,419); setfillstyle(LINE_FILL,BLUE); bar(300,120,350,419); setfillstyle(LINE_FILL,YELLOW); bar(375,180,425,419); break; default: break; } getch(); closegraph(); return 0; } OUTPUT:-
  • 5.
  • 6.
  • 7.
    Page | 7 2.Writea Program using inbuilt function for the followings: i) Display coordinates axes. CODE:- #include<stdio.h> #include<graphics.h> #include<math.h> int main() { int gd=DETECT,gm; //float m; int midx,midy; initgraph(&gd,&gm,"C:Turboc3BGI"); midx=getmaxx()/2; midy=getmaxy()/2; line(midx,0,midx,getmaxy()); line(0,midy,getmaxx(),midy); getch(); closegraph(); return 0; } OUTPUT:-
  • 8.
    Page | 8 ii)Displaynested circles. CODE:- #include<stdio.h> #include<graphics.h> #include<conio.h> int main() { int gd = DETECT,gm; int x ,y; initgraph(&gd, &gm, "C:Turboc3BGI"); x = getmaxx()/2; y = getmaxy()/2; outtextxy(240, 50, "Concentric Circles"); setcolor(WHITE); circle(x, y, 30); setcolor(GREEN); circle(x, y, 50); setcolor(RED); circle(x, y, 70); setcolor(YELLOW); circle(x, y, 90); getch(); closegraph(); return 0; } OUTPUT:-
  • 9.
    Page | 9 iii)Display nested rectangles. CODE:- #include<stdio.h> #include<conio.h> #include<graphics.h> #include<stdlib.h> #include<direct.h> int main(void) { int gdriver = DETECT, gmode; initgraph(&gdriver, &gmode, "C:Turboc3BGI"); outtextxy(240, 50, "Nested Rectangles"); setcolor(YELLOW); rectangle(200,120,400,300); setcolor(RED); rectangle(220,140,380,280); setcolor(WHITE); rectangle(240,160,360,260); /* clean up */ getch(); closegraph(); return 0; } OUTPUT:-
  • 10.
    Page | 10 3.Write a Program using inbuilt function for the followings: i) Display different colorful shapes. CODE:- #include<graphics.h> #include<conio.h> #include<stdio.h> int main() { int gd=DETECT,gm; initgraph (&gd,&gm,"c:turboc3BGI"); setbkcolor(BLACK); setcolor(BLUE); printf("tttnnLINE"); line(50,40,190,40); setcolor(GREEN);printf("ttnnnnRECTANGLE"); rectangle(125,115,215,165); setcolor(WHITE); printf("tttnnnnnnnARC"); arc(120,200,180,0,30); setcolor(YELLOW); printf("tnnnnCIRCLE"); circle(120,270,30); setcolor(BROWN); printf("tnnnnECLIPSE"); ellipse(120,350,0,360,30,20); getch(); closegraph(); return 0; } OUTPUT:-
  • 11.
    Page | 11 ii)Display a string “Hello User” in the centre of the screen using Outtextxy() function. CODE:- #include <graphics.h> #include<stdio.h> #include<conio.h> int main() { int gd = DETECT, gm;initgraph(&gd, &gm, (char*)"C:Turboc3BGI"); outtextxy(200, 150, "Hello User"); getch(); closegraph(); return 0; } OUTPUT:-
  • 12.
    Page | 12 4.Write a Program to make bar chart and pie chart for students for five subjects CODE:- #include <graphics.h> #include <conio.h> #include<stdio.h> int main() { int gd = DETECT, gm; int s, midx, midy, o,e,c,w;float total,o1,e1,c1,w1, o2,e2,c2,w2; initgraph(&gd, &gm,"C:Turboc3BGI " ); printf("ENTER THE NUMBER TO PRINTn"); printf(" 1 FOR BARGRAPH:"); printf(" 2 FOR PIE CHART:"); scanf("%d",&s); switch(s) { case 1: outtextxy(275,0,"BAR GRAPH"); setlinestyle(SOLID_LINE,0,2); line(90,410,90,50); line(90,410,590,410); line(85,60,90,50); line(95,60,90,50); line(585,405,590,410); line(585,415,590,410); outtextxy(65,60,"Y"); outtextxy(570,420,"X"); outtextxy(70,415,"O"); setfillstyle(XHATCH_FILL, GREEN); bar(150,80,200,410); bar(225,100,275,410); bar(300,120,350,410); bar(375,170,425,410); bar(450,135,500,410); break; case 2: midx = getmaxx() / 2; midy = getmaxy() / 2; printf("Enter the marks for Operaing System: "); scanf("%d",&o); printf("Enterthe marks for E-Commerce: "); scanf("%d",&e);
  • 13.
    Page | 13 printf("Enterthe marks for Computer Graphics: "); scanf("%d",&c); printf("Enter the marksfor Web Based Programming: "); scanf("%d",&w);total=o+e+c+w; o2=(360/total); e2=(360/total); c2=(360/total); w2=(360/total); o1=o2*o; e1=e2*e;c1=c2*c;w1=w2*w; printf("ANGLES ARE: "); printf("nOS: %f",o1); printf("tE-COM: %f",e1); printf("tCG: %f",c1); printf("tWBP: %f",w1); setfillstyle(SOLID_FILL, BLUE); pieslice(midx, midy, 0, o1, 100); setfillstyle(SOLID_FILL, YELLOW); pieslice(midx, midy, o1, o1+e1, 100); setfillstyle(SOLID_FILL, GREEN); pieslice(midx, midy, o1+e1, o1+e1+c1, 100); setfillstyle(SOLID_FILL, BROWN); pieslice(midx, midy, o1+e1+c1, o1+e1+c1+w1,100); break; default: break; } getch(); closegraph(); return 0; }
  • 14.
  • 15.
    Page | 15 5.Write a Program to revolve a coin on a table. CODE:- #include <graphics.h> #include <stdlib.h> #include <stdio.h> #include <conio.h> int main(void) { int gdriver = DETECT, gmode, errorcode; int midx=250, midy=200; endangle = 360;int yradius = 50,xradius; initgraph(&gdriver, &gmode, "C:Turboc3BGI "); while(!kbhit()){for(xradius=35;xradius<=0;xradius--) { ellipse(midx, midy, stangle, endangle,xradius, yradius); setfillstyle(SOLID_FILL,RED);fillellipse(midx,midy,xradius,yradius); delay(100); } cleardevice(); for(xradius=0;xradius<=35;xradius++) { ellipse(midx, midy, stangle, endangle,xradius, yradius); setfillstyle(SOLID_FILL,RED); fillellipse(midx,midy,xradius,yradius); delay(100); } } getch(); closegraph(); return 0; } OUTPUT:-
  • 16.
    Page | 16 6.Write a Program to design flying colored balloons CODE:- #include <graphics.h> #include <stdlib.h> #include <stdio.h> #include <conio.h> #include<direct.h> int main(void) { int start_angle,end_angle,xrad,yrad; int gdriver = DETECT, gmode;/* initialize graphics mode */ initgraph(&gdriver, &gmode, (char *)"C:turboc3BGI"); setfillstyle(SOLID_FILL,BLUE); fillellipse(100,350,40,60); ellipse(100,350,start_angle=0,end_angle=360,xrad=40,yrad=60); line(100,450,100,410); setfillstyle(SOLID_FILL,WHITE); fillellipse(300,350,40,60); ellipse(300,350,start_angle=0,end_angle=360,xrad=40,yrad=60); line(300,450,300,410); setfillstyle(SOLID_FILL,BLUE); fillellipse(500,350,40,60); ellipse(500,350,start_angle=0,end_angle=360,xrad=40,yrad=60); line(500,450,500,410); delay(500);cleardevice();setfillstyle(SOLID_FILL,BLUE); fillellipse(100,300,40,60); ellipse(100,300,start_angle=0,end_angle=360,xrad=40,yrad=60); line(100,400,100,360);setfillstyle(SOLID_FILL,WHITE); fillellipse(300,300,40,60); ellipse(300,300,start_angle=0,end_angle=360,xrad=40,yrad=60); line(300,400,300,360); setfillstyle(SOLID_FILL,BLUE); fillellipse(500,300,40,60); ellipse(500,300,start_angle=0,end_angle=360,xrad=40,yrad=60); line(500,400,500,360); delay(500);cleardevice(); { setfillstyle(SOLID_FILL,BLUE); fillellipse(100,200,40,60); ellipse(100,200,start_angle=0,end_angle=360,xrad=40,yrad=60); line(100,300,100,260); setfillstyle(SOLID_FILL,WHITE); fillellipse(300,200,40,60); ellipse(300,200,start_angle=0,end_angle=360,xrad=40,yrad=60);
  • 17.
  • 18.
  • 19.
    Page | 19 7.Write a program to implement scan convert line using DDA Algorithm. CODE:- #include <graphics.h> #include <conio.h> #include<stdio.h> int main(){ int gd=DETECT,gm,i; float x,y,dx,dy,steps; int x1,x2,y1,y2; initgraph(&gd,&gm,"C:Turboc3BGI"); outtextxy(240,90,"DDA LINE DRAWING ALGORITHM"); setbkcolor(BLACK); x1=100, y1=200, x2=200, y2=300; dx=(float)(x2-x1); dy=(float)(y2-y1); if(dx>=dy) {steps=dx;} else{ steps=dy;} dx=x/steps; dy=dy/steps; x=x1; y=y1; i=1; while(i<=steps){ putpixel(x,y,WHITE); x+=dx; y+=dy; i=i+1;} getch(); closegraph(); return 0; }
  • 20.
  • 21.
    Page | 21 8.Write a program to implement scan convert line using Bresenhem Algorithm. CODE:- #include <graphics.h> #include <conio.h> #include<stdio.h> void drawline(int x1, int y1, int x2, int y2) { int x,y,dx,dy,p; dx=x2-x1; dy=y2-y1; x=x1; y=y1; p=2*dy-dx; while(x<x2){ if(p>=0){ putpixel(x,y,7); y=y+1; p=p+2*dy-2*dx;} else{ putpixel(x,y,7); p=p+2*dy;} x=x+1;} } int main(){ int gd=DETECT, gm, x1,y1,x2,y2; int midx, midy; initgraph(&gd,&gm,"C:Turboc3BGI"); outtextxy(350,50,"BRESENHEM LINE DRAWING ALGORITHM"); midx=getmaxx()/2; midy=getmaxy()/2; line(midx,0,midx,getmaxy()); line(0,midy,getmaxx(),midy); printf("Enter Coordinates of first Point: "); scanf("%d%d",&x1,&y1); printf("Enter coordinates of second point: "); scanf("%d%d",&x2,&y2); drawline(x1,y1,x2,y2); getch(); closegraph(); return 0; }
  • 22.
  • 23.
    Page | 23 9.Write a Program to scan convert circle using Mid-point algorithm CODE:- #include<graphics.h> #include<conio.h> #include<math.h> void setPixel(int x, int y, int h, int k) { outtextxy(310,150,"****** CIRCLE USING MID POINT ****"); putpixel(x+h, y+k, GREEN); putpixel(x+h, -y+k, YELLOW); putpixel(-x+h, -y+k, RED); putpixel(-x+h, y+k, WHITE); putpixel(y+h, x+k, GREEN); putpixel(y+h, -x+k, WHITE); putpixel(-y+h, -x+k, RED); putpixel(-y+h, x+k, YELLOW; ) } int main() { int gd=0, gm,h,k,r; int x,y,p; h=200, k=200, r=100; initgraph(&gd, &gm, (char *)"C:Turboc3BGI"); x=0;y=r;p=1-r; while(x<=y) { setPixel(x,y,h,k); if(p<0)p=p + 2*x + 3; else{p=p+2*(x-y)+5;y--; } x++; } getch(); closegraph(); return 0; }
  • 24.
  • 25.
    Page | 25 10.Write a program to implement scan convert Circle using Bresenhem Algorithm. CODE:- #include<graphics.h> #include<conio.h> #include<math.h> void setPixel(int x, int y, int h, int k) { putpixel(x+h, y+k,RED); putpixel(x+h, -y+k,RED); putpixel(-x+h, -y+k,WHITE); putpixel(-x+h, y+k,WHITE); putpixel(y+h, x+k,YELLOW); putpixel(y+h, -x+k,GREEN); putpixel(-y+h, -x+k,GREEN); putpixel(-y+h, x+k,YELLOW);} int main(){ int gd=0, gm,h,k,r; int x,y,d; h=250,k=250,r=200; initgraph(&gd,&gm,"C:Turboc3BGI"); outtextxy(400,50,"BRESENHEM CIRCLE DRAWING"); setbkcolor(BLACK); x=0; y=r; d=3-2*r; while(x<=y){ setPixel(x,y,h,k); delay(10); if(d<0) d=d+4*x-6; else{ d=d+4*(x-y)+10; y=y-1;} x++; } getch(); closegraph(); return 0; }
  • 26.
  • 27.
    Page | 27 11.Write a Program to scan convert ellipse using Mid-point algorithm CODE:- #include<stdio.h> #include<conio.h> #include<graphics.h> #include<ctype.h> #include<math.h> #include<stdlib.h> void sd_ellipse(int x1,int y1,int rx, int ry); void plotellipse(int x1, int y1, int x, int y); void main() { int rx,x1,y1,u,v,x,y,ry; int gdriver=DETECT,gmode; //float x,y,xinc,yinc,dx,dy; clrscr(); initgraph(&gdriver,&gmode,"c:turboc3BGI"); u=getmaxx(); v=getmaxy(); printf("ntt ***** MID-POINT ELLIPSE ALGORITHM *****"); printf("nnThe Centre Coordinates are: "); printf("(%d, %d)",u/2,v/2); line(0,v/2,u,v/2); line(u/2,0,u/2,v); printf("nnEnter the starting coordinates: "); scanf("%d%d",&x1,&y1); printf("Enter the Major Axis: "); scanf("%d",&rx); printf("Enter the Minor Axis: "); scanf("%d",&ry); sd_ellipse(x1,y1,rx,ry); plotellipse(x1,y1,x,y); setbkcolor(0); getch(); closegraph(); return 0; } void sd_ellipse(int x1, int y1,int rx,int ry) {int dx,dy,p1,p2; int x=0; int y=ry; plotellipse(x1,y1,x,y); p1=(ry*ry)-(rx*rx*ry)+(1/4*rx*rx); dx=2*ry*ry*x;
  • 28.
  • 29.
  • 30.
    Page | 30 12.Write a Program to implement Cohen and Sutherland line clipping algorithm CODE:- #include<stdio.h> #include<stdlib.h> #include<math.h> #include<graphics.h> #include<dos.h> typedef struct coordinate {int x,y;char code[4]; }PT; // typedef struct coordinate PT; void drawwindow(); void drawline(PT pl, PT p2); PT setcode(PT p); PT resetendpt(PT pl, PT p2); int visibility(PT pl, PT p2); void main(){int gd = DETECT, v, gm; PT p1, p2, p3, p4, ptemp;printf("nEnter x1 and y1:n"); scanf("%d %d",&p1.x,&p1.y); printf("nEnter x2 and y2:n"); scanf("%d %d", &p2.x,&p2.y); initgraph(&gd,&gm,"c:turboc3BGI"); drawwindow(); delay(500); drawline(p1, p2); delay(500); cleardevice(); delay(500); p1 = setcode(p1); p2 = setcode(p2); v = visibility(p1,p2); delay(500); switch(v) { case 0: drawwindow(); delay(500);drawline(p1,p2); break; case 1: drawwindow(); delay(500); break;
  • 31.
    Page | 31 case2: p3 = resetendpt(p1, p2); p4 = resetendpt(p2, p1); drawwindow(); delay(500); drawline(p3, p4); break; } delay(5000); closegraph(); getch(); } void drawwindow() { line(150,100,450,100); line(450,100,450,350); line(450,350,150,350); line(150,350,150,100); } void drawline(PT p1, PT p2) { line(p1.x, p1.y, p2.x, p2.y); } PT setcode(PT p) { PT ptemp; if(p.y < 100) ptemp.code[0] = '1'; else ptemp.code[0] = '0'; if(p.y > 350) ptemp.code[1] = '1'; else ptemp.code[1] = '0'; if(p.x > 450) ptemp.code[2] = '1'; else ptemp.code[2] = '0'; if(p.x < 150) ptemp.code[3] = '1'; else ptemp.code[3] = '0'; ptemp.x = p.x; ptemp.y = p.y; return(ptemp); }
  • 32.
    Page | 32 intvisibility(PT pl, PT p2) {int i, flag = 0;for(i = 0; i < 4; i++) { if((pl.code[i] != '0') || (p2.code[i] != '0')) flag=1;} if(flag==0) return(0); for(i = 0; i < 4; i++) { if((pl.code[i] == p2.code[i]) && (pl.code[i] == '1'))flag='0';} if(flag==0)return(1);return(2); } PT resetendpt(PT p1, PT p2){PT temp; int x, y, i;float m, k;if(p1.code[3] == '1')x = 150; if(p1.code[2] == '1')x=450; if((p1.code[3] == '1') || (p1.code[2] == '1')){m = (float)(p2.y -p1.y) / (p2.x -p1.x); k = (p1.y + (m * (x -p1.x))); temp.y = k; temp.x = x; for(i = 0; i < 4; i++) temp.code[i]=p1.code[i]; if(temp.y <= 350 && temp.y >= 100) return (temp); } if(p1.code[0] == '1') y=100; if(p1.code[1] == '1') y=350; if((p1.code[0] == '1') || (p1.code[1] =='1')) { m = (float)(p2.y -p1.y) / (p2.x -p1.x); k = (float)p1.x + (float)(y -p1.y) / m; temp.x = k; temp.y = y; for(i = 0; i < 4; i++) temp.code[i] = p1.code[i]; return(temp); } else return(p1); }
  • 33.
  • 34.
    Page | 34 13.Write a Program to get the Translation vector, Rotation vector and Scaling vector from the user and translate, rotate and scale the triangle accordingly CODE:- #include<stdio.h> #include<conio.h> #include<stdlib.h> #include<dos.h> #include<graphics.h> #include<process.h> #include<math.h> int main(void) { int ps,x,y,x1,y1,x2,y2,tx,ty,mx,my,d,x3,y3; int a1,a2,a3,b1,b2,b3,sa,sb; double s,c, angle; int gd=DETECT,gm; initgraph(&gd,&gm,"C:Turboc3BGI"); printf("ENTER THE COORDINATES"); printf("n Enter first coordinate of the triangle: "); scanf("%d %d", &x,&y); printf("n Enter second coordinate of the triangle: "); scanf("%d %d",&x1,&y1); printf("nEnter third coordinate of the triangle: "); scanf("%d %d",&x2,&y2); printf("ENTER THE NUMBER TO PRINTn"); printf(" 1 To Transition the Triangle n 2 To Rotate the Triangle n 3 To Scale the Trianglen"); scanf("%d",&ps); printf("ntt********** TRIANGLE before & after translation ***********"); switch(ps){ case 1: line(x,y,x1,y1); line(x1,y1,x2,y2); line(x2,y2,x,y); printf("n Now enter the translation vector: "); scanf("%d%d",&tx,&ty); setcolor(RED); ine(x+tx,y+ty,x1+tx,y1+ty); line(x1+tx,y1+ty,x2+tx,y2+ty); line(x2+tx,y2+ty,x+tx,y+ty); break; case 2: setcolor(RED); line(x1,y1,x2,y2);
  • 35.
    Page | 35 line(x2,y2,x3,y3); line(x3, y3, x1, y1); getch(); printf("Enter rotation angle: "); scanf("%lf", &angle); setbkcolor(WHITE); c = cos(angle *M_PI/180); s = sin(angle *M_PI/180); x1 = floor(x1 * c + y1 * s); y1 = floor(-x1 * s + y1 * c); x2 = floor(x2 * c + y2 * s); y2 = floor(-x2 * s + y2 * c); x3 = floor(x3 * c + y3 * s); y3 = floor(-x3 * s + y3 * c); cleardevice(); line(x1, y1 ,x2, y2); line(x2,y2, x3,y3); line(x3, y3, x1, y1); break; case 3: line(x1,y1,x2,y2); line(x2,y2,x3,y3); line(x3,y3,x1,y1); printf("Enter the scaling coordinates:"); scanf("%d%d",&sa,&sb); mx=(x1+x2+x3)/3; my=(y1+y2+y3)/3; cleardevice(); a1=mx+(x1-mx)*sa; b1=my+(y1-my)*sb; a2=mx+(x2-mx)*sa; b2=my+(y2-my)*sb; a3=mx+(x3-mx)*sa; b3=my+(y3-my)*sb; line(a1,b1,a2,b2); line(a2,b2,a3,b3); line(a3,b3,a1,b1); default: break; } getch(); closegraph(); return 0; }
  • 36.
  • 37.