-
-
Save jkwok91/8f88c1bf14835b18af02 to your computer and use it in GitHub Desktop.
yay
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
/* | |
sierpinski's triangle | |
*/ | |
int cx = 75; | |
int cy = 149; | |
color pink = color(255,102,255); | |
color black = color(0); //-16777216 | |
void setup() { | |
size(cx*2,cy+1); | |
background(0); | |
loadPixels(); | |
pixels[(cy*width)+cx] = pink; | |
updatePixels(); | |
} | |
void mousePressed() { | |
noLoop(); | |
} | |
void mouseReleased() { | |
loop(); | |
} | |
void draw() { | |
renderScreen(); | |
} | |
void renderScreen() { | |
/* | |
shift everything up a row to give illusion of scrolling | |
*/ | |
loadPixels(); | |
int j; | |
for (j = 0; j < cy; j++) { | |
for (int i = 0; i < width; i++) { | |
pixels[(j*width)+i] = pixels[((j+1)*width)+i]; | |
} | |
} | |
int lineStart = (j-1)*width; | |
int newLineStart = j*width; | |
for (int i = 1; i < width-1; i++) { | |
if ((pixels[lineStart+(i-1)] != pixels[lineStart+(i+1)]) && ((pixels[lineStart+(i-1)] != -16777216) || (pixels[lineStart+(i+1)] != -16777216))) { | |
pixels[newLineStart+i] = pink; | |
} else { | |
pixels[newLineStart+i] = black; | |
} | |
} | |
updatePixels(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment