Вход на сайт
Воспоминания, Turbo C 01.06.2024
1944 просмотров
Перейти к просмотру всей ветки
в ответ uscheswoi_82 08.06.24 20:24
Всем добрый вечер! Закрыл группы, потому-что была странная активность, мои посты начали смотреть по 100-200 е в день ![]()
. Сейчас опять открыл. Короче продолжим болтавню программирования на Си. Сделаем симулятор планет, но потом код подправлю. Вот код:
#include <graphics.h>
#include <math.h>
#include <stdlib.h>
#include <stdio.h>
#define PI 3.14159265359
#define PLANETS_COUNT 9
void draw_planet(int cx, int cy, int x, int y, float angle, int fg, int bg);
int main(void) {
float x[PLANETS_COUNT], y[PLANETS_COUNT], angle[PLANETS_COUNT], step[PLANETS_COUNT];
int planets;
char buf[80];
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(250, 250, 20);
setfillstyle(SOLID_FILL, YELLOW);
floodfill(252, 252, WHITE);
for(planets=0; planets<PLANETS_COUNT; planets++) {
angle[planets] += step[planets];
if(angle[planets] >= 359) angle[planets] = 0;
draw_planet(250, 250, x[planets], y[planets], angle[planets], WHITE, BLUE);
sprintf(buf, "%d %f", planets, angle[planets]);
outtextxy(10, 20+(planets*10),buf);
}
cleardevice();
}
getch();
closegraph();
return 0;
}
void draw_planet(int cx, int cy, int x, int y, float angle, int fg, int bg) {
float nx, ny;
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);
}
Улучшу код, а так-же покажу программу в дейтсвие чуть позже.
Если я кому-то отвечаю, это не значит что я ему симпатизирую, каждый остаётся при своём мнении
Моя ФЛ Он и Она
Моя ФЛ Он и Она