Hello everyone; I am trying to create a simulation for Big Bang Theory. I would like to create a sphere in the middle then make it explode and then I would like to create the sun(as a new sphere) and the solar system.
I tried my best but something is definitely not working as I want. I would appreciate If you guys can help me. It is very urgent since it is my final project.
import peasy.org.apache.commons.math.geometry.*;
PeasyCam cam; Planet sun; Particle [] particles = new Particle [800]; Sun mySun;
void setup () {
size (700, 700, P3D); smooth (); cam = new PeasyCam(this, 700); sun = new Planet(40, 0, 0); sun.spawnMoons(3, 1); for (int i=0; i<particles.length; i++) { particles [i] = new Particle (); }
mySun = new Sun(); }
void draw () { background (0); //clear the background for (int i=0; i<particles.length; i++) { particles[i].update(); } float time= millis(); if (millis() > 5500) { mySun.display(); time= millis (); }
if ( millis() >7500) { lights(); sun.display(); sun.orbit(); time= millis(); } }
class Particle {
float x; float y;
float aX; // speed float aY;
Particle () { //x and y position to be in middle of screen x = width/2; y = height/2;
aX = random (-10,10);
aY = random (-10,15);
}
void update () {
x+=aX;
y+=aY;
fill (255);
ellipse (x,y,7,7);
} }
class Planet { // solar system works as I want float radius; float distance;
Planet[] planets; float angle; float orbitspeed; PVector v; PShape globe;
Planet(float r, float d, float o) {
v = PVector.random3D();
radius = r;
distance = d;
v.mult(distance);
angle = random(PI-45);
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/(level2); 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 display() { pushMatrix(); noStroke(); PVector v2 = new PVector(1, 0, 1); PVector p = v.cross(v2); rotate(angle, p.x, p.y, p.z); stroke(255);
translate(v.x, v.y, v.z);
noStroke();
fill(170);
sphere(radius);
if (planets != null) {
for (int i = 0; i < planets.length; i++) {
planets[i].display();
}
}
popMatrix();
} } class Sun { // the sphere I want to explode
void display(){ lights();
pushMatrix(); translate(350, 350, 0); noStroke(); fill(255); sphere(40); popMatrix(); } }