#include <iostream>
#include <cmath>
const int WIDTH = 60;
const int HEIGHT = 30;
const double PI = 3.14159265358979323846;
struct Point {
double x, y;
};
void setPixel(char screen[][WIDTH], int x, int y, char c) {
if (x >= 0 && x < WIDTH && y >= 0 && y < HEIGHT)
screen[y][x] = c;
}
void drawLine(char screen[][WIDTH], Point p1, Point p2, char c) {
double dx = p2.x - p1.x;
double dy = p2.y - p1.y;
int steps = (abs(dx) > abs(dy)) ? abs(dx) : abs(dy);
double incX = dx / (double)steps;
double incY = dy / (double)steps;
double x = p1.x, y = p1.y;
setPixel(screen, round(x), round(y), c);
for (int i = 0; i < steps; ++i) {
x += incX;
y += incY;
setPixel(screen, round(x), round(y), c);
}
}
void drawConstellation(char screen[][WIDTH], Point points[], int numPoints, char c) {
for (int i = 0; i < numPoints - 1; ++i) {
drawLine(screen, points[i], points[i + 1], c);
}
}
int main() {
char sky[HEIGHT][WIDTH];
for (int i = 0; i < HEIGHT; ++i) {
for (int j = 0; j < WIDTH; ++j) {
sky[i][j] = ' ';
}
}
Point orionBelt[] = {
{20.0, 15.0},
{30.0, 20.0},
{40.0, 15.0}
};
Point orionSword[] = {
{25.0, 25.0},
{30.0, 20.0},
{35.0, 25.0}
};
drawConstellation(sky, orionBelt, sizeof(orionBelt) / sizeof(orionBelt[0]), '*');
drawConstellation(sky, orionSword, sizeof(orionSword) / sizeof(orionSword[0]), '*');
for (int i = 0; i < HEIGHT; ++i) {
for (int j = 0; j < WIDTH; ++j) {
std::cout << sky[i][j];
}
std::cout << std::endl;
}
return 0;
}