CG/Assignment C-7b (Bouncing Ball).cpp

43 lines
831 B
C++
Raw Permalink Normal View History

2023-11-30 00:26:35 +05:30
/*
Problem Statement:
Code from Computer Graphics (SPPU - Second Year - Computer Engineering - Content) repository on KSKA Git: https://git.kska.io/sppu-se-comp-codes/CG
*/
// BEGINNING OF CODE
#include <iostream>
#include <cstdlib>
#include <graphics.h>
using namespace std;
int main() {
int gd = DETECT, gm;
int i, x, y, flag=0;
initgraph(&gd, &gm,NULL);
/* get mid positions in x and y-axis */
x = getmaxx()/2;
y = 30;
while (1) {
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);
/* delay for 50 milli seconds */
delay(50);
/* clears screen */
cleardevice();
if(flag) {
y = y + 5;
}
else {
y = y - 5;
}
}
delay(5000);
closegraph();
return 0;
}
// END OF CODE