Hi!
I’m quite new to programming and I’m trying to make a poster generator, therefore I want people to be able to upload an image which needs to have a tint. On top of that image there are elements like circles and text which can be changed using sliders (so my sketch needs to run in an constant loop). I use three createGraphics buffers for this. 1 for the tinted image, 1 for the elements and 1 to combine them together. I found out that using tint just on the image didn’t work, so now I tint the complete image buffer.
Using tint over and over makes my sketch quite slow, so I prefer to do it only once when the image is changed. But when I tried to do this, the image disappears. However other elements on that same buffer do not disappear. I don’t understand why this is happening and I hope you can help me with this.
The code below is an example of my problem.
Thank you!
let inputimage;
let img;
let frame, frame2, ren;
function setup() {
createCanvas(windowWidth, windowHeight);
frame = createGraphics(400,400);
frame2 = createGraphics(400,400);
ren = createGraphics(800,400);
inputimage = createFileInput(handleFile);
inputimage.position(10,220);
}
function draw() {
background(220);
drawFrame2();
drawRen();
image(frame2,400,0);
image(ren,0,0);
}
function drawFrame(){
frame.clear();
frame.ellipse(mouseX,40,40,70); //the ellipse stays visible
frame.image(img, 0, 0, 200, 200); //the image disappears
print('image');
frame.push();
frame.tint(255, 0, 0,);
frame.image(frame,0,0);
frame.pop();
}
function drawFrame2(){
if (img) {
frame2.image(img, 0, 0, img.width, img.height);
}
}
function drawRen(){
ren.clear();
ren.image(frame,0,0);
ren.image(frame2,400,0);
}
function handleFile(file) {
print(file);
if (file.type === 'image') {
img = createImg(file.data, '');
img.hide();
drawFrame();
print('handlefile');
} else {
img = null;
}
}