I’m struggling with the cursor function,
I was wondering the reason why the cursor didn’t change.
I thought p5.js allows the file extension including .png; Is there anything I did wrong?
Thank you so much!
let img;
let minT = 3;
let maxT = 7;
function preload() {
img = loadImage("data/sheep.png");
}
function setup() {
createCanvas(600, 400);
background(83, 145, 101);
noStroke();
for (let y = 20; y < 400; y += 20) {
for (let x = 20; x < 600; x += 20) {
let r = random(minT, maxT);
fill(157, 192, 139);
triangle(x, y, x - r, y + r, x + r, y + r);
}
}
}
function draw() {
cursor(img);
let randomD1 = random(15, 30);
let randomD2 = random(5, 15);
let randomX = mouseX + random(-10, 10);
let randomY = mouseY + random(-10, 10);
if (mouseIsPressed) {
fill(102, 90, 72);
square(mouseX, mouseY, randomD1);
fill(159, 135, 114);
square(randomX, randomY, randomD2);
}
}
If you are trying to set an image as the cursor, the recommended size is 16×16 or 32×32 pixels. The values for parameters x and y must be less than the dimensions of the image.
But I wanted to use the brown random squares as a drawing paint,
so I think I can’t see the brown paint when I put the background and the image on the draw() function.
Is there any way I can try?
Thank you so much for answering my awesome question, Awesome people!