C program to Draw Stars in Night Sky
Here, you will get the program code to draw stars in night sky using C graphics. To making this night sky program we will be using various graphics functions from graphics.h header file.
In this program, we will draw hundreds of blinking stars in the night sky. We will use putpixel graphics function to make stars.
For example:-
putpixel(200,200,15);
Here first parameter is x coordinate, second parameter is y coordinate, and last parameter is color of pixel.
C program Code to Draw Stars in Night Sky
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | #include <conio.h> #include <graphics.h> #include <dos.h> #include <stdlib.h> main() { int gd=DETECT,gm; int i, x, y; initgraph(&gd,&gm,"C:\TURBOC3\BGI"); // untill user press any key while (!kbhit()) { //display 300 white color pixel on screen for(i=0; i<=300; i++) { outtextxy(200,100," Stars Night "); x=rand()%getmaxx(); y=rand()%getmaxy(); putpixel(x,y,15); } delay(300); cleardevice(); } getch(); closegraph(); } |
Output
Read Also