+ 3

How to animate in canvas????

I want to make a line move in a 360 degree motion. How do I do this I only know how to draw it so please write out the program so I can see how it works.

28th Jan 2018, 7:19 PM
Someone Else
Someone Else - avatar
8 odpowiedzi
+ 2
are trying to do a clock?that's very complex
28th Jan 2018, 7:40 PM
᠌᠌Code X
᠌᠌Code X - avatar
+ 2
you would have to plot Math.sin values against Math.cosine values then create points and switch the lineTo() between each of those points
28th Jan 2018, 7:41 PM
᠌᠌Code X
᠌᠌Code X - avatar
+ 1
you would have to know how to use functions,where's the code?
28th Jan 2018, 7:44 PM
᠌᠌Code X
᠌᠌Code X - avatar
+ 1
This would work
28th Jan 2018, 7:49 PM
᠌᠌Code X
᠌᠌Code X - avatar
0
No..just trying to move it around. Or even move it forward or something. I just want to get familiar with animating on it
28th Jan 2018, 7:41 PM
Someone Else
Someone Else - avatar
0
I don’t have the code yet. I know how to use JavaScript functions...but not how to animate with the canvas and JavaScript
28th Jan 2018, 7:45 PM
Someone Else
Someone Else - avatar
0
function animate(){ ctx.clearRect(0,0,canvas.width,canvas.height); ctx.beginPath(); ctx.moveTo(100,100); ctx.lineTo(Math.random()*100,100); ctx.stroke(); requestAnimationFrame(animate); }
28th Jan 2018, 7:49 PM
᠌᠌Code X
᠌᠌Code X - avatar
0
Would that make it spin in a 360 degree motion?????
28th Jan 2018, 7:49 PM
Someone Else
Someone Else - avatar