Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- for (var x = 0; x < img.width; x++) {
- for (var y = 0; y < img.height; y++ ) {
- // Calculate the 1D location from a 2D grid
- var loc = x + y*img.width;
- // Get the R,G,B values from image
- var r,g,b;
- r = red (img.pixels[loc]);
- g = green (img.pixels[loc]);
- b = blue (img.pixels[loc]);
- // Calculate an amount to change brightness based on proximity to the mouse
- var maxdist = 50;//dist(0,0,width,height);
- var d = dist(x, y, mouseX, mouseY);
- var adjustbrightness = 255*(maxdist-d)/maxdist;
- r += adjustbrightness;
- g += adjustbrightness;
- b += adjustbrightness;
- // Constrain RGB to make sure they are within 0-255 color range
- r = constrain(r, 0, 255);
- g = constrain(g, 0, 255);
- b = constrain(b, 0, 255);
- // Make a new color and set pixel in the window
- var c = color(r, g, b);
- //color c = color(r);
- pixels[y*width + x] = c; //???
- }
- }
- updatePixels();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement