C program to draw a solar system using computer graphics
Required header files:
- #include <stdio.h>
- #include <conio.h>
- #include <graphics.h>
- #include <dos.h>
- #include <math.h>
- getmaxx(): It returns the maximum X coordinate for current graphics mode and driver.
- setcolor(): It is used to set the current drawing color to the new color.
- outtextxy(): It is used to display the text or string at a specified point (x, y) on the screen.
- rectangle(): It is used to draw a rectangle.
- Coordinates of left top and right bottom corner are required to draw the rectangle.
- Left specifies the X-coordinate of top left corner, top specifies the Y-coordinate of top left corner, right specifies the X-coordinate of bottom right corner, bottom specifies the Y-coordinate of bottom right corner.
- To draw a solar system, start with a concentric ellipse because all the planet’s paths are elliptical.
- Make a circle in the center of the ellipse and fill it with yellow paint to represent the sun.
- Draw different circles, fill them with different colors and then choose the correct coordinate to place all of these in the ellipse’s path.
- Change the positions of all the planets so that they appear to be moving on an ellipse.
Below is the C program to draw the solar system using the above functions discussed:
Take a step-up from those “Hello World” programs. Learn to implement data structures like Heap, Stacks, Linked List and many more! Check out our Data Structures in C course to start learning today.
My Personal Notes arrow_drop_up