Move elements along the ellipse path.
in
Programming Questions
•
1 year ago
Hi,
I am trying to move some elements along the path of an ellipse, something like the following attachment except it's a circle. I grabbed some sketch from another forum the other day (couldn't tracked the old link). Here's the modified sketch from that post:
- void setup()
- {
- size(1024, 768);
- textFont(createFont("Arial", 30));
- }
- void draw()
- {
- background(0);
- stroke(255);
- int cx = 500;
- int cy = 350;
- int r = 300; //radius of the circle
- float t = millis()/4000.0f; //increase to slow down the movement
- ellipse(cx, cy, 10, 10);
- for (int i = 1 ; i <= 12; i++) {
- t = t + 100;
- int x = (int)(cx + r * cos(t));
- int y = (int)(cy + r * sin(t));
- text(i, x, y);
- }
- }
The sketch outputs this:
And what I am trying to achieve is to move the texts along an ellipse path like this:
Any idea how can I achieve the algorithm for this? Thanks!
1