Skip to content

Instantly share code, notes, and snippets.

@volfegan
Last active July 16, 2024 01:37
Show Gist options
  • Save volfegan/c7292dae4edbace6bf23ad0b1268f599 to your computer and use it in GitHub Desktop.
Save volfegan/c7292dae4edbace6bf23ad0b1268f599 to your computer and use it in GitHub Desktop.
Pseudo3D 8bit tunnel effect created by logical operators insanity
//inspired by Orbital Decay's 8bit demoscene code
//https://www.youtube.com/watch?v=VP0wOxSAH38
int t;
void setup() {
size(1280, 720);
colorMode(HSB);
noStroke();
clear();
}
int mode = 0; //spacebar for mode change
void keyPressed() {
if (key == ' ') {
mode++;
mode%=8;
println("Mode="+mode);
t=0;
}
}
void draw() {
t++;
//println(frameRate);
for (int i=0; i<width; i+=4) {
for (int j=0; j<height; j+=4) {
int x = i-width/2;
int y = j-height/2;
int u = (int)(1024*atan2(y, x)/PI);
int v = (int)(64*4096/(sqrt(x*x+y*y+1)));
int b = v+t;
int c = u+v+t;
float o = 150;//colour offset, cyan
//chessboard squares
if (mode==0) {
int s=3; //size of the square tiling
float bg=15*(((x^y)>>s)&8) + o;//cyan + red, chessboard squares
fill(bg, 255, bg-o>0 ? 0:255);//remove red colours to black
}
//chessboard squares + circular ripples
if (mode==1) {
int s=3; //size of the square tiling
float bg=15*(((x^y)>>s)&(8+int(.01*(b+v/2048))%2)) + o;//cyan + red, chessboard + circular ripples
fill(bg, 255, bg-o>0?0:255);
}
//flat chessboard squares tunnel
if (mode==2) {
float bg=15*(((x^y)>>3)&9) + o;//cyan + red, chessboard flaw-gap squares (&9 instead of &8)
o=160+10*sin(b*.05);//offset colour to blue shades gradient
fill(bg, 255, bg-o>0?0:255);
bg=15*(((u^b)>>4)&8) + o;//deep blue + red chessboard squares tunnel
//conditional to show tunnel except the centre area
if ((v/(1024*3))%64==0) fill(bg, 255, bg-o>0?0:255);
}
//Background chessboard + spiraling chessboard squares tunnel
if (mode==3) {
float bg=15*(((x^y)>>4)&8) + o;//cyan + red, chessboard squares
int s = 3;//size of chessboard square strips on rotating tunnel
int d = 7;//deep of spiral tunnel
if ((b/(1024*d))%64==0 && (c/(128*s))%2==0) {
o = 200;//pink
bg=15*(((u^c)>>4)&8) + o;//pink + red spiral strips chessboard squares tunnel
}
fill(bg, 255, bg-o>0?0:255);
}
//2 colour spiraling chessboard squares + flat chessboard squares tunnel
if (mode==4) {
o=150+20*sin(b*.05);
float bg=15*(((u^b)>>4)&8) + o;//deep blue gradient + red, chessboard squares tunnel
int s = 5;//size of chessboard square strips on rotating tunnel
if ((b/(1024*4))%64==0 && (c/(128*s))%2==0) {
//rotating strips of chessboard squares tunnel
o = 20+20*sin((b+v-5*t)*.01);//offset colour to red-orange-yellow shades gradient
bg=15*(((u^c+2*t)>>3)&8) + o;//red-orange-yellow + red spiral strips chessboard squares tunnel
}
fill(bg, 255, bg-o>0?0:255);
}
//chessboard with gaps spiraling gradient ring colours tunnel
if (mode==5) {
o=140;
float bg=15*(((x^y)>>2)&9) + o;//cyan + red, chessboard flaw-gap squares (&9 instead of &8)
o=160+20*sin(b*.05);//deep blue-cyan gradient
fill(bg, 255, bg-o>0?0:255);
bg=15*(((u^c)>>5)&9) + o;//blue-cyan + red, chessboard with gaps spiral tunnel (&9 instead of &8)
if ((v/(1024*4))%64==0) fill(bg, 255, bg-o>0?0:255);
if (bg-o>0 && (v/(1024*4))%64==0) {//selects black spots, except the centre
bg=(((b/8))&8)%2==0 ? (((5*t%128-b)/8)&8)*7-90+v%64 : 0;//orange+red hue inward step sync rings
fill(bg, 255, bg);//brown+black rings
}
}
//spiraling gradient colour tunnel + OR retangular pattern
if (mode==6) {
float bg=15*(((((u-2*t)&v+t*3)>>3)|8)&31) + o; //rotating cyan multi-square shapes on red
int s = 4;//size of spiral strips on rotating tunnel
if ((b/(1024*7))%64==0 && ((c/(64*s))%2)==0) {
o = 200;//pink
bg=15*((((u+c+2*t)>>4)&4)&2) + o;//continuous pink spiral strips
//bg=15*(((u+c+2*t)>>4)&4) + o;//dash lines pink spiral strips
}
fill(bg, 255, bg-o>0? ((b/8)&8)*4+20 :255);
if (bg==200) {//selects pink colour
o=0;
bg=(b/8)%50+120; //cyan+blue hue gradient ring
fill(bg, ((b/8)&16)*20, 180);//white+cyan+blue gradient ring on spiral strips
}
//circular outer strip tunnel
if (bg>320) {
bg=(((b/8+t)^c)&8)%2==0?((b/8)&8)*16+10:0;
fill(bg, 255, bg);
}
}
//spiraling gradient colour tunnel + Sierpinski Triangles
if (mode==7) {
o = 100+(v/5)%64;//colour offset gradient green-cyan-blue + sparks
float bg=15*(((((u-2*t)&v+t*5)>>3)^0)&63) + o;//Sierpinski Triangles
int s = 3;//size of spiral strips on rotating tunnel
if ((b/(1024*7))%64==0 && (c/(64*s))%2==0) {
o = 200;
bg=15*((((u+c+2*t)>>4)&4)&2) + o;//continuous lines pink spiral strips
//bg=15*(((u+c+2*t)>>4)&4) + o;//dash lines pink spiral strips
}
fill(bg, 255, bg-o>0?0:255);
if (bg==200) {//selects pink colour
o=0;
bg=(b/8)%50+140;//pink+cyan+blue hue gradient ring
fill(bg, 200, 255);//gradient ring on spiral strips
}
//circular outer strip tunnel
if (bg>320) {
bg=(((b/8))&8)%2==0 ? ((b/8)&8)*5-20 : 0;//orange+red hue rings
fill(bg, 255, bg);//brown+black rings
}
}
rect(i, j, 4, 4);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment