Skip to content

Commit

Permalink
Merge pull request #537 from pimoroni/feature/galactic_unicorn
Browse files Browse the repository at this point in the history
Galactic Unicorn
  • Loading branch information
Gadgetoid authored Oct 19, 2022
2 parents 3405130 + d736342 commit e928129
Show file tree
Hide file tree
Showing 49 changed files with 15,178 additions and 14 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/micropython-picow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ jobs:

build:
needs: deps
name: Build ${{matrix.board}}
name: Build ${{matrix.name}} (${{matrix.board}})
runs-on: ubuntu-20.04
strategy:
matrix:
Expand All @@ -70,6 +70,8 @@ jobs:
board: PICO_W
- name: picow_enviro
board: PICO_W_ENVIRO
- name: picow_galactic_unicorn
board: PICO_W

env:
# MicroPython version will be contained in github.event.release.tag_name for releases
Expand Down
1 change: 1 addition & 0 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,4 @@ add_subdirectory(servo2040)
add_subdirectory(motor2040)
add_subdirectory(inventor2040w)
add_subdirectory(encoder)
add_subdirectory(galactic_unicorn)
125 changes: 125 additions & 0 deletions examples/galactic_unicorn/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
add_executable(
rainbow_text
rainbow_text.cpp
)

# Pull in pico libraries that we need
target_link_libraries(rainbow_text pico_stdlib hardware_pio hardware_adc hardware_dma pico_graphics galactic_unicorn)
pico_enable_stdio_usb(rainbow_text 1)

# create map/bin/hex file etc.
pico_add_extra_outputs(rainbow_text)



add_executable(
rainbow
rainbow.cpp
)

# Pull in pico libraries that we need
target_link_libraries(rainbow pico_stdlib hardware_pio hardware_adc hardware_dma pico_graphics galactic_unicorn)
pico_enable_stdio_usb(rainbow 1)

# create map/bin/hex file etc.
pico_add_extra_outputs(rainbow)



add_executable(
nostalgia_prompt
nostalgia_prompt.cpp
)

# Pull in pico libraries that we need
target_link_libraries(nostalgia_prompt pico_stdlib hardware_pio hardware_adc hardware_dma pico_graphics galactic_unicorn)
pico_enable_stdio_usb(nostalgia_prompt 1)

# create map/bin/hex file etc.
pico_add_extra_outputs(nostalgia_prompt)



add_executable(
eighties_super_computer
eighties_super_computer.cpp
)

# Pull in pico libraries that we need
target_link_libraries(eighties_super_computer pico_stdlib hardware_pio hardware_adc hardware_dma pico_graphics galactic_unicorn)
pico_enable_stdio_usb(eighties_super_computer 1)

# create map/bin/hex file etc.
pico_add_extra_outputs(eighties_super_computer)




add_executable(
fire_effect
fire_effect.cpp
)

# Pull in pico libraries that we need
target_link_libraries(fire_effect pico_stdlib hardware_pio hardware_adc hardware_dma pico_graphics galactic_unicorn)
pico_enable_stdio_usb(fire_effect 1)

# create map/bin/hex file etc.
pico_add_extra_outputs(fire_effect)




add_executable(
scroll_text
scroll_text.cpp
)

# Pull in pico libraries that we need
target_link_libraries(scroll_text pico_stdlib hardware_pio hardware_adc hardware_dma pico_graphics galactic_unicorn)
pico_enable_stdio_usb(scroll_text 1)

# create map/bin/hex file etc.
pico_add_extra_outputs(scroll_text)


add_executable(
balls
balls.cpp
)

# Pull in pico libraries that we need
target_link_libraries(balls pico_stdlib hardware_pio hardware_adc hardware_dma pico_graphics galactic_unicorn)
pico_enable_stdio_usb(balls 1)

# create map/bin/hex file etc.
pico_add_extra_outputs(balls)



add_executable(
lava_lamp
lava_lamp.cpp
)

# Pull in pico libraries that we need
target_link_libraries(lava_lamp pico_stdlib hardware_pio hardware_adc hardware_dma pico_graphics galactic_unicorn)
pico_enable_stdio_usb(lava_lamp 1)

# create map/bin/hex file etc.
pico_add_extra_outputs(lava_lamp)



add_executable(
feature_test
feature_test.cpp
audio_samples.cpp
)

# Pull in pico libraries that we need
target_link_libraries(feature_test pico_stdlib hardware_pio hardware_adc hardware_dma pico_graphics galactic_unicorn)
pico_enable_stdio_usb(feature_test 1)

# create map/bin/hex file etc.
pico_add_extra_outputs(feature_test)
7,847 changes: 7,847 additions & 0 deletions examples/galactic_unicorn/audio_samples.cpp

Large diffs are not rendered by default.

87 changes: 87 additions & 0 deletions examples/galactic_unicorn/balls.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "pico/stdlib.h"

#include "libraries/pico_graphics/pico_graphics.hpp"
#include "galactic_unicorn.hpp"
#include "okcolor.hpp"

using namespace pimoroni;

PicoGraphics_PenRGB888 graphics(53, 11, nullptr);
GalacticUnicorn galactic_unicorn;

// extra row of pixels for sourcing flames and averaging
float heat[53][13] = {0.0f};

int main() {

stdio_init_all();

galactic_unicorn.init();

while(true) {
if(galactic_unicorn.is_pressed(galactic_unicorn.SWITCH_BRIGHTNESS_UP)) {
galactic_unicorn.adjust_brightness(+0.01);
}
if(galactic_unicorn.is_pressed(galactic_unicorn.SWITCH_BRIGHTNESS_DOWN)) {
galactic_unicorn.adjust_brightness(-0.01);
}

graphics.set_pen(0, 0, 0);
graphics.clear();

for(int y = 0; y < 12; y++) {
for(int x = 0; x < 53; x++) {
if(heat[x][y] > 0.5f) {
graphics.set_pen(255, 255, 180);
graphics.pixel(Point(x, y));
}else if(heat[x][y] > 0.4f) {
graphics.set_pen(220, 160, 0);
graphics.pixel(Point(x, y));
}else if(heat[x][y] > 0.3f) {
graphics.set_pen(180, 50, 0);
graphics.pixel(Point(x, y));
}else if(heat[x][y] > 0.2f) {
graphics.set_pen(40, 40, 40);
graphics.pixel(Point(x, y));
}

// update this pixel by averaging the below pixels
if(x == 0) {
heat[x][y] = (heat[x][y] + heat[x][y + 2] + heat[x][y + 1] + heat[x + 1][y + 1]) / 4.0f;
} else if(x == 52) {
heat[x][y] = (heat[x][y] + heat[x][y + 2] + heat[x][y + 1] + heat[x - 1][y + 1]) / 4.0f;
} else {
heat[x][y] = (heat[x][y] + heat[x][y + 2] + heat[x][y + 1] + heat[x - 1][y + 1] + heat[x + 1][y + 1]) / 5.0f;
}

heat[x][y] -= 0.01f;
heat[x][y] = heat[x][y] < 0.0f ? 0.0f: heat[x][y];
}
}

galactic_unicorn.update(&graphics);

// clear the bottom row and then add a new fire seed to it
for(int x = 0; x < 53; x++) {
heat[x][11] = 0.0f;
}

// add a new random heat source
for(int c = 0; c < 5; c++) {
int px = (rand() % 51) + 1;
heat[px][11] = 1.0f;
heat[px + 1][11] = 1.0f;
heat[px - 1][11] = 1.0f;
heat[px][12] = 1.0f;
heat[px + 1][12] = 1.0f;
heat[px - 1][12] = 1.0f;
}

sleep_ms(50);
}

return 0;
}
68 changes: 68 additions & 0 deletions examples/galactic_unicorn/eighties_super_computer.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "pico/stdlib.h"

#include "libraries/pico_graphics/pico_graphics.hpp"
#include "galactic_unicorn.hpp"
#include "okcolor.hpp"

using namespace pimoroni;

PicoGraphics_PenRGB888 graphics(53, 11, nullptr);
GalacticUnicorn galactic_unicorn;

float lifetime[53][11];
float age[53][11];

int main() {

stdio_init_all();

for(int y = 0; y < 11; y++) {
for(int x = 0; x < 53; x++) {
lifetime[x][y] = 1.0f + ((rand() % 10) / 100.0f);
age[x][y] = ((rand() % 100) / 100.0f) * lifetime[x][y];
}
}

galactic_unicorn.init();

while(true) {
if(galactic_unicorn.is_pressed(galactic_unicorn.SWITCH_BRIGHTNESS_UP)) {
galactic_unicorn.adjust_brightness(+0.01);
}
if(galactic_unicorn.is_pressed(galactic_unicorn.SWITCH_BRIGHTNESS_DOWN)) {
galactic_unicorn.adjust_brightness(-0.01);
}

graphics.set_pen(0, 0, 0);
graphics.clear();

for(int y = 0; y < 11; y++) {
for(int x = 0; x < 53; x++) {
if(age[x][y] < lifetime[x][y] * 0.3f) {
graphics.set_pen(230, 150, 0);
graphics.pixel(Point(x, y));
}else if(age[x][y] < lifetime[x][y] * 0.5f) {
float decay = (lifetime[x][y] * 0.5f - age[x][y]) * 5.0f;
graphics.set_pen(decay * 230, decay * 150, 0);
graphics.pixel(Point(x, y));
}

if(age[x][y] >= lifetime[x][y]) {
age[x][y] = 0.0f;
lifetime[x][y] = 1.0f + ((rand() % 10) / 100.0f);
}

age[x][y] += 0.01f;
}
}

galactic_unicorn.update(&graphics);

sleep_ms(10);
}

return 0;
}
Loading

0 comments on commit e928129

Please sign in to comment.