Hello all,
I want to fill a text’s (avg 450 words or more) color with the same color of preload image on canvas in P5js.
Actually, I am trying to recreate this image with the same colors as the text I wrote.
Is anybody can help me with how to do that?
Cross post from StackOverflow. Please let us know when you are cross posting.
2 Likes
the answer by Luke Garrigan on stackoverflow solves the problem
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);
}
however it would be even better if you sample the color directly from the image by img.get(0, 0)
.
(oh I don’t like cross posting because of this reason. I don’t have an account on stackoverflow so I’m sharing the solution here, but I hate that the information is scattered everywhere…)
2 Likes
sorry about that, I will if I did again.