G
G
Grigory Dikiy2015-10-04 10:46:38
JavaScript
Grigory Dikiy, 2015-10-04 10:46:38

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

Can't write motion function:
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>

Maybe someone faced a similar problem?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Zuev, 2015-10-04
@frilix

Most likely 0 <= t <= 2 π
633b8ab4282c4396aeff94ba5d8af458.pngwikipedia
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 t
if(t > 2*Math.PI) t = 0;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question