Can I ask for help with a simple orbit program?
in
Programming Questions
•
1 year ago
Hey guys.
I'm new here and new to Processing. I wonder if I can ask for some noob help
with this simple program i'm trying to put together:
Basicly I simply want to create 3 planets that orbit a sun. Being a beginner to
processing I'm making some simple mistake with my code below. I'd really
appreciate it if someone could cast their eye over it an explain in laymens terms
what i'm doing wrong. As you can probably see i'm trying to use a class and
my problem is that all 3 planets are being drawn in the same location (as far as
i can tell).
I'm new here and new to Processing. I wonder if I can ask for some noob help
with this simple program i'm trying to put together:
Basicly I simply want to create 3 planets that orbit a sun. Being a beginner to
processing I'm making some simple mistake with my code below. I'd really
appreciate it if someone could cast their eye over it an explain in laymens terms
what i'm doing wrong. As you can probably see i'm trying to use a class and
my problem is that all 3 planets are being drawn in the same location (as far as
i can tell).
- //DECLARE VARS
planetoid myplanetoid;
planetoid myplanetoid2;
planetoid myplanetoid3;
void setup () {
size(600, 600);
smooth();
//INITIALISE
myplanetoid = new planetoid(230, 250);
myplanetoid2 = new planetoid(200,200);
myplanetoid3 = new planetoid(100, 200);
}
void draw() {
background(0);
ellipse(width/2, height/2, 50, 50);
//CALL FUNCTIONALITY
myplanetoid.run();
myplanetoid2.run();
myplanetoid3.run();
} - class planetoid {
float orbitDuration = 5*1000; // 5 second orbit
float orbitRad = 50;
float x = 0;
float y = 0;
//CONSTRUCTOR
planetoid(float _x, float _y) {
//_x = x;
//_y = y;
}
//FUNCTIONS - declare, run once
void run() {
display();
//orbit();
}
void display() {
//for (int i = 0; i< 20; i++) {
float ang = TWO_PI * millis()/orbitDuration;
float x = cos(ang)*orbitRad;
float y = sin(ang)*orbitRad;
translate(width/2, height/2);
ellipse(x, y, 5, 5);
}
}
Thanks for any help
1