Booking open Available Pune Call Girls Nanded City 6297143586 Call Hot India...
Â
Graphic Design Lab File.docx
1. Department of Computer Science and
Engineering
Computer Graphics
Lab File
Submitted to: Submitted By: -
Prof. Nidhi Srivastava Payal Jindal
(T114)
2. Page | 2
Table of Content
S.No. Program Name Page
No.
1. Write a program to study and implementations of graphic functions
and VGA standards. Draw line, circle, ellipse, arc, sector, and bar using
inbuilt functions in switch statement
3
2. Write a Program using inbuilt function for the followings:
1. Display coordinates axes.
2. Display nested circles.
3. Display nested rectangles.
10
3. Write a Program using inbuilt function for the followings:
1. Display different colorful shapes.
2. Display a string “Hello User” in the centre of the screen using
Outtextxy() function.
11
4. Write a Program to make bar chart and pie chart for students for five
subjects
12
5. Write a Program to revolve a coin on a table 15
6. Write a Program to design flying colored balloons 16
7. Write a program to implement scan convert line using DDA Algorithm. 19
8. Write a program to implement scan convert line using Bresenhem
Algorithm.
21
9. Write a Program to scan convert circle using Mid-point algorithm 23
10. Write a program to implement scan convert Circle using Bresenhem
Algorithm.
25
11. Write a Program to scan convert ellipse using Mid-point algorithm 27
12. Write a Program to implement Cohen and Sutherland line clipping
algorithm
28
13. Write a Program to get the Translation vector, Rotation vector and
Scaling vector from the user and translate, rotate and scale the triangle
accordingly
34
3. Page | 3
1. Write a program to study and implementations of graphic
functions and VGA standards. Draw line, circle, ellipse, arc,
sector, and bar using inbuilt functions in switch statement.
CODE:-
#include<stdio.h>
#include<graphics.h>
#include<dos.h>
#include<stdlib.h>
#include<conio.h>
int main()
{
int gd=DETECT, gm;
int s;
initgraph(&gd,&gm,"C:Turboc3BGI");
printf("ENTER THE NUMBER TO PRINTn");
printf(" 1 FOR LINEn 2 FOR CIRCLEn 3 FOR ELLIPSEn");
printf(" 4 FOR ARCn 5 FOR SECTORn 6 FOR BARnENTER:");
scanf("%d",&s);
switch(s)
{
case 1:
outtextxy(260,150,"****LINE****");
line(150,300,500,300);
break;
case 2:
outtextxy(260,150,"****CIRCLE****");
circle(300,300,100);
break;
case 3:
outtextxy(260,150,"****ELLIPSE****");
ellipse(290,300,0,360,100,50);
break;
case 4:
outtextxy(260,150,"****ARC****");
arc(400,300,120,250,100);
break;
case 5:
outtextxy(260,150,"****SECTOR****");
sector(200,200,30,120,90,85);
break;
7. Page | 7
2.Write a Program using inbuilt function for the followings:
i) Display coordinates axes.
CODE:-
#include<stdio.h>
#include<graphics.h>
#include<math.h>
int main()
{
int gd=DETECT,gm;
//float m;
int midx,midy;
initgraph(&gd,&gm,"C:Turboc3BGI");
midx=getmaxx()/2;
midy=getmaxy()/2;
line(midx,0,midx,getmaxy());
line(0,midy,getmaxx(),midy);
getch();
closegraph();
return 0;
}
OUTPUT:-
8. Page | 8
ii)Display nested circles.
CODE:-
#include<stdio.h>
#include<graphics.h>
#include<conio.h>
int main()
{
int gd = DETECT,gm;
int x ,y;
initgraph(&gd, &gm, "C:Turboc3BGI");
x = getmaxx()/2;
y = getmaxy()/2;
outtextxy(240, 50, "Concentric Circles");
setcolor(WHITE);
circle(x, y, 30);
setcolor(GREEN);
circle(x, y, 50);
setcolor(RED);
circle(x, y, 70);
setcolor(YELLOW);
circle(x, y, 90);
getch();
closegraph();
return 0;
}
OUTPUT:-
10. Page | 10
3. Write a Program using inbuilt function for the followings:
i) Display different colorful shapes.
CODE:-
#include<graphics.h> #include<conio.h>
#include<stdio.h>
int main()
{
int gd=DETECT,gm;
initgraph (&gd,&gm,"c:turboc3BGI");
setbkcolor(BLACK);
setcolor(BLUE);
printf("tttnnLINE");
line(50,40,190,40);
setcolor(GREEN);printf("ttnnnnRECTANGLE");
rectangle(125,115,215,165);
setcolor(WHITE);
printf("tttnnnnnnnARC");
arc(120,200,180,0,30);
setcolor(YELLOW);
printf("tnnnnCIRCLE");
circle(120,270,30);
setcolor(BROWN);
printf("tnnnnECLIPSE");
ellipse(120,350,0,360,30,20);
getch();
closegraph();
return 0;
}
OUTPUT:-
11. Page | 11
ii) Display a string “Hello User” in the centre of the screen
using Outtextxy() function.
CODE:-
#include <graphics.h>
#include<stdio.h>
#include<conio.h>
int main()
{
int gd = DETECT, gm;initgraph(&gd, &gm, (char*)"C:Turboc3BGI");
outtextxy(200, 150, "Hello User");
getch();
closegraph();
return 0;
}
OUTPUT:-
12. Page | 12
4. Write a Program to make bar chart and pie chart for students for
five subjects
CODE:-
#include <graphics.h>
#include <conio.h>
#include<stdio.h>
int main()
{
int gd = DETECT, gm;
int s, midx, midy, o,e,c,w;float total,o1,e1,c1,w1, o2,e2,c2,w2;
initgraph(&gd, &gm,"C:Turboc3BGI " );
printf("ENTER THE NUMBER TO PRINTn");
printf(" 1 FOR BARGRAPH:");
printf(" 2 FOR PIE CHART:");
scanf("%d",&s);
switch(s)
{
case 1:
outtextxy(275,0,"BAR GRAPH");
setlinestyle(SOLID_LINE,0,2);
line(90,410,90,50);
line(90,410,590,410);
line(85,60,90,50);
line(95,60,90,50);
line(585,405,590,410);
line(585,415,590,410);
outtextxy(65,60,"Y");
outtextxy(570,420,"X");
outtextxy(70,415,"O");
setfillstyle(XHATCH_FILL, GREEN);
bar(150,80,200,410);
bar(225,100,275,410);
bar(300,120,350,410);
bar(375,170,425,410);
bar(450,135,500,410);
break;
case 2:
midx = getmaxx() / 2;
midy = getmaxy() / 2;
printf("Enter the marks for Operaing System: ");
scanf("%d",&o);
printf("Enterthe marks for E-Commerce: ");
scanf("%d",&e);
34. Page | 34
13. Write a Program to get the Translation vector, Rotation vector and
Scaling vector from the user and translate, rotate and scale the triangle
accordingly
CODE:-
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<dos.h>
#include<graphics.h>
#include<process.h>
#include<math.h>
int main(void)
{
int ps,x,y,x1,y1,x2,y2,tx,ty,mx,my,d,x3,y3;
int a1,a2,a3,b1,b2,b3,sa,sb;
double s,c, angle;
int gd=DETECT,gm;
initgraph(&gd,&gm,"C:Turboc3BGI");
printf("ENTER THE COORDINATES");
printf("n Enter first coordinate of the triangle: ");
scanf("%d %d", &x,&y);
printf("n Enter second coordinate of the triangle: ");
scanf("%d %d",&x1,&y1);
printf("nEnter third coordinate of the triangle: ");
scanf("%d %d",&x2,&y2);
printf("ENTER THE NUMBER TO PRINTn");
printf(" 1 To Transition the Triangle n 2 To Rotate the Triangle n 3 To Scale the
Trianglen");
scanf("%d",&ps);
printf("ntt********** TRIANGLE before & after translation ***********");
switch(ps){
case 1:
line(x,y,x1,y1);
line(x1,y1,x2,y2);
line(x2,y2,x,y);
printf("n Now enter the translation vector: ");
scanf("%d%d",&tx,&ty);
setcolor(RED);
ine(x+tx,y+ty,x1+tx,y1+ty);
line(x1+tx,y1+ty,x2+tx,y2+ty);
line(x2+tx,y2+ty,x+tx,y+ty);
break;
case 2:
setcolor(RED);
line(x1,y1,x2,y2);