-
-
Save sutaburosu/b513bad099ffa5a9e1c750a7262f14d5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Original Lua/TIC-80 source was live-coded in | |
25 minutes by exoticorn during a 256-byte battle | |
at outlinedemoparty.nl 2021-05-15 | |
function TIC()t=time()/1e3 | |
for i=0,32639 do | |
x=i%240-120 | |
y=i//240-68 | |
z=20/(x*x+y*y)^.5+t | |
q=z%9<6 and z-z%9+6 or z | |
w=9/y+t | |
c=y>0 and w<q and | |
(((x*(w-t))^2<99 and 14 or 6)+w%2)or | |
(-y*(q-t)<99/((x*(q-t)/50)^2+1)and(q==z and z%2 or 3)or 10) | |
poke4(i,c) | |
end | |
end | |
*/ | |
#include "Teensy4_ShieldV5_RBG.h"> // SmartLED Shield for Teensy 4 (V5) | |
#include <SmartMatrix.h> | |
#define COLOR_DEPTH 24 // Choose the color depth used for storing pixels in the layers: 24 or 48 (24 is good for most sketches - If the sketch uses type `rgb24` directly, COLOR_DEPTH must be 24) | |
const uint16_t kMatrixWidth = 128; // Set to the width of your display, must be a multiple of 8 | |
const uint16_t kMatrixHeight = 64; // Set to the height of your display | |
const uint8_t kRefreshDepth = 36; // Tradeoff of color quality vs refresh rate, max brightness, and RAM usage. 36 is typically good, drop down to 24 if you need to. On Teensy, multiples of 3, up to 48: 3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42, 45, 48. On ESP32: 24, 36, 48 | |
const uint8_t kDmaBufferRows = 4; // known working: 2-4, use 2 to save RAM, more to keep from dropping frames and automatically lowering refresh rate. (This isn't used on ESP32, leave as default) | |
const uint8_t kPanelType = SM_PANELTYPE_HUB75_64ROW_MOD32SCAN; // Choose the configuration that matches your panels. See more details in MatrixCommonHub75.h and the docs: https://github.com/pixelmatix/SmartMatrix/wiki | |
const uint32_t kMatrixOptions = (SM_HUB75_OPTIONS_NONE); // see docs for options: https://github.com/pixelmatix/SmartMatrix/wiki | |
const uint8_t kBackgroundLayerOptions = (SM_BACKGROUND_OPTIONS_NONE); | |
SMARTMATRIX_ALLOCATE_BUFFERS(matrix, kMatrixWidth, kMatrixHeight, kRefreshDepth, kDmaBufferRows, kPanelType, kMatrixOptions); | |
SMARTMATRIX_ALLOCATE_BACKGROUND_LAYER(backgroundLayer, kMatrixWidth, kMatrixHeight, COLOR_DEPTH, kBackgroundLayerOptions); | |
const uint16_t kHalfWidth = kMatrixWidth / 2; | |
const uint16_t kHalfHeight = kMatrixHeight / 2; | |
// https://github.com/nesbox/TIC-80/wiki/palette | |
rgb24 sweetie16[] = { | |
rgb24(0x1a, 0x1c, 0x2c), rgb24(0x5d, 0x27, 0x5d), rgb24(0xb1, 0x3e, 0x53), rgb24(0xef, 0x7d, 0x57), | |
rgb24(0xff, 0xcd, 0x75), rgb24(0xa7, 0xf0, 0x70), rgb24(0x38, 0xb7, 0x64), rgb24(0x25, 0x71, 0x79), | |
rgb24(0x29, 0x36, 0x6f), rgb24(0x3b, 0x5d, 0xc9), rgb24(0x41, 0xa6, 0xf6), rgb24(0x73, 0xef, 0xf7), | |
rgb24(0xf4, 0xf4, 0xf4), rgb24(0x94, 0xb0, 0xc2), rgb24(0x56, 0x6c, 0x86), rgb24(0x33, 0x3c, 0x57)}; | |
void setup() { | |
Serial.begin(115200); | |
delay(300); | |
matrix.addLayer(&backgroundLayer); | |
matrix.begin(); | |
backgroundLayer.setBrightness(128); | |
} | |
void loop() { | |
while(backgroundLayer.isSwapPending()); | |
rgb24 *led = backgroundLayer.backBuffer(); | |
byte c; | |
float t = millis() / 1000.f, z, q, w; | |
for (int16_t y = -kHalfHeight-kHalfHeight/9; y < kHalfHeight-kHalfHeight/9; y++) { | |
for (int16_t x = -kHalfWidth; x <= 0; x++) { | |
z = 20.0f / sqrtf(x*x + y*y) + t; | |
q = (fmod(z, 9) < 6) ? z - fmod(z, 9) + 6 : z; | |
w = 9.0f / y + t; | |
if (y > 0 && w < q) | |
c = (powf(x*(w-t), 2) < 9 ? 14 : 6) + fmod(w, 2); | |
else | |
if (-y*(q-t) < 99.f / (powf(x*(q-t) / 50.f, 2)+1)) | |
c = (q==z) ? fmod(z, 2) : 3; | |
else | |
c = 9 - y/12 + ((0b111101001000 >> (-y%12)) & 1); | |
// c = 10; // I didn't see the original Lua sky gradient/dither code | |
*led++ = sweetie16[c]; | |
} | |
rgb24 *src = led-1; | |
for (uint16_t x = 1; x < kHalfWidth; x++) | |
*led++ = *--src; | |
} | |
// buffer is filled completely each time, use swapBuffers without buffer copy to save CPU cycles | |
backgroundLayer.swapBuffers(false); | |
matrix.countFPS(); // print the loop() frames per second to Serial | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment