Skip to content

Instantly share code, notes, and snippets.

@robynitp
Created March 5, 2015 21:05
Show Gist options
  • Save robynitp/f9f00e80c90034334d1a to your computer and use it in GitHub Desktop.
Save robynitp/f9f00e80c90034334d1a to your computer and use it in GitHub Desktop.
Pixel manipulation in P5
var img;
function preload(){
img = loadImage("lisa.png");
}
function setup(){
createCanvas(500,382);
image(img,0,0);
loadPixels();
for (var i = 0; i < (width*height); i++) {
var index = i*4;
pixels[index] = 255; // red
pixels[index+1] = 255; // green
pixels[index+2] = 255; // blue
pixels[index+3] = 100; //alpha
// Note: you don't have to change ALL of the RGBA values.
// You could only change alpha to make the image more transparent
// or change only the blue to make it more or less blue
// Try commenting out some of the 4 lines for setting pixels and see what results you get.
}
updatePixels();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment