summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkdx <kikoodx@paranoici.org>2023-03-17 11:41:21 +0100
committerkdx <kikoodx@paranoici.org>2023-03-17 11:41:21 +0100
commit9b549158ef22cc845867ac44c4d333b05fa94a44 (patch)
treec7e5d804fc6414f437e8afcc9509894ab536a8f7
parent46aa297e363bcc1aff30bd4c6870b8f0b1a54b39 (diff)
downloadhyperultra-9b549158ef22cc845867ac44c4d333b05fa94a44.tar.gz
not quite
-rw-r--r--src/background.c55
1 files changed, 29 insertions, 26 deletions
diff --git a/src/background.c b/src/background.c
index 2b32c49..c33492b 100644
--- a/src/background.c
+++ b/src/background.c
@@ -9,36 +9,39 @@ static const int center_y = DISPLAY_HEIGHT / 2;
static void
rotate(double *x, double *y, double angle)
{
- const int ox = *x;
- *x = *x * cos(angle) + *y * sin(angle);
- *y = *y * cos(angle) + ox * sin(angle);
+ const double s = sin(angle);
+ const double c = cos(angle);
+ const double ox = *x;
+ const double oy = *y;
+
+ *x = ox * c - ox * s;
+ *y = ox * s + oy * c;
}
static void
draw_square(int size, double angle)
{
- double x0 = size / 2.0;
- double y0 = size / 2.0;
- double x1 = size / 2.0;
- double y1 = -size / 2.0;
- rotate(&x0, &y0, angle);
- rotate(&x1, &y1, angle);
- double x2 = 0 - x0;
- double y2 = 0 - y0;
- double x3 = 0 - x0;
- double y3 = 0 - y0;
- x0 += center_x;
- y0 += center_y;
- x1 += center_x;
- y1 += center_y;
- x2 += center_x;
- y2 += center_y;
- x3 += center_x;
- y3 += center_y;
- LZY_DrawLine(x0, y0, x1, y1);
- LZY_DrawLine(x1, y1, x2, y2);
- LZY_DrawLine(x2, y2, x3, y3);
- LZY_DrawLine(x3, y3, x0, y0);
+ double x[4] = {
+ size / 2.0,
+ size / 2.0,
+ -size / 2.0,
+ -size / 2.0
+ };
+ double y[4] = {
+ -size / 2.0,
+ size / 2.0,
+ size / 2.0,
+ -size / 2.0
+ };
+ for (int i = 0; i < 4; i++) {
+ rotate(&x[i], &y[i], angle);
+ x[i] += center_x;
+ y[i] += center_y;
+ }
+ 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]);
}
void
@@ -46,5 +49,5 @@ background_draw(void)
{
tick += 1;
LZY_DrawSetColor(0, 0, 0);
- draw_square(tick % 128, (double)tick / 10);
+ draw_square(64, (double)tick / 10);
}