Hi. I’m definitely having trouble to make my drag and drop function working. The sketch below grabs the image from the user but don’t manage to save it as a p5 image every time. I’m around 33% successful drops.
Any idea for fixing this ? Or where the problem could be from ?
You can try my sketch here
var userFile;
var c = 0;
var d = 0;
function setup() {
canvas = createCanvas(windowWidth, windowHeight);
}
function gotFile(file) {
var img;
var gr;
img = createImg(file.data).hide();
if(img.width != 0){
userFile = img;
d++;
}
else print("missed");
c++;
print(int(d/c*100)+"%");
}
function draw() {
background(255);
canvas.drop(gotFile);
if(userFile) image(userFile,0,0,width,height);
}