Created
May 14, 2021 20:56
-
-
Save volfegan/e8486a5f67542d5c458d9e0eccd00a28 to your computer and use it in GitHub Desktop.
8bit background effects like waterfall, lava, XOR mesh/grid/munching squares
This file contains hidden or 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
//inspired from Flopine's 8bit demoscene code | |
//https://www.youtube.com/watch?v=_JQm46HuDEE | |
float t; | |
void setup() { | |
size(1280, 720); | |
colorMode(HSB); | |
noStroke(); | |
clear(); | |
} | |
int mode = 0; //spacebar for mode change | |
void keyPressed() { | |
if (key == ' ') { | |
mode++; | |
mode%=6; | |
println("Mode="+mode); | |
} | |
} | |
void draw() { | |
t++; | |
for (int y=0; y< height; y+=5) { | |
for (int x=0; x< width; x+=5) { | |
//diamond strip flow | |
if (mode==0) { | |
float u = abs(x-width/2); | |
float v = abs(y-height/2); | |
fill((u+v+t)%150+69, 255, 255); | |
rect(x, y, 5, 5); | |
} | |
//XOR squares | |
if (mode==1) { | |
fill((x^y)%150+69, 255, 255); | |
rect(x, y, 5, 5); | |
} | |
//XOR munching squares | |
if (mode==2) { | |
fill(((x^y)+t*5)/2%150+69, 255, 255); | |
rect(x, y, 5, 5); | |
} | |
//digital logical XOR mesh | |
if (mode==3) { | |
fill(120*abs(sin(((x^y)+t*.05)))+69, 255, 255); | |
rect(x, y, 5, 5); | |
} | |
//cascading waterfall | |
if (mode == 4) { | |
fill((((x*x)^y)+t*5)/4%20+140, 255, 255); | |
rect(width-5-x, height-5-y, 5, 5); | |
} | |
//cascading lava merge | |
if (mode == 5) { | |
fill((((x*x)^y)+t*5)/.75%90-40, 255, (((x*x)^y)+t*5)/.75%90>16 ? 255:150); | |
rect(width-5-x, height*.7-y, 5, 5); | |
rect(x, height-5-y*.3, 5, 5); | |
} | |
} | |
} | |
//Balls dancing in the centre | |
float r=69, s=240, o=0; | |
for (int i=0; i<5; i++) { | |
s-=40; | |
o+=i*20; | |
float x = width/2+sin(cos(.4*t*.1)*PI+o)*r; | |
float y = height/2+cos((.4*t*.2+o))*r; | |
float z = s/5; | |
fill(-1); | |
circle(x, y, s*1.1); | |
fill(0); | |
circle(x, y, s); | |
fill(-1); | |
circle(x+z, y-z, z*1.5); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment