Answer the question
In order to leave comments, you need to log in
The movement of a square in a circle?
Hello, I have a task:
Write a script for moving a colored square in a circle. It is convenient to describe the trajectory by parametric equations:
x = R*cos(t),
y = R*sin(t) ,
where: R is the radius of the circle, 0 <= t <= 2
st = false;
function Move ()
{
if(st)
{
window.clearInterval(proc);
st = false;
document.all.button.innerHTML = "Запустить";
}
else
{
proc = window.setInterval("MoveCircle()", 100);
st = true;
document.all.button.innerHTML = "Стоп";
}
}
function MoveCircle ()
{
}
<button type="submit" onclick="Move()" id="button">Запустить</button>
<div class="cub" id="cub" style="position:absolute;top: 0;left: 0;"></div>
Answer the question
In order to leave comments, you need to log in
Most likely 0 <= t <= 2 π wikipedia
Implementation example
But in essence, you can go beyond these limits, and consider t as just a time that increases with each iteration. Those. in the code, you can remove zeroing tif(t > 2*Math.PI) t = 0;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question