Skip to content

Instantly share code, notes, and snippets.

@thcrack
Created April 25, 2019 11:58
Show Gist options
  • Save thcrack/4bb63fbba248abd329cdf2a200a31e64 to your computer and use it in GitHub Desktop.
Save thcrack/4bb63fbba248abd329cdf2a200a31e64 to your computer and use it in GitHub Desktop.
PImage img ;
int r = 10;//size of ecllipse
boolean hasLoadedPixels = false;
void setup () {
size(400, 400) ;
img = loadImage("SpongeBob.jpg") ;
image(img, 0, 0) ;
loadPixels();
}
void draw() {
if(mousePressed){
int R = 0, G = 0, B = 0, count = 0;
for(int i = -r; i < r; i++){
for(int j = -r; j < r; j++){
int x = mouseX + i;
int y = mouseY + j;
if(x < 0 || x >= width || y < 0 || y >= height) continue;
if(dist(x, y, mouseX, mouseY) > r) continue;
R += red(pixels[x + y * width]);
G += green(pixels[x + y * width]);
B += blue(pixels[x + y * width]);
count++;
}
}
if(count > 0){
color newColor = color(R / count, G / count, B/ count);
for(int i = -r; i < r; i++){
for(int j = -r; j < r; j++){
int x = mouseX + i;
int y = mouseY + j;
if(x < 0 || x >= width || y < 0 || y >= height) continue;
if(dist(x, y, mouseX, mouseY) > r) continue;
pixels[x + y * width] = newColor;
}
}
}
updatePixels();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment