summaryrefslogtreecommitdiff
path: root/src/background.c
blob: 4d17af367fda0757d62aae14962952815c04ce10 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include "lzy.h"
#include "cfg.h"
#include <math.h>

static long tick = 0;

static void
rotate(double *x, double *y, double angle)
{
	const double s = sin(angle);
	const double c = cos(angle);
	const double ox = *x;
	const double oy = *y;

	*x = ox * c - oy * s;
	*y = ox * s + oy * c;
}

static void
draw_square(int size, double angle)
{
	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] += DISPLAY_WIDTH / 2.0;
		y[i] += DISPLAY_HEIGHT / 2.0;
	}
	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
background_draw(void)
{
	tick += 1;
	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);
}