#### Howdy, Stranger!

We are about to switch to a new forum software. Until then we have removed the registration on this forum.

• Help with p5.js solar system sketch

There might be some relevant previous discussion on the forum of solar system / planet modeling specifically:

When you say "I can's seem to do the final step and I think it has to do with the vectors" could you say more about what specifically you mean?

Example vector sketch:

• Help with p5.js solar system sketch

Hey everyone, I am doing this sketch which is following up dan's shiffman tutorial in processing, however I am doing it in p5.js for some reason I can's seem to do the final step and I think it has to do with the vectors. If anyone can help me, I would really appreciate it. Here is the code in processing:

``````import peasy.*;
Planet sun;

PeasyCam cam;

void setup() {
size(600, 600, P3D);
cam = new PeasyCam(this, 500);
sun = new Planet(50, 0, 0);
sun.spawnMoons(4, 1);
}

void draw() {
background(0);
lights();
sun.show();
sun.orbit();
}
``````

// planet class

``````class Planet {
float distance;
Planet[] planets;
float angle;
float orbitspeed;
PVector v;

PShape globe;

Planet(float r, float d, float o) {

v = PVector.random3D();

distance = d;
v.mult(distance);
angle = random(TWO_PI);
orbitspeed = o;
}

void orbit() {
angle = angle + orbitspeed;
if (planets != null) {
for (int i = 0; i < planets.length; i++) {
planets[i].orbit();
}
}
}

void spawnMoons(int total, int level) {
planets = new Planet[total];
for (int i = 0; i < planets.length; i++) {
float r = radius/(level*2);
float d = random((radius + r), (radius+r)*2);
float o = random(-0.1, 0.1);
planets[i] = new Planet(r, d, o);
if (level < 2) {
int num = int(random(0, 3));
planets[i].spawnMoons(num, level+1);
}
}
}

void show() {
pushMatrix();
noStroke();
PVector v2 = new PVector(1, 0, 1);
PVector p = v.cross(v2);
rotate(angle, p.x, p.y, p.z);
stroke(255);
//line(0, 0, 0, v.x, v.y, v.z);
//line(0, 0, 0, p.x, p.y, p.z);

translate(v.x, v.y, v.z);
noStroke();
fill(255);
if (planets != null) {
for (int i = 0; i < planets.length; i++) {
planets[i].show();
}
}
popMatrix();
}
}
``````

And this is the p5.js code

``````var easycam;

function setup() {
createCanvas(windowWidth,windowHeight,WEBGL);
easycam = createEasyCam();
sun = new Planet(20, 0, 0, random(TWO_PI));
sun.spawnMoons(2, 1);
}

function draw() {
background(0);
cursor(HAND);

sun.show();
sun.orbit();
}
``````

//planet class

``````        class Planet {
constructor(radius, distance, orbitspeed, angle,mass) {
this.distance = distance;
this.orbitspeed = orbitspeed;
this.angle = angle;
this.planets = [];
this.mass=mass;

// this should be correct
// this is the vector coming out of the planet itself.

this.v = createVector();
this.v = p5.Vector.random3D();
this.v. mult(this.distance);
// park this for now.
// this.v = createVector();
// this.v = p5.Vector.random3D();
// this.v.mult(this.distance);
// var v = new p5.Vector.random3D();
// v. mult(this.distance);

}

orbit() {
this.angle += this.orbitspeed/this.mass;
for (let i in this.planets) {
this.planets[i].orbit();
}
}

spawnMoons(total, level) {
for (let i = 0; i < total; i++) {
let r = this.radius/(level*2);
let d = random(50, 150);
let o = random(-0.1, 0.1);
let a = random(TWO_PI);
this.planets.push(new Planet(r, d/level, o, a));
if (level < 1) {
let num = Math.floor(random(0, 4));
this.planets[i].spawnMoons(num, level+1);
}
}
}

show() {
push();
noStroke(0)
// fill(255);
// let v2 = createVector(1,0,1);
// let p = createVector(v.cross);
// this.v2 = createVector(0, 0, 1);
// this. p = this.v.cross(this.v2);
// rotateY(this.angel);
// translate(v.x,v.y,v.z);
this.v2= createVector(1,0,1);
this.p= this.v.cross(this.v2);
rotate(this.angel,this.p.x,this.p.y,this.p.z);
translate(this.v.x,this.v.y,this.v.z);
//lights
ambientLight(5,100);
directionalLight(255, 255, 255, 0.2, 0.2, 0.7);
specularMaterial(255);

for (let i in this.planets) {
this.planets[i].show();
}
pop();
}

}
``````

I would really really appreciate some help, its quite difficult to find references on vectors in p5.js.

• I'm trying to run a small sketch on openprocessing.org and all I keep getting is a blank screen.
``````void setup() {
frameRate(20);
}

double mercuryAngle = random(0, TWO_PI);
double venusAngle = random(0, TWO_PI);
double earthAngle = random(0, TWO_PI);
double marsAngle = random(0, TWO_PI);
double earthMoonAngle = random(0, TWO_PI);
double jupiterAngle = random(0, TWO_PI);
double saturnAngle = random(0, TWO_PI);
double uranusAngle = random(0, TWO_PI);
double neptuneAngle = random(0, TWO_PI);
double plutoAngle = random(0, TWO_PI);
double sunspot1Angle = random(0, TWO_PI);
double sunspot2Angle = random(0, TWO_PI);
double halleyAngle = random(0, TWO_PI);
double nemesisAngle = random(0, PI);
double days = 0;

float A = 525;
float B = 220;
float p = 1;

int n = 0;

float sunX = 500*random(1,1.001);
float sunY = 500*random(1,1.001);
float nemesunX = sunX;
float nemesunY = sunY;

void draw() {
background(0);
noStroke();
size(1000, 1000);
fill(20, 20, 20);
ellipse(sunX, sunY, 1000*2, 1000*2);
fill(0, 0, 0);
ellipse(sunX, sunY, 491*2, 482*2);
fill(255, 255, 255);
textSize(30);
text("Welcome to Solar System 6.0.orbit! ", 300, 100);
textSize(12);
text("Time Info", 20, 20);
text("| Earth Days Completed: "+int(days/6.75), 40, 40);
text("| Earth Weeks Completed: "+int(days/6.75/7), 40, 60);
text("| Earth Years Completed: "+int(days/365.24/6.75), 40, 80);
text("| Earth Centuries Completed: "+int(days/365.24/6.75/100), 40, 100);

for(int i = 0; i <= 1000; i++){
double size = random(0, 1.5);
ellipse(random(0, 1000), random(0, 1000), size, size);
}

fill(40, 40, 40);
ellipse(sunX, sunY, 181*2, 189*2);
fill(10, 10, 0);
ellipse(sunX, sunY, 92*2, 99*2);
fill(21, 21, 0);
ellipse(sunX, sunY, 58*2, 58*2);
fill(34, 34, 0);
ellipse(sunX, sunY, 42*2, 42*2);
fill(50, 50, 0);
ellipse(sunX, sunY, 29*2, 29*2);
fill(124, 124, 0);
ellipse(sunX, sunY, 25*2, 25*2);
fill(255, 255, 0);
ellipse(sunX, sunY, 40, 40);
fill(58, 58, 11);
ellipse(sunX, sunY, 1, 1);

mercuryAngle += 0.14;
venusAngle -= 0.07;
earthAngle += 0.035;
marsAngle += 0.0145001;
earthMoonAngle += 0.26;
jupiterAngle += 0.00497;
saturnAngle += 0.00218;
uranusAngle += 0.00118;
neptuneAngle += 0.000487202;
plutoAngle += 0.000487201;
halleyAngle += 0.119119;
nemesisAngle += 0.119119/5;
days += 365.24*0.035;

fill(201, 201, 201);
ellipse(sunX+41*cos(mercuryAngle), sunY+46*sin(mercuryAngle), 4, 4);
text("Mercury",sunX+41*cos(mercuryAngle),sunY+46*sin(mercuryAngle));
fill(128, 128, 0);
ellipse(sunX+56*cos(venusAngle), sunY+56*sin(venusAngle), 6, 6);
text("Venus",sunX+56*cos(venusAngle),sunY+56*sin(venusAngle));
fill(0, 109, 255);
ellipse(sunX+70*cos(earthAngle), sunY+73*sin(earthAngle), 6.001, 6.001);
text("Earth",sunX+70*cos(earthAngle),sunY+73*sin(earthAngle));
fill(200, 0, 0);
ellipse(sunX+104*cos(marsAngle), sunY+98*sin(marsAngle), 5, 5);
text("Mars",sunX+104*cos(marsAngle),sunY+98*sin(marsAngle));
fill(100, 100, 100);
ellipse((sunX+70*cos(earthAngle))+8*cos(earthMoonAngle), (sunY+73*sin(earthAngle))+8.29*sin(earthMoonAngle), 3.5, 3.5);
fill(200, 93, 29);
ellipse(sunX+174*cos(jupiterAngle), sunY+189*sin(jupiterAngle), 19, 19);
text("Jupiter",sunX+174*cos(jupiterAngle)+9,sunY+189*sin(jupiterAngle));
fill(200, 143, 0);
ellipse(sunX+213*cos(saturnAngle), sunY+249*sin(saturnAngle), 18, 18);
text("Saturn",sunX+213*cos(saturnAngle)+8.5,sunY+249*sin(saturnAngle));
fill(151, 200, 255);
ellipse(sunX+357*cos(uranusAngle), sunY+387*sin(uranusAngle), 13, 13);
text("Uranus",sunX+357*cos(uranusAngle)+6.5,sunY+387*sin(uranusAngle));
fill(0, 0, 200);
ellipse(sunX+468*cos(neptuneAngle), sunY+421*sin(neptuneAngle), 11, 11);
text("Neptune",sunX+468*cos(neptuneAngle)+6,sunY+421*sin(neptuneAngle));
fill(151, 151, 151);
ellipse(sunX+498*cos(plutoAngle), sunY+418*sin(plutoAngle), 3.6, 3.6);
text("Pluto",sunX+498*cos(plutoAngle),sunY+418*sin(plutoAngle));
fill(255, 255, 212);
ellipse((sunX-100)+125*cos(halleyAngle), sunY+89*sin(halleyAngle), 3, 3);
text("Halley's Comet",(sunX-90)+125*cos(halleyAngle),sunY+89*sin(halleyAngle));

//Code works up until this point

if ( (0) <=  n*TWO_PI/(A-B)  && (PI/2) <= (PI/2)  )
{
fill(255, 55, 25);
ellipse((nemesunX-10)+A*cos(nemesisAngle), nemesunY+B*sin(nemesisAngle), 5, 5);
text("NEMESIS",(nemesunX)+A*cos(nemesisAngle),nemesunY+B*sin(nemesisAngle));
A = A - p;
B = B + p;
n += 1;
}

if ( (PI/2) <=  n*TWO_PI/(A-B)  <=  (PI)  )
{
fill(255, 55, 25);
ellipse((nemesunX-10)+A*cos(nemesisAngle), nemesunY+B*sin(nemesisAngle), 5, 5);
text("NEMESIS",(nemesunX)+A*cos(nemesisAngle),nemesunY+B*sin(nemesisAngle));
A = A + p;
B = B - p;
n += 1;
}

if ( (PI) <=  n*TWO_PI/(A-B)  <=  (3* PI/2)  )
{
fill(255, 55, 25);
ellipse((nemesunX-10)+A*cos(nemesisAngle), nemesunY+B*sin(nemesisAngle), 5, 5);
text("NEMESIS",(nemesunX)+A*cos(nemesisAngle),nemesunY+B*sin(nemesisAngle));
A = A - p;
B = B + p;
n += 1;
}

if ( (3*PI/2) <=  n*TWO_PI/(A-B)  <=  (TWO_PI)  )
{
fill(255, 55, 25);
ellipse((nemesunX-10)+A*cos(nemesisAngle), nemesunY+B*sin(nemesisAngle), 5, 5);
text("NEMESIS",(nemesunX)+A*cos(nemesisAngle),nemesunY+B*sin(nemesisAngle));
A = A + p;
B = B - p;
n += 1;
}

if (  n*TWO_PI/(A-B)  >=  (TWO_PI)  )
{
n = 0;
}

} //Draw Loop
``````
• Get RadialGradientPaint to work in processing 3

I found this code on github that works fine on processing 2, but doens't on processing 3. It is supossed to draw radial gradients influenced by the mouse position using a java library. But in processing 3 it just shows a grey screen. I tried altering some things and a lot of google searches but I can't find the cause.

I had to add this line for it to find PGraphicsJava2D too:

``````import processing.awt.PGraphicsJava2D;
import java.awt.Graphics2D;
import java.awt.Color;
import java.awt.geom.*;

Graphics2D g2;
Rectangle2D.Double rectangle;

Point2D center;
Point2D focus;
float[] dist = { 0.0f, 0.4f, 1.0f };

Color[] gradColors = new Color[dist.length];

Color[] endColors = {
new Color(254, 189, 75), // yellow
new Color(255, 98, 43), // red
new Color(87, 25, 198) // violet
};

Color[] startColors = {
new Color(232, 185, 71),
new Color(180, 98, 56),
new Color(87, 36, 68)
};

void setup() {
size(300, 600); // make sure NOT to use P2D
g2 = ((PGraphicsJava2D)g).g2;

rectangle = new Rectangle2D.Double(0, 0, width, height);
center = new Point2D.Float(width/2.0f, height);
focus = new Point2D.Float(width/2.0f, height);
updateColors(0);
}

void draw() {
focus,
dist,
g2.fill(rectangle);
}

void mouseMoved() {
updateColors((float) mouseY / height);
}

void updateColors(double blend) {
for(int i = 0; i < gradColors.length; i++) {
gradColors[i] = lerpColor(startColors[i], endColors[i], blend);
}
}

Color lerpColor(Color color1, Color color2, double blend) {
double inverseBlend = 1.0 - blend;
int redPart = (int) (color1.getRed() * blend + color2.getRed() * inverseBlend);
int greenPart = (int) (color1.getGreen() * blend + color2.getGreen() * inverseBlend);
int bluePart = (int) (color1.getBlue() * blend + color2.getBlue() * inverseBlend);
return new Color(redPart, greenPart, bluePart);
}
``````
• How to make an array of ellipses travel along the circumference of another array of larger ellipses

@kfrajer -- beautiful demo sketch.

@637pm -- with two gears this is a simple Spirograph:

https://en.wikipedia.org/wiki/Spirograph

you can extend this Spirograph approach to an arbitrary number of gears if you want the curves to be more complex, or if you want to draw with multiple Spirograph pens at the same time -- on the same gear, or on different gearings (like tracing multiple planets and moons in the same solar system).

To find the location of one pen in your graph, rotate to the orientation of the current gear and then travels its radius -- then does it again (rotate, travel), as many times as you want. In other words, find a pen using a turtle.

This means you can store a pen gearing (that is, an orbit path) as an array or ArrayList of PVectors, one vec per gear leading from the center out:

``````(initial orientation, radius, speed)
(initial orientation, radius, speed)
``````

So, for example, a lunar satellite would be stored as three gears / vectors: 1. Earth orientation/radius/speed (around Sun), 2. Moon o/r/s (around Earth), 3. satellite o/r/s (around Moon). (Note this is for a 2D model with circular orbits)

To find the current rotation of each gear, use the initial orientation, speed, and elapsed time since the starting clock or frameRate. This avoids drift due to cumulative rounding errors.

• Clear Animated GIF from Sketch

to clear the sketch before loading a new gif file but are not sure how to achieve that.

I am not sure how yo are loading your sketch? Please ensure ou provide some code with your question. Also consider checking the examples that comes with the library. In the PDE, go to file>>Examples and then go to folder Contributed libraries>>GifAnaimation.

Kf

``````Gif myAnimation,myAnimation2;
int cplay=0;  //Current gif playing. Either 0 or 1

void setup() {
size(400,400);
myAnimation = new Gif(this, "lavalamp.gif");
myAnimation2 = new Gif(this, "solar.gif");

myAnimation.play();
cplay=0;
}

void draw() {

background(0);

if(ctr==0){
image(myAnimation, 10, 10);
}
else{
image(myAnimation2, 10, 10);
}

}

void mouseReleased(){
ctr= (ctr+1)%2; //Either 0 or 1

myAnimation .stop();
myAnimation2.stop();

if(ctr==0){
myAnimation.play();
}
else{
myAnimation2.loop();
}
}
``````
• Solar System in Processing - Part 4 (Light?)

Hi everyone,

I had recently viewed this video: Coding Challenge #9: Solar System in Processing - Part 3 (3D textures)

At 10:30s of this video, shiffman wants to create a effect like sunlight using pointLight at the position same as the sun sphere. The sun effect is done, but sun itself is darken. An there is no next video about Solar System in Processing which gives a solution. Can anybody help me how to create a sunlight effect?

pointLight inside the sun:

pointLight inside the sun + ambientLight: (not perfect effect):

• Shapes3D is beyond Coool : But can I do dynamic textures

Interesting. In practice how are you using Sidereal time -- are you converting solar time inputs into it to find the correct rotation of your skybox / skysphere? Are you doing everything internally in sidereal time, then converting to solar, or vice versa (or no solar at all)?

• Porting a perl script to Processing

(it is, based on the filename - Enecsys are a range of solar panels)

• Could you help me with PeasyCam, ControlP5, 3D and pdf export, please?

from my point of view, my solar system rotates clockwise, but this is wrong. I need a view from the other side, so that the system rotates counter clockwise.

• need help from physicists with my calculation methods in the solar system

Hey guys, I´m Theresa, student of Visual Communication in Germany, so English is not my native language and I am new in processing but I will try my best, so here is my question. I try to simulate a moving solar system in processing with all physically components like gravitation, forces, velocity, acceleration, positions etc. the coordinates I got from the nasa website. Please, could anyone help me with the calculations and correct them? Till monday, please :)

``````/////// SONNE zum 1.1. 2000
/////// X = -7.139143380212697E-03 Y = -2.792019770161695E-03 Z = 2.061838852554664E-04
/////// VX= 5.374260940168566E-06 VY=-7.410965396701423E-06 VZ=-2.522925180072137E-03

/////// MERKUR zum 1.1. 2000
/////// X =-1.478672233442572E-01 Y =-4.466929775364947E-01 Z =-2.313937582786785E-02
/////// VX= 2.117424563261189E-02 VY=-7.105386404267509E-03 VZ=-2.522925180072137E-03

/////// VENUS zum 1.1. 2000
/////// X =-7.257693602841776E-01 Y =-2.529582082587794E-02 Z = 4.137802526208009E-02
/////// VX= 5.189070188671265E-04 VY=-2.031355258779472E-02 VZ=-3.072687386494688E-04

/////// ERDE zum 1.1. 2000
/////// X =-1.756637922977122E-01   Y = 9.659912850526895E-01   Z = 2.020629118443605E-04
/////// VX=-1.722857156974862E-02   VY=-3.015071224668472E-03   VZ=-5.859931223618532E-08

/////// MARS zum 1.1. 2000
/////// X = 1.383221922520998E+00 Y =-2.380174081741852E-02 Z =-3.441183028447500E-02
/////// VX= 7.533013850513376E-04 VY= 1.517888771209419E-02 VZ= 2.996589710207392E-04

/////// https://rechneronline.de/planeten/masse.php

import peasy.*;
import peasy.org.apache.commons.math.*;
import peasy.org.apache.commons.math.geometry.*;

Boid Merkur = new Boid(
new PVector(-1.478672233442572E-01, -4.466929775364947E-01, -2.313937582786785E-02),
new PVector(2.117424563261189E-02, -7.105386404267509E-03, -2.522925180072137E-03),
new PVector(0, 0, 0),
1.66060697e-7,
0.999,
100);

Boid Venus = new Boid(
new PVector(-7.257693602841776E-01, -2.529582082587794E-02, 4.137802526208009E-02),
new PVector(5.189070188671265E-04, -2.031355258779472E-02, -3.072687386494688E-04),
new PVector(0, 0, 0),
0.000002448,
0.999,
155);

Boid Erde = new Boid(
new PVector(-1.756637922977122E-01, 9.659912850526895E-01, 2.020629118443605E-04),
new PVector(-1.722857156974862E-02, -3.015071224668472E-03, -5.859931223618532E-08),
new PVector(0, 0, 0),
0.000002988,
0.999,
255);

Boid Mars = new Boid(
new PVector(1.383221922520998E+00, -2.380174081741852E-02, -3.441183028447500E-02),
new PVector(7.533013850513376E-04, 1.517888771209419E-02, 2.996589710207392E-04),
new PVector(0, 0, 0),
3.22772875e-7,
0.999,
100);

PeasyCam cam;

void setup() {
size(1600, 1200, P3D);
background(150);
frameRate(26);
cam = new PeasyCam(this, 10000);
}

void draw() {
background(0);
lights();
translate(width / 2, height / 2);
fill(255, 215, 0);
sphere(170);
scale(2000);
Merkur.bewegDich();
Merkur.zeichneDich(0.01);
Venus.bewegDich();
Venus.zeichneDich(0.01);
Erde.bewegDich();
Erde.zeichneDich(0.01);
Mars.bewegDich();
Mars.zeichneDich(0.01);
}

class Boid {
PVector pos;
PVector vel;
PVector acc;
float mas;
float deltaT;
float far;

Boid(PVector position, PVector velocity, PVector acceleration, float masse, float deltaZeit, float farbe) {
pos = position;
vel = velocity;
acc = acceleration;
mas = masse;
deltaT = deltaZeit;
far = farbe;
}

void bewegDich() {
PVector posS = new PVector();
float masS = 1;                                     // Sonne in Sonnenmassen
float G_SI = 6.674E-11;                             // m^3 kg^-1 s^-2
float sekundenTag;
float kiloSonnenmassen;
float meterAE;
float Grav;

float r = PVector.dist(posS, pos);
sekundenTag = (24 * 60 * 60);
kiloSonnenmassen = 1.98892E+30;
meterAE = (1 / (1.49597E+11));
Grav = (G_SI * (sekundenTag * sekundenTag) * kiloSonnenmassen * (meterAE * meterAE * meterAE));               // 0.017204072^2
PVector Anziehungskraft = (PVector.sub(posS, pos)).mult(Grav * mas * masS * (1 / (r * r * r)));               // anziehungskraft der sonne

acc = PVector.div(Anziehungskraft, mas);
vel = PVector.add(vel, (acc.mult(deltaT)));
pos = PVector.add(pos, vel);                                                                                  // DIE GESCHWINDIGKEIT WIRD AUF DIE POSITION AUFADDIERT
acc = PVector.mult(acc, 0);
}

void zeichneDich(float groesse) {
println(pos);
pushMatrix();                                       // ändert die koordinaten innerhalb von push/pop matrix
translate(pos.x, pos.y, pos.z);
fill(far);
noStroke();
sphere(groesse);
popMatrix();
}
}
``````
• How to move the solar system?

Yes, post complete updated code for people to test and post in English if possible, and the community can help you.

Also notice that if you search the forum (or search the forum using Google) for words like "solar" that you will find related past examples.

• How to move the solar system?

Hey guys, I´m Theresa, student of Visual Communication in Germany, so English is not my native language and I am new in processing but I will try my best, so here is my question. I try to simulate a moving solar system in processing with all physics components like gravitation, forces, velocity, acceleration, positions etc. the coordinates I got from the nasa website. I have two mainly problems. the first is the physic, I don't know, if the calculating methods are right and the second problem is that only one planet is visible but I defined two. Ah, and it must be ready till Monday :-P please, could anyone help me? Here is my code:

``````/////// SONNE zum 1.1. 2000
/////// X = -7.139143380212697E-03 Y = -2.792019770161695E-03 Z = 2.061838852554664E-04
/////// VX= 5.374260940168566E-06 VY=-7.410965396701423E-06 VZ=-2.522925180072137E-03

/////// MERKUR zum 1.1. 2000
/////// X =-1.478672233442572E-01 Y =-4.466929775364947E-01 Z =-2.313937582786785E-02
/////// VX= 2.117424563261189E-02 VY=-7.105386404267509E-03 VZ=-2.522925180072137E-03

/////// VENUS zum 1.1. 2000
/////// X =-7.257693602841776E-01 Y =-2.529582082587794E-02 Z = 4.137802526208009E-02
/////// VX= 5.189070188671265E-04 VY=-2.031355258779472E-02 VZ=-3.072687386494688E-04

/////// ERDE zum 1.1. 2000
/////// X =-1.756637922977122E-01   Y = 9.659912850526895E-01   Z = 2.020629118443605E-04
/////// VX=-1.722857156974862E-02   VY=-3.015071224668472E-03   VZ=-5.859931223618532E-08

/////// MARS zum 1.1. 2000
/////// X = 1.383221922520998E+00 Y =-2.380174081741852E-02 Z =-3.441183028447500E-02
/////// VX= 7.533013850513376E-04 VY= 1.517888771209419E-02 VZ= 2.996589710207392E-04

/////// https://rechneronline.de/planeten/masse.php

import peasy.*;
import peasy.org.apache.commons.math.*;
import peasy.org.apache.commons.math.geometry.*;

PVector pos;
PVector vel;
PVector acc;
float mas;
float deltaT;
float far;

Boid Erde = new Boid(
new PVector(-1.756637922977122E-01, 9.659912850526895E-01, 2.020629118443605E-04),
new PVector(-1.722857156974862E-02, -3.015071224668472E-03, -5.859931223618532E-08),
new PVector(0, 0, 0),
0.000002988,
0.999,
255);

Boid Venus = new Boid(
new PVector(-7.257693602841776E-01, -2.529582082587794E-02, 4.137802526208009E-02),
new PVector(5.189070188671265E-04, -2.031355258779472E-02, -3.072687386494688E-04),
new PVector(0, 0, 0),
0.000002448,
0.999,
155);

PeasyCam cam;

void setup() {
size(1600, 1200, P3D);
background(150);
frameRate(10);
cam = new PeasyCam(this, 10000);
}

void draw() {
lights();
translate(width / 2, height / 2);
scale(2000);
Erde.bewegDich();
Erde.zeichneDich();
Venus.bewegDich();
Venus.zeichneDich();
}
``````

and than a second tab called "boid"

``````class Boid {
Boid(PVector position, PVector velocity, PVector acceleration, float masse, float deltaZeit, float farbe) {
pos = position;
vel = velocity;
acc = acceleration;
mas = masse;
deltaT = deltaZeit;
far = farbe;
}

void bewegDich() {
PVector posS = new PVector();
float masS = 1;                                     // Sonne in Sonnenmassen
float G_SI = 6.674E-11;                             // m^3 kg^-1 s^-2
float sekundenTag;
float kiloSonnenmassen;
float meterAE;
float Grav;

float r = PVector.dist(posS, pos);                  //muss in AE umgerechnet werden
sekundenTag = (24 * 60 * 60);
kiloSonnenmassen = 1.98892E+30;
meterAE = (1 / (1.49597E+11));
Grav = (G_SI * (sekundenTag * sekundenTag) * kiloSonnenmassen * (meterAE * meterAE * meterAE));               // 0.017204072^2
PVector Anziehungskraft = (PVector.sub(posS, pos)).mult(Grav * mas * masS * (1 / (r * r * r)));               // anziehungskraft der sonne

acc = PVector.div(Anziehungskraft, mas);
vel = PVector.add(vel, (acc.mult(deltaT)));
pos = PVector.add(pos, vel);                                                                                  // DIE GESCHWINDIGKEIT WIRD AUF DIE POSITION AUFADDIERT
acc = PVector.mult(acc, 0);
}

void zeichneDich() {
background(0);
println(pos);
pushMatrix();                                       // ändert die koordinaten innerhalb von push/pop matrix
translate(pos.x, pos.y, pos.z);
fill(far);
noStroke();
sphere(0.1);
popMatrix();
}
}
``````
• (Fixed)Need Help With My Code/If Statements :(

IT does everything correctly, and its suppose to reflect the solar system with all the ellipses I drew in the program. But it doesn't execute key presses when its looping the draw function specifically my if statement= if (Menus==2) {. It Loops everything inside it and the orbits work but any if statement or key press that is pressed or executed after its(if (Menus==2); execution doesn't seem to work. The Loops Continues On But Nothing New Can Be Added.

• (Fixed)Need Help With My Code/If Statements :(

Hi, I'm Doing A School Project About The Sol System In My Computer Science Class And My If Statements Don't Seem To Work As I'm Kind Of Ahead Of The Class So Haven't Had Time To Fully Understand Processing. Could Any Of You Tell Me What I Did Wrong? MY Code Unfinished:

``````int Menus=0;
int Trails=0;

float SunDiameter = 1.914;
float MercuryDiameter = 0.4879;
float MercuryOrbitDistance = 7.8;
float MercuryOrbitSpeed = 0;

float VenusDiameter = 1.2104;
float VenusOrbitDistance = 14.4;
float VenusOrbitSpeed = 0;

float EarthDiameter = 1.2742;
float EarthOrbitDistance = 20;
float EarthOrbitSpeed = 0;
float EarthX = 0;
float EarthY = 0;

float MoonDiameter = 0.3474;
float MoonOrbitDistance = 5;
float MoonOrbitSpeed = 0;

float MarsDiameter = 0.64779;
float MarsOrbitDistance = 30.4;
float MarsOrbitSpeed = 0;

float JupiterDiameter = 13.9822;
float JupiterOrbitDistance = 102;
float JupiterOrbitSpeed = 0;

float SaturnDiameter = 11.6464;
float SaturnOrbitDistance = 190.8;
float SaturnOrbitSpeed = 0;

float UranusDiameter = 5.0724;
float UranusOrbitDistance = 384;
float UranusOrbitSpeed = 0;

float NeptuneDiameter = 4.9244;
float NeptuneOrbitDistance = 602;
float NeptuneOrbitSpeed = 0;

float PlutoDiameter = 0.2374;
float PlutoOrbitDistance = 788;
float PlutoOrbitSpeed = 0;

//PImage Earth;
//PImage Stars;
void keyPressed() {
if (key =='T') {
Trails=1;
}
}

void mousePressed () {
if (mouseX>683 && mouseX<833 && mouseY>470 && mouseY<520) {
}
}
if (mouseX>583 && mouseX<946 && mouseY>570 && mouseY<620) {
}
}
}

void setup() {
background(0);
size(1366, 768);
frameRate(60);
}

void draw() {
fill(255);
textSize(25);
text("Sol System", 683, 384);
fill(#8A15EA);
rect(683, 470, 150, 50);
fill(255);
textSize(30);
text("Play Scene", 683, 500);
fill(#8A15EA);
rect(583, 570, 360, 50);
fill(255);
textSize(30);
text("Instructions And Secrets", 583, 600);
}
background(0);
fill(255);
textSize(25);
fill(255);
textSize(10);
text("Fun Facts About My Project : ", 633, 180);
fill(255);
textSize(10);
text("Each Pixel For Distance Is 7.4 Million Kilometers ", 583, 200);
fill(255);
textSize(10);
text("Planets And Gas Giants Are Scaled Correctly In Comparison To Each Other. The Sun Is Not ", 553, 220);
fill(255);
textSize(10);
text("The Planets And Gas Giants Are Not Scaled Correctly In Terms Of Size To Distance Due To Size Of The Solar System", 488, 240);
fill(255);
textSize(30);
text("Instructions:", 488, 280);
fill(255);
textSize(10);
text("All You Have To Do Is Sit Back And Watch The Orbits Of The Planets.", 488, 300);
text("Press The Coresponding Keys For The Planets MVEMJSUNP To Learn About Them", 488, 320);
text("Click The Sun To Make It Become A Red Giant And Consume The Inner Planets.", 488, 340);
text("Click T To Show The Trails Of The Planets.", 488, 360);
}
if (Menus==2 && Trails==0) {
background(0);
}
{
translate(width/2, height/2); // Moves The Coordinates To The Centre. So 0,0 is at the centre of the screen.
noStroke(); // No Stroke For The Sun/Planets
fill(#FCD440); // Color Of The Sun Even Though Its Actually White In Real Life :(
ellipse(0, 0, SunDiameter, SunDiameter);
pushMatrix();
fill(#6F5757);
rotate(MercuryOrbitSpeed);
translate(MercuryOrbitDistance, 0);
ellipse(0, 0, MercuryDiameter, MercuryDiameter);
popMatrix();
pushMatrix();
fill(#C4A122);
rotate(VenusOrbitSpeed);
translate(VenusOrbitDistance, 0);
ellipse(0, 0, VenusDiameter, VenusDiameter);
popMatrix();
pushMatrix();
rotate(MarsOrbitSpeed);
translate(MarsOrbitDistance, 0);
ellipse(0, 0, MarsDiameter, MarsDiameter);
popMatrix();
pushMatrix();
rotate(JupiterOrbitSpeed);
translate(JupiterOrbitDistance, 0);
ellipse(0, 0, JupiterDiameter, JupiterDiameter);
popMatrix();
pushMatrix();
rotate(SaturnOrbitSpeed);
translate(SaturnOrbitDistance, 0);
ellipse(0, 0, SaturnDiameter, SaturnDiameter);
popMatrix();
pushMatrix();
fill(#4BBDDB);
rotate(UranusOrbitSpeed);
translate(UranusOrbitDistance, 0);
ellipse(0, 0, UranusDiameter, UranusDiameter);
popMatrix();
pushMatrix();
fill(#426DC6);
rotate(NeptuneOrbitSpeed);
translate(NeptuneOrbitDistance, 0);
ellipse(0, 0, NeptuneDiameter, NeptuneDiameter);
popMatrix();
pushMatrix();
fill(#426DC6);
rotate(PlutoOrbitSpeed);
translate(PlutoOrbitDistance, 0);
ellipse(0, 0, PlutoDiameter, PlutoDiameter);
popMatrix();
fill(#2EACD1);
rotate(EarthOrbitSpeed);
translate(EarthOrbitDistance, 0);
ellipse(0, 0, EarthDiameter, EarthDiameter);
fill(#AAA3A9);
rotate(MoonOrbitSpeed);
translate(MoonOrbitDistance, 0);
ellipse(0, 0, MoonDiameter, MoonDiameter);

VenusOrbitSpeed += 0.03244444444;
EarthOrbitSpeed += 0.02;
MoonOrbitSpeed += 7.3;
MarsOrbitSpeed += 0.01062590975;
MercuryOrbitSpeed += 0.08295454545;
JupiterOrbitSpeed += 0.00166666666;
SaturnOrbitSpeed += 0.00067895576;
UranusOrbitSpeed += 0.00023809523;
NeptuneOrbitSpeed += 0.00012135922;
PlutoOrbitSpeed += 0.00008045375;
}
}
``````
• Random color for ellipses on key press (Created in class)

Hey, I understand the title may be a bit confusing but I'm extremely new to Processing so please bare with me.

I'm trying to generate random colors each time a key is pressed. I took code from this example: http://learningprocessing.com/examples/chp14/example-14-18-solar-system-OOP

I've tweaked it for my own project but I'm having a hard time changing the fill each time a key is pressed. All I'm getting is gray ellipses. Initially, I wanted to set a different color for each key [Q, W, E] but at this point, even random colors generated by the keys will do.

Main File:

``````boolean colorChange = false;

// An array of 8 planet objects
Planet[] planets = new Planet[30];
ArrayList<Planet> newPlanets = new ArrayList<Planet>() ;

void setup() {
//size(900, 900);
fullScreen();

// The planet objects are initialized using the counter variable
for (int i = 0; i < planets.length; i++ ) {

planets[i] = new Planet(185 + i*5, 8);
}
}

void draw() {
background(0);

/* Stars */
randomSeed(103);

for (int i = 0; i < 300; i++) {
float x = random(0, width);
float y = random(0, height);

ellipse(x, y, 2, 2);
fill(255);
}

// Drawing the Earth
pushMatrix();
translate(width/2, height/2);
stroke(0);
fill(0, 191, 255);
ellipse(0, 0, 350, 350);
noFill() ;
// Drawing all Planets
for (int i = 0; i < planets.length; i++ ) {
planets[i].update();
planets[i].display();
}

if (newPlanets.size() > 0) {
for (int i = 0; i < newPlanets.size(); i++) {
println("newPlanets should be drawing") ;
Planet p = newPlanets.get(i) ;
p.update() ;
p.display() ;
}
}

popMatrix();

fill(255, 0, 0);
text("[Press E for Air Pollution]", width/9, height - (height/8));
fill(255, 255, 0);
text("[Press W for Ground Level Pollution]", width/9, height - (height/8 + 15));
fill(0, 255, 0);
text("[Press Q for Greenhouse Gasses]", width/9, height - (height/8 + 30));
}

void keyPressed() {
if (key == 'q' || key == 'Q') {
for (int i = 0; i < planets.length; i++) {
newPlanets.add(new Planet(185 + i*5, 8));
}
}

if (key == 'w' || key == 'W') {
for (int i = 0; i < planets.length; i++) {
newPlanets.add(new Planet(185 + i*5, 8)) ;
}
}

if (key == 'e' || key == 'E') {
for (int i = 0; i < planets.length; i++) {
newPlanets.add(new Planet(185 + i*5, 8));
}
}
}
``````

Class File

``````// Example 14-18: Object-oriented solar system

class Planet {
// Each planet object keeps track of its own angle of rotation.
float theta;      // Rotation around sun
float diameter;   // Size of planet
float distance;   // Distance from sun
float orbitspeed; // Orbit speed
float resetingDistance ;
color planetColor;
boolean colorChange = false;

Planet(float distance_, float diameter_) {
distance = distance_;
resetingDistance = distance_ ;
diameter = diameter_;
theta = 0;
orbitspeed = random(0.01, 0.03);
//planetColor = color( random(255), random(255), random(255), random(255));
}

void update() {
// Increment the angle to rotate
theta += orbitspeed;
}

void display() {
// Before rotation and translation, the state of the matrix is saved with pushMatrix().
pushMatrix();
// Rotate orbit
rotate(theta);
// Translate out distance
translate(distance, 0);
stroke(0);
fill(175);

if (colorChange == true) {
//fill(random(255), random(255), random(255), random(255));
planetColor = color( random(255), random(255), random(255), random(255));
}

ellipse(0, 0, diameter, diameter);
// Once the planet is drawn, the matrix is restored with popMatrix() so that the next planet is not affected.
popMatrix();
}
}
``````
• Creating multiple arrays from a txt file

I'm currently trying to create a visual diagram of solar winds within processing, but I'm struggling on trying to structure it and I need help.

Using http://services.swpc.noaa.gov/text/ace-swepam.txt I need to collect proton density, bulk speed and ion temperature and create a visual diagram which I will get into once I've collected all 120 points of data (1 per minute over the course of 2 hours)

I've worked with txt files before because they're easier to determine and separate different values, but I would still struggle with removing certain values from a row of multiple values.

This was my original idea on how to do it, but doing it this way would require copying and pasting this 120 times and adjusting it along the way.

I want to do what I've done, but using i+ 120 times to get everything stored in a single array but I have no idea how.

• Need Ideas

Draw a circle in the center of the sketch. Then any time you click in the circle, you draw a triangle on it and you show the label of each side and in the console, you could output the length of each side of this triangle, and calculate the sin, cos and tan related to either or both the x and the y axis (x axis should be ok to start). Don't forget to output the angle in both degrees and radians units.

A second task, draw the solar system at each planet showing their respective motion. Then draw the Moon orbiting around Earth on this solar system. This demo is usually done in Processing using rotation and translation functions provided by Processing itself. The challenge here is to use trig functions instead.

Kf

• Embedding sketch in webpage(html)

Hello. I am working on a sketch based on the "Solar system generator" (video link below).

I modified the code such that it retrieves the number of moons and the appropriate image file from a .csv, and managed to get it working.

However, I have trouble embedding it to a html file. Below are the contents of the html and processing code. I also attached an image of the working directory.

Any pointers on what's going wrong is greatly appreciated. (I have a feeling it has something to do with the *@pjs preload command of the .pde ..., but not sure)

Many thanks in advance.

-----html code--------

``````<html>
<title> My first webpage</title>
<script src="Processing.js"></script>

<body>
Hello World!
<marquee> this is a test!</marquee>
<canvas data-processing-sources="solargenerator_sunrotate_ver6.pde planet.pde"></canvas>
</body>
</html>
``````

-----sketch code solargenerator_sunrotate_ver6--------

``````import peasy.*;
Planet[] sun;

PeasyCam cam;

PImage sunTexture;
PImage[] textures = new PImage[3];
Table holidaytable;
int nrows;

void setup() {
size(900, 700, P3D);

cam = new PeasyCam(this, 1000);

int nrows =holidaytable.getRowCount();

sun = new Planet[nrows];

for (int i = 0; i < nrows; i++) {
TableRow row = holidaytable.getRow(i);

int ID = row.getInt("no");
int holiday = row.getInt("holidays");
String picture = row.getString("image");

sun[i]= new Planet(50, 450, 0, true, ID, sunTexture);
sun[i].spawnMoons(holiday,1);
}
}

void draw() {
background(0);
lights();

for (Planet sun2 : sun) {
sun2.show();
sun2.orbit();
}
}
``````

OS: windows 10 Processing version: 3.3.4