Documente Academic
Documente Profesional
Documente Cultură
ye=y2; }
else
{
x=x2;
y=y2;
ye=y1; }
putpixel(x,y,c);
for(i=0;y<ye;i++)
{
y=y+1;
if(py<=0)
{
py=py+2*dx1; }
else
{
if((dx<0 && dy<0) || (dx>0 && dy>0))
{ x=x+1;}
else
{
x=x-1;}
py=py+2*(dx1-dy1);
putpixel(x,y,c);
} }}
void main()
{
int gd = DETECT, gm;
int dx, dy, p, end;
float x1, x2, y1, y2;
initgraph(&gd, &gm, "c:\tc\bgi");
cout<<"Enter the coordinates (x1,y1): ";
cin>>x1>>y1;
cout<<"Enter the coordinates (x2,y2): ";
cin>>x2>>y2;
cleardevice();
bhm_line(x1,y1,x2,y2,2);
getch();
closegraph();}
111318
Sumit Gupta
closegraph();}
111318
Sumit Gupta
circle(50,50,30);
t=bfilll(x,y,fco,bco);
t=bfillr(x-1,y,fco,bco);
getch();
return;
}
else if(ch==3){
outtext("after translation by 100 towards bottom");
rectangle(100,250,400,450);}
getch();
}
Ques 11. Program to demonstrate view port, clipping and lines with
different Colors, line styles and co- ordinates
#include<graphics.h>
#include<conio.h>
#include<stdlib.h>
#include<dos.h>
#include<stdio.h>
void main()
{
int gm,gd=DETECT;
int x1,x2,y1,y2,c,i,k=0;
clrscr();
printf("enter starting coordinates of viewport\n");
scanf("%d%d",&x1,&y1);
printf("enter ending coordinates of viewport\n");
scanf("%d%d",&x2,&y2);
initgraph(&gd,&gm,"..\\BGI");
rectangle(x1,y1,x2,y2);
setviewport(x1,y1,x2,y2,1);
while(k<=10)
{
k++;
111318
Sumit Gupta
x1=rand()%getmaxx();
x2=rand()%getmaxx();
y1=rand()%getmaxy();
y2=rand()%getmaxy();
setcolor(k+1);
line(x1,y1,x2,y2);
delay(200);
}
getch();
closegraph();
}
setcolor(2);
settextstyle(4,1,7);
outtextxy(100,150,"Computer Graphics");
getch();
}
Ques 13. Program to draw a moving vehicle (car). The different graphical
functions and transformations are used to draw different parts and
movements of the car.
#include<dos.h>
#include<conio.h>
#include<graphics.h>
#include<stdlib.h>
#define PI 3.14159
void draw_wheel(int x,int y,int theta)
{
int incr=45;
double i;
setcolor(getmaxcolor());
setfillstyle(EMPTY_FILL,getmaxcolor());
for( i=theta;i<theta+360.0;i+=2*incr)
{
sector(x,y,i,i+incr,20,20);
arc(x,y,i+incr,i+2*incr,20);
}
}
void draw_car(int ang)
{
int car_color=RED;
draw_wheel(50,200,ang);
draw_wheel(200,200,ang);
setcolor(car_color);
line(0,80,639,80);
line(0,300,639,300);
line(25,200,0,200);
line(0,200,0,160);
line(0,160,40,160);
line(40,160,70,130);
line(70,130,170,130);
line(170,130,200,160);
line(200,160,260,160);
line(260,160,260,200);
line(260,200,225,200);
line(175,200,75,200);
111318
Sumit Gupta
arc(50,200,0,180,25);
arc(200,200,0,180,25);
setfillstyle(SOLID_FILL,car_color);
floodfill(150,170,car_color);
}
void main(void)
{
int gd,gm,i,j;
void *bitmap1,*bitmap2;
detectgraph(&gd,&gm);
initgraph(&gd,&gm,"c:\\tc ");
draw_car(0);
bitmap1=malloc(imagesize(0,130,270,230));
getimage(0,130,270,230,bitmap1);
putimage(0,130,bitmap1,XOR_PUT);
draw_car(22);
bitmap2=malloc(imagesize(0,130,270,230));
getimage(0,130,270,230,bitmap2);
putimage(0,130,bitmap2,XOR_PUT);
for(i=0;!kbhit();i+=10)
{
if(i>500) i=0;
putimage(i,130,bitmap1,OR_PUT);
delay(100);
putimage(i,130,bitmap1,XOR_PUT);
putimage(i+5,130,bitmap2,OR_PUT);
delay(50);
putimage(i+5,130,bitmap2,XOR_PUT);
}
closegraph();}
scanf("%d%d",&x,&y);
cleardevice();
for(i=0;i<n;i++)
{
delay(50);
setcolor(14);
arc(x,y,0,180,r=r+2);
arc(x+2,y,180,360,r=r+2);
}
getch();
closegraph();
}
Input
25 rings
Origin center
111318
Sumit Gupta