Fill Object with certain RGB color of an image
in
Programming Questions
•
1 year ago
Hey All,
im new to processing and a bit nerdy about some detail. i made a logo in processing and want to fill the objects with a random color of the image i chose. instead of just picking one color and fill the object, the whole think is flickering around and picking some new color every single frame. what do i have to do to pick just one color and fill the object?
tanks for your help
PImage img;
int pointillize = 10;
void setup() {
size(1000,800);
img = loadImage("img4.jpg");
background(255);
smooth();
}
void draw() {
// Pick a random point
int x = int(random(img.width));
int y = int(random(img.height));
int loc = x + y;
// Look up the RGB color in the source image
loadPixels();
float r = red(img.pixels[loc]);
float g = green(img.pixels[loc]);
float b = blue(img.pixels[loc]);
noStroke();
// Pick a random point1
int w = int(random(img.width));
int f = int(random(img.height));
int loc1 = w + f;
// Look up the RGB color in the source image1
loadPixels();
float r1 = red(img.pixels[loc1]);
float g1 = green(img.pixels[loc1]);
float b1 = blue(img.pixels[loc1]);
noStroke();
// Pick a random point2
int d = int(random(img.width));
int c = int(random(img.height));
int loc2 = d + c;
// Look up the RGB color in the source image2
loadPixels();
float r2 = red(img.pixels[loc2]);
float g2 = green(img.pixels[loc2]);
float b2 = blue(img.pixels[loc2]);
noStroke();
// Pick a random point3
int h = int(random(img.width));
int j = int(random(img.height));
int loc3 = h + j;
// Look up the RGB color in the source image3
loadPixels();
float r3 = red(img.pixels[loc3]);
float g3 = green(img.pixels[loc3]);
float b3 = blue(img.pixels[loc3]);
noStroke();
// Draw an rectangle at that location with that color
fill(r,g,b,100);
triangle(300, 330, 300, 570, 507.85, 450);
fill(r1,g1,b1,100);
triangle(507.85, 210, 300, 330, 507.85, 450);
fill(r2,g2,b2,100);
triangle(715.69, 330, 507.85, 210, 507.85, 450);
fill(r3,g3,b3,100);
triangle(715.69, 570, 715.69, 330, 507.85, 450);
}
1