summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPhilip J Freeman <elektron@halo.nu>2018-04-03 17:41:31 -0700
committerVito Caputo <vcaputo@pengaru.com>2019-11-10 19:22:07 -0800
commit76248e7443fa9d967cc6d63d953e70a00fe4791e (patch)
tree6f05a80a69152dc40b38ebf7295b8892789bab73 /src
parent3653ac23907c051d2a29d8917f1bd1cded655558 (diff)
pixbounce: add pixbounce module
Diffstat (limited to 'src')
-rw-r--r--src/modules/pixbounce/Makefile.am3
-rw-r--r--src/modules/pixbounce/draw.h16
-rw-r--r--src/modules/pixbounce/pixbounce.c172
3 files changed, 191 insertions, 0 deletions
diff --git a/src/modules/pixbounce/Makefile.am b/src/modules/pixbounce/Makefile.am
new file mode 100644
index 0000000..a55374a
--- /dev/null
+++ b/src/modules/pixbounce/Makefile.am
@@ -0,0 +1,3 @@
+noinst_LIBRARIES = libpixbounce.a
+libpixbounce_a_SOURCES = draw.h pixbounce.c
+libpixbounce_a_CPPFLAGS = -I@top_srcdir@/src
diff --git a/src/modules/pixbounce/draw.h b/src/modules/pixbounce/draw.h
new file mode 100644
index 0000000..0b68c00
--- /dev/null
+++ b/src/modules/pixbounce/draw.h
@@ -0,0 +1,16 @@
+#ifndef _DRAW_H
+#define _DRAW_H
+
+#include <stdint.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));
+}
+
+#endif
diff --git a/src/modules/pixbounce/pixbounce.c b/src/modules/pixbounce/pixbounce.c
new file mode 100644
index 0000000..764f559
--- /dev/null
+++ b/src/modules/pixbounce/pixbounce.c
@@ -0,0 +1,172 @@
+#include <stdlib.h>
+#include <time.h>
+#include <unistd.h>
+
+#include "draw.h"
+#include "rototiller.h"
+
+/* Copyright (C) 2018 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, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 0,
+ 0, 1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 1, 0,
+ 0, 0, 1, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 1, 0, 0,
+ 0, 0, 0, 1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0,
+ 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0,
+ },
+};
+
+/* randomly pick another pixmap from the list, excluding the current one. */
+static int pick_pix(int num_pics, int last_pic)
+{
+ int pix_num = last_pic;
+
+ while(pix_num == last_pic)
+ pix_num = rand() % num_pics;
+
+ return pix_num;
+}
+
+static void pixbounce_render_fragment(void *context, fb_fragment_t *fragment)
+{
+ static int initialized=0;
+ static int x, y, multiplier;
+ static int x_dir, y_dir;
+ static int pix_num;
+
+ int width = fragment->width, height = fragment->height;
+
+ if(!initialized) {
+ srand(time(NULL) + getpid());
+ int multiplier_x = width / pix_width;
+ int multiplier_y = height / pix_height;
+ if(multiplier_x>multiplier_y) {
+ multiplier = multiplier_y * 77 / 100;
+ } else if(multiplier_y>multiplier_x) {
+ multiplier = multiplier_x * 77 / 100;
+ }
+ x = rand()%(width - (pix_width * multiplier));
+ y = rand()%(height - (pix_height * multiplier));
+ pix_num = rand() % num_pix;
+ x_dir = 1;
+ y_dir = 1;
+ initialized = 1;
+ }
+
+ /* blank the frame */
+ fb_fragment_zero(fragment);
+
+ /* translate pixmap to multiplier size and draw it to the fragment */
+ for(int cursor_y=0; cursor_y < pix_height*multiplier; cursor_y++) {
+ for(int cursor_x=0; cursor_x < pix_width*multiplier; cursor_x++) {
+ int pix_offset = ((cursor_y/multiplier)*pix_width) + (cursor_x/multiplier);
+ if(pix_map[pix_num][pix_offset] == 0) continue;
+ fb_fragment_put_pixel_unchecked(
+ fragment, x+cursor_x, y+cursor_y,
+ makergb(0xFF, 0xFF, 0xFF, 1)
+ );
+ }
+ }
+
+ /* update pixmap location */
+ if(x+x_dir < 0) {
+ x_dir = 1;
+ pix_num = pick_pix(num_pix, pix_num);
+ }
+ if((x+(pix_width*multiplier))+x_dir > width) {
+ x_dir = -1;
+ pix_num = pick_pix(num_pix, pix_num);
+ }
+ if(y+y_dir < 0) {
+ y_dir = 1;
+ pix_num = pick_pix(num_pix, pix_num);
+ }
+ if((y+(pix_height*multiplier))+y_dir > height) {
+ y_dir = -1;
+ pix_num = pick_pix(num_pix, pix_num);
+ }
+ x = x+x_dir;
+ y = y+y_dir;
+}
+
+rototiller_module_t pixbounce_module = {
+ .render_fragment = pixbounce_render_fragment,
+ .name = "pixbounce",
+ .description = "pixmap bounce",
+ .author = "Philip J Freeman <elektron@halo.nu>",
+ .license = "GPLv2",
+};
© All Rights Reserved