Professional Documents
Culture Documents
delay(50);
int main() {
int gd = DETECT, gm;
int i, x, y, flag=0;
initgraph(&gd, &gm, "C:\\TC\\BGI");
while (!kbhit()) {
if(y >= getmaxy()-60 || y <= 60)
flag = !flag;
/* draws the gray board */
setcolor(RED);
setfillstyle(SOLID_FILL, YELLOW);
circle(x, y, 60);
floodfill(x, y, RED);
/* clears screen */
cleardevice();
if(flag){
y = y + 5;
} else {
y = y - 5;
}
}
getch();
closegraph();
return 0;
}
void main(){
int gd=DETECT,gm;
int i,x,y,j;
initgraph(&gd,&gm,"C:\\TC\\BGI");
// man
for(j=1;j<600;j=j+5)
{
line(0,400,800,400);
circle(30+j,280,20); //head
line(30+j,300,30+j,350); //body
line(30+j,330,70+j,330); //hand
if(j%2==0){
line(30+j,350,25+j,400); //left leg
line(30+j,350,10+j,400); // right
}
else{
line(30+j,350,35+j,400); //transition
delay(20);
}
//umbrela
line(70+j,250,70+j,330);
pieslice(70+j,250,180,0,80);
// rain
for(i=0;i<300;i++)
{
x=random(800);
y=random(800);
outtextxy(x,y,"/");
}
delay(170);
cleardevice();
}
getch();
closegraph();
}
EN20CS301423 Shreyash Jain
Practical 8
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:\\tc\\bgi");
return 0;
}
Practical 11
EN20CS301423 Shreyash Jain
Aim:- Write a program to draw a circle using Bresenham’s Algorithm.
#include <stdio.h>
#include <dos.h>
#include <graphics.h>
x++;
// Driver code
int main()
{
int xc = 200, yc = 200, r = 80;
int gd = DETECT, gm;
initgraph(&gd, &gm, "C:\\TC\\BGI"); // initialize graph
circleBres(xc, yc, r); // function call
return 0;
}
Practical 12
EN20CS301423 Shreyash Jain
Aim:- Write a program to implement 3 basic transformation.
Translation:-
/* translation */
#include<conio.h>
#include<graphics.h>
#include<stdio.h>
void main()
{
int gd=DETECT,gm;
int x,y,x1,y1,x2,y2,tx,ty;
clrscr();
initgraph(&gd,&gm,"C:\\TC\\BGI");
printf("\n Please enter first coordinate of the triangle= ");
scanf("%d %d", &x,&y);
printf("\n Enter second coordinate of the trinagle = ");
scanf("%d %d",&x1,&y1);
printf("\n Enter third coordinate of the triangle = ");
scanf("%d %d",&x2,&y2);
printf("\n\t\t********** TRIANGLE before & after translation ***********");
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);
line(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);
getch();
closegraph();
}
line(x,y,x1,y1);
line(x1,y1,x2,y2);
line(x2,y2,x,y);
getch();
closegraph();
}
Rotation :-
#include<stdio.h>
#include<graphics.h>
#include<math.h>
main()
{
int gd=0,gm,x1,y1,x2,y2,x3,y3;
double s,c, angle;
initgraph(&gd, &gm, "C:\\TC\\BGI");
setcolor(RED);
printf("Enter coordinates of triangle: ");
scanf("%d%d%d%d%d%d",&x1,&y1,&x2,&y2, &x3, &y3);
setbkcolor(WHITE);
cleardevice();
EN20CS301423 Shreyash Jain
line(x1,y1,x2,y2);
line(x2,y2, x3,y3);
line(x3, y3, x1, y1);
getch();
setbkcolor(BLACK);
printf("Enter rotation angle: ");
scanf("%lf", &angle);
setbkcolor(WHITE);
c = cos(angle *M_PI/180);
s = sin(angle *M_PI/180);
x1 = floor(x1 * c + y1 * s);
y1 = floor(-x1 * s + y1 * c);
x2 = floor(x2 * c + y2 * s);
y2 = floor(-x2 * s + y2 * c);
x3 = floor(x3 * c + y3 * s);
y3 = floor(-x3 * s + y3 * c);
cleardevice();
line(x1, y1 ,x2, y2);
line(x2,y2, x3,y3);
line(x3, y3, x1, y1);
getch();
closegraph();
return 0;
}
int main()
{
int gm,gd=DETECT,radius;
int x,y;
printf("Enter x and y positions for circle\n");
scanf("%d%d",&x,&y);
printf("Enter radius of circle\n");
scanf("%d",&radius);
initgraph(&gd,&gm,"c:\\tc\\bgi");
circle(x,y,radius);
boundaryfill(x,y,4,15);
delay(5000);
closegraph();
return 0;
}