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.
![draw stars in night sky draw stars in night sky](https://coderevise.com/wp-content/uploads/2022/10/stars-in-night-sky.webp)
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
![night sky drawing night sky drawing C graphics](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjijU5zayIZjTP5Tsq2yKb0J7ssW3hmQZwkerj5XV5zKyWViaC06yuXGWwLCtrleKk1fx0ebBfimjfFgTGVshgdGJgdZPGMBntVAHDUyXNPbRfeTbUF6EvooMpNdVIGmuB5jbranK_fyJehTg9IVMHxRAN5fGgYJMSlBOHfVXxT0DCFRSwlN3Yd9T6Q/w640-h360/Star-night-program-in-computer-graphics.gif)
Read Also