We are about to switch to a new forum software. Until then we have removed the registration on this forum.
So I have an Array of 5 large ellipses, but I want to make an array of 5 smaller ellipses where each smaller ellipse travels around the circumference of a larger ellipse from the other array. So basically the larger ellipses act as an orbit path for the smaller ellipses. Below is my code for the 5 larger ellipses
int[] orbit = {50, 100, 150, 200, 250};
void setup() {
background(148, 103, 252);
size(400,400);
}
void draw() {
background(148, 103, 252);
// draws earth shadow
noStroke();
fill(30, 40, 0);
ellipse(200, 400, 400, 120);
// draws sun
noStroke();
fill(255, 255, 0);
ellipse(200, 25, 25, 25);
// draws glow
fill(255, 255, 0, 120);
ellipse(200, 25, 50, 50);
//draws orbits for planets to travel around
for (int i = 0; i < orbit.length; i++){
noFill();
stroke(103, 230, 252);
ellipse(200, 200, orbit[i], orbit[i]);
}
}
Answers
A version in p5.js (aka. javascript)
http://p5js.sketchpad.cc/sp/pad/view/cBsGAgGbjz/latest
Kf
@kfrajer -- beautiful demo sketch.
@637pm -- with two gears this is a simple Spirograph:
https://en.wikipedia.org/wiki/Spirograph
you can extend this Spirograph approach to an arbitrary number of gears if you want the curves to be more complex, or if you want to draw with multiple Spirograph pens at the same time -- on the same gear, or on different gearings (like tracing multiple planets and moons in the same solar system).
To find the location of one pen in your graph, rotate to the orientation of the current gear and then travels its radius -- then does it again (rotate, travel), as many times as you want. In other words, find a pen using a turtle.
This means you can store a pen gearing (that is, an orbit path) as an array or ArrayList of PVectors, one vec per gear leading from the center out:
So, for example, a lunar satellite would be stored as three gears / vectors: 1. Earth orientation/radius/speed (around Sun), 2. Moon o/r/s (around Earth), 3. satellite o/r/s (around Moon). (Note this is for a 2D model with circular orbits)
To find the current rotation of each gear, use the initial orientation, speed, and elapsed time since the starting clock or frameRate. This avoids drift due to cumulative rounding errors.
sketch from above with better variable names; it's angle, not radius
Somebody might like this addition that moves the ellipse by clicking the mouse. click with the mouse on the left of screen and it moves one way, right side and it moves the other way.