This is the entire program. It is an exercise from Khan Academy. It is a tutorial on objects.
var paintBrush = {
x: 300,
y: 100,
img: getImage("space/collisioncircle")
};
var paintCanvas = function() {
imageMode(CENTER);
image(paintBrush.img, paintBrush.x, paintBrush.y);
};
mouseMoved = function() {
paintBrush.x = mouseX;
paintBrush.y = mouseY;
paintCanvas();
};
I’m trying to substitute the image with stars I made from a function (this is how I’ve been saving the exercises to my machine up until now).
Other functions in the program are using paintBrush.x and paintBrush.y. Why can I not use it for my stars?
This is my original function before trying to apply it to this exercise:
function star(x, y) {
stroke(69, 33, 5);
fill(255, 255, 0);
ellipse(x, y, 15, 15);
line(x-5, y + 6, x, y - 7); //#1
line(x, y - 7, x + 5, y + 6); //#2
line(x + 5, y + 6, x - 8, y - 1); //#3
line(x-8, y - 1, x + 7, y - 1); //#4
line(x + 7, y - 1, x - 5, y + 6);
}
As you can see, I simply attempted to adapt it to the program.
I tried to read the MDN Web Docs, but I am a beginner, and it assumes knowledge I do not already have. I understand all of their examples. But I do not see a difference in pattern between what they are doing, and what I’m trying to do… and the explanations match none of the tutorials I’ve taken already, and make no sense to me.
In trying to understand this, following where the paintbrush.x would go throughout the code, I can kind of see how using it the way I am might be a bit circular.
Or should I declare a separate x and y, outside of the paintbrush? For the star function?
I even tried just a simple ellipse assigned to img. That did not work either. The program wants the ellipse in setup().
Why would their predefined image work, and my substitute not work?
I’m about to upload an image of a tiny star and see if I can get that to work.