2021BCS0103_CSE411_LAB-9
2021BCS0103_CSE411_LAB-9
Name-S.Vaishnavi Reddy
Roll no-2021BCS0103
Batch-1
Q) Develop a visual simulation of a simplified solar
system that includes Sun and the Planets (with unique
size and color in a circular orbit around the sun ).
Include at least three planets. Implement smooth
animation to show the planets rotating around the Sun
and spinning on their axes.
Code:
#ifdef _WIN32
#include <windows.h>
#endif
#include <GL/glut.h>
#include <cmath>
#include <cstring>
const float radius_of_orbit[] = {0.1f, 0.2f, 0.3f, 0.4f, 0.5f, 0.6f, 0.7f, 0.8f};
const float size_of_planet[] = {0.02f, 0.03f, 0.025f, 0.04f, 0.035f, 0.05f,
0.045f, 0.055f};
const float COLORS[][3] = {
{0.5f, 0.5f, 0.5f},
{1.0f, 0.5f, 0.0f},
{0.0f, 0.0f, 1.0f},
{1.0f, 0.0f, 0.0f},
{1.0f, 0.8f, 0.4f},
{1.0f, 1.0f, 0.0f},
{0.0f, 1.0f, 1.0f},
{0.0f, 0.0f, 1.0f}
};
const char* names_of_planet[] = {"Mercury", "Venus", "Earth", "Mars",
"Jupiter", "Saturn", "Uranus", "Neptune"};
float angle[] = {0.0f, 45.0f, 90.0f, 135.0f, 180.0f, 225.0f, 270.0f, 315.0f};
const float SPEED[] = {1.0f, 0.8f, 0.6f, 0.5f, 0.3f, 0.2f, 0.1f, 0.05f};
// Draw Sun
glColor3f(1.0f, 1.0f, 0.0f);
func_drawCircle(0.0f, 0.0f, 0.07f, 100);
// Draw orbits and planets
for (int i = 0; i < 8; i++) {
glColor3f(1.0f, 1.0f, 1.0f); // White color for orbits
func_drawOrbit(radius_of_orbit[i]);
glutSwapBuffers();
}
init();
glutDisplayFunc(display);
glutTimerFunc(0, timer, 0);
glutMainLoop();
return 0;
}
Output: