rotating squares
This commit is contained in:
parent
9b549158ef
commit
b6e8281daa
|
@ -3,8 +3,6 @@
|
|||
#include <math.h>
|
||||
|
||||
static long tick = 0;
|
||||
static const int center_x = DISPLAY_WIDTH / 2;
|
||||
static const int center_y = DISPLAY_HEIGHT / 2;
|
||||
|
||||
static void
|
||||
rotate(double *x, double *y, double angle)
|
||||
|
@ -14,7 +12,7 @@ rotate(double *x, double *y, double angle)
|
|||
const double ox = *x;
|
||||
const double oy = *y;
|
||||
|
||||
*x = ox * c - ox * s;
|
||||
*x = ox * c - oy * s;
|
||||
*y = ox * s + oy * c;
|
||||
}
|
||||
|
||||
|
@ -25,18 +23,18 @@ draw_square(int size, double angle)
|
|||
size / 2.0,
|
||||
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
|
||||
-size / 2.0,
|
||||
};
|
||||
for (int i = 0; i < 4; i++) {
|
||||
rotate(&x[i], &y[i], angle);
|
||||
x[i] += center_x;
|
||||
y[i] += center_y;
|
||||
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]);
|
||||
|
@ -49,5 +47,7 @@ background_draw(void)
|
|||
{
|
||||
tick += 1;
|
||||
LZY_DrawSetColor(0, 0, 0);
|
||||
draw_square(64, (double)tick / 10);
|
||||
draw_square(64 * sin((double)tick / 50), (double)tick / 40);
|
||||
draw_square(64 * sin((double)tick / 40), (double)tick / 30);
|
||||
draw_square(64 * sin((double)tick / 30), (double)tick / 20);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue