Graphics Assignment PDF
Graphics Assignment PDF
midx=getmaxx()/2;
midy=getmaxy()/2;
line(0,midy,midx*2,midy);
line(midx,0,midx,midy*2);
line(midx/2,0,midx/2,midy*2);
line(getmaxy(),0,getmaxy(),midy*2);
outtextxy(65,219,(char*)"Line");
outtextxy(220,219,(char*)"Circle");
outtextxy(375,219,(char*)"Polygon");
outtextxy(540,219,(char*)"Sector");
outtextxy(50,459,(char*)"Rectangle");
outtextxy(220,459,(char*)"Ellipse");
outtextxy(390,459,(char*)"Arc");
outtextxy(535,459,(char*)"Pieslice");
//Line
line(10,30,149,170);
//Circle
circle(239,119,75);
//Polygon
drawpoly(4, arr);
//Sector
sector(560,119,30,250,75,40);
//Rectangle
rectangle(10,319,148,379);
//Ellipse
ellipse(239,355,0,360,75,40);
//Arc
arc(400,355,0,150,60);
//Pieslice
pieslice(560,355,20, 340,75);
getch();
}
int dx,dy,step,i;
float x,y,xinc,yinc;
dx=x2-x1;
dy=y2-y1;
if(abs(dx)>abs(dy))
step=abs(dx);
else
step=abs(dy);
xinc=dx/(float)step;
yinc=dy/(float)step;
x=x1;
y=y1;
while(x<=y) {
if(d<=0)
d=d+(4*x)+6;
else {
d=d+(4*x)-(4*y)+10;
y=y-1;
}
x=x+1;
drawCircle(xc,yc,x,y);
}
}
int main(void) {
int gd = DETECT, gm, x, y, r;
initgraph(&gd, &gm, (char*)"");
getch();
return 0;
}
setcolor (5);
line(P[0][0], P[0][1], P[1][0], P[1][1]);
outtextxy(80,210,(char*)"Original line");
setcolor(3);
line(P[0][0], P[0][1], P[1][0], P[1][1]);
outtextxy(440,300,(char*)"Translated line");
getch();
}
int main() {
int P[2][2] = {100, 150, 500, 400}; // coordinates of point
int T[2] = {75, 10}; // translation factor
translateLine (P, T);
return 0;
}
void TriAngle(int x1, int y1, int x2, int y2, int x3, int y3) {
line(x1, y1, x2, y2);
line(x2, y2, x3, y3);
line(x3, y3, x1, y1);
}
void Rotate(int x1, int y1, int x2, int y2, int x3, int y3) {
int a1, b1, a2, b2, a3, b3, p = x2, q = y2;
float Angle;
printf("Enter the angle for rotation:");
scanf("%f", &Angle);
Angle = (Angle * 3.14) / 180;
a1 = p + (x1 - p) * cos(Angle)-(y1 - q) * sin(Angle);
b1 = q + (x1 - p) * sin(Angle)+(y1 - q) * cos(Angle);
a2 = p + (x2 - p) * cos(Angle)-(y2 - q) * sin(Angle);
b2 = q + (x2 - p) * sin(Angle)+(y2 - q) * cos(Angle);
a3 = p + (x3 - p) * cos(Angle)-(y3 - q) * sin(Angle);
b3 = q + (x3 - p) * sin(Angle)+(y3 - q) * cos(Angle);
TriAngle(a1, b1, a2, b2, a3, b3);
}
int main() {
int gd = DETECT, gm;
int x1, y1, x2, y2, x3, y3;
printf("Enter the 1st point for the triangle:");
scanf("%d%d", &x1, &y1);
printf("Enter the 2nd point for the triangle:");
scanf("%d%d", &x2, &y2);
printf("Enter the 3rd point for the triangle:");
scanf("%d%d", &x3, &y3);
initgraph(&gd, &gm, (char*)"");
setcolor(15);
TriAngle(x1, y1, x2, y2, x3, y3);
outtextxy(250,230,(char*)"Original form");
setcolor(2);
Rotate(x1, y1, x2, y2, x3, y3);
outtextxy(80,230,(char*)"Rotation form");
getch();
}
rectangle(50,50,250,250);
line(50,50,250,250);
line(50,250,250,50);
flood(151,150,1,0);//right
flood(150,151,4,0);//bottom
flood(149,150,2,0);//left
flood(150,149,14,0);//top
getch();
}