How can we make a dynamic drawing an element on canvas? Please help!! | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How can we make a dynamic drawing an element on canvas? Please help!!

24th Jan 2018, 6:36 AM
sushant gupta
sushant gupta - avatar
2 Answers
0
@Jonathan thank you for your response.. I am making triangle in canvas by dragging the mouse .the size of triangle is depending on how much i drag the mouse.. and now what i want to make those triangle element on the html page so i can add event listeners to them and drag them to one place to another place. i have to use only pure javascript no external libraries or frameworks
24th Jan 2018, 8:27 AM
sushant gupta
sushant gupta - avatar
- 1
I'm not sure if this is what you mean... to be able to draw dynamically in canvas, you would need animation methods like using setInterval or the requestAnimationFrame. You will need to draw everything over and over again to achieve the result you want.... Here's an example code: https://code.sololearn.com/W5VAi1syt4k8/?ref=app This code only draws small circles but changes the coordinates in small amounts in every draw to achieve the effect of drawing.
24th Jan 2018, 7:21 AM
Jonathan Pizarra (JS Challenger)
Jonathan Pizarra (JS Challenger) - avatar