/* built with Studio Sketchpad: * https://sketchpad.cc * * observe the evolution of this sketch: * https://studio.sketchpad.cc/sp/pad/view/ro.NgkxhpStPKy/rev.2 * * authors: * GoToLoop * license (unless otherwise specified): * creative commons attribution-share alike 3.0 license. * https://creativecommons.org/licenses/by-sa/3.0/ */ /** * Satellite Earth Orbit (v2.0) * by ClayLake (2013/Jun) * mod GoToLoop * * http://forum.processing.org/topic/javascript-trouble */ float ext = 5; int siz = 700; float trans = siz/2.0; float def = 100.0; float spa = 10; float rotation = 0; float xpos=0; float zpos=0; float ypos=0; float an=0; int c = 0; float dconv = 1.67; void setup() { size(700, 700, P3D); strokeWeight(2); stroke(255); noFill(); //smooth(8); } void draw() { float orbitRadius = 5; an= HALF_PI*0.5; xpos = sin(radians(rotation))*orbitRadius; ypos = cos(radians(rotation))*orbitRadius; zpos = 120; xpos /= ext; ypos /= ext; xpos *= trans; ypos *= trans; camera(xpos + trans, ypos + trans, -zpos+trans, trans, trans, trans, 0, 0, 1); background(0); earth(); sat(); ++rotation; } void earth() { hint(ENABLE_DEPTH_TEST); fill(0); noStroke(); sph(0, 0, 0, 70); noFill(); stroke(255); for (float j = 1.0/spa; j <= 1; j = j + 1.0/spa) { beginShape(); for (float i = 0; i < 1.1; i = i + 1.0/def) vert(sin(j*TWO_PI)*cos(i*TWO_PI), sin(j*TWO_PI)*sin(i*TWO_PI), cos(j*TWO_PI)); endShape(); } for (float j = 1.0/spa; j <= 1; j = j + 1.0/spa) { beginShape(); for (float i = 0; i < 1.1; i = i + 1.0/def) vert(cos(j*TWO_PI)*sin(i*TWO_PI), sin(j*TWO_PI)*sin(i*TWO_PI), cos(i*TWO_PI)); endShape(); } camera(); hint(DISABLE_DEPTH_TEST); strokeWeight(3.5); beginShape(); for (float i = 0; i < 1.1; i = i + 1.0/def) vert2d(dconv*sin(i*TWO_PI), dconv*cos(i*TWO_PI)); endShape(); beginShape(); vert2d(4, -4); vert2d(4-cos(radians(rotation))*.5, -4 - sin(radians(rotation))*.5); endShape(); c=0; for (float i = 0; i < 1.1; i = i + 1.0/12, ++c) { beginShape(); vert2d(4-cos(i*TWO_PI)*0.55, -4 - sin(i*TWO_PI)*0.55); if (c%3 == 0) vert2d(4-cos(i*TWO_PI)*0.65, -4 - sin(i*TWO_PI)*0.65); else vert2d(4-cos(i*TWO_PI)*0.6, -4 - sin(i*TWO_PI)*0.6); endShape(); } strokeWeight(2); } void sat() { float orbitRadius = 2; an= HALF_PI*0.5; final float rad = radians(rotation); xpos = sin(rad) * orbitRadius; ypos = cos(rad) * orbitRadius; zpos = 120; xpos /= ext; ypos /= ext; xpos *= trans; ypos *= trans; translate(xpos + trans, ypos + trans, -zpos+trans); rotate(radians(rotation), 0, .5, -.5); hint(ENABLE_DEPTH_TEST); fill(0); box(25, 12, 8); noFill(); translate(-xpos - trans, -ypos - trans, zpos - trans); } void vert(float x, float y, float z) { x /= ext; y /= ext; z /= ext; x *= trans; y *= trans; z *= trans; vertex(x + trans, y + trans, z + trans); } void vert2d(float x, float y) { x /= ext; y /= ext; x *= trans; y *= trans; vertex(x + trans, y + trans); } void sph(float x, float y, float z, float s) { x /= ext; y /= ext; z /= ext; x *= trans; y *= trans; z *= trans; translate(x + trans, y + trans, z + trans); sphere(s); translate(-x - trans, -y - trans, -z - trans); }