Computer Graphics Lab
Computer Graphics Lab
#include "graphics.h"
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#include <math.h>
int main() {
int gdriver = DETECT, gmode;
int x1, y1, x2, y2, step, xn, yn, dx, dy;
initgraph( & gdriver, & gmode, NULL);
printf("Enter the starting coordinates\n");
scanf("%d%d", & x1, & y1);
printf("Enter the end coordinates\n");
scanf("%d%d", & x2, & y2);
dx = x2 - x1;
dy = y2 - y1;
if (abs(dx) > abs(dy)) step = abs(dx);
Output:
Bresenham's Line Drawing Algorithm
#include<stdio.h>
#include<graphics.h>
dx = x1 - x0;
dy = y1 - y0;
x = x0;
y = y0;
p = 2 * dy - dx;
int main() {
int gdriver = DETECT, gmode, error, x0, y0, x1, y1;
initgraph( & gdriver, & gmode, "c:\\turboc3\\bgi");
Output:
2.Implementation of Circle Drawing Algorithms.
Bresenham Circle Drawing Algorithm:
#include <stdio.h>
#include <dos.h>
#include <graphics.h>
x++;
if (d > 0) {
y--;
d = d + 4 * (x - y) + 10;
} else
d = d + 4 * x + 6;
drawCircle(xc, yc, x, y);
delay(50);
}
}
int main() {
int xc = 300, yc = 200, r2 = 100;
int gd = DETECT, gm;
initgraph( & gd, & gm, ""); // initialize graph
circleBres(xc, yc, r2);
getch(); // function call
return 0;
}
Output:
Mid-point Circle Drawing Algorithm:
#include<stdio.h>
#include<graphics.h>
while (x >= y) {
delay(50);
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");
return 0;
}
Output:
3.Programs on 2D and 3D Transformations: Translation, Rotation,
Scaling and Shearing of an Object
2D Transformation:
#include<iostream>
#include<graphics.h>
#include<math.h>
Rotation of Rectangle:
Scaling of rectangle:
Shearing of Rectangle:
#include<iostream>
#include<stdlib.h>
#include<math.h>
#include<graphics.h>
#include<dos.h>
using namespace std;
static int LEFT = 1, RIGHT = 2, BOTTOM = 4, TOP = 8, xmin, ymin, xmax, ymax;
int main() {
int gd = DETECT, gm;
initgraph( & gd, & gm, (char * )
"");
setcolor(WHITE);
cout << "Enter window minimum and maximum values";
cin >> xmin >> ymin >> xmax >> ymax;
rectangle(xmin, ymin, xmax, ymax);
int x1, y1, x2, y2;
cout << "Enter the endpoint of the line: ";
cin >> x1 >> y1 >> x2 >> y2;
line(x1, y1, x2, y2);
getch();
int outcode1 = getcode(x1, y1), outcode2 = getcode(x2, y2);
int accept = 0;
while (1) {
float m = (float)(y2 - y1) / (x2 - x1);
if (outcode1 == 0 && outcode2 == 0) {
accept = 1;
break;
} else if ((outcode1 & outcode2) != 0) {
break;
} else {
int x, y;
int temp;
if (outcode1 == 0)
temp = outcode2;
else
temp = outcode1;
if (temp & TOP) {
x = x1 + (ymax - y1) / m;
y = ymax;
} else if (temp & BOTTOM) {
x = x1 + (ymin - y1) / m;
y = ymin;
} else if (temp & LEFT) {
x = xmin;
y = y1 + m * (xmin - x1);
} else if (temp & RIGHT) {
x = xmax;
y = y1 + m * (xmax - x1);
}
if (temp == outcode1) {
x1 = x;
y1 = y;
outcode1 = getcode(x1, y1);
} else {
x2 = x;
y2 = y;
outcode2 = getcode(x2, y2);
}
}
}
cout << "After Clipping";
if (accept)
cleardevice();
rectangle(xmin, ymin, xmax, ymax);
setcolor(RED);
line(x1, y1, x2, y2);
getch();
closegraph();
}
Output
#include<bits/stdc++.h>
#include<graphics.h>
#define round(a)((int)(a+0.5))
using namespace std;
int k;
float xmin,ymin,xmax,ymax,arr[20],m;
void clipleft(float x1,float y1,float x2,float y2)
{
if(x2-x1)
m=(y2-y1)/(x2-x1);
else
m=100000;
if(x1>=xmin && x2>=xmin)
{
arr[k]=x2;
arr[k+1]=y2;
k+=2;
}
if(x1<xmin && x2>=xmin)
{
arr[k]=xmin;
arr[k+1]=y1+m*(xmin-x1);
arr[k+2]=x2;
arr[k+3]=y2;
k+=4;
}
if(x1>=xmin && x2<xmin)
{
arr[k]=xmin;
arr[k+1]=y1+m*(xmin-x1);
k+=2;
}
}
void cliptop(float x1, float y1, float x2, float y2)
{
if(y2-y1)
m=(x2-x1)/(y2-y1);
else
m=100000;
if(y1<=ymax && y2<=ymax)
{
arr[k]=x2;
arr[k+1]=y2;
k+=2;
}
if(y1>ymax && y2<= ymax)
{
arr[k]=x1+m*(ymax-y1);
arr[k+1]=ymax;
arr[k+2]=x2;
arr[k+3]=y2;
k+=4;
}
if(y1<= ymax && y2>ymax)
{
arr[k]=x1+m*(ymax-y1);
arr[k+1]=ymax;
k+=2;
}
}
void clipright(float x1, float y1, float x2, float y2)
{
if(x2-x1)
m=(y2-y1)/(x2-x1);
else
m=100000;
if(x1<=xmax && x2<= xmax)
{
arr[k]=x2;
arr[k+1]=y2;
k+=2;
}
if(x1>xmax && x2<=xmax)
{
arr[k]=xmax;
arr[k+1]=y1+m*(xmax-x1);
arr[k+2]=x2;
arr[k+3]=y2;
k+=4;
}
if(x1<xmax && x2>xmax)
{
arr[k]=xmax;
arr[k+1]=y1+m*(xmax-x1);
k+=2;
}
}
void clipbottom(float x1, float y1, float x2,float y2)
{
if(y2-y1)
m=(x2-x1)/(y2-y1);
else
m=100000;
if(y1>=ymin && y2>=ymin)
{
arr[k]=x2;
arr[k+1]=y2;
k+=2;
}
if(y1<ymin&& y2>=ymin)
{
arr[k]=x1+m*(ymin-y1);
arr[k+1]=ymin;
arr[k+2]=x2;
arr[k+3]=y2;
k+=4;
}
if(y1>=ymin && y2 <ymin)
{
arr[k]=x1+m*(ymin-y1);
arr[k+1]=ymin;
k+=2;
}
}
int main()
{
int gd=DETECT,gm,n,poly[20],i;
float xi,yi,xf,yf,polyy[20];
cout<<"coordinates of rectanglular clip window :\nxmin,ymin:";
cin>>xmin>>ymin;
cout<<"xmax,ymax:";
cin>>xmax>>ymax;
cout<<"\n\n polygon to be clipped:\nnumber of sildes:\n";
cin>>n;
cout<<"enter the coordinates:\n";
for(i=0;i<2*n;i++)
cin>>polyy[i];
polyy[i]=polyy[0];
polyy[i+1]=polyy[1];
for(i=0;i<2*n+2;i++)
poly[i]=round(polyy[i]);
initgraph(&gd,&gm,"");
setcolor(YELLOW);
rectangle(xmin,ymax,ymax,ymin);
setcolor(WHITE);
outtextxy(50,50,"Unclipped Polygon");
fillpoly(n,poly);
getch();
cleardevice();
k=0;
for(i=0;i<2*n;i+=2)
clipleft(polyy[i],polyy[i+1],polyy[i+2],polyy[i+3]);
n=k/2;
for(i=0;i<k;i++)
polyy[i]=arr[i];
polyy[i]=polyy[0];
polyy[i+1]=polyy[1];
k=0;
for(i=0;i<2*n;i+=2)
cliptop(polyy[i],polyy[i+1],polyy[i+2],polyy[i+3]);
n=k/2;
for(i=0;i<k;i++)
polyy[i]=arr[i];
polyy[i]=polyy[0];
polyy[i+1]=polyy[1];
k=0;
for(i=0;i<2*n;i+=2)
clipright(polyy[i],polyy[i+1],polyy[i+2],polyy[i+3]);
n=k/2;
for(i=0;i<k;i++)
polyy[i]=arr[i];
polyy[i]=polyy[0];
polyy[i+1]=polyy[1];
k=0;
for(i=0;i<2*n;i+=2)
clipbottom(polyy[i],polyy[i+1],polyy[i+2],polyy[i+3]);
for(i=0;i<k;i++)
poly[i]=round(arr[i]);
if(k)
fillpoly(k/2,poly);
setcolor(YELLOW);
rectangle(xmin,ymax,xmax,ymin);
outtextxy(50,50,"Clipped Polygon");
getch();
closegraph();
}
Output:
5. Write a program to apply composite scaling and rotation to 2D-
shapes.
Composite 2d transformation:
#include<iostream>
#include<graphics.h>
#include<math.h>
int main() {
int gd, gm, n, i, xa[10], ya[10], op, tx, ty, xa1[10], ya1[10], theta,
xf, yf, rx, ry,
sx, sy, shx, shy, xref, yref;
char d;
gd = DETECT;
initgraph( & gd, & gm, "");
printf("enter the no of points");
scanf("%d", & n);
for (i = 0; i < n; i++) {
printf("enter the coordinates");
scanf("%d%d", & xa[i], & ya[i]);
}
do {
printf("menu");
printf("\n1.rotation\n2.scaling\n3.exit");
scanf("%d", & op);
switch (op) {
case 1:
printf("enter the rotation angle");
scanf("%d", & theta);
theta = (theta * 3.14) / 180;
printf("enter the reference points");
scanf("%d%d", & xf, & yf);
for (i = 0; i < 3; i++) {
xa1[i] = xf + (xa[i] - xf) * cos(theta) - (ya[i] - yf) *
sin(theta);
ya1[i] = yf + (xa[i] - xf) * sin(theta) - (ya[i] - yf) *
cos(theta);
}
cleardevice();
printf("before rotation");
for (i = 0; i < 3; i++) {
line(xa[i], ya[i], xa[(i + 1) % n], ya[(i + 1) % n]);
}
printf("after rotation");
for (i = 0; i < 3; i++) {
line(xa1[i], ya1[i], xa1[(i + 1) % n], ya1[(i + 1) % n]);
}
getch();
cleardevice();
break;
case 2:
printf("enter the scaling factor x and y");
scanf("%d%d", & sx, & sy);
printf("enter the reference point x and y");
scanf("%d%d", & rx, & ry);
for (i = 0; i < 3; i++) {
xa1[i] = xa[i] * sx + rx * (1 - sx);
ya1[i] = ya[i] * sy + ry * (1 - sy);
}
cleardevice();
printf("before scaling");
for (i = 0; i < 3; i++) {
line(xa[i], ya[i], xa[(i + 1) % n], ya[(i + 1) % n]);
}
printf("after scaling");
case 3:
exit(0);
break;
}
} while (op != 3);
}
#include <graphics.h>
int main() {
int gd, gm, x, y, z, ang, x1, x2, y1, y2;
detectgraph( & gd, & gm);
initgraph( & gd, & gm, (char * )
"");
setfillstyle(3, 25);
// Orignal 3D object
bar3d(left, top, right, bottom, depth, topflag);
getchar();
closegraph();
return 0;
}
Output:
7.Write a program to create empty fill, solid fill, line fill, wide dot
fill, close dot fill and user fill using ellipse attribute.
#include <bits/stdc++.h>
#include <graphics.h>
using namespace std;
/*
EMPTY FILL 0
SOLID FILL 1
LINE FILL 2
WIDE DOT FILL 10
CLOSE DOR FILL 11
USER FILL 12
*/
int main() {
int gd = DETECT, gm;
initgraph( & gd, & gm, (char * )
"");
int FILL_STYLE = 0;
while (true) {
cout << "chose fill style: " << endl;
cout << "\t0.EMPTY_FILL\n\t1.SOLID_FILL\n\t2.LINE_FILL\n\
t10.WIDE_DOT_FILL\n\t11.CLOSE_DOT_FILL\n\t12.USER_FILL\n\t6.EXIT" << endl;
cin >> FILL_STYLE;
if (FILL_STYLE == 6) break;
setfillstyle(FILL_STYLE, 1);
ellipse(x, y, 0, 360, xc, yc);
fillellipse(x, y, xc, yc);
delay(1000);
getch();
cleardevice();
}
closegraph();
}
Output
8. Create a Bouncing Ball using key frame animation and path
animation.
#include <bits/stdc++.h>
#include <graphics.h>
using namespace std;
int main() {
int gd = DETECT, gm;
int i, x, y, flag = 0;
initgraph(&gd, &gm, (char *)"");
while (!kbhit())
{
if (y >= getmaxy() - 30 || y <= 30)
flag = !flag;
/* draws the gray board */
setcolor(RED);
setfillstyle(SOLID_FILL, RED);
circle(x, y, 30);
floodfill(x, y, RED);
/* clears screen */
cleardevice();
if (flag)
{
y = y + 5;
}
else
{
y = y - 5;
}
}
getch();
closegraph();
return 0;
}
Output
9. Write a Program to show animation of a ball moving in a helical
path.
#include <stdio.h>
#include <conio.h>
#include <graphics.h>
#include <dos.h>
#include <math.h>
/* manipulates the position of planets on the orbit */
void planetMotion(int xrad, int yrad, int midx, int midy, int x[60], int
y[60]) {
int i, j = 0;
/* positions of planets in their corresponding orbits */
for (i = 360; i > 0; i = i - 6) {
x[j] = midx - (xrad * cos((i * 3.14) / 180));
y[j++] = midy - (yrad * sin((i * 3.14) / 180));
}
return;
}
int main() {
/* request auto detection */
int gd = DETECT, gm, err;
int i = 0, midx, midy;
int xrad[9], yrad[9], x[9][60], y[9][60];
int pos[9], planet[9], tmp;
/* initialize graphic mode */
initgraph(&gd, &gm, "");
/* mid positions at x and y-axis */
midx = getmaxx() / 2;
midy = getmaxy() / 2;
/* manipulating radius of all 9 planets */
planet[7] = 20;
planet[8]=planet[7]+1;
/* offset position for the planets on their corresponding orbit */
for (i = 0; i < 9; i++) {
pos[i] = i * 6;
}
/* orbits for all 9 planets */
xrad[7] = 200, yrad[7] = 20;
xrad[8] = xrad[7] + 30;
yrad[8] = yrad[7] + 15;
}
setcolor(LIGHTRED);
setfillstyle(SOLID_FILL, LIGHTRED);
pieslice(x[8][pos[8]], y[8][pos[8]], 0, 360, planet[8]);
Output:
10. Write a program to show ticking clock using graphics.
#include <bits/stdc++.h>
#include <graphics.h>
using namespace std;
void rotate( int figure[], int edges, double angle, int cx, int cy ) {
double x, y;
angle = -1 * (angle*3.14/180);
double cos_a = cos(angle);
double sin_a = sin(angle);
for (int i=0; i < edges; i++) {
x = figure[2*i] - cx;
y = figure[2*i+1] - cy;
figure[2*i] = floor( (x * cos_a) - (y * sin_a) + cx +
0.5 );
figure[2*i+1] = floor( (x * sin_a)+(y * cos_a) + cy +
0.5 );
}
}
void drawClock(int,int,int);
int main() {
int second_hand[4],minute_hand[4], hour_hand[4], edges = 2 ;
double angle;
int cx=300, cy=200;
int gd = DETECT, gm;
initgraph( &gd, &gm, (char*)"");
int max_y = getmaxy();
cleardevice();
angle = -6;
// Set the initial position of the second, minute and the hour
hands.
second_hand[0] = cx ;
second_hand[1] = max_y - cy;
second_hand[2] = cx;
second_hand[3] = max_y - 320;
hour_hand[0] = cx;
hour_hand[1] = max_y - cy;
hour_hand[2] = cx + 90;
hour_hand[3] = max_y - 200;
minute_hand[0] = cx;
minute_hand[1] = max_y - cy;
minute_hand[2] = cx;
minute_hand[3] = max_y - 310;
cleardevice();
setbkcolor(WHITE);
// Draw the clock
drawClock(cx,max_y - cy,150);
setlinestyle(SOLID_FILL,0,1);
// Draw the minute and the hour hand
drawpoly(2,minute_hand);
drawpoly(2,hour_hand);
int i=0;
while(!kbhit()) {
setcolor(RED);
drawpoly(2,second_hand);
setcolor(GREEN);
drawpoly(2,minute_hand);
setcolor(BLUE);
drawpoly(2,hour_hand);
delay(1000);
// set delay(10) to tick the clock fast
setcolor(0);
drawpoly(2,second_hand);
rotate(second_hand,edges,angle,cx,max_y - cy);
i++;
// Reset the second hand and move the minute hand
// when the second hand has moved 60 times.
if(i%60 == 0) {
second_hand[0] = cx ;
second_hand[1] = max_y - cy;
second_hand[2] = cx;
second_hand[3] = max_y - 320;
drawpoly(2,minute_hand);
rotate(minute_hand,edges,angle,cx,max_y - cy);
}
// Move the minute hand
// when the second hand has moved 720 (60*12) times.
if(i%720 == 0) {
i = 0;
drawpoly(2,hour_hand);
rotate(hour_hand,edges,angle,cx,max_y - cy);
}
}
getch();
}
// Function to draw the clock
void drawClock(int cx, int cy, int r) {
setcolor(WHITE);
setlinestyle(SOLID_FILL,0,3);
circle(cx,cy,r);
int max_y = getmaxy();
int center[2] = {
cx, max_y - 340
}
;
for (int i=0; i<60; i++) {
if(i%5 == 0) {
circle(center[0],center[1],2);
} else {
circle(center[0],center[1],1);
}
rotate(center,1,-6,cx,cy);
}
}
Output:
11. Create and rotate a triangle about the origin and a fixed point.
#include<GL/glut.h>
#include<stdio.h>
int x,y;
int where_to_rotate=0; // don't rotate initially
float rotate_angle=0; // initial angle
float translate_x=0,translate_y=0; // initial translation
void draw_pixel(float x1, float y1)
{
glPointSize(5);
glBegin(GL_POINTS);
glVertex2f(x1,y1); // plot a single point
glEnd();
}
void triangle(int x, int y)
{
glColor3f(1,0,0);
glBegin(GL_POLYGON); // drawing a Triangle
glVertex2f(x,y);
glVertex2f(x+400,y+300);
glVertex2f(x+300,y+0);
glEnd();
}
void display()
{
glClear(GL_COLOR_BUFFER_BIT);
glLoadIdentity();
glColor3f(1,1,1); // mark origin point as white dot
draw_pixel(0,0); // plot origin - white colour
if (where_to_rotate == 1) // rotate around origin
{
translate_x = 0; // no translation for rotation around origin
translate_y = 0;
rotate_angle += 1; // the amount of rotation angle
}
if (where_to_rotate == 2) // rotate around Fixed Point
{
translate_x = x; // SET the translation to wherever the customer says
translate_y = y;
rotate_angle += 1; // the amount of rotation angle
glColor3f(0,0,1); // mark the customer coordinate as blue dot
draw_pixel(x,y); // plot the customer coordinate - blue colour
}
glTranslatef(translate_x, translate_y, 0); // ACTUAL translation +ve
glRotatef(rotate_angle, 0, 0, 1); // rotate
glTranslatef(-translate_x, -translate_y, 0); // ACTUAL translation -ve
triangle(translate_x,translate_y); // what to rotate? – TRIANGLE boss
glutPostRedisplay(); // call display function again and again
glutSwapBuffers(); // show the output
}
void init()
{
glClearColor(0,0,0,1); //setting to black
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(-800, 800, -800, 800);
glMatrixMode(GL_MODELVIEW);
}
void rotateMenu (int option)
{
if(option==1)
where_to_rotate=1; // rotate around origin
if(option==2)
where_to_rotate=2; // rotate around customer's coordinates
if(option==3)
where_to_rotate=3; // stop rotation
}
int main(int argc, char **argv)
{
printf( "Enter Fixed Points (x,y) for Rotation: \n");
scanf("%d %d", &x, &y); // getting the user's coordinates to rotate
glutInit(&argc, argv); // initialize the graphics system
glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB); // SINGLE also works
glutInitWindowSize(800, 800); // 800 by 800 size..you can change it
glutInitWindowPosition(0, 0); // where do you wanna see your window
glutCreateWindow("Create and Rotate Triangle"); // title
init(); // initialize the canvas
glutDisplayFunc(display); // call display function
glutCreateMenu(rotateMenu); // menu items
glutAddMenuEntry("Rotate around ORIGIN",1);
glutAddMenuEntry("Rotate around FIXED POINT",2);
glutAddMenuEntry("Stop Rotation",3);
glutAttachMenu(GLUT_RIGHT_BUTTON);
glutMainLoop(); // run forever
}
Output:
Output:
13. Develop Programs for making Simple animation using
transformations like rotation scaling and translation.
Circle Moving from left to right and vice versa
#include <bits/stdc++.h>
#include <graphics.h>
using namespace std;
int main() {
int gd = DETECT, gm;
int i, x, y, flag = 0;
initgraph(&gd, &gm, (char *)"");
while (!kbhit())
{
if (x >= getmaxy() - 100 || x <= 100)
flag = !flag;
/* draws the gray board */
setcolor(RED);
setfillstyle(SOLID_FILL, RED);
circle(x, y, 30);
floodfill(x, y, RED);
/* clears screen */
cleardevice();
if (flag)
{
x = x + 5;
}
else
{
x = x - 5;
}
}
getch();
closegraph();
return 0;
}
Output:
Man object moving:
#include<stdio.h>
#include<dos.h>
#include<conio.h>
#include<graphics.h>
#include<stdlib.h>
int main()
{
int gd = DETECT, gm = DETECT, c = -200, i = 0, x = 40, l = 15, h = 15, ht =
0;
initgraph(&gd, &gm, "C:\\TurboC3\\BGI");
cleardevice();
setcolor(BROWN);
line(0, 201, 600, 201);
cont:
while (!kbhit()) {
setcolor(4);
line(x, 100, x, 150);
line(x+20, 100, x+20, 150);
circle(x - 20, 115, 15);
line(x - 20, 130, x - 20, 175);
line(x - 20, 175, x - 20 - l, 200);
line(x - 20, 175, x - 20 + l, 200);
line(x - 20, 140, x, 150);
line(x - 20, 140, x - 20 - h, 160);
setcolor(0);
delay(50);
line(x, 100, x, 150);
circle(x - 20, 115, 15);
line(x - 20, 130, x - 20, 175);
line(x - 20, 175, x - 20 - l, 200);
line(x - 20, 175, x - 20 + l, 200);
line(x - 20, 140, x, 150);
line(x - 20, 140, x - 20 - h, 160);
line(x + 50, 100, x + 50, 200);
x++;
l--;
if (l == -15)
l = 15;
if (ht == 1)
h++;
else
h--;
if (h == 15)
ht = 0;
else if (h == -15)
ht = 1;
}
if (getch() == ' ') {
while (!kbhit());
getch();
goto cont;
}
}
output
Man Walking:
#include<stdio.h>
#include<dos.h>
#include<conio.h>
#include<graphics.h>
#include<stdlib.h>
int main()
{
int gd = DETECT, gm = DETECT, c = -200, i = 0, x = 40, l = 15, h = 15, ht =
0;
initgraph(&gd, &gm, "C:\\TurboC3\\BGI");
cleardevice();
setcolor(BROWN);
line(0, 201, 600, 201);
cont:
while (!kbhit()) {
setcolor(4);
Output:
Output:
Simple animation of a football goal:
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<dos.h>
int main()
{
int x=0,gd=DETECT,gm,points[]={0,220,1600,220,1600,900,0,900,0,220};
float y=0;
initgraph(&gd,&gm,"C:\\TURBOC3\\BGI");
setcolor(MAGENTA);
settextstyle(6,HORIZ_DIR,6);
outtextxy(200,250,"Hi");
delay(1000);
cleardevice();
settextstyle(7,VERT_DIR,1);
outtextxy(200,50,"GET READY FOR ANIMATION");
delay(1000);
cleardevice();
setcolor(GREEN);
setfillstyle(SOLID_FILL,GREEN);
fillpoly(5,points);
setcolor(WHITE);
circle(100,100,25);
delay(1000);
line(100,125,100,185);
delay(1000);
line(100,135,125,170);
delay(1000);
line(100,135,75,170);
delay(1000);
line(100,185,125,220);
delay(1000);
line(100,185,75,220);
delay(1000);
setcolor(RED);
setfillstyle(SOLID_FILL,RED);
fillellipse(135+x,210-y,10,10);
for(x=0;x<50;x++)
{
setcolor(WHITE);
line(100,185,75+x,220-y);
delay(100);
setcolor(BLACK);
line(100,185,75+x,220-y);
y=y+0.25;
}
setcolor(WHITE);
line(100,185,125,220);
line(100,185,75,220);
for(x=0,y=0;y<100;x++)
{
setcolor(RED);
setfillstyle(SOLID_FILL,RED);
fillellipse(135+x,210-y,10,10);
delay(10);
setcolor(GREEN);
setfillstyle(SOLID_FILL,GREEN);
fillpoly(5,points);
setcolor(BLACK);
setfillstyle(SOLID_FILL,BLACK);
fillellipse(135+x,210-y,10,10);
y=y+0.5;
}
for(;x<490;x++)
{
setcolor(RED);
setfillstyle(SOLID_FILL,RED);
fillellipse(135+x,y,10,10);
delay(10);
setcolor(BLACK);
setfillstyle(SOLID_FILL,BLACK);
fillellipse(135+x,y,10,10);
y=y+0.25;
}
setcolor(RED);
setfillstyle(SOLID_FILL,RED);
fillellipse(135+x,y,10,10);
delay(2000);
cleardevice();
setbkcolor(CYAN);
settextstyle(3,HORIZ_DIR,10);
outtextxy(200,80,"GOAL");
getch();
closegraph();
}
Output: