
More playing around with Processing this morning. Came up with a nice little sketch in which ‘planets’ orbit a ‘sun’, which is moveable with the mouse. I like the animation of the lines to the planets which gives the whole thing a nice atomosephere.
Its meant to move, so for those with Processing (and for those without, it IS free!) here is the source code:
Orbit planet;
Orbit planet2;
Orbit planet3;
Orbit planet4;
void setup() {
size(800,600);
smooth();
ellipseMode(RADIUS);
planet = new Orbit(50,0.01,12);
planet2 = new Orbit(70,-0.02,10);
planet3 = new Orbit(90,0.03,7.5);
planet4 = new Orbit(110,-0.04,5);
}
void draw() {
background(0);
planet.atmos();
planet2.atmos();
planet3.atmos();
planet4.atmos();
planet.move();
planet.display();
planet2.move();
planet2.display();
planet3.move();
planet3.display();
planet4.move();
planet4.display();
}
class Orbit {
float x;
float y;
float angle = 0.0;
float easing = 0.025;
float scalar;
float speed;
float mass;
float xOrb;
float yOrb;
Orbit(float tempScal, float tempSpeed, float tempMass) {
scalar = tempScal;
speed = tempSpeed;
mass = tempMass;
}
void move() {
// Calculate planet's orbit
xOrb = x+sin(angle)*scalar;
yOrb = y+cos(angle)*scalar;
angle+=speed;
//Ease sun to follow mouse when mouse pressed
if (mousePressed==true) {
x+=(mouseX-x)*easing;
y+=(mouseY-y)*easing;
}
}
void display() {
noStroke();
fill(200,128);
//draw 'planet'
ellipse(xOrb,yOrb,mass,mass);
//draw centre 'sun'
ellipse(x,y,mass*2,mass*2);
//link line sun to 'planet'
stroke(255,100);
line(x,y,xOrb,yOrb);
//draw line from planet to mouse position
line(mouseX,mouseY,xOrb,yOrb);
//location crosshair for sun destination
line(0,mouseY,width,mouseY);
line(mouseX,0,mouseX,height);
//location crosshair for sun position
line(0,y,width,y);
line(x,0,x,height);
//location crosshair for planet
line(0,yOrb,width,yOrb);
line(xOrb,0,xOrb,height);
//draw 'orbit' path
noFill();
ellipse(x,y,scalar,scalar);
}
void atmos() {
strokeWeight(0.5);
stroke(100,100);
for (int i = 1; i < width;i += 10) {
line(i,0,xOrb,yOrb);
line(i,height,xOrb,yOrb);
}
for (int i = 1; i < width;i += 10) {
line(0,i,xOrb,yOrb);
line(width,i,xOrb,yOrb);
}
}
}
I'm sure there is a more efficient way to code such a simple program, but its still early days. I think the next step I want to take is to use this program to output some sort of data (perhaps OSC protocol) to control aspects of Max/MSP...