xxxxxxxxxx
65
function setup() {
createCanvas(400, 400, WEBGL);
perspective(PI / 3.0, width / height, 0.1, 500);
print("earth (flat) in center\nsun orbit 1d\nmoon orbit 28.2d\nuse: mouse drag xy, mouseWheel zoom??");
}
function draw() {
background(0, 0, 80);
orbitControl(0.5, 0.5);
earth();
sun_move();
moon_move();
}
function earth() {
push();
fill(0, 100, 150);
stroke(0, 0, 200);
strokeWeight(0.1);
//noStroke();
cylinder(30, 5);
pop();
}
let sr = 150;
let sang = 0,
dsang = 0.01745;
function sun_move() {
push();
let x = sr * sin(sang);
let z = sr * cos(sang);
let y = 0;
translate(x, y, z);
sang += dsang;
fill(200, 200, 0);
noStroke();
sphere(10);
stroke(200);
pop();
push(); // add path
noFill();
stroke(200,200,0);
strokeWeight(0.8);
rotateX(-PI/2);
circle(0,0,sr);
pop();
}
let mr = 100, mra=0.9,mrb=1.1;
let mang = 1.57, dmang = 0.01745;
function moon_move() {
push();
let x = mra * mr * sin(mang);
let z = mrb * mr * cos(mang);
let y = 0;
translate(x, y, z);
mang += dmang / 28.2;
fill(120,120, 100);
noStroke();
sphere(25);
pop();
//no path
}