Skip to content

Instantly share code, notes, and snippets.

@simme
Created February 5, 2018 21:42
Show Gist options
  • Save simme/0fc3a02dae05605baf9e3371c4013843 to your computer and use it in GitHub Desktop.
Save simme/0fc3a02dae05605baf9e3371c4013843 to your computer and use it in GitHub Desktop.
Processing pixel manip
void setup() {
fullScreen();
frameRate(15);
}
void draw() {
// Loads all pixels on screen into an array of size width*height
loadPixels();
color onColor = #000000;
color offColor = #FFFFFF;
for(int x = 0; x<width/2; x++) {
for(int y = 0; y<height/2; y++) {
// Calculates a random new coordinate
// **Bonus points** if the screensaver allows for modifications to the parameter to `random`. Changing the value of one to 4
// for example, gives another neat effect.
int x_new = 2*x+int(random(2));
int y_new = 2*y+int(random(2));
// If our new coordinate is within the screen flip the color of that pixel.
if (x_new < width && y_new < height) {
int dest_pixel = (y_new*width + x_new);
color c = pixels[y*width+x];
if(c == onColor){
pixels[dest_pixel] = offColor;
}
else {
pixels[dest_pixel] = onColor;
}
}
}
}
updatePixels();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment