Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Computer Graphics Practical File

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 13

DEPARTMENT OF COMPUTER SCIENCE & APPLICATIONS

KURUKSHETRA UNIVERSITY, KURUKSHETRA

|| योगस्थ: कुरु कर्माणि ||


समबुद्धि व योग युक्त होकर कर्म करो

Master of Science (M.Sc.) Computer Science (Software) (CBCS)

PRACTICAL FILE
BASED ON

DATA MINING AND ANALYTICS USING R (MS-20-31)


MS-20-35

SUBMITTED BY: SUBMITTED TO:

CHANDERHASS MS. KOMAL SHARMA

ROLL NO.:15

UNIVERSITY ROLL NO.: 4170013

MSc C.S. III SEM


Index

S.No Topic Page No


1 Write a program to draw a stickman.
2 Write a program to draw an emoji-smilee
3 Write a program to draw a grid using line function.
4 Write a program to draw a line using DDA Line Algorithm.
5 Write a program to draw a line using Bresenhem Line
Algorithm.
6 Write a program to draw a circle using midpoint algorithm.
7 Write a program to draw a circle using Bresenhem Algorithm.
8 Write a program to draw an ellipse using Midpoint Algorithm.
9 Write a program to draw Bezier Curve.
10 Write a program for point clipping.
11 Write a program for line clipping using Cohen-Sutherland
Algorithm.
12 Write a program for polygon clipping using Sutherland-
Hodgeman Algorithm.
13 Write a program for color filling using flood fill algorithm.
14 Write a program for 2D transformation of a triangle.
15 Write a program for 3D transformation of Cube.
Program-1 : Write a Program to draw a Stickman.

#include<graphics.h>

#include<iostream.h>

#include<stdlib.h>

#include<stdio.h>

#include<conio.h>

void main()

int gd=DETECT,gm;

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

//for head

ellipse(320,95,360,0,25,20);

line(298,85,341,85);

circle(310,90,2);

circle(330,90,2);

arc(320,100,200,-20,10);

//for neck

line(313,115,313,125);

line(328,115,328,125);

//For centre part

arc(320,225,72,107,100);

line(290,129,290,200);

line(350,129,350,200);

line(290,193,350,193);

line(290,200,350,200);
//for legs

line(290,200,285,280);

line(320,225,305,280);

line(322,225,335,280);

line(350,200,355,280);

//for right hand

line(290,129,255,165);

line(255,165,290,200);

line(290,149,275,165);

line(275,165,290,182);

//for left hand

line(350,129,385,165);

line(385,165,350,200);

line(350,149,365,165);

line(365,165,350,182);

getch();

closegraph();

}
Program-2: Write a program to draw a Rectangle using Line Function.

#include<iostream.h>

#include<graphics.h>

#include<conio.h>

void main()

int gd=DETECT,gm;

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

line(300,100,500,100);

line(300,100,300,200);

line(300,200,500,200);

line(500,100,500,200);

getch();

Program 3: Write a program to draw a line using DDA Line Algorithm.

#include<iostream.h>

#include<math.h>

#include<conio.h>

#include<graphics.h>

void main()

int i,gd=DETECT,gm;

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

int x0,x1,y0,y1;

float x,y,dx,dy,steps;
x0=100,y0=200,x1=500,y1=300;

dx=(float)(x1-x0);

dy=(float)(y1-y0);

if(dx >= dy)

steps=dx;

else{

steps=dy;

dx=dx/steps;

dy=dy/steps;

x=x0;

y=y0;

i=1;

while(i<= steps)

putpixel(x,y,5);

x+=dx;

y+=dy;

i=i+1;

getch();

closegraph();

}
Program 4: Write a program to draw a line using Bresenhem Line Algorithm.

#include<iostream.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;

getch();

int main()

int gdriver=DETECT, gmode, error, x0, y0, x1, y1;

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

cout<<"Enter co-ordinates of first point: ";

cin>>x0>>y0;

cout<<"Enter co-ordinates of second point: ";

cin>>x1>>y1;

drawline(x0, y0, x1, y1);

return 0;

}
Program 5: Write a program to draw a circle using midpoint algorithm.

#include<iostream.h>

#include<graphics.h>

#include<conio.h>

void drawcircle(int x0, int y0, int radius)

int x = radius;

int y = 0;

int p = 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 (p <= 0)

y += 1;

p+= 2*y + 1;

if (p > 0)

x -= 1;

p -= 2*x + 1;

getch();

int main()

int gd=DETECT, gm, p, x, y, r;

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

cout<<"Enter radius of circle: ";

cin>>r;

cout<<"Enter co-ordinates of center(x and y): ";

cin>>x>>y;

drawcircle(x, y, r);

return 0;
}

Program 6: Write a program to draw a circle using Bresenhem Algorithm.

#include<iostream.h>

#include<conio.h>

#include<graphics.h>

void drawCircle(int x, int y, int xc, int yc);

void main()

int gd = DETECT, gm;

int r, xc, yc, p, x, y;

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

cout<<"Enter the center co-ordinates\n";

cin>>xc>>yc;

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

cin>>r;

p = 3 - 2*r;

x=0; y = r;

drawCircle(x,y,xc,yc);

while(x < y)
{

if(p <= 0)

p= p + (4*x) + 6;

drawCircle(++x,y,xc,yc);

else

p = p + (4*(x-y)) + 10;

drawCircle(++x,--y,xc,yc);

getch();

closegraph();

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

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

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

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

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

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

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

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

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

}
Program 7: Write a program to draw an ellipse using Bresenham Algorithm.

Program 8: Write a program to draw an ellipse using Midpoint Algorithm.

Program 9: Write a program to draw Bezier Curve.

Program 10: Write a program for point clipping.

Program 11: Write a program for line clipping using Cohen-Sutherland Algorithm.

Program 12: Write a program for polygon clipping using Sutherland-Hodgemann Algorithm.

Program 13: Write a program for area filling.

Program 14: Write a program for 2D transformation of a triangle.

Program 15: Write a program for 3D transformation of Cube.

You might also like