hyperultra/src/background.c

54 lines
1.0 KiB
C
Raw Normal View History

2023-03-17 11:33:08 +01:00
#include "lzy.h"
#include "cfg.h"
#include <math.h>
2023-03-17 19:03:59 +01:00
long tick = 0;
2023-03-17 11:33:08 +01:00
static void
rotate(double *x, double *y, double angle)
{
2023-03-17 11:41:21 +01:00
const double s = sin(angle);
const double c = cos(angle);
const double ox = *x;
const double oy = *y;
2023-03-17 11:56:08 +01:00
*x = ox * c - oy * s;
2023-03-17 11:41:21 +01:00
*y = ox * s + oy * c;
2023-03-17 11:33:08 +01:00
}
static void
draw_square(int size, double angle)
{
2023-03-17 11:41:21 +01:00
double x[4] = {
size / 2.0,
size / 2.0,
-size / 2.0,
2023-03-17 11:56:08 +01:00
-size / 2.0,
2023-03-17 11:41:21 +01:00
};
double y[4] = {
-size / 2.0,
size / 2.0,
size / 2.0,
2023-03-17 11:56:08 +01:00
-size / 2.0,
2023-03-17 11:41:21 +01:00
};
for (int i = 0; i < 4; i++) {
rotate(&x[i], &y[i], angle);
2023-03-17 11:56:08 +01:00
x[i] += DISPLAY_WIDTH / 2.0;
y[i] += DISPLAY_HEIGHT / 2.0;
2023-03-17 11:41:21 +01:00
}
LZY_DrawLine(x[0], y[0], x[1], y[1]);
LZY_DrawLine(x[1], y[1], x[2], y[2]);
LZY_DrawLine(x[2], y[2], x[3], y[3]);
LZY_DrawLine(x[3], y[3], x[0], y[0]);
2023-03-17 11:33:08 +01:00
}
void
background_draw(void)
{
tick += 1;
2023-03-17 13:45:20 +01:00
LZY_DrawSetColor(BLACK);
draw_square(300 * sin((double)tick / 50), (double)tick / 40);
draw_square(300 * sin((double)tick / 40), (double)tick / 30);
draw_square(300 * sin((double)tick / 30), (double)tick / 20);
2023-03-17 11:33:08 +01:00
}