I want to set/fill my text(avg 450 words) color with the same color of preload image to my canvas in P5js / JS. Is anybody can help me with how to do that?
You want to get the colour of an image and then fill with that colour so the text will be the same colour.
Here's a link to the documentation for the get() method which is what you're looking for.
In order to do this, we use the get(x, y) method to get the pixel at a specific location, this returns us an RGBA value which we can use to fill.
I've put together a really simple example to demonstrate this:
let img;
function preload() {
img = loadImage('img.jpg');
}
function setup() {
createCanvas(400, 400);
image(img, 0, 0);
let c = get(0, 0);
fill(c);
}
function draw() {
background(0);
image(img, 0, 0);
textSize(20);
text('I am the same colour', 100, 350);
}
I'm just grabbing the very first pixel and filling with that. Here's a link to a p5.js sketch so you can see it running.