summaryrefslogtreecommitdiff
path: root/src/modules/stars/stars.c
diff options
context:
space:
mode:
authorVito Caputo <vcaputo@gnugeneration.com>2017-01-18 17:14:52 -0800
committerVito Caputo <vcaputo@gnugeneration.com>2017-01-18 17:31:44 -0800
commit524db0cf19648e3c7c78d3e73103b7a0bdcd6bfc (patch)
tree6fd682629904a210927797c92d956c208666b03a /src/modules/stars/stars.c
parentee2073d4e411555aba878277131b56f7eb562c84 (diff)
*: move source into src/ subdir
Restoring some organizational sanity since adopting autotools.
Diffstat (limited to 'src/modules/stars/stars.c')
-rw-r--r--src/modules/stars/stars.c63
1 files changed, 63 insertions, 0 deletions
diff --git a/src/modules/stars/stars.c b/src/modules/stars/stars.c
new file mode 100644
index 0000000..e009714
--- /dev/null
+++ b/src/modules/stars/stars.c
@@ -0,0 +1,63 @@
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+#include <inttypes.h>
+#include <time.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+#include "draw.h"
+#include "fb.h"
+#include "rototiller.h"
+#include "starslib.h"
+
+/* Copyright (C) 2017 Philip J. Freeman <elektron@halo.nu> */
+
+static void stars(fb_fragment_t *fragment)
+{
+ static int initialized, z;
+ static struct universe* u;
+
+ struct return_point rp;
+ int x, y, width = fragment->width, height = fragment->height;
+
+ if (!initialized) {
+ z = 128;
+ srand(time(NULL) + getpid());
+
+ // Initialize the stars lib (and pre-add a bunch of stars)
+ new_universe(&u, width, height, z);
+ for(y=0; y<z; y++) {
+ while (process_point(u, &rp) != 0);
+ for(x=0; x<rand()%128; x++){
+ new_point(u);
+ }
+ }
+ initialized = 1;
+ }
+
+ // draw space (or blank the frame, if you prefer)
+ memset(fragment->buf, 0, ((fragment->width << 2) + fragment->stride) * fragment->height);
+
+ // draw stars
+ for (;;) {
+ int ret = process_point( u, &rp );
+ if (ret==0) break;
+ if (ret==1) draw_pixel(fragment, rp.x+(width/2), rp.y+(height/2),
+ makergb(0xFF, 0xFF, 0xFF, (float)rp.opacity/OPACITY_MAX)
+ );
+ }
+
+ // add stars at horizon
+ for (x=0; x<rand()%128; x++) {
+ new_point(u);
+ }
+}
+
+rototiller_renderer_t stars_renderer = {
+ .render = stars,
+ .name = "stars",
+ .description = "basic starfield",
+ .author = "Philip J Freeman <elektron@halo.nu>",
+ .license = "GPLv2",
+};
© All Rights Reserved