Skip to content

Instantly share code, notes, and snippets.

@tomaes
Last active April 11, 2016 12:51
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomaes/352eeef9d1ae76cf14c3 to your computer and use it in GitHub Desktop.
Save tomaes/352eeef9d1ae76cf14c3 to your computer and use it in GitHub Desktop.
Sierpinsky Carpet bömbing; stylish fractal things + parallax scrolling
// PDE 3.02
// Sierpinski's Carpet bömbing (v3)
// updt: better, faster, interactive
PImage img = createImage(729,729, RGB);
void setup()
{
size( 729, 729, P2D ); //729 243 324
}
void draw()
{
int inrow = 0;
int _t = int(millis()*0.01);
img.loadPixels();
for(int y = 0; y < height; y++)
for(int x = 0; x < width; x++)
{
int ax = x + _t;
int ay = y + _t;
if ( (x %3 == 0 && ay %3 == 2) || // 0 2
((x / 3) %3 == 1 && (ay/3) %3 == 1) || // 1 1
((ax/ 9) %3 == 0 && (y/ 9) %3 == 2) || // 0 2
((ax/27) %3 == 0 && (y/27) %3 == 2) || // 0 2
((ax/81) %3 == 0 && (y/81) %3 == 2) || // 0 2
((ax/243)%3 == 1 && (y/243)%3 == 1) ) // 1 1
{
img.pixels[width * y + x] = color( ((ax+ay)/8)%3*50 + sin(ax*0.18)*(40-inrow) );
if (inrow < 40) inrow++;
}
else
{
img.pixels[width * y + x] = color(255 - random(0,3)*((ax+y) % 81) );
inrow = 0;
}
}
img.updatePixels();
// interactive delayed zoom, depending on mouse movement
tint(255, 235, 225 - min(abs(mouseX-pmouseX),20), 255 - min(abs(mouseX-pmouseX),200) );
// render buffer
image(img, -mouseX, -mouseX, width + mouseX*2, height + mouseX*2);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment