Skip to content

Commit

Permalink
Merge pull request #641 from pimoroni/cosmic
Browse files Browse the repository at this point in the history
Cosmic
  • Loading branch information
Gadgetoid committed Feb 21, 2023
2 parents 93ac854 + 2176e0f commit 049219c
Show file tree
Hide file tree
Showing 68 changed files with 15,325 additions and 208 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/micropython-picow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ jobs:
board: PICO_W_ENVIRO
- name: picow_galactic_unicorn
board: PICO_W
- name: picow_cosmic_unicorn
board: PICO_W
- name: picow_inky_frame
board: PICO_W_INKY

Expand Down
1 change: 1 addition & 0 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,4 @@ add_subdirectory(inventor2040w)
add_subdirectory(encoder)
add_subdirectory(galactic_unicorn)
add_subdirectory(gfx_pack)
add_subdirectory(cosmic_unicorn)
84 changes: 84 additions & 0 deletions examples/cosmic_unicorn/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
add_executable(
cosmic_rainbow_text
cosmic_rainbow_text.cpp
)

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

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



add_executable(
cosmic_rainbow
cosmic_rainbow.cpp
)

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

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




add_executable(
cosmic_eighties_super_computer
cosmic_eighties_super_computer.cpp
)

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

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




add_executable(
cosmic_fire_effect
cosmic_fire_effect.cpp
)

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

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




add_executable(
cosmic_scroll_text
cosmic_scroll_text.cpp
)

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

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


add_executable(
cosmic_lava_lamp
cosmic_lava_lamp.cpp
)

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

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

7,847 changes: 7,847 additions & 0 deletions examples/cosmic_unicorn/audio_samples.cpp

Large diffs are not rendered by default.

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

#include "libraries/pico_graphics/pico_graphics.hpp"
#include "cosmic_unicorn.hpp"

using namespace pimoroni;

PicoGraphics_PenRGB888 graphics(32, 32, nullptr);
CosmicUnicorn cosmic_unicorn;

float lifetime[32][32];
float age[32][32];

int main() {

stdio_init_all();

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

cosmic_unicorn.init();

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

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

for(int y = 0; y < 32; y++) {
for(int x = 0; x < 32; 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;
}
}

cosmic_unicorn.update(&graphics);

sleep_ms(10);
}

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

#include "libraries/pico_graphics/pico_graphics.hpp"
#include "cosmic_unicorn.hpp"

using namespace pimoroni;

PicoGraphics_PenRGB888 graphics(32, 32, nullptr);
CosmicUnicorn cosmic_unicorn;

// extra row of pixels for sourcing flames and averaging
int width = 32;
int height = 33;

// a buffer that's at least big enough to store 55 x 15 values (to allow for both orientations)
float heat[2000] = {0.0f};

void set(int x, int y, float v) {
heat[x + y * width] = v;
}

float get(int x, int y) {
/*if(x < 0 || x >= width || y < 0 || y >= height) {
return 0.0f;
}*/
x = x < 0 ? 0 : x;
x = x >= width ? width - 1 : x;

return heat[x + y * width];
}

int main() {

stdio_init_all();

cosmic_unicorn.init();
cosmic_unicorn.set_brightness(0.2);

bool landscape = true;
/*
while(true) {
cosmic_unicorn.set_pixel(0, 0, 255, 0, 0);
cosmic_unicorn.set_pixel(1, 1, 0, 255, 0);
cosmic_unicorn.set_pixel(2, 2, 0, 0, 255);
}*/

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


for(int y = 0; y < height; y++) {
for(int x = 0; x < width; x++) {
float value = get(x, y);

graphics.set_pen(0, 0, 0);
if(value > 0.5f) {
graphics.set_pen(255, 255, 180);
}else if(value > 0.4f) {
graphics.set_pen(220, 160, 0);
}else if(value > 0.3f) {
graphics.set_pen(180, 30, 0);
}else if(value > 0.22f) {
graphics.set_pen(20, 20, 20);
}

if(landscape) {
graphics.pixel(Point(x, y));
}else{
graphics.pixel(Point(y, x));
}

// update this pixel by averaging the below pixels
float average = (get(x, y) + get(x, y + 2) + get(x, y + 1) + get(x - 1, y + 1) + get(x + 1, y + 1)) / 5.0f;

// damping factor to ensure flame tapers out towards the top of the displays
average *= 0.98f;

// update the heat map with our newly averaged value
set(x, y, average);
}
}

cosmic_unicorn.update(&graphics);

// clear the bottom row and then add a new fire seed to it
for(int x = 0; x < width; x++) {
set(x, height - 1, 0.0f);
}

// add a new random heat source
int source_count = landscape ? 5 : 1;
for(int c = 0; c < source_count; c++) {
int px = (rand() % (width - 4)) + 2;
set(px , height - 2, 1.0f);
set(px + 1, height - 2, 1.0f);
set(px - 1, height - 2, 1.0f);
set(px , height - 1, 1.0f);
set(px + 1, height - 1, 1.0f);
set(px - 1, height - 1, 1.0f);
}

sleep_ms(20);
}

return 0;
}
Loading

0 comments on commit 049219c

Please sign in to comment.