Skip to content

Instantly share code, notes, and snippets.

@jkwok91
Created March 7, 2014 18:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jkwok91/8f88c1bf14835b18af02 to your computer and use it in GitHub Desktop.
Save jkwok91/8f88c1bf14835b18af02 to your computer and use it in GitHub Desktop.
yay
/*
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