0% found this document useful (0 votes)
175 views

Computer Graphics (Lab File) - Satyam

The document is a lab manual for computer graphics. It contains 30 experiments covering basic graphics concepts like drawing basic shapes, lines, circles, ellipses and other curves. It also includes transformations like translation, rotation, scaling. More advanced topics covered are 3D graphics, animation, filling shapes with color. Experiments are listed with their page numbers and include programs to write and graphics concepts to implement.

Uploaded by

satyam garg
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
175 views

Computer Graphics (Lab File) - Satyam

The document is a lab manual for computer graphics. It contains 30 experiments covering basic graphics concepts like drawing basic shapes, lines, circles, ellipses and other curves. It also includes transformations like translation, rotation, scaling. More advanced topics covered are 3D graphics, animation, filling shapes with color. Experiments are listed with their page numbers and include programs to write and graphics concepts to implement.

Uploaded by

satyam garg
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 61

LAB MANUAL OF COMPUTER GRAPHICS

DR. PREETI KHATRI Satyam Garg


ASSISTANT PROFESSOR 1900980149022
S No Content Page Date Signature
Number

1 Basic Functions of Computer Graphics.

2 WAP to find the biggest of two numbers using text


functions graphics.

3 WAP to draw basic shapes.

4 WAP using various text styles and fonts.

5 WAP using drawpoly() function.

6 WAP to draw a colored HUT shape.

7 WAP to draw a fish.

8 WAP to implement DDA line drawing algorithm.

9 WAP to implement Bresenhem’s line


drawing algorithm.

10 WAP to implement Midpoint circle drawing algorithm.

11 WAP to implement Bresenhem’s circle


drawing algorithm.

12 WAP to implement Midpoint Ellipse algorithm.

13 WAP of 2D Translation, Rotation, Scaling.

14 WAP of Reflection along Y-axis.

15 WAP of Reflection along X-axis.


16 WAP of 3d Translation, Rotation, Scaling of an object.

17 WAP using the Floodfill function.

18 WAP of animation. To draw a car and move it


in a horizontal direction.

19 WAP to fill polygon using Fillpoly Function.

20 WAP using Fillstyle Function.

21 WAP for 4-connected Floodfill.

22 WAP for 8 connected Flood Fill.

23 Draw Bezier Curve.

24 Basics of Blender

25 Draw sharp edge over a plane

27 Draw smooth bouncing ball

28 Draw a mug in blender

29 Draw a pencil in blender

30 Draw bezier curve


Q1. Basic Functions of Computer Graphics.

Sol: The Functions Of Computer Graphics are as follows:-

1. Putpixel

Purpose:-Putpixel function is to draw the pixel on the screen. Pixel is a small dot on the

screen. Syntax:-putpixel(x coordinate, y coordinate,COLOR);

Example: – putpixel(100,100,BLUE);

2. SetbkColor

Purpose:-Setbkcolor function is used to set background color of the

screen. Syntax:-setbkcolor(COLOR);

Example:-setbkcolor(RED);

3. Setlinestyle

Purpose:-setlinestyle function is used to set the current line style, width and

pattern Syntax:-setlinestyle(linestyle, pattern, thickness);

Example:-setlinestyle(SOLID_LINE,1,2);

4. Setcolor

Purpose:-setcolor is to set the color of the objects which is to be drawn after this

setcolor line. Syntax:-setcolor(COLOR);

Example:-setcolor(RED);

5. Rectangle

Purpose:- Rectangle function is used to draw the rectangle on the screen. X1,y1 are the
lower left coordinates of the rectangle and the x2,y2 are the upper right coordinates of
the rectangle.

Syntax:– rectangle(x1,,y1,x2,y2);

Example:– rectangle(100,100,200,200);
6. Textheight

Purpose:-textheight returns the height of a string in pixels.

Syntax:-textheight(STRING);

Example:-i=textheight(“HELLO”);

7. Textwidth

Purpose:-textwidth returns the width of a string in

pixels Syntax:-textwidth(STRING);

Example:-i=textwidth(“HELLO”);

8. Getx

Purpose:-getx returns the current position of x o-

ordinate Syntax:-getx();

Example:-x=getx();

9. Gety

Purpose:-gety returns the current position of y

coordinate Syntax:-gety();

Example:-y=gety();

10. Getmaxx

Purpose:-getmaxx returns the maximum x coordinate on the

screen Syntax:-getmaxx();

Example:-maxx=getmaxx();

11. Getmaxy

Purpose:-getmaxy returns the maximum y coordinate on the

screen Syntax:-getmaxy();

Example:-maxy=getmaxy();
12. Line

Purpose:-Line function is used to draw the line on the

screen. Syntax: line(x1,y1,x2,y2);

Example:-line(100,100,200,100);

13. Closegraph

Purpose:-closegraph function shut down the graphic system

Syntax:-closegraph();

Example:-closegraph();

14. Moveto

Purpose:-moveto function moves current cursor position on the

screen Syntax:-moveto(x coordinate, y coordinate);

Example:-moveto(getmaxx/2, getmaxy/2);

15. Settextstyle

Purpose:-settextstyle sets the current text characteristics like font, direction

and size Syntax:-settextstyle(font, direction size);

Example:-settextstyle(1,1,10);

Font 1 DEFAULT

2 TRIPLEX

3 SMALL

4 SANS SERIF

5 GOTHIC

Direction 0 HORIZ_DIR

VERT_DIR

Size 0 SMALL
10 large

16. Circle

Purpose: Circle function is used to draw the circle on the

screen Syntax:– circle(x,y,radius);

Example:circle(100,100,50);

17. Cleardevice

Purpose: cleardevice function is used to clear the contents or graphic images on the
screen in graphics mode.

Syntax:cleardevice();

Example:cleardevice();

18. Outtextxy

Purpose: outtextxy function is used to print the text on the screen in

graphics mode. Syntax:outtext(x,y,text);

Example:-outtextxy(100,100,”HELLO”);

19. Sector

Purpose:sector function draws and fills an elliptical pie slice.

Syntax:sector(x, y, starting angle, ending angle, xradius, yradius);

Example:sector(100,100,45 135 100 50);

20. Arc

Purpose:arc draws the arc on the screen, arc is a part of the circle

Syntax:arc(x, y, starting angle, ending angle, radius);

Example:arc( 100,100,90,180,50);

21. Setfillstyle

Purpose: setfillstyle is used to set the color and style to be filled in the object using
the flood fill method.
Syntax:setfillstyle(STYLE, COLOR);

Example:setfillstyle(1,RED)

22. Floodfill

Purpose:floodfill function is used to fill the color in the object, object may be circle,
rectangle or any other closed image.

Syntax:floodfill(x,y,boundary color);

Example:floodfill(100,100,BLUE);

23. Ellipse

Purpose:ellipse function is used to draw the ellipse on the screen.

Syntax:ellipse(x, y, starting angle, ending angle, xradius, yradius);

Example:ellipse(100,100,90,200,20,20);

24. Outtext

Purpose:outtext function is used to display the text on the screen, using this
function text is display in the current position.

Syntax:outtext(STRING);

Example:outtex(“HELLO”);

25. Getcolor

Purpose:getcolor returns the current drawing color.

Syntax:getcolor();

Example:intclr = getcolor();

26. Getpixel

Purpose:getpixel gets the color of a specified pixel.

Syntax:getpixel(x,y);

Example: color=getpixel(100,100);

Q2. WAP to find the biggest of two numbers using text functions graphics.
Sol: #include<stdio.h>

#include<conio.h>

#include<graphics.h>

void main()

int a,b;

clrscr();

textmode(C80);

textbackground(WHITE);

textcolor(BLUE);

gotoxy(20,10);

cputs("PLEASE Enter the First Number:");

scanf("%d",&a);

gotoxy(20,12);

cputs("PLEASE Enter the Second Number:");

scanf("%d",&b);

textcolor(DARKGRAY);

if(a>b)

gotoxy(20,15);

printf("%d",a);

cputs("IS THE BIGGEST NUMBER"); }

else

gotoxy(20,15);

printf("%d",b);

cputs("IS THE BIGGEST NUMBER"); }


getch();

restorecrtmode();

Q3. WAP to draw basic shapes.


Sol: #include<stdio.h>

#include<conio.h>

#include<graphics.h>

void main()

int gd=DETECT,gm;

int arr[]={320,150,400,250,250,350,320,150};

initgraph(&gd,&gm,"c://turboc3//bgi");

//polygon

setcolor(RED);

drawpoly(4,arr);

outtextxy(320,130,"polygn");

//Line

setcolor(RED);

setbkcolor(LIGHTGREEN);
line(50,40,190,40);

outtextxy(30,30,"Line");

//Triangle

line(150,100,100,200);

line(100,200,200,200);

line(200,200,150,100);

outtextxy(160,100,"Triangl

e"); //Square

line(400,300,550,300);

line(400,300,400,450);

line(550,300,550,450);

line(400,450,550,450);

outtextxy(420,350,"Square

"); //Rectangle

line(400,100,600,100);

line(400,100,400,200);

line(400,200,600,200);

line(600,100,600,200);

outtextxy(420,120,"Rectangl

e"); //Circle

circle(120,280,30);

outtextxy(150,250,"Circl

e"); //Arc

arc(120,210,180,0,30);

outtextxy(120,210,"Arc");

//Pieslice

pieslice(250,450,30,60,90);

outtextxy(250,450,"Pieslice");

//Ellipse
ellipse(120,350,0,360,30,20);

outtextxy(150,330,"Ellipse");

//Sector

sector(150,450,0,135,50,60);

outtextxy(150,460,"Sector");

getch();

closegraph();

Q4. WAP using various text styles and fonts.

Sol: #include <graphics.h>

#include <conio.h>

int main()

//initilizing graphic driver and

//graphic mode variable

int graphicdriver=DETECT,graphicmode;

//calling initgraph with parameters

initgraph(&graphicdriver,&graphicmode,"c:\\turboc3\\bgi");
//Printing message for user

outtextxy(20, 20 + 20, "Program to print different fonts in C graphics");


//initilizing variables

int x = 75, y = 75, f = 0;

//for loop to print different fonts

for (f = 0; f <= 5; f++)

settextstyle(f, HORIZ_DIR, 1);

outtextxy(x, y, "Hi! My Name Is Toquir Iqbal..");

y = y + 20;

getch();

return 0;

Q5.WAP using drawpoly() function.


Sol: /* C Program to draw a Polygon using drawpoly() function*/

#include <graphics.h>

#include <stdio.h>

#include <stdlib.h>

#include <conio.h>

int main()

/* Declaring a variable */

int gdriver, gmode;

/* Polygon array to define points on

the polygon shape */ int poly[10];

/* Initialize the variables */

gdriver = DETECT;

/* Initialize the graph and set

path to BGI files */

initgraph(&gdriver, &gmode,

"c:\\turboc3\\bgi");

/* Polygon Points in Pairs */

poly[0] = 20; /* 1st vertex */

poly[1] = 100;

poly[2] = 120;

poly[3] = 140; /* 2nd vertex */

poly[4] = 240;

poly[5] = 260; /* 3rd vertex */

poly[6] = 120;

poly[7] = 320; /* 4th vertex */


poly[8] = poly[0];

poly[9] = poly[1]; /* The polygon does not

close automatically, so we close it */

/* Draw the Polygon */

drawpoly(5, poly);

getch();

/* Close the graph */

closegraph();

return 0;
}

Q6. WAP to draw a colored HUT shape.


Sol: #include<stdio.h>

#include<conio.h>

#include<graphics.h>

int main(){

int gd = DETECT,gm;

initgraph(&gd, &gm, "c:\\turboc3\\bgi");

/* Draw Hut */
setcolor(WHITE);

rectangle(150,180,2

50,300);

rectangle(250,180,420

,300);

rectangle(180,250,220

,300);

line(200,100,150,180);

line(200,100,250,180);

line(200,100,370,100);

line(370,100,420,180);

/* Fill colours */

setfillstyle(SOLID_FILL

, BROWN);

floodfill(152, 182,

WHITE); floodfill(252,

182, WHITE);

setfillstyle(SLASH_FILL

, BLUE);

floodfill(182, 252,

WHITE);

setfillstyle(HATCH_FILL

, RED); floodfill(200,
105, WHITE);

floodfill(210, 105,

WHITE);

getch();

closegraph();

return 0;

Q7. WAP to draw a fish.


Sol: #include <stdio.h>
#include <conio.h>
#include <graphics.h>
#include <dos.h>

int main() {
/* request auto detection */
int gdriver = DETECT, gmode;
int errcode, i;

/* initialize graphic mode */


initgraph(&gdriver, &gmode, "C:/TURBOC3/BGI");
errcode = graphresult();

if (errcode != grOk) {
/* error occurred */
getch();
printf("Error in graphics!!\n");
return 0;
}

/* fish movement implementation */


for (i = 0; i <= 300; i = i + 3) {
/* sleep for 30 milliseconds */
delay(30);
/* clear graphic screen */
cleardevice();

/* drawing tail */
setcolor(DARKGRAY);
setfillstyle(SLASH_FILL, DARKGRAY);
pieslice(90 + i, getmaxy()/2,
135, 225, 50); floodfill(90 + i,
getmaxy()/2, DARKGRAY);

/* drawing the body of the fish */

setcolor(LIGHTGRAY);

setfillstyle(SOLID_FILL, LIGHTGRAY);

ellipse(150 + i, getmaxy()/2, 0,

360, 80, 25); floodfill(150 + i,

getmaxy()/2, 7);

/* drawing pelvic fins */

setcolor(DARKGRAY);

setfillstyle(SLASH_FILL, DARKGRAY);

pieslice(170 + i, getmaxy()/2,

205, 250, 40); floodfill(170 + i,

getmaxy()/2, DARKGRAY);

/* draw eyes for the fish */

setcolor(BLACK);
setfillstyle(SOLID_FILL, BLACK);

circle(210 + i, getmaxy()/2 - 1, 2);

floodfill(210 + i, getmaxy()/2 - 1, BLACK);

setcolor(BLACK);

arc(210 + i, getmaxy()/2 - 1, 70, 225, 6);

/* sleep for 120 milliseconds */

delay(120);

/* clears the graphic screen */

cleardevice();

/* tail of the fish */

setcolor(DARKGRAY);

setfillstyle(SLASH_FILL, DARKGRAY);

pieslice(90 + i, getmaxy()/2, 135, 225, 50);

floodfill(90 + i, getmaxy()/2, DARKGRAY);

/* body of the fish */

setcolor(LIGHTGRAY);

setfillstyle(SOLID_FILL, LIGHTGRAY);

ellipse(150 + i, getmaxy()/2, 0, 360, 80, 25);

floodfill(150 + i, getmaxy()/2, LIGHTGRAY);

/* place fin at different position to

get motion */ setcolor(DARKGRAY);

setfillstyle(SLASH_FILL, DARKGRAY);
pieslice(170 + i, getmaxy()/2,

180, 210, 40); floodfill(170 + i,

getmaxy()/2, DARKGRAY);

/* eye of the fish */

setcolor(BLACK);

setfillstyle(SOLID_FILL, BLACK);

circle(210 + i, getmaxy()/2 - 1, 2);

floodfill(210 + i, getmaxy()/2 - 1, BLACK);

setcolor(BLACK);

arc(210 + i, getmaxy()/2 - 1, 70, 225, 6);

/* sleep for 120 milliseconds */

delay(120);

/* clear the graphic screen */

cleardevice();

/* draw fish tail */

setcolor(DARKGRAY);

setfillstyle(SLASH_FILL, DARKGRAY);

pieslice(90 + i, getmaxy()/2,

135, 225, 50); floodfill(90 + i,

getmaxy()/2, DARKGRAY);

/* body of the fish */

setcolor(LIGHTGRAY);

setfillstyle(SOLID_FILL, LIGHTGRAY);

ellipse(150 + i, getmaxy()/2, 0, 360, 80, 25);


floodfill(150 + i, getmaxy()/2, LIGHTGRAY);

/* locate fin at different position to

get motion */ setcolor(DARKGRAY);

setfillstyle(SLASH_FILL, DARKGRAY);

pieslice(170 + i, getmaxy()/2, 125, 170, 40);

floodfill(170 +i, getmaxy()/2, DARKGRAY);

setcolor(BLACK);

setfillstyle(SOLID_FILL, BLACK);

circle(210 + i, getmaxy()/2 - 1, 2);

floodfill(210 + i, getmaxy()/2 - 1, BLACK);

setcolor(BLACK);

arc(210 + i, getmaxy()/2 - 1, 70, 225, 6);

/* clears the graphic screen */

cleardevice();

/* deallocate memory allocated for

graphic screen */ closegraph();

return 0;

}
Q8. WAP to implement DDA line drawing algorithm.
Sol: #include <graphics.h>

#include <iostream.h>

#include <math.h>

#include <dos.h>

#include<conio.h>

void main( )

float x,y,x1,y1,x2,y2,dx,dy,step;

int i,gd=DETECT,gm;

initgraph(&gd,&gm,"c:\\turboc3\\bgi");

cout<<"Enter the value of x1 and y1 : ";

cin>>x1>>y1;

cout<<"Enter the value of x2 and y2: ";

cin>>x2>>y2;

dx=abs(x2-x1);

dy=abs(y2-y1);
if(dx>=dy)

step=dx;

else

step=dy;

dx=dx/step;

dy=dy/step;

x=x1;

y=y1;

i=1;

while(i<=step)

putpixel(x,y,5);

x=x+dx;

y=y+dy;

i=i+1;

delay(100);

getch();

closegraph();
}

Q9. WAP to implement Bresenhem’s line drawing algorithm.


Sol:
#include<stdio.h>

#include<graphics.h>

#include<conio.h>

void drawline(int x0, int y0, int x1, int y1)

int dx, dy, p, x, y;

dx=x1-x0
dy=y1-y0;

x=x0;

y=y0;

p=2*dy-dx;
while(x<x1)

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 gdriver=DETECT, gmode, error, x0, y0, x1, y1;

initgraph(&gdriver, &gmode, "c:\\turboc3\\bgi");

printf("Enter coordinates of first point: ");

scanf("%d%d", &x0, &y0);

printf("Enter coordinates of second point: ");

scanf("%d%d", &x1, &y1);

drawline(x0, y0, x1, y1);


getch();

Q10. WAP to implement Midpoint circle drawing algorithm.


Sol: #include<iostream.h>

#include<graphics.h>

#include<conio.h>

void drawcircle(int x0, int y0,

int radius) {

int x = radius;

int y = 0;

int err = 0;

while (x >= y)

putpixel(x0 + x, y0 + y, 7);

putpixel(x0 + y, y0 + x, 7);

putpixel(x0 - y, y0 + x, 7);

putpixel(x0 - x, y0 + y, 7);

putpixel(x0 - x, y0 - y, 7);

putpixel(x0 - y, y0 - x, 7);
putpixel(x0 + y, y0 - x, 7);

putpixel(x0 + x, y0 - y, 7);

if (err <= 0)

y += 1;

err += 2*y + 1;

if (err > 0)

x -= 1;

err -= 2*x + 1;

int main()

int gdriver=DETECT, gmode, error, x, y, r;

initgraph(&gdriver, &gmode,

"c:\\turboc3\\bgi"); cout<<"Enter

radius of circle: ";

cin>>r;

cout<<"Enter coordinates of center(x

and y): "; cin>>x>>y;

drawcircle(x, y, r);

getch();
}
Q11. WAP to implement Bresenhem’s circle drawing algorithm.
Sol: #include<stdio.h>

#include <graphics.h>

#include <stdlib.h>

#include <stdio.h>

#include <conio.h>

#include <math.h>

void EightWaySymmetricPlot(int xc,int yc,int x,int y)

putpixel(x+xc,y+yc,YELLOW);

putpixel(x+xc,-y+yc,WHITE);

putpixel(-x+xc,-y+yc,GREEN);

putpixel(-

x+xc,y+yc,DARKGRAY);

putpixel(y+xc,x+yc,12);

putpixel(y+xc,-x+yc,14);

putpixel(-y+xc,-x+yc,15);
putpixel(-y+xc,x+yc,6);

void BresenhamCircle(int xc,int

yc,int r) {

int x=0,y=r,d=3-(2*r);

EightWaySymmetricPlot(xc,yc,x,y);

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;

EightWaySymmetricPlot(xc,yc,x,y);

int main(void)

/* request auto detection */

int xc,yc,r,gdriver = DETECT, gmode, errorcode;


/* initialize graphics and local variables */

initgraph(&gdriver, &gmode, "C:\\TURBOC3\\BGI");

/* read result of initialization */

errorcode = graphresult();

if (errorcode != grOk) /* an error occurred */

{ printf("Graphics error: %s\n", grapherrormsg(errorcode)); printf("Press any


key to halt:");
getch();

exit(1); /* terminate with an error code */

printf("Enter the values of xc and yc :");

scanf("%d%d",&xc,&yc);

printf("Enter the value of radius :");

scanf("%d",&r);

BresenhamCircle(xc,yc,r);
getch();

closegraph();

return 0;

}
Q12. WAP to implement Midpoint Ellipse algorithm.
Sol: #include<stdio.h>

#include<iostream.h>

#include<dos.h>

#include<conio.h>

#include<math.h>

#include<graphics.h>

void display (int xs1, int ys1, int x, int y);

void ellips1(int xs1,int ys1,int rx, int ry)

int x,y;

float d1,d2,dx,dy;

x = 0; // take start position as (0,ry) y = ry; //

finding decision parameter d1 d1 = pow(ry,2) - (pow(rx,2)

* ry) + (0.25 * pow(rx,2)); dx = 2 * pow(ry,2) * x;

dy = 2 * pow(rx,2) * y;

do // region one

display(xs1,ys1,x,y);

if(d1<0)

x++;

dx = dx + (2 * (pow(ry,2)));

d1 = d1 + dx +(pow(ry,2));

else

x++;

y--;
dx = dx + (2 * (pow(ry,2)));

dy = dy - (2 * (pow(rx,2)));

d1 = d1 + dx - dy + (pow(ry,2));

}while(dx<dy); // change over condition for region-2 do //

region two

display(xs1,ys1,x,y);

if(d2>0)

x = x;

y--;

dy = dy - (2 * (pow(rx,2)));

d2 = d2 - dy + pow(rx,2);

else

x++;

y--;

dy = dy - (2 * (pow(rx,2)));

dx = dx + (2 * (pow(ry,2)));

d2 = d2 +dx - dy + pow(rx,2);

}while(y>0);

void display(int xs,int ys,int x,int y)

putpixel(xs+x,ys+y,WHITE); // plot points by using 4 point symmetry

putpixel(xs-x,ys-y,WHITE);
putpixel(xs+x,ys-y,WHITE);

putpixel(xs-x,ys+y,WHITE);

int main(void)

int xs1,ys1;

float rx1,ry1;

int gd = DETECT,gm; // Initialise the graphics system

initgraph(&gd,&gm,"c:\\turboc3\\bgi");

cout<<"\t\tMidpoint Ellipe Drawing Algorithm\n";

cout<<"Enter the Center Co-ordinates\n";

cout<<"xc = \t";

cin>>xs1;

cout<<"yc = \t";

cin>>ys1;

cout<<"Enter the X Radius\t";

cin>>rx1;

cout<<"Enter the Y Radius\t";

cin>>ry1;

ellips1(xs1,ys1,rx1,ry1);

getch();

closegraph();

return 0;

}
Q13. WAP of 2D Translation, Rotation, Scaling.
Sol: #include<stdio.h>

#include<conio.h>

#include<stdlib.h>

#include<graphics.h>

#include<math.h>

void main()

int gm;

int gd=DETECT;
int x1,x2,x3,y1,y2,y3,nx1,nx2,nx3,ny1,ny2,ny3,c;

int sx,sy,xt,yt,r;

float t;

initgraph(&gd,&gm,"c:\\turboc3\\bgi");

printf("\t program for basic transactions");

printf("\n\t Enter the point of triangle");

setcolor(1);

scanf("%d%d%d%d%d

%d",&x1,&y1,&x2,&y2,&x3,&y3);

line(x1,y1,x2,y2);

line(x2,y2,x3,y3);

line(x3,y3,x1,y1);

getch();

printf("\n 1.Transaction\n 2.Rotation\n

3.Scaling\n 4.exit"); printf("Enter your

choice:");

scanf("Enter your choice:");

scanf("%d",&c);

switch(c)

case 1:

printf("\n Enter the translation factor");

scanf("%d%d",&xt,&yt);

nx1=x1+xt;

ny1=y1+yt;

nx2=x2+xt;

ny2=y2+yt;

nx3=x3+xt;
ny3=y3+yt;

line(nx1,ny1,nx2,ny2);

line(nx2,ny2,nx3,ny3);

line(nx3,ny3,nx1,ny1);

getch();

case 2:

printf("\n Enter the angle of

rotation"); scanf("%d,&r");

t=3.14*r/180;

nx1=abs(x1*cos(t)-y1*sin(t));

ny1=abs(x1*sin(t)+y1*cos(t));

nx2=abs(x2*cos(t)-y2*sin(t));

ny2=abs(x2*sin(t)+y2*cos(t));

nx3=abs(x3*cos(t)-y3*sin(t));

ny3=abs(x3*sin(t)+y3*cos(t));

line(nx1,ny1,nx2,ny2);

line(nx2,ny2,nx3,ny3);

line(nx3,ny3,nx1,ny1);

case 3:

printf("\n Enter the scaling

factor"); scanf("%d

%d",&sx,&sy);

nx1=x1*sx;

ny1=y2*sy;

nx2=x2*sx;

ny2=y2*sy;

nx3=x3*sx;
ny3=y3*sy;

line(nx1,ny1,nx2,ny2);

line(nx2,ny2,nx3,ny3);

line(nx3,ny3,nx1,ny1);

getch();

case 4:

break;

default:

printf("Enter the correct choice");

closegraph();

Q14. WAP of Reflection along Y-axis and Reflection along X-axis.

Sol:
#include<stdio.h>

#include<conio.h>

#include<graphics.h>

#include<stdlib.h>

Void main()
{

int gd=DETECT,gm;

int x1,y1,x2,y2,x3,y3;

int a;

clrscr();

initgraph(&gd,&gm,c:\\turboc3\\bgi”);

printf(“\n enter the coordinates of the triangle”);

scanf(“%d%d%d%d%d%d”,&x1,&y1,&x2,&y2,&x3,&y3);

line(x1,y1,x2,y2);

line(x2,y2,x3,y3);

line(x3,y3,x1,y1);

line(320,0,320,430);

line(0,240,640,240);

printf(”\n enter 1 for x axis and 2 for y axis for reflection”);

scanf(“%d”,&a);

if(a==1)

X1=x1;

X2=x2;

X3=x3;

Y1=y1+240;

Y2=y2+240;

Y3=y3+240;

Else

If(a==2)

{
Y1=y1;

Y2=y2;

Y3=y3;

X1+=320;

X2+=320;

X3+=320;

Printf(“\n triangle after reflection”);

line(x1,y1,x2,y2);

line(x2,y2,x3,y3);

line(x3,y3,x1,y1);

getch();

closegraph();

}
Q17. WAP of 3d Translation, Rotation, Scaling of an object.
Sol: /* 3d Translation */

#include<stdio.h>

#include<conio.h>

#include<graphics.h>

#include<math.h>

int maxx,maxy,midx,midy;

void axis()

cleardevice();

line(midx,0,midx,midy);

line(0,midy,maxx,midy);

void main()

getch();
{

int gd,gm,x,y,z,ang,x1,x2,y1,y2;

detectgraph(&gd,&gm);

initgraph(&gd,&gm,"c:\\turboc3\\bgi");

setfillstyle(9,30);

maxx=getmaxx();

maxy=getmaxy();

midx=maxx/2;

midy=maxy/2;

outtextxy(100,100,"Original object");

line(midx,0,midx,maxy);

line(0,midy,maxx,midy);

bar3d(midx+100,midy-20,midx+60,midy-

90,20,5); axis();

outtextxy(100,20,"Translation");

printf("\n\n Enter the Translation vector:");

scanf("%d%d",&x,&y);

bar3d(midx+100,midy-20,midx+60,midy-90,20,5);

bar3d(midx+(x+100),midy-(y+20),midx+(x+60),midy-

(y+90),20,5); axis();

outtextxy(100,20,"Scaling");

printf("\n Enter the Scaling Factor:");

scanf("%d%d%d",&x,&y,&z);

bar3d(midx+100,midy-20,midx+60,midy-90,20,5);

bar3d(midx+(x*100),midy-(y*20),midx+(x*60),midy-

(y*90),20*z,5); axis();

outtextxy(100,20,"Rotation");

printf("\n Enter the Rotation angle:");


scanf("%d",&ang);

x1=100*cos(ang*3.14/180)-

20*sin(ang*3.14/180);

y1=100*sin(ang*3.14/180)+20*sin(ang*3.

14/180); x2=100*cos(ang*3.14/180)-

90*sin(ang*3.14/180);

y2=100*sin(ang*3.14/180)+90*sin(ang*3.

14/180); axis();

printf("\n After rotating about z-axis\n");

bar3d(midx+100,midy-20,midx+60,midy-90,20,5);

bar3d(midx+x1,midy-y1,midx+x2,midy-y2,20,5);

axis();

printf("\n After rotating about x-xaxis\n");

bar3d(midx+100,midy-20,midx+60,midy-90,20,5);

bar3d(midx+100,midy-x1,midx+60,midy-x2,20,5);

axis();

printf("\n After rotating about y-axis\n");

bar3d(midx+100,midy-20,midx+60,midy-90,20,5);

bar3d(midx+x1,midy-20,midx+x2,midy-90,20,5);

axis();

closegraph();
}
Q18. WAP using the Floodfill function.
Sol: #include<iostream.h>

#include<graphics.h>
#include<dos.h>

void floodFill(int x,int y,int oldcolor,int newcolor)

if(getpixel(x,y) == oldcolor)

putpixel(x,y,newcolor);

floodFill(x+1,y,oldcolor,newcolor);

floodFill(x,y+1,oldcolor,newcolor);

floodFill(x-1,y,oldcolor,newcolor);

floodFill(x,y-1,oldcolor,newcolor);

//getpixel(x,y) gives the color of specified pixel

int main()

int gm,gd=DETECT,radius;

int x,y;

cout<<"Enter x and y positions for

circle\n"; cin>>x>>y;

cout<<"Enter radius of circle\n";

cin>>radius;

initgraph(&gd,&gm,"c:\\turboc3\

\bgi"); circle(x,y,radius);

floodFill(x,y,0,15);
delay(5000);

closegraph();

return 0;

Q19. WAP of animation. To draw a car and move it in a horizontal direction.


Sol: #include<iostream.h>

#include<conio.h>

#include<graphics.h>

#include<dos.h>

void main()

clrscr();

int gd=DETECT,gm;

initgraph(&gd,&gm,"C:\\turboc3\\bgi");

for (int

i=0;i<500;i++) {

/***CAR BODY ******/

line(50+i,370,90+i,3

70);

arc(110+i,370,0,180,

20);

line(130+i,370,220+i,3

70);

arc(240+i,370,0,180,20

);
line(260+i,370,300+i,3

70);

line(300+i,370,300+i,3

50);

line(300+i,350,240+i,3

30);

line(240+i,330,200+i,3

00);

line(200+i,300,110+i,3

00);

line(110+i,300,80+i,33

0);

line(80+i,330,50+i,340

);

line(50+i,340,50+i,370

);

/***CAR Windows***/

line(165+i,305,165+i,3

30);

line(165+i,330,230+i,3

30);

line(230+i,330,195+i,3

05);

line(195+i,305,165+i,3

05);

line(160+i,305,160+i,3

30);

line(160+i,330,95+i,33

0);
line(95+i,330,120+i,30

5);

line(120+i,305,160+i,305);

/**Wheels**/

circle(110+i,370,17);

circle(240+i,370,17);

delay(10);

cleardevice();

line(0,390,639,390); //ROAD

getch();

}
Q20. WAP to fill polygon using Fillpoly Function.

Sol: /* C Implementation for fillpoly() */

#include<stdio.h>

#include<conio.h>

#include<graphics.h>

// driver code

int main(){

// Here gm1 is Graphics mode which is a computer

display mode that // produces image using pixels.

DETECT is a macro defined in // "graphics.h" header

file

int gd = DETECT, gm;

// Different coordinates for polygon

int arr[] = {320, 150, 400, 250, 250, 350, 320, 150};

// Here initgraph initializes the

// graphics system by loading a


// graphics driver from disk

initgraph(&gd,&gm,"c://turboc3//bgi");

// fillpoly function

fillpoly(4, arr);

getch();

// Here closegraph function closes the

// graphics mode and deallocates

// all memory allocated by

// graphics system .

closegraph();

return 0;

Q21. WAP using Fillstyle Function.


Sol: #include<graphics.h>
#include<conio.h>

main()

int gd = DETECT, gm;

initgraph(&gd, &gm, "C:\\TC\\BGI");

setfillstyle(XHATCH_FILL, RED);

circle(100, 100, 50);

floodfill(100, 100, WHITE);

getch();

closegraph();

return 0;

Q22. WAP for 4-connected Floodfill.


Sol: #include<stdio.h>

#include<graphics.h>

#include<dos.h>
#include<conio.h>

void floodfill(int x,int y,int old,int newcol)

int current;

current=getpixel(x,y);

if(current==old)

delay(5);

putpixel(x,y,newcol);

floodfill(x+1,y,old,newcol);

floodfill(x-1,y,old,newcol);

floodfill(x,y+1,old,newcol);

floodfill(x,y-1,old,newcol);

floodfill(x+1,y+1,old,newcol);

floodfill(x-1,y+1,old,newcol);

floodfill(x+1,y-1,old,newcol);

floodfill(x-1,y-1,old,newcol);

void main()

int gd=DETECT,gm;

initgraph(&gd,&gm,"C:\\TURBOC3\\B

GI"); rectangle(50,50,150,150);

floodfill(70,70,0,15);

closegraph();

}
Q23. WAP for 8 connected Flood Fill.
Sol: #include<stdio.h>

#include<graphics.h>

#include<conio.h>

#include<dos.h>

void floodfill(int x,int y,int old,int newcol)

int current;

current=getpixel(x,y);

if(current==old)

delay(5);

putpixel(x,y,newcol);

floodfill(x+1,y,old,newcol);

floodfill(x-1,y,old,newcol);

floodfill(x,y+1,old,newcol);

floodfill(x,y-1,old,newcol);

floodfill(x+1,y+1,old,ne

wcol); floodfill(x-
1,y+1,old,newcol);

floodfill(x+1,y-

1,old,newcol);

floodfill(x-1,y-

1,old,newcol);

void main()

int gm,gd=DETECT;

initgraph(&gd,&gm,"c\\turbo3\\

bgi");

rectangle(50,50,150,150);

floodfill(70,70,0,15);

getch();

closegraph();

Q24.Draw Bezier Curve.


Sol: #include<graphics.h>

#include<math.h>

#include<conio.h>

#include<stdio.h>

void main()

int x[4],y[4],i;

double put_x,put_y,t;

int gr=DETECT,gm;

initgraph(&gr,&gm,"c:\\turboc3\\bgi");

printf("\n****** Bezier curve **********");

printf("\n Please enter x and y coordinates ");

for(i=0;i<4;i++)

scanf("%d%d", &x[i],&[i]);

putpixel(x[i],y[i],3); //Control Points

for(t=0.0;t<=1;t=t+0.001) // t always lies between 0 and 1

put_x = pow(1-t,3)*x[0] + 3*t*pow(1-t,2)*x[1] + 3*t*t*(1-t)*x[2]+


pow(t,3)*x[3]; // Formula to draw curve

put_y = pow(1-t,3)*y[0] + 3*t*pow(1-t,2)*y[1] + 3*t*t*(1-t)*y[2]+ pow(t,3)*y[3];

putpixel(put_x,put_y, WHITE); // putting pixel

getch();

closegraph();

}
Q25 Basics of Blender Software

RENDERING:
A rendering is a pictorial output of a 3D scene or object. Features like materials,
lighting, oversampling and shadows control the effects and quality of the
rendering. The more of these features you add, the more realistic your scene
become, but also lengthens rendering times.

Materials and Textures:


You can control the way an object appears by applying color and textures.
Materials provide realism with added effects. You can control glossiness
(specularity), self-emitting lighting characteristics, transparency and pattern
repetition. Ray-tracing can provide reflection (mirror) and refraction
(transparency) effects. Textures can be made from any scanned photograph or
drawn object in an image-editing or painting-type program. Images in almost
any format (jpeg, bitmap, png) can be used. Blender also has many built-in
texture generators that can simulate a variety of surface characteristics such as
wood, marble, clouds, waves and surface roughness.

Lighting:
Lighting provides the realism to your scene through reflections and shadows. You
can control the type of light, intensity and color. Some lights can give a “fog” or
“dusty” look with a halo or volume lighting effect. Illumination distances can also
be set.

Cameras:
Your camera is your point-of-view for the scene. Just like a real camera, you can
control lens length to achieve close-ups or wide angles. Clipping distance can
also be set to control how far and near the camera sees. Depth-of-field can
be controlled using nodes.

ANIMATION:
An animation is a series of rendered images that form a movie. The quality of
your movie is controlled by all of the above mentioned features including frames
per second (fps), output size, file type and compression. The most common
The method of animation is called key-framing. Key frames are created at various
points in the animation while the computer generates all of the transition frames
between the two keys. Basic animation options include changing size, rotation
and location of objects.

Q26 Draw Sharp edge over plane

1. Delete the cube and go to mesh and add plane

2. go to edit mode (by pressing tab or switch from the menu)

3. Subdivide the plane by clicking left mouse button multiple times


until the plane is subdivided into smaller parts

4. go to proportional editing object option and switch on it

6. Select the point/pixel on the plane and go to the proportional


editing object option and take any shape which you want to apply on
the plane.

7. Press G and translate the point in upward direction


8. Apply the steps 6-7 multiple times to create multiple sharp edges
over the plane

9. go to object mode((by pressing tab or switch from the menu)

10. go to material and select the color which you want to apply over
the object

11. Finally render it by pressing F12 or from the menu bar button

Q27 . Draw smooth bouncing balls over a surface

1. Take a plane and give it the shape of a base.


2. take UV sphere and give shape= smooth
3. move one sphere towards the top and press I and click on
LOCROTSCALE
4. press red button near the animation play button
5. repeat the above step multiple times
6. apply above steps to other UV sphere also
7. goto material and give them color
8. finally animate them

Q28 Draw a Mug using Blender

1. delete the cube and add cylinder

2. zoom it and click on smooth in object tool

3. goto edit mode

4. click on center point on the top of the mug and delete faces

5. goto object mode

6. add solidify modifier and set thickness= 0.100

7. subdivide the mug 4 to 5 times by pressing ctrl + R

8. create handle of the mug

9. goto material and click on new and add image texture


10. apply image texture on the mug

11. render it

Q29 Draw coloured pencils using Blender


Q30 Draw Bezier Curve
1. Delete the default cube

2. press 5 and then 7

3. goto mesh and add bezier curve and zoom it

4. goto edit mode

5. press A to select or deselect the object

6. click left mouse button to the centre dot of the left handler

7. press G and drag mouse

8. press A to deselect

9. again do above steps for all the handlers

10. press E to extrude the shape of the curve

11. subdivide the curve by pressing W and give the shape to the

curve12. goto object mode and render it

You might also like