The document provides source code for generating and manipulating computer graphics using various algorithms. It includes algorithms for drawing lines, circles and curves, as well as algorithms for translating, rotating, and scaling two-dimensional and three-dimensional objects. The source code is written in C/C++ and uses graphics libraries to output the results. Various input parameters are taken from the user and output is displayed to demonstrate the algorithms.
ICT role in 21st century education and it's challenges.
Computer graphics lab manual
1. 1
Computer Graphics LAB
s.no Date content pg.no Sign
1. Digital Differential Analyzer line
drawing algorithm
2. Bresenham’s line drawing algorithm
3. Midpoint circle generation algorithm
4. Creating various types of texts and
fonts
5. Creating two-dimensional objects
6. Two-dimensional translation
7. Two-dimensional scaling
8. Two-dimensional rotation
9. Three-dimensional translation
10. Three-dimensional scaling
11. Three-dimensional rotation
12. Curve generation
13. Moving circle in different directions
14. Man walking using simple animation
15. Coloring the object using
a) 4-connected Floodfill
b) Floodfill function
7. 7
SOURCE CODE:
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
void main()
{
int x,y,x1,y1,x2,y2,p,dx,dy;
int gd=DETECT,gm;
initgraph(&gd,&gm,"C:TurboC3BGI");
printf("nEnter the x-coordinate of the first point ::");
scanf("%d",&x1);
printf("nEnter the y-coordinate of the first point ::");
scanf("%d",&y1);
printf("nEnter the x-coordinate of the second point ::");
scanf("%d",&x2);
printf("nEnter the y-coordinate of the second point ::");
scanf("%d",&y2);
x=x1;
y=y1;
dx=x2-x1;
dy=y2-y1;
putpixel(x,y,2);
p=(2*dy-dx);
while(x<=x2)
{
if(p<0)
{
x=x+1;
p=p+2*dy;
}
11. 11
SOURCE CODE:
#include<dos.h>
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
void draw_circle(int,int,int);
void symmetry(int,int,int,int);
void main()
{
int xc,yc,R;
int gd=DETECT,gm;
initgraph(&gd,&gm,"C:TurboC3BGI");
printf("Enter the center of the circle:n");
printf("Xc =");
scanf("%d",&xc);
printf("Yc =");
scanf("%d",&yc);
printf("Enter the radius of the circle :");
scanf("%d",&R);
draw_circle(xc,yc,R);
getch();
closegraph();
}
void draw_circle(int xc,int yc,int rad)
{
int x = 0;
int y = rad;
int p = 1-rad;
symmetry(x,y,xc,yc);
for(x=0;y>x;x++)
{
21. 21
SOURCE CODE:
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<math.h>
void main()
{
int gd=DETECT,gm;
int x1,y1,x2,y2,tx,ty,x3,y3,x4,y4;
initgraph(&gd,&gm,"C:TurboC3BGI");
printf("Enter the starting point of line segment:");
scanf("%d %d",&x1,&y1);
printf("Enter the ending point of line segment:");
scanf("%d %d",&x2,&y2);
printf("Enter translation distances tx,ty:n");
scanf("%d%d",&tx,&ty);
setcolor(5);
line(x1,y1,x2,y2);
outtextxy(x2+2,y2+2,"Original line");
x3=x1+tx;
y3=y1+ty;
x4=x2+tx;
y4=y2+ty;
setcolor(7);
line(x3,y3,x4,y4);
outtextxy(x4+2,y4+2,"Line after translation");
getch();
}
43. 43
Void main()
{
int x[4], y[4];
int i;
printf ("Enter the x- and y-coordinates of the four control points.n");
for (i=0; i<4; i++)
scanf ("%d%d", &x[i], &y[i]);
bezier (x, y);
}
46. 46
SOURCE CODE:
#include<stdio.h>
#include<graphics.h>
#include<conio.h>
#include<dos.h>
void main()
{
int gd=DETECT,gm,i;
initgraph(&gd,&gm,"C:TurboC3BGI");
//for moving circle from left to right,the following loop works
for(i=50;i<=getmaxx();i++)
{
setcolor(3);
setfillstyle(SOLID_FILL,9);
circle(50+i,50,50);
floodfill(52+i,52,3);
delay(20);
cleardevice();
}
//for moving circle from right to left, the following loop works
for(i=getmaxy();i>=0;i--)
{
setcolor(3);
setfillstyle(SOLID_FILL,9);
circle(i,50,50);
floodfill(i+2,52,3);
delay(20);
cleardevice();
}
//for moving circle from top to bottom,the following loop works