Вход на сайт
Воспоминания, Turbo C 01.06.2024
1944 просмотров
Перейти к просмотру всей ветки
в ответ uscheswoi_82 14.06.24 02:33
С поворотом картинке позже покажу, а вот код в анимации солнечной системы подправил :
#include <graphics.h>
#include <math.h>
#include <stdlib.h>
#include <stdio.h>
#define PI 3.14159265359
#define PLANETS_COUNT 8
#define C_PLANET_MERCURY LIGHTGRAY /* 1 */
#define C_PLANET_VENUS BROWN /* 2 */
#define C_PLANET_EARTH LIGHTBLUE /* 3 */
#define C_PLANET_MARS BROWN /* 4 */
#define C_PLANET_JUPITER BROWN /* 5 */
#define C_PLANET_URANUS LIGHTCYAN /* 6 */
#define C_PLANET_NEPTUNE LIGHTBLUE /* 7 */
#define C_PLANET_PLUTO LIGHTGRAY /* 8 */
/* #define IS_DEBUG */
#define SUN_X 300
#define SUN_Y 220
void draw_planet(int cx, int cy, int x, int y, float angle, int fg, int bg);
void draw_track(int cx, int cy, int radius, int color);
int main(void) {
int planets;
int radius[PLANETS_COUNT] = {56, 77, 98, 120, 140, 163, 185, 205};
float x[PLANETS_COUNT], y[PLANETS_COUNT], angle[PLANETS_COUNT], step[PLANETS_COUNT];
int plant_colors[PLANETS_COUNT] = { C_PLANET_MERCURY, C_PLANET_VENUS,
C_PLANET_EARTH, C_PLANET_MARS,
C_PLANET_JUPITER, C_PLANET_URANUS,
C_PLANET_NEPTUNE, C_PLANET_PLUTO
};
int gdriver = DETECT, gmode, errorcode;
initgraph(&gdriver, &gmode, "");
errorcode = graphresult();
if(errorcode != grOk) return -1;
for(planets=0; planets<PLANETS_COUNT; planets++) {
if(planets > 0) { x[planets] = x[planets-1] + 15; y[planets]=y[planets-1] + 15; }
else { x[planets] = 40; y[planets]=40; }
}
for(planets=0; planets<PLANETS_COUNT; planets++) { angle[planets] = rand() % 50; step[planets] = 1 + rand() % 4; }
while(!kbhit()) {
setcolor(WHITE);
circle(SUN_X, SUN_Y, 20);
setfillstyle(SOLID_FILL, YELLOW);
floodfill(SUN_X + 2, SUN_Y + 2, WHITE);
for(planets=0; planets<PLANETS_COUNT; planets++) {
angle[planets] += step[planets];
if(angle[planets] >= 359) angle[planets] = 0;
draw_planet(SUN_X, SUN_Y, x[planets], y[planets], angle[planets], WHITE, plant_colors[planets]);
draw_track(SUN_X, SUN_Y, radius[planets], WHITE);
}
setcolor(WHITE);
outtextxy(10, 460, "Press any key, to exit...");
#ifndef IS_DEBUG
delay(1500);
cleardevice();
#endif
}
getch();
closegraph();
return 0;
}
void draw_track(int cx, int cy, int radius, int color) {
setcolor(color);
circle(cx, cy, radius);
}
void draw_planet(int cx, int cy, int x, int y, float angle, int fg, int bg) {
float nx, ny;
char buf[80];
nx = (x * cos(angle * (PI / 180))) - (y * sin(angle * (PI / 180)));
ny = (x * cos(angle * (PI / 180))) + (y * sin(angle * (PI / 180)));
setcolor(fg);
circle(cx + nx, cy + ny, 5);
setfillstyle(SOLID_FILL, bg);
floodfill(cx + 2 + nx, cy + 2 + ny, fg);
}
Вуаля!
#define IS_DEBUG:

/*#define IS_DEBUG*/:

Если я кому-то отвечаю, это не значит что я ему симпатизирую, каждый остаётся при своём мнении
Моя ФЛ Он и Она
Моя ФЛ Он и Она