Skip to content

Instantly share code, notes, and snippets.

@wonderburg7
Last active January 4, 2019 18:29
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 wonderburg7/ff3b604157c9e84355486f5bcd16a922 to your computer and use it in GitHub Desktop.
Save wonderburg7/ff3b604157c9e84355486f5bcd16a922 to your computer and use it in GitHub Desktop.
PImage img;
float transparencyValue;
void setup() {
size(200, 200);
img = loadImage( "https://i.imgur.com/vpFQBfR.png" );
img.resize(width, height);
}
void draw() {
background(123, 123, 123, 0);
float d = (dist(width/2, height/2, mouseX, mouseY))+150;
// transparencyValue = map(mouseX, 0, width, 0, 255);
tint(255, 255-d);
image(img, 0, 0);
}
/*
PImage img;
void setup() {
size(400, 400);
img = loadImage( "https://i.imgur.com/vpFQBfR.png" );
img.resize(width, height);
}
void draw() {
loadPixels();
background(0, 0, 0, 0);
img.loadPixels();
// We must also call loadPixels() on the PImage since we are going to read its pixels. img.loadPixels();
for (int x = 0; x < img.width; x++ ) {
for (int y = 0; y < img.height; y++ ) {
// Calculate the 1D pixel location
int loc = x + y*img.width;
// Get the R,G,B values from image
float r = red (img.pixels[loc]);
float g = green(img.pixels[loc]);
float b = blue (img.pixels[loc]);
// Calculate an amount to change brightness
// based on proximity to the mouse
float distance = dist(x, y, mouseX, mouseY);
// The closer the pixel is to the mouse, the lower the value of "distance"
// We want closer pixels to be brighter, however, so we invert the value using map()
// Pixels with a distance of 50 (or greater) have a brightness of 0.0 (or negative which is equivalent to 0 here)
// Pixels with a distance of 0 have a brightness of 1.0.
float adjustBrightness = map(distance, 0, 50, 8, 0);
r *= adjustBrightness;
g *= adjustBrightness;
b *= adjustBrightness;
// Constrain RGB to between 0-255
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
color c = color(r, g, b, 255);
pixels[loc] = c;
}
}
updatePixels();
}
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment