How to draw a circle (in js) on top of a stimulus image? #1774
-
Hello, I would like to create a stimulus image on the basis of a png image I have, but I need to draw a circle on top of this image (automatically in javascript), so that on each trial, the basis remains the same but the color of the circle changes. So far, I tried to draw a circle using snapsvg library, but it doesn't draw it on top of my stimulus image, it draws it below the image. Here is my code (which is a wrong solution for the problem, but still):
Could somebody point me to a possible solution? I was thinking of using canvas to draw on top of the image (using my basis image as a canvas) but I haven't found a way to implement it. Any help would be greatly appreciated! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Hi @Alinaedr, I would use a canvas approach for this. You could use one of the canvas-* plugins, and in the stimulus function, draw the image and circle. See docs here for info on the drawImage function, and here's an example of drawing a circle. I think there are also some examples of drawing circles in the canvas-* plugin example HTML files. Hope this helps! Let us know if you need further guidance. |
Beta Was this translation helpful? Give feedback.
Hi @Alinaedr, I would use a canvas approach for this. You could use one of the canvas-* plugins, and in the stimulus function, draw the image and circle. See docs here for info on the drawImage function, and here's an example of drawing a circle. I think there are also some examples of drawing circles in the canvas-* plugin example HTML files. Hope this helps! Let us know if you need further guidance.