summaryrefslogtreecommitdiff
path: root/modules/sparkler/sparkler.c
diff options
context:
space:
mode:
authorVito Caputo <vcaputo@gnugeneration.com>2016-12-13 08:20:24 -0800
committerGitHub <noreply@github.com>2016-12-13 08:20:24 -0800
commit2e292bd40f67e6e2612ad93fd77cdcd3449e4892 (patch)
tree4600607eb8c12af034b2bf29eec4f8207f9413c4 /modules/sparkler/sparkler.c
parent3ea61db55a9c21f7621f8a64d91153cb1955b2ff (diff)
parent173cac2fe990496fca2403aa3a4bfcbd6007e7e6 (diff)
Merge pull request #2 from vcaputo/moar
More candy
Diffstat (limited to 'modules/sparkler/sparkler.c')
-rw-r--r--modules/sparkler/sparkler.c53
1 files changed, 53 insertions, 0 deletions
diff --git a/modules/sparkler/sparkler.c b/modules/sparkler/sparkler.c
new file mode 100644
index 0000000..de2123e
--- /dev/null
+++ b/modules/sparkler/sparkler.c
@@ -0,0 +1,53 @@
+#include <stdlib.h>
+#include <string.h>
+#include <sys/types.h>
+#include <time.h>
+#include <unistd.h>
+
+#include "fb.h"
+#include "rototiller.h"
+#include "util.h"
+
+#include "particles.h"
+
+/* particle system gadget (C) Vito Caputo <vcaputo@pengaru.com> 2/15/2014 */
+/* 1/10/2015 added octree bsp (though not yet leveraged) */
+/* 11/25/2016 refactor and begun adapting to rototiller */
+
+#define INIT_PARTS 100
+
+extern particle_ops_t simple_ops;
+
+
+/* Render a 3D particle system */
+static void sparkler(fb_fragment_t *fragment)
+{
+ static particles_t *particles;
+ static int initialized;
+ uint32_t *buf = fragment->buf;
+
+ if (!initialized) {
+ srand(time(NULL) + getpid());
+
+ particles = particles_new();
+ particles_add_particles(particles, NULL, &simple_ops, INIT_PARTS);
+
+ initialized = 1;
+ }
+
+ particles_age(particles);
+ memset(buf, 0, ((fragment->width << 2) + fragment->stride) * fragment->height);
+
+ particles_draw(particles, fragment);
+ particles_sim(particles);
+ particles_add_particles(particles, NULL, &simple_ops, INIT_PARTS / 4);
+}
+
+
+rototiller_renderer_t sparkler_renderer = {
+ .render = sparkler,
+ .name = "sparkler",
+ .description = "Particle system with spatial interactions",
+ .author = "Vito Caputo <vcaputo@pengaru.com>",
+ .license = "GPLv2",
+};
© All Rights Reserved