0% found this document useful (0 votes)
11 views2 pages

code2

The document contains a C++ program that simulates the motion of satellites orbiting the Earth using graphics. It initializes a graphical window, draws the Earth and its continents, and animates multiple satellites with varying orbital distances and speeds. The program runs until a key is pressed, continuously updating the positions of the satellites in a loop.

Uploaded by

kthamayanthi8
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views2 pages

code2

The document contains a C++ program that simulates the motion of satellites orbiting the Earth using graphics. It initializes a graphical window, draws the Earth and its continents, and animates multiple satellites with varying orbital distances and speeds. The program runs until a key is pressed, continuously updating the positions of the satellites in a loop.

Uploaded by

kthamayanthi8
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

#include <graphics.

h>

#include <conio.h>

#include <math.h>

#define PI 3.14159265

int main() {

int gd = DETECT, gm;

initgraph(&gd, &gm, ""); // Initialize graphics mode

int earth_x = getmaxx()/2; // Earth's position

int earth_y = getmaxy()/2;

int earth_radius = 50;

// Satellite parameters

int num_satellites = 8;

int sat_radius = 5;

float angles[num_satellites];

int orbit_radius[num_satellites];

// Initialize satellite positions

for(int i=0; i<num_satellites; i++) {

angles[i] = 0;

orbit_radius[i] = 100 + i*30; // Different orbital distances

while(!kbhit()) { // Run until key is pressed

cleardevice(); // Clear previous frame

// Draw Earth

setcolor(COLOR(0, 0, 255));
setfillstyle(SOLID_FILL, COLOR(0, 0, 255));

fillellipse(earth_x, earth_y, earth_radius, earth_radius);

// Draw green continents

setcolor(COLOR(0, 255, 0));

arc(earth_x, earth_y, 45, 135, earth_radius+5);

arc(earth_x, earth_y, 225, 315, earth_radius+5);

// Draw satellites

for(int i=0; i<num_satellites; i++) {

// Calculate satellite position

int x = earth_x + orbit_radius[i] * cos(angles[i]);

int y = earth_y + orbit_radius[i] * sin(angles[i]);

// Draw satellite

setcolor(RED);

setfillstyle(SOLID_FILL, RED);

fillellipse(x, y, sat_radius, sat_radius);

// Update angle for orbital motion

angles[i] += PI/180 * (2.0/(i+1)); // Different speeds

if(angles[i] > 2*PI) angles[i] = 0;

delay(50); // Control animation speed

closegraph();

return 0;

You might also like