Last active
April 9, 2016 16:58
-
-
Save tomaes/d29c7653d28a481ffa6fda5cd7a04d2c to your computer and use it in GitHub Desktop.
P5.js test port / conversion. Fast it is not. :/
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
// Sierpinski's Carpet bömbing (v3) | |
// p5.js port (slow...) | |
var img; | |
function setup() | |
{ | |
createCanvas( 729, 729, P2D ); //729 243 324 | |
img = createImage(729,729, RGB); | |
} | |
function draw() | |
{ | |
var inrow = 0; | |
var _t = int(millis()*0.01); | |
img.loadPixels(); | |
for(var y = 0; y < height; y++) | |
for(var x = 0; x < width; x++) | |
{ | |
var ax = x + _t; | |
var ay = y + _t; | |
// fast integer operations in js == clownfest :/ | |
if ( ( (x|0) %3 === 0 && (ay|0) %3 === 2) || // 0 2 | |
( (x / 3|0) %3 === 1 && (ay/3|0) %3 === 1) || // 1 1 | |
( (ax/ 9|0) %3 === 0 && (y/ 9|0) %3 === 2) || // 0 2 | |
( (ax/27|0) %3 === 0 && (y/27|0) %3 === 2) || // 0 2 | |
( (ax/81|0) %3 === 0 && (y/81|0) %3 === 2) || // 0 2 | |
( (ax/243|0)%3 === 1 && (y/243|0)%3 === 1) ) // 1 1 | |
{ | |
img.set( x,y, color( ((ax+ay)/8|0)%3*50 + sin(ax*0.18)*(40-inrow)|0 ) ); | |
if (inrow < 40) inrow++; | |
} | |
else | |
{ | |
img.set( x,y, color(255 - ( (ax+y) % 81)|0 ) ); | |
inrow = 0; | |
} | |
} | |
img.updatePixels(); | |
// interactive delayed zoom | |
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); | |
// cube test | |
/* | |
background(200); | |
translate(0,-50,0); | |
rotateY(0.6); | |
texture(img); | |
box(200); | |
*/ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment