CG Practicals

  • View
    26

  • Download
    2

Embed Size (px)

DESCRIPTION

CG Practicals for RJ Engineering Institute.

Text of CG Practicals

Computer graphics PRACTICAL:4

Enrollment no:100050131030

Aim: Write a program to implement 2D translation, rotation, scaling. Program Code: #include #include #include #include void translate(); void scalling(); void rotate(); void main() { int gd=DETECT,gm; int c; initgraph(&gd,&gm,"C:\\TC\\BGI");

printf("\n 1. translation:"); printf("\n 2. scalling:"); printf("\n 3. rotate:"); printf("\n enter choice:"); scanf("%d",&c); switch(c) { case 1:translate(); break;1

Computer graphics case 2:scalling(); break; case 3:rotate(); break; default:printf("\n invalid choice"); break; } getch(); closegraph(); } void translate() { int tx,ty; rectangle(100,150,150,100); printf("\n enter tx:"); scanf("%d",&tx); printf("\n enter ty:"); scanf("%d",&ty); printf("after translation \n"); rectangle(100+tx,150+ty,150+tx,100+ty); }

Enrollment no:100050131030

void scalling() { int sx,sy;2

Computer graphics rectangle(100,150,150,100); printf("\n enter sx:"); scanf("%d",&sx); printf("\n enter sy:"); scanf("%d",&sy); rectangle(100*sx,150*sy,150*sx,100*sy); }

Enrollment no:100050131030

void rotate() { int xref,yref,x1,y1,x2,y2,x3,y3,x4,y4,a1,b1,a2,b2,a3,b3,a4,b4; float theta,angle; xref=100; yref=100;

x1=150; y1=100;

x2=150; y2=150;

x3=100; y3=150;

x4=100;3

Computer graphics y4=100; printf("\n enter angle:"); scanf("%f",&angle); theta=angle*(3.14/180);

Enrollment no:100050131030

a1=(x1-xref)*cos(theta)-(y1-yref)*sin(theta); b1=(x1-xref)*sin(theta)+(y1-yref)*cos(theta);

a2=(x2-xref)*cos(theta)-(y2-yref)*sin(theta); b2=(x2-xref)*sin(theta)+(y2-yref)*cos(theta);

a3=(x3-xref)*cos(theta)-(y3-yref)*sin(theta); b3=(x3-xref)*sin(theta)+(y3-yref)*cos(theta);

a4=(x4-xref)*cos(theta)-(y4-yref)*sin(theta); b4=(x4-xref)*sin(theta)+(y4-yref)*cos(theta);

rectangle(100,150,150,100); line(a1+100,b1+100,a2+100,b2+100); line(a2+100,b2+100,a3+100,b3+100); line(a3+100,b3+100,a4+100,b4+100); line(a4+100,b4+100,a1+100,b1+100); }

4

Computer graphics Program Output:

Enrollment no:100050131030

5

Computer graphics

Enrollment no:100050131030

6

Computer graphics PRACTICAL:5

Enrollment no:100050131030

Aim: Write a program to implement 2D fix point rotation and fix point scaling. Program Code: /* ROTATION */

#include #include #include #include void main() { int i,j,n,p[8],xr,yr; int ch; double angle,p1[2]; int gd=DETECT,gm; initgraph(&gd,&gm,"g:\\tc\\bgi "); cleardevice(); printf("\n Enter no of vertices of polygon:"); scanf("%d",&n); printf("\n Enter co ordinates "); for(i=0;i