Воспоминания, Turbo C 01.06.2024
Результат работы кода, мерцает немножко:

Моя ФЛ Он и ОнаУлучшил код см.:
#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 SUN_X 300 /* Позиция солнце на экране*/
#define SUN_Y 200 /* Позиция солнце на экране */
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 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 planets;
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]);
}
setcolor(WHITE);
outtextxy(10, 460, "Press any key, to exit...");
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);
}
Моя ФЛ Он и ОнаПоследнее, и я наверное пойду спатенькать. Если помните мы тут см. https://groups.germany.ru/12994140000001/f/41010308.html?C... делали просмоторщик картинок, а так-же программу, которая переконвиртирует фотографию в бинарный формат см.:

Вот код, программа читает бинарный файл, считывает бинарные данные из файла, и выводит изображение на экран:
#include <stdio.h>
#include <graphics.h>
int main(void) {
int gdriver = DETECT, gmode, errorcode;
FILE *f;
int x = 0, y = 0, sx = 0, sy = 0;
f = fopen("demo.bin", "r+b");
if(f != NULL) {
printf("\nSize X?");
scanf("%d", &sx);
printf("\nSize Y?");
scanf("%d", &sy);
initgraph(&gdriver, &gmode, "");
errorcode = graphresult();
if(errorcode != grOk) return -1;
while(!feof(f)) {
if(x >= sx) { x = 0; y++; }
if(y >= sy) { break; }
putpixel(x, y, fgetc(f));
x ++ ;
}
outtextxy(10, 450, "Press any key to quit...");
getch();
closegraph();
}
}
Вот результат, это изображение которое я закодировал выше написанным софтом:
1. Сначало спрашивает программа какой размер картинки, введём 320 и 200:

2. Вуаля! А вот и наша картинка см:

На последок хотел показать, что одна старая тётка про меня пишит в этом форуме:
Посмеюсь перед сном над ней
:

Ну ладно я баенкать пошёл.
Моя ФЛ Он и ОнаЗавтра попробуем повернуть картику ну скажем на 30 градусов по формуле:
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)));
Ну ладно, всё теперь точно я спать! Всем спок. ночи!
Моя ФЛ Он и ОнаС поворотом картинке позже покажу, а вот код в анимации солнечной системы подправил :
#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*/:

Моя ФЛ Он и ОнаВсем доброй ночи! Только что посмотрел Форсаж 7, и занимался программирование симуляции движения тела брошенного под углом к горизонту:
#include <stdio.h>
#include <graphics.h>
#include <math.h>
#define PI 3.14159265359
int main(void) {
int gdriver = DETECT, gmode, errorcode;
double vx, vy, t, step, x, y;
int angle, v0;
char buf[80];
printf("v0, angle=");
scanf("%d %d", &v0, &angle);
sprintf(buf, "v0=%d angle=%d", v0, angle);
initgraph(&gdriver, &gmode, "");
errorcode = graphresult();
if(errorcode != grOk) return -1;
step = 0.005;
t = 0;
x = 1;
y = 1;
vx = v0 * cos((angle * PI) / 180);
vy = v0 * sin((angle * PI) / 180);
outtextxy(10, 10, buf);
while(y > 0) {
t = t + step;
vy = vy - t;
x = x + (vx * step);
y = y + (vy * step);
putpixel(x, 350 - y, WHITE);
delay(20);
}
outtextxy(10, 400, "Press any key to exit...");
getch();
closegraph();
return 0;
}
Вуаля! А вот и результат:

Моя ФЛ Он и ОнаПосмеюсь ![]()

Моя ФЛ Он и ОнаВсем привет! Продолжим болтавню. Сегодня реализуем алгоритм пузырчатой сортировки.
Алгоритм поиска больше:
#include <stdio.h>
int main(void) {
int a = 3, b = 2;
if(a > b)
printf("%d больше, чем %d", a, b);
return 0;
}
Алгоритм поиска меньше:
#include <stdio.h>
int main(void) {
int a = 2, b = 3;
if(a < b)
printf("%d меньше, чем %d", a, b);
return 0;
}
Алгоритм поменять местами 2 элемента:
if(z[a] > z<b>) {
temp = z<b>;
z<b> = z[a];
z[a] = temp;
}
Вот так нужно представлять себе алгоритм с тремя чашками и водой:
А теперь сам алгоритм сортировки полностью, с маленького числа, в большое:
#include <stdio.h>
#define COUNT 10
int main(void) {
int z[COUNT] = {10, 5, 4, 6, 1, 2, 7, 9, 3, 8};
int temp;
int a, b;
for(a=0; a<COUNT; a++) printf("%d ", z[a]);
printf("\n");
for(a=0; a<COUNT; a++) {
for(b=a; b<COUNT; b++) {
if(z[a] > z<b>) {
temp = z<b>;
z<b> = z[a];
z[a] = temp;
}
}
}
for(a=0; a<COUNT; a++) printf("%d ", z[a]);
return 0;
}
Результат работы алгоритма:
10 5 4 6 1 2 7 9 3 8 1 2 3 4 5 6 7 8 9 10
Посмеёмся ![]()

Моя ФЛ Он и ОнаАлгоритм пузырчатой сортировки и гравитации мы изучали в университете в Алматы в 2000 году. Но мы алгоритм строили на языке программирования Паскаль.
Моя ФЛ Он и ОнаТочнее сначало алгоритм а потом код на языке программирования Паскаль.
Моя ФЛ Он и ОнаЗавтра нарисую спомощью BGI солнце, облака, машину и дом. Чтобы это нарисовать, я написал программу, которая рисует сетку.
Вот код:
#include <graphics.h>
#include <conio.h>
#include <stdio.h>
int main(void) {
int gdriver = DETECT, gmode, errorcode, j;
char buf[80];
initgraph(&gdriver, &gmode, "");
errorcode = graphresult();
if(errorcode != grOk) return -1;
setcolor(WHITE);
for(j=25; j<getmaxy() - 25; j+=27) {
sprintf(buf, "%d", j);
outtextxy(1, j - 5, buf);
line(25, j, getmaxx()-25, j);
}
line(25, j - 3, getmaxx()-25, j - 3);
for(j=25; j<getmaxx() - 25; j+=27) {
sprintf(buf, "%d", j);
outtextxy(j - 5, 5, buf);
line(j, 25, j, getmaxy() - 25);
}
line(j - 4, 25, j - 4, getmaxy() - 25);
getch();
closegraph();
return 0;
}
Вот результат:

Моя ФЛ Он и ОнаПосмеёмся ![]()

Моя ФЛ Он и ОнаВсем добрый вечер, примерно в 2000 году сделал алгоритм расщепитель строки на массивы, там указываешь символ разделитель, по которому программа будет ориентироваться. Вот алгоритм:
#include <stdio.h>
char splits[10][250];
int split_str(char *buf, char del, int idx);
int main(void) {
int cnt;
for(cnt=0; cnt < split_str("HELLO FROM uscheswoi_82", ' ', 3) + 1; cnt++)
printf("\n%s", splits[cnt]);
return 0;
}
int split_str(char *buf, char del, int idx) {
int j=0, i=0, k=-1;
for(j=0; j<idx; j++) splits[j][0] = '\0';
for(j=0; j<strlen(buf); j++) {
k++;
splits[ i ][k] = buf[j];
if(buf[j] == del) {
splits[ i ][k] = '\0';
i++;
k=-1;
}
}
splits[ i ][k+1] = '\0';
return i;
}
Результат работы программы:
HELLO FROM uscheswoi_82
Посмеёмся:

Моя ФЛ Он и ОнаТут см. https://groups.germany.ru/12994140000001/f/41061285.html?C... воспоминания про Zortech C++/Symantec C++ который нам дали после Turbo C 2.0 или Borland C++ 3.0
Моя ФЛ Он и Она