summaryrefslogtreecommitdiff
path: root/modules/sparkler/draw.h
diff options
context:
space:
mode:
authorVito Caputo <vcaputo@gnugeneration.com>2016-12-13 07:51:23 -0800
committerVito Caputo <vcaputo@gnugeneration.com>2016-12-13 07:51:23 -0800
commit8add1663d9a02db2bc65224cdceb480733a81379 (patch)
treefea6aa880a366c007d2b7fdda87c746e6345b301 /modules/sparkler/draw.h
parentaf49b97cd819cec3a19b1ff5ed6076a0d23f4233 (diff)
sparkler: introduce a particle system
A while ago I made this particle system on SDL, and had the beginnings of an octree implemented within it, but never finished actually using the octree to accelerate the proximity searches. This now has the octree completed and of course more particle interactions now that neighbors could be found more quickly. The simulation somewhat resembles a fireworks display. Every particle is drawn as a single pixel. The visual effect is dominated by spontaneously spawned rockets which explode into thousands of particles accompanied by bursts that thrust particles away from the explosion radially in an expanding sphere resembling a shock wave. When the shock wave happens to strike another rocket, it explodes, resulting in another shock wave. This can produce spectacular chain reactions, so it's worth running for some time and seeing what transpires.
Diffstat (limited to 'modules/sparkler/draw.h')
-rw-r--r--modules/sparkler/draw.h32
1 files changed, 32 insertions, 0 deletions
diff --git a/modules/sparkler/draw.h b/modules/sparkler/draw.h
new file mode 100644
index 0000000..58a4a36
--- /dev/null
+++ b/modules/sparkler/draw.h
@@ -0,0 +1,32 @@
+#ifndef _DRAW_H
+#define _DRAW_H
+
+#include <stdint.h>
+
+#include "fb.h"
+
+/* helper for scaling rgb colors and packing them into an pixel */
+static inline uint32_t makergb(uint32_t r, uint32_t g, uint32_t b, float intensity)
+{
+ r = (((float)intensity) * r);
+ g = (((float)intensity) * g);
+ b = (((float)intensity) * b);
+
+ return (((r & 0xff) << 16) | ((g & 0xff) << 8) | (b & 0xff));
+}
+
+static inline int draw_pixel(fb_fragment_t *f, int x, int y, uint32_t pixel)
+{
+ uint32_t *pixels = f->buf;
+
+ if (y < 0 || y >= f->height || x < 0 || x >= f->width) {
+ return 0;
+ }
+
+ /* FIXME this assumes stride is aligned to 4 */
+ pixels[(y * f->width + (f->stride >> 2)) + x] = pixel;
+
+ return 1;
+}
+
+#endif
© All Rights Reserved