Skip to content

Instantly share code, notes, and snippets.

@AaronC81
Created March 13, 2019 11:07
Show Gist options
  • Save AaronC81/869ee3ec2b5eb09fabb583d9f842fa4e to your computer and use it in GitHub Desktop.
Save AaronC81/869ee3ec2b5eb09fabb583d9f842fa4e to your computer and use it in GitHub Desktop.
DVD animation for HackSoc RPi OS - call rng_init then dvd_animation
#include "framebuffer.h"
#include "main.h"
#include "mem.h"
#include "mailbox.h"
#include "rng.h"
#include <stdbool.h>
#define DVD_LOGO_WIDTH 250
#define DVD_LOGO_HEIGHT 155
/* XPM */
static char * dvd_logo[] = {
"250 155 2 1",
" c None",
". c #FFFFFF",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ..................................................................................... ",
" ....................................................................................... ............................................................ ",
" ....................................................................................... .................................................................. ",
" ........................................................................................ ...................................................................... ",
" ........................................................................................ ......................................................................... ",
" ........................................................................................ ............................................................................ ",
" .......................................................................................... .............................................................................. ",
" .......................................................................................... ................................................................................ ",
" .......................................................................................... .................................................................................. ",
" .......................................................................................... ..................................................................................... ",
" ........................................................................................... ....................................................................................... ",
" ............................................................................................ ......................................................................................... ",
" ............................................................................................ .......................................................................................... ",
" ............................................................................................. ........................................................................................... ",
" ........................................................ ........................ ................................ ",
" ..................................................... ........................ ............................. ",
" .................................................... ........................ ............................ ",
" .................................................. ....................... ........................... ",
" ....................... ................................................. ........................ ...................... .......................... ",
" ....................... ................................................. ........................ ....................... ......................... ",
" ....................... ................................................ ........................ ....................... ......................... ",
" ....................... ................................................ ........................ ....................... ........................ ",
" ........................ ......................... ...................... ....................... ....................... ........................ ",
" ....................... ......................... ...................... ....................... ....................... ....................... ",
" ....................... ......................... ..................... ....................... ....................... ........................ ",
" ....................... ......................... ..................... ....................... ....................... ........................ ",
" ........................ ........................ ...................... ....................... ....................... ........................ ",
" ....................... ......................... ..................... ....................... ....................... ........................ ",
" ....................... ......................... ..................... ....................... ....................... ....................... ",
" ....................... ......................... ..................... ....................... ....................... ....................... ",
" ....................... ......................... ..................... ....................... ....................... ........................ ",
" ....................... .......................... ..................... ....................... ....................... ........................ ",
" ....................... ......................... ..................... ...................... ....................... ........................ ",
" ....................... ......................... ..................... ...................... ....................... ........................ ",
" ....................... .......................... ..................... ...................... ....................... ......................... ",
" ....................... .......................... ..................... ....................... ........................ ........................ ",
" ....................... ........................... ..................... ....................... ....................... ......................... ",
" ....................... ........................... ..................... ...................... ....................... ......................... ",
" ....................... ............................ .......................................... ....................... .......................... ",
" ....................... ............................ ......................................... ........................ ........................... ",
" ....................... ............................. ........................................ ....................... ............................ ",
" ....................... ............................. ...................................... ....................... ............................. ",
" ....................... ............................... ..................................... ....................... .............................. ",
" ....................... ................................ .................................... ....................... ................................ ",
" ....................... ................................... ................................... ....................... ................................... ",
" ....................... ...... ........................................ .................................. ....................................................................... ",
" ...................................................................... ................................. ...................................................................... ",
" ..................................................................... ............................... ..................................................................... ",
" ................................................................... .............................. .................................................................... ",
" ................................................................. ............................ .................................................................. ",
" ................................................................ ........................... ................................................................. ",
" ............................................................. .......................... ............................................................... ",
" ............................................................ ........................ .............................................................. ",
" ........................................................ ....................... ........................................................... ",
" ..................................................... ...................... ......................................................... ",
" ................................................ ..................... ...................................................... ",
" ............................................ .................... ................................................... ",
" ..................................... .................. .............................................. ",
" .................... ................. ",
" ................ ",
" .............. ",
" ............. ",
" ............. ",
" ........... ",
" .......... ",
" ......... ",
" ....... ",
" ...... ",
" .... ",
" ... ",
" .. ",
" .. ",
" ............................................................... ",
" .................................................................................................... ",
" ............................................................................................................................ ",
" ............................................................................................................................................. ",
" ............................................................................................................................................................ ",
" ......................................................................................................................................................................... ",
" ..................................................................................................................................................................................... ",
" .................................................................................... ........................................................................................ ",
" ................................................................................ .................................................................................... ",
" .............................................................................. ................................................................................ ",
" ............................................................................ ................................................................................ ",
" ............................................................................. ................................................................................ ",
" ............................................................................ ............................................................................... ",
" ............................................................................. ................................................................................ ",
" ............................................................................ ................................................................................ ",
" .............................................................................. ................................................................................ ",
" .............................................................................. ................................................................................. ",
" ............................................................................... ................................................................................... ",
" ................................................................................ .................................................................................... ",
" ................................................................................. ..................................................................................... ",
" ..................................................................................... ....................................................................................... ",
" .......................................................................................... .............................................................................................. ",
" ....................................................................................................................................................................................................... ",
" ................................................................................................................................................................................................ ",
" ........................................................................................................................................................................................ ",
" .............................................................................................................................................................................. ",
" ................................................................................................................................................................. ",
" .................................................................................................................................................. ....... ",
" .................................................................................................................................. ...... ",
" ............................................................................................................ . .... ",
" .................................................................................. . .... ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ........ ",
" ....... ....... ....... ................ ...................... ............... ",
" ...... ....... ....... ................... ...................... .................... ",
" ....... ....... ....... .................... ...................... ....................... ",
" ...... ....... ....... ...... .......... ........ ......... .......... ",
" ....... ...... ....... ..... ........ ....... ........ ........ ",
" ...... ....... ....... ..... ....... ....... ........ ........ ",
" ....... ...... ....... ..... ....... ....... ....... ....... ",
" ....... ...... ....... ..... ........ ....... ....... ....... ",
" ....... ...... ....... ..... ....... ...................... ...... ....... ",
" ....... ...... ....... ..... ....... ...................... ...... ...... ",
" ....... ...... ....... ..... ....... ...................... ...... ...... ",
" ...... ....... ....... ..... ....... ........ ...... ....... ",
" ...... ...... ....... ..... ....... ....... ....... ....... ",
" ............ ....... ..... ........ ....... ...... ........ ",
" ........... ....... ..... ........ ....... ....... ........ ",
" .......... ....... ..... ........ ....... ........ ......... ",
" ......... ....... ..... ......... ....... ......... .......... ",
" ........ ....... ..................... ...................... ........................ ",
" ....... ....... .................... ...................... ..................... ",
" ...... ....... .................. ...................... ................... ",
" ..... ..... .............. ...................... ............. ",
" . . . . ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" "};
/* XPM */
static char * blank_dvd_logo[] = {
"250 155 2 1",
" c None",
". c #000000",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ..................................................................................... ",
" ....................................................................................... ............................................................ ",
" ....................................................................................... .................................................................. ",
" ........................................................................................ ...................................................................... ",
" ........................................................................................ ......................................................................... ",
" ........................................................................................ ............................................................................ ",
" .......................................................................................... .............................................................................. ",
" .......................................................................................... ................................................................................ ",
" .......................................................................................... .................................................................................. ",
" .......................................................................................... ..................................................................................... ",
" ........................................................................................... ....................................................................................... ",
" ............................................................................................ ......................................................................................... ",
" ............................................................................................ .......................................................................................... ",
" ............................................................................................. ........................................................................................... ",
" ........................................................ ........................ ................................ ",
" ..................................................... ........................ ............................. ",
" .................................................... ........................ ............................ ",
" .................................................. ....................... ........................... ",
" ....................... ................................................. ........................ ...................... .......................... ",
" ....................... ................................................. ........................ ....................... ......................... ",
" ....................... ................................................ ........................ ....................... ......................... ",
" ....................... ................................................ ........................ ....................... ........................ ",
" ........................ ......................... ...................... ....................... ....................... ........................ ",
" ....................... ......................... ...................... ....................... ....................... ....................... ",
" ....................... ......................... ..................... ....................... ....................... ........................ ",
" ....................... ......................... ..................... ....................... ....................... ........................ ",
" ........................ ........................ ...................... ....................... ....................... ........................ ",
" ....................... ......................... ..................... ....................... ....................... ........................ ",
" ....................... ......................... ..................... ....................... ....................... ....................... ",
" ....................... ......................... ..................... ....................... ....................... ....................... ",
" ....................... ......................... ..................... ....................... ....................... ........................ ",
" ....................... .......................... ..................... ....................... ....................... ........................ ",
" ....................... ......................... ..................... ...................... ....................... ........................ ",
" ....................... ......................... ..................... ...................... ....................... ........................ ",
" ....................... .......................... ..................... ...................... ....................... ......................... ",
" ....................... .......................... ..................... ....................... ........................ ........................ ",
" ....................... ........................... ..................... ....................... ....................... ......................... ",
" ....................... ........................... ..................... ...................... ....................... ......................... ",
" ....................... ............................ .......................................... ....................... .......................... ",
" ....................... ............................ ......................................... ........................ ........................... ",
" ....................... ............................. ........................................ ....................... ............................ ",
" ....................... ............................. ...................................... ....................... ............................. ",
" ....................... ............................... ..................................... ....................... .............................. ",
" ....................... ................................ .................................... ....................... ................................ ",
" ....................... ................................... ................................... ....................... ................................... ",
" ....................... ...... ........................................ .................................. ....................................................................... ",
" ...................................................................... ................................. ...................................................................... ",
" ..................................................................... ............................... ..................................................................... ",
" ................................................................... .............................. .................................................................... ",
" ................................................................. ............................ .................................................................. ",
" ................................................................ ........................... ................................................................. ",
" ............................................................. .......................... ............................................................... ",
" ............................................................ ........................ .............................................................. ",
" ........................................................ ....................... ........................................................... ",
" ..................................................... ...................... ......................................................... ",
" ................................................ ..................... ...................................................... ",
" ............................................ .................... ................................................... ",
" ..................................... .................. .............................................. ",
" .................... ................. ",
" ................ ",
" .............. ",
" ............. ",
" ............. ",
" ........... ",
" .......... ",
" ......... ",
" ....... ",
" ...... ",
" .... ",
" ... ",
" .. ",
" .. ",
" ............................................................... ",
" .................................................................................................... ",
" ............................................................................................................................ ",
" ............................................................................................................................................. ",
" ............................................................................................................................................................ ",
" ......................................................................................................................................................................... ",
" ..................................................................................................................................................................................... ",
" .................................................................................... ........................................................................................ ",
" ................................................................................ .................................................................................... ",
" .............................................................................. ................................................................................ ",
" ............................................................................ ................................................................................ ",
" ............................................................................. ................................................................................ ",
" ............................................................................ ............................................................................... ",
" ............................................................................. ................................................................................ ",
" ............................................................................ ................................................................................ ",
" .............................................................................. ................................................................................ ",
" .............................................................................. ................................................................................. ",
" ............................................................................... ................................................................................... ",
" ................................................................................ .................................................................................... ",
" ................................................................................. ..................................................................................... ",
" ..................................................................................... ....................................................................................... ",
" .......................................................................................... .............................................................................................. ",
" ....................................................................................................................................................................................................... ",
" ................................................................................................................................................................................................ ",
" ........................................................................................................................................................................................ ",
" .............................................................................................................................................................................. ",
" ................................................................................................................................................................. ",
" .................................................................................................................................................. ....... ",
" .................................................................................................................................. ...... ",
" ............................................................................................................ . .... ",
" .................................................................................. . .... ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ........ ",
" ....... ....... ....... ................ ...................... ............... ",
" ...... ....... ....... ................... ...................... .................... ",
" ....... ....... ....... .................... ...................... ....................... ",
" ...... ....... ....... ...... .......... ........ ......... .......... ",
" ....... ...... ....... ..... ........ ....... ........ ........ ",
" ...... ....... ....... ..... ....... ....... ........ ........ ",
" ....... ...... ....... ..... ....... ....... ....... ....... ",
" ....... ...... ....... ..... ........ ....... ....... ....... ",
" ....... ...... ....... ..... ....... ...................... ...... ....... ",
" ....... ...... ....... ..... ....... ...................... ...... ...... ",
" ....... ...... ....... ..... ....... ...................... ...... ...... ",
" ...... ....... ....... ..... ....... ........ ...... ....... ",
" ...... ...... ....... ..... ....... ....... ....... ....... ",
" ............ ....... ..... ........ ....... ...... ........ ",
" ........... ....... ..... ........ ....... ....... ........ ",
" .......... ....... ..... ........ ....... ........ ......... ",
" ......... ....... ..... ......... ....... ......... .......... ",
" ........ ....... ..................... ...................... ........................ ",
" ....... ....... .................... ...................... ..................... ",
" ...... ....... .................. ...................... ................... ",
" ..... ..... .............. ...................... ............. ",
" . . . . ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" "};
void dvd_animation(uint32_t *fb) {
uint32_t speed_range = 8;
// Assumes rng_init already called
int32_t pos_x = 100, pos_y = 100, speed_x = 0, speed_y = 0;
while (speed_x == 0) speed_x = rng_read() % speed_range - speed_range / 2;
while (speed_y == 0) speed_y = rng_read() % speed_range - speed_range / 2;
while (1) {
blit_image(pos_x, pos_y, dvd_logo);
delay(1000000);
blit_image(pos_x, pos_y, blank_dvd_logo);
delay(10000);
pos_x += speed_x;
pos_y += speed_y;
bool due_colour_change = false;
// When we hit the edge, invert speed and move slightly out of the
// colision range
if (pos_x + DVD_LOGO_WIDTH >= 1920) {
speed_x = -speed_x;
pos_x = 1920 - 1 - DVD_LOGO_WIDTH;
due_colour_change = true;
} else if (pos_x <= 0) {
speed_x = -speed_x;
pos_x = 1;
due_colour_change = true;
} else if (pos_y + DVD_LOGO_HEIGHT >= 1080) {
speed_y = -speed_y;
pos_y = 1080 - 1 - DVD_LOGO_HEIGHT;
due_colour_change = true;
} else if (pos_y <= 0) {
speed_y = -speed_y;
pos_y = 1;
due_colour_change = true;
}
if (due_colour_change) {
// Randomly generate a hex colour and overwrite chars of the xpm
for (int i = 0; i < 5; i++) {
uint8_t number = rng_read() % 16;
char digits[] = {
'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'
};
dvd_logo[2][6 + i] = digits[number];
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment