-
Notifications
You must be signed in to change notification settings - Fork 117
/
Copy pathdots3d.c
68 lines (52 loc) · 1.84 KB
/
dots3d.c
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include "vc.c"
float sqrtf(float x);
float atan2f(float y, float x);
float sinf(float x);
float cosf(float x);
#define PI 3.14159265359
#define WIDTH 960
#define HEIGHT 720
#define BACKGROUND_COLOR 0xFF181818
#define GRID_COUNT 10
#define GRID_PAD 0.5/GRID_COUNT
#define GRID_SIZE ((GRID_COUNT - 1)*GRID_PAD)
#define CIRCLE_RADIUS 5
#define Z_START 0.25
#define ABOBA_PADDING 50
static uint32_t pixels[WIDTH*HEIGHT];
static float angle = 0;
Olivec_Canvas vc_render(float dt)
{
angle += 0.25*PI*dt;
Olivec_Canvas oc = olivec_canvas(pixels, WIDTH, HEIGHT, WIDTH);
olivec_fill(oc, BACKGROUND_COLOR);
for (int ix = 0; ix < GRID_COUNT; ++ix) {
for (int iy = 0; iy < GRID_COUNT; ++iy) {
for (int iz = 0; iz < GRID_COUNT; ++iz) {
float x = ix*GRID_PAD - GRID_SIZE/2;
float y = iy*GRID_PAD - GRID_SIZE/2;
float z = Z_START + iz*GRID_PAD;
float cx = 0.0;
float cz = Z_START + GRID_SIZE/2;
float dx = x - cx;
float dz = z - cz;
float a = atan2f(dz, dx);
float m = sqrtf(dx*dx + dz*dz);
dx = cosf(a + angle)*m;
dz = sinf(a + angle)*m;
x = dx + cx;
z = dz + cz;
x /= z;
y /= z;
uint32_t r = ix*255/GRID_COUNT;
uint32_t g = iy*255/GRID_COUNT;
uint32_t b = iz*255/GRID_COUNT;
uint32_t color = 0xFF000000 | (r<<(0*8)) | (g<<(1*8)) | (b<<(2*8));
olivec_circle(oc, (x + 1)/2*WIDTH, (y + 1)/2*HEIGHT, CIRCLE_RADIUS, color);
}
}
}
size_t size = 8;
olivec_text(oc, "aboba", ABOBA_PADDING, HEIGHT - ABOBA_PADDING - olivec_default_font.height*size, olivec_default_font, size, 0xFFFFFFFF);
return oc;
}