10 static void draw_disc(float x, float y, float rad, int sub);
11 static void draw_line(float x0, float y0, float x1, float y1, float rad);
13 static int nverts = 256;
14 static long start_time;
16 #define LOOPTIME 1.45f
18 void init_census(void *pixels, int xsz, int ysz)
20 float aspect = (float)xsz / (float)ysz;
29 g3d_framebuffer(xsz, ysz, fb_pixels);
30 g3d_polygon_mode(G3D_FLAT);
32 g3d_viewport(0, 0, xsz, ysz);
33 g3d_matrix_mode(G3D_PROJECTION);
35 g3d_scale(1.0f / aspect , 1.0f, 1.0f);
37 start_time = TICKS_TO_MSEC(nticks);
40 void draw_census(void)
43 long msec = TICKS_TO_MSEC(nticks);
44 float t = (float)msec / 1000.0f;
46 float anim, alpha, center_alpha;
48 memset(fb_pixels, 0, fb_width * fb_height * 4);
50 anim = fmod(t / 6.0f, LOOPTIME);
51 alpha = 1.0f - ((anim - (LOOPTIME - 0.075)) / 0.06f);
52 if(alpha < 0.0f) alpha = 0.0f;
53 if(alpha > 1.0f) alpha = 1.0f;
55 dt = (anim > 1.0f ? 1.0f : anim) / (float)(nverts - 1);
57 g3d_color4f(1, 1, 1, alpha);
58 for(i=0; i<nverts-1; i++) {
59 float t0 = (float)i * dt;
60 float t1 = (float)(i + 1) * dt;
63 draw_line(a[0], a[1], b[0], b[1], 0.02);
68 draw_disc(a[0], a[1], 0.05, 22);
72 draw_disc(b[0], b[1], 0.05, 22);
76 center_alpha = 2.0 * (anim - 1.0f) / (LOOPTIME - 1.0f);
77 if(center_alpha > 0.4) {
78 g3d_color4f(0.8, 0, 0, center_alpha);
79 draw_disc(0, 0, 0.14, 30);
84 static void draw_disc(float x, float y, float rad, int sub)
87 float dt = 1.0f / (float)(sub - 1);
88 float da = dt * M_PI * 2.0;
90 g3d_begin(G3D_TRIANGLES);
91 for(i=0; i<sub; i++) {
95 g3d_vertex(cos(theta) * rad + x, sin(theta) * rad + y, 0);
96 g3d_vertex(cos(theta + da) * rad + x, sin(theta + da) * rad + y, 0);
101 static void draw_line(float x0, float y0, float x1, float y1, float rad)
103 float dx, dy, rx, ry, len;
107 len = sqrt(dx * dx + dy * dy);
110 ry = -rad * dx / len;
112 draw_disc(x0, y0, rad, 12);
113 draw_disc(x1, y1, rad, 12);
115 g3d_begin(G3D_QUADS);
116 g3d_vertex(x0 + rx, y0 + ry, 0);
117 g3d_vertex(x1 + rx, y1 + ry, 0);
118 g3d_vertex(x1 - rx, y1 - ry, 0);
119 g3d_vertex(x0 - rx, y0 - ry, 0);