Last active
May 20, 2025 08:39
-
-
Save tai2/88f50432c73d227d83dca52359b2541b to your computer and use it in GitHub Desktop.
Revisions
-
tai2 revised this gist
May 20, 2025 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -7,6 +7,7 @@ float planet_extent = 10; void setup() { size(1000, 1000); pixelDensity(1); sun = new PVector(width * 0.5, height * 0.5); } -
tai2 revised this gist
Mar 1, 2025 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -40,7 +40,7 @@ void draw() { noStroke(); fill(255, 0, 0); circle(mars.x, mars.y, planet_extent); mars_angle += PI * earth_velocity * 365.2422 / 686.980; // Draw the orbit of Mars stroke(0, 0, 0); -
tai2 revised this gist
Feb 26, 2025 . 1 changed file with 1 addition and 27 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,15 +2,12 @@ float earth_angle = 1; float mars_angle = 0; float earth_velocity = -0.005; PVector sun; float mars_circle_extent = 150; float planet_extent = 10; void setup() { size(1000, 1000); sun = new PVector(width * 0.5, height * 0.5); } void draw() { @@ -59,17 +56,8 @@ void draw() { mars.x + sight.x * 1000, mars.y + sight.y * 1000 ); // Draw the orbit of Mars based on Earth PVector mars_circle_pos = new PVector(width * 0.9, height * 0.1); stroke(0, 0, 0); circle(mars_circle_pos.x, mars_circle_pos.y, mars_circle_extent); noStroke(); @@ -82,19 +70,6 @@ void draw() { mars_circle_pos.y + mars_circle_extent * 0.5 * sight.y, planet_extent ); } PVector getEarthPos(float angle, float radius) { @@ -111,7 +86,6 @@ PVector getMarsPos(float angle, float radius) { ); } float getEarthOrbitRadius() { return width * 0.15; } -
tai2 revised this gist
Feb 26, 2025 . No changes.There are no files selected for viewing
-
tai2 revised this gist
Feb 26, 2025 . 1 changed file with 55 additions and 36 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,14 +1,16 @@ float earth_angle = 1; float mars_angle = 0; float earth_velocity = -0.005; PVector sun; PVector prev_earth, prev_mars; float mars_circle_extent = 150; float planet_extent = 10; void setup() { size(1000, 1000); sun = new PVector(width * 0.5, height * 0.5); prev_earth = getEarthPos(earth_angle, getEarthOrbitRadius()); prev_mars = getMarsPos(mars_angle, getMarsOrbitRadius()); } void draw() { @@ -18,61 +20,70 @@ void draw() { background(255, 255, 255); noStroke(); // Draw the Sun noStroke(); fill(0xFF, 0xA5, 0x00); circle(sun.x, sun.y, planet_extent); // Draw Earth PVector earth = getEarthPos(earth_angle, getEarthOrbitRadius()); noStroke(); fill(0, 0, 255); circle(earth.x, earth.y, planet_extent); earth_angle += PI * earth_velocity; // Draw the orbit of Earth stroke(0, 0, 0); noFill(); ellipse(sun.x, sun.y, getEarthOrbitRadius() * 2, 0.98 * getEarthOrbitRadius() * 2); // Draw Mars PVector mars = getMarsPos(mars_angle, getMarsOrbitRadius()); noStroke(); fill(255, 0, 0); circle(mars.x, mars.y, planet_extent); mars_angle += PI * earth_velocity * 0.5; // Draw the orbit of Mars stroke(0, 0, 0); noFill(); ellipse(sun.x, sun.y, getMarsOrbitRadius() * 2, 0.94 * getMarsOrbitRadius() * 2); // Draw the direction of view from Earth PVector sight = new PVector(earth.x - mars.x, earth.y - mars.y); sight.normalize(); stroke(0, 255, 0); line( mars.x - sight.x * 1000, mars.y - sight.y * 1000, mars.x + sight.x * 1000, mars.y + sight.y * 1000 ); // Draw the tangent bector to sight PVector sight_tan = new PVector(sight.y, sight.x); stroke(0, 0, 0); line( earth.x - sight_tan.x * 100, earth.y + sight_tan.y * 100, earth.x + sight_tan.x * 100, earth.y - sight_tan.y * 100 ); PVector mars_circle_pos = new PVector(width * 0.9, height * 0.1); // Draw the orbit of Mars based on Earth stroke(0, 0, 0); circle(mars_circle_pos.x, mars_circle_pos.y, mars_circle_extent); noStroke(); fill(0, 0, 255); circle(mars_circle_pos.x, mars_circle_pos.y, planet_extent); noStroke(); fill(255, 0, 0); circle( mars_circle_pos.x + mars_circle_extent * 0.5 * sight.x, mars_circle_pos.y + mars_circle_extent * 0.5 * sight.y, planet_extent ); PVector earth_to_mars_curr = new PVector(mars.x - earth.x, mars.y - earth.y); PVector earth_to_mars_prev = new PVector(prev_mars.x - prev_earth.x, prev_mars.y - prev_earth.y); PVector movement = new PVector(earth_to_mars_curr.x - earth_to_mars_prev.x, earth_to_mars_curr.y - earth_to_mars_prev.y); @@ -86,17 +97,25 @@ void draw() { prev_mars = mars; } PVector getEarthPos(float angle, float radius) { return new PVector( sun.x + radius * sin(angle), sun.y + 0.98 * radius * cos(angle) ); } PVector getMarsPos(float angle, float radius) { return new PVector( sun.x + radius * sin(angle), sun.y + 0.94 * radius * cos(angle) ); } float getEarthOrbitRadius() { return width * 0.15; } float getMarsOrbitRadius() { return getEarthOrbitRadius() * 2.26; } -
tai2 revised this gist
Feb 26, 2025 . 1 changed file with 62 additions and 35 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,10 +1,14 @@ float earthAngle = 1; float marsAngle = 0; float earthVelocity = -0.005; PVector sun; PVector prev_earth, prev_mars; void setup() { size(1000, 1000); sun = new PVector(width * 0.5, height * 0.5); prev_earth = getPlanetPos(earthAngle, getEarthOrbitRadius()); prev_mars = getPlanetPos(marsAngle, getMarsOrbitRadius()); } void draw() { @@ -15,61 +19,84 @@ void draw() { background(255, 255, 255); noStroke(); noStroke(); fill(0xFF, 0xA5, 0x00); circle(sun.x, sun.y, 10); PVector earth = getPlanetPos(earthAngle, getEarthOrbitRadius()); noStroke(); fill(0, 0, 255); circle(earth.x, earth.y, 10); earthAngle += PI * earthVelocity; PVector earth_tan = new PVector(cos(earthAngle), -sin(earthAngle)); //PVector earth_normal = new PVector(sin(earthAngle), cos(earthAngle)); //stroke(0, 0, 0); //noFill(); //line(earth.x - earth_tan.x * 1000, earth.y - earth_tan.y * 1000, earth.x + earth_tan.x * 1000, earth.y + earth_tan.y * 1000); //line(earth.x - earth_normal.x * 1000, earth.y - earth_normal.y * 1000, earth.x + earth_normal.x * 1000, earth.y + earth_normal.y * 1000); stroke(0, 0, 0); noFill(); circle(sun.x, sun.y, getEarthOrbitRadius() * 2); PVector mars = getPlanetPos(marsAngle, getMarsOrbitRadius()); noStroke(); fill(255, 0, 0); circle(mars.x, mars.y, 10); marsAngle += PI * earthVelocity * 0.5; stroke(0, 0, 0); noFill(); circle(sun.x, sun.y, getMarsOrbitRadius() * 2); PVector sight = new PVector(earth.x - mars.x, earth.y - mars.y); sight.normalize(); float cross_prod = sight.x * earth_tan.y - sight.y * earth_tan.x; //float inner_prod = sight_x * earth_tanX + sight_y * earth_tanY; if (cross_prod < 0.5) { stroke(0, 255, 0); } else { stroke(255, 255, 0); } line( mars.x - sight.x * 1000, mars.y - sight.y * 1000, mars.x + sight.x * 1000, mars.y + sight.y * 1000 ); PVector sight_tan = new PVector(sight.y, sight.x); stroke(0, 0, 0); line( earth.x - sight_tan.x * 100, earth.y + sight_tan.y * 100, earth.x + sight_tan.x * 100, earth.y - sight_tan.y * 100 ); PVector earth_to_mars_curr = new PVector(mars.x - earth.x, mars.y - earth.y); PVector earth_to_mars_prev = new PVector(prev_mars.x - prev_earth.x, prev_mars.y - prev_earth.y); PVector movement = new PVector(earth_to_mars_curr.x - earth_to_mars_prev.x, earth_to_mars_curr.y - earth_to_mars_prev.y); float movement_sight_tan_mag = movement.dot(sight_tan); //PVector movement_sight_tan = new PVector(sight_tan.x * movement_sight_tan_mag, sight_tan.y * movement_sight_tan_mag); fill(0, 0, 0); text(nf(movement_sight_tan_mag, 0, 2), 10, 10, 280, 320); prev_earth = earth; prev_mars = mars; } PVector getPlanetPos(float angle, float radius) { return new PVector( sun.x + radius * sin(angle), sun.y + radius * cos(angle) ); } float getEarthOrbitRadius() { return width * 0.20; } float getMarsOrbitRadius() { return width * 0.30; } -
tai2 revised this gist
Feb 26, 2025 . 1 changed file with 11 additions and 11 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,6 @@ float earthAngle = 1; float marsAngle = 0; float earthVelocity = -0.005; void setup() { size(1000, 1000); @@ -30,7 +30,7 @@ void draw() { float earthX = cx + earth_orbit_radius * earth_normalX; float earthY = cy + earth_orbit_radius * earth_normalY; circle(earthX, earthY, 10); earthAngle += PI * earthVelocity; float earth_tanX = cos(earthAngle); @@ -55,21 +55,21 @@ void draw() { noFill(); circle(cx, cy, mars_orbit_radius * 2); float sight_x = earthX - marsX; float sight_y = earthY - marsY; float earth_mars_dist = sqrt(sight_x * sight_x + sight_y * sight_y); sight_x /= earth_mars_dist; sight_y /= earth_mars_dist; float cross_prod = sight_x * earth_tanY - sight_y * earth_tanX; //float inner_prod = sight_x * earth_tanX + sight_y * earth_tanY; if (cross_prod < 0.5) { stroke(0, 255, 0); } else { stroke(255, 255, 0); } line(marsX - sight_x * 1000, marsY - sight_y * 1000, marsX + sight_x * 1000, marsY + sight_y * 1000); stroke(0, 0, 0); line(earthX - sight_y * 100, earthY + sight_x * 100, earthX + sight_y * 100, earthY - sight_x * 100); } -
tai2 revised this gist
Feb 26, 2025 . 1 changed file with 0 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,3 @@ float earthAngle = 1; float marsAngle = 0; float earthVelocity = 0.005; -
tai2 revised this gist
Feb 26, 2025 . 1 changed file with 14 additions and 6 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -23,19 +23,25 @@ void draw() { fill(0xFF, 0xA5, 0x00); circle(cx, cy, 10); float earth_normalX = sin(earthAngle); float earth_normalY = cos(earthAngle); fill(0, 0, 255); float earth_orbit_radius = width * 0.20; float earthX = cx + earth_orbit_radius * earth_normalX; float earthY = cy + earth_orbit_radius * earth_normalY; circle(earthX, earthY, 10); earthAngle += PI * 0.005; float earth_tanX = cos(earthAngle); float earth_tanY = -sin(earthAngle); stroke(0, 0, 0); noFill(); //line(earthX - earth_tanX * 1000, earthY - earth_tanY * 1000, earthX + earth_tanX * 1000, earthY + earth_tanY * 1000); //line(earthX - earth_normalX * 1000, earthY - earth_normalY * 1000, earthX + earth_normalX * 1000, earthY + earth_normalY * 1000); stroke(0, 0, 0); noFill(); circle(cx, cy, earth_orbit_radius * 2); @@ -59,11 +65,13 @@ void draw() { float cross_prod = vx * earth_tanY - vy * earth_tanX; float inner_prod = vx * earth_tanX + vy * earth_tanY; if (cross_prod < 0.5) { stroke(0, 255, 0); } else { stroke(255, 255, 0); } line(marsX - vx * 1000, marsY - vy * 1000, marsX + vx * 1000, marsY + vy * 1000); stroke(0, 0, 0); line(earthX - vy * 1000, earthY + vx * 1000, earthX + vy * 1000, earthY - vx * 1000); } -
tai2 revised this gist
Feb 25, 2025 . 1 changed file with 2 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,6 @@ float earthAngle = 1; float marsAngle = 0; float earthVelocity = 0.005; @@ -66,5 +66,4 @@ void draw() { } line(marsX - vx * 1000, marsY - vy * 1000, marsX + vx * 1000, marsY + vy * 1000); } -
tai2 created this gist
Feb 25, 2025 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,70 @@ float earthAngle = 0; float marsAngle = 0; float earthVelocity = 0.005; void setup() { size(1000, 1000); noStroke(); } void draw() { if (keyPressed == true) { return; } background(255, 255, 255); noStroke(); float cx = width * 0.5; float cy = height * 0.5; fill(0xFF, 0xA5, 0x00); circle(cx, cy, 10); fill(0, 0, 255); float earth_orbit_radius = width * 0.20; float earthX = cx + earth_orbit_radius * sin(earthAngle); float earthY = cy + earth_orbit_radius * cos(earthAngle); circle(earthX, earthY, 10); earthAngle += PI * 0.005; float earth_tanX = cos(earthAngle); float earth_tanY = -sin(earthAngle); stroke(0, 0, 0); noFill(); line(earthX - earth_tanX * 1000, earthY - earth_tanY * 1000, earthX + earth_tanX * 1000, earthY + earth_tanY * 1000); stroke(0, 0, 0); noFill(); circle(cx, cy, earth_orbit_radius * 2); fill(255, 0, 0); float mars_orbit_radius = width * 0.30; float marsX = cx + mars_orbit_radius * sin(marsAngle); float marsY = cy + mars_orbit_radius * cos(marsAngle); circle(marsX, marsY, 10); marsAngle += PI * earthVelocity * 0.5; stroke(0, 0, 0); noFill(); circle(cx, cy, mars_orbit_radius * 2); float vx = earthX - marsX; float vy = earthY - marsY; float earth_mars_dist = sqrt(vx * vx + vy * vy); vx /= earth_mars_dist; vy /= earth_mars_dist; float cross_prod = vx * earth_tanY - vy * earth_tanX; float inner_prod = vx * earth_tanX + vy * earth_tanY; if (cross_prod < 0) { stroke(0, 255, 0); } else { stroke(255, 255, 0); } line(marsX - vx * 1000, marsY - vy * 1000, marsX + vx * 1000, marsY + vy * 1000); }