#include <conio.h>
#include <graphics.h>
#include <dos.h>
int main() {
/* request auto detection */
int gdriver = DETECT, gmode, err;
int i = 0, x = 0, y = 0, flag = 0;
/* initialize graphic mode */
initgraph(&gdriver, &gmode, "C:/TURBOC3/BGI");
err = graphresult();
if (err != grOk) {
/* error happened */
printf("Graphics Error: %s\n",
grapherrormsg(err));
return 0;
}
/* ball movement */
while (x <= getmaxx() && !kbhit()) {
/* set the current drawing color */
setcolor(LIGHTRED);
/* fill the ball with given pattern & color */
setfillstyle(SOLID_FILL, LIGHTRED);
/* ball with light red color */
pieslice(x, y, 0, 360, 12);
/* ball movement towards x-axis */
if (i % 5 == 0) {
/* left to right */
x = x + 3;
i = 0;
}
/* ball movement towards y-axis */
if (flag) {
/* bottom to top */
y = y - 10;
} else {
/* top to bottom */
y = y + 10;
}
/* check whether ball reached y-axis maximum */
if (y >= getmaxy()) {
flag = 1;
} else if (y <= 0) {
flag = 0;
}
/* sleeps for 50 milliseconds */
delay(50);
/* clear the graphic screen */
cleardevice();
i++;
}
getch();
/* deallocate memory allocated for graphic system */
closegraph();
return 0;
}
OUTPUT: (Bouncing Ball - C Graphics)
Do not be compiled
ReplyDeletethe graphics header file has an error
ReplyDeleteGreat piece of informative post
ReplyDeleteUses of C programming
This comment has been removed by the author.
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteGo Lang
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteI really appreciate your efforts for this blog. This is so informative. Keep it up and keep sharing such posts.
ReplyDeleteSometimes it is difficult for students to manage their studies with job. In academic life they have to make lengthy assignments and assessments due to which they don’t get enough time to focus on studies. Therefore many students seek assignment help Melbourne. Many different subjects where students mostly seek online assignment help are chcece018 assessment answers Help, Management Assignment Help, bsbdiv501 assessment answers, etc.
Great! This is the way to help people i really like it Carry on, thanks to the admin for sharing this informative stuff with us. I like to visit here again for further beneficial posts.
ReplyDeleteCheckout our post and give your precious suggestions!
How to unlock pattern without data lose
How cell phone repair business profitable