-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
466 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
abstract class GraphicObject { | ||
PVector location; | ||
PVector velocity; | ||
PVector acceleration; | ||
|
||
color fillColor = color (255); | ||
color strokeColor = color (255); | ||
float strokeWeight = 1; | ||
|
||
abstract void update(float deltaTime); | ||
|
||
abstract void display(); | ||
|
||
|
||
} |
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
class Vaisseau extends GraphicObject { | ||
float angularVelocity = 0.0; | ||
float angularAcceleration = 0.0; | ||
|
||
float angle = 0.0; | ||
float heading = 0.0; | ||
|
||
float w = 20; | ||
float h = 10; | ||
|
||
float mass = 1.0; | ||
|
||
float speedLimit = 5; | ||
boolean thrusting = false; | ||
|
||
Vaisseau() { | ||
initValues(); | ||
} | ||
|
||
void initValues() { | ||
location = new PVector(); | ||
velocity = new PVector(); | ||
acceleration = new PVector(); | ||
} | ||
|
||
void applyForce (PVector force) { | ||
PVector f; | ||
|
||
if (mass != 1) | ||
f = PVector.div (force, mass); | ||
else | ||
f = force; | ||
|
||
this.acceleration.add(f); | ||
} | ||
|
||
void checkEdges() { | ||
if (location.x < -size) location.x = width + size; | ||
if (location.y < -size) location.y = height + size; | ||
if (location.x > width + size) location.x = -size; | ||
if (location.y > height + size) location.y = -size; | ||
} | ||
|
||
void thrust(){ | ||
float angle = heading - PI/2; | ||
|
||
PVector force = new PVector (cos(angle), sin(angle)); | ||
force.mult(0.1); | ||
|
||
applyForce(force); | ||
|
||
thrusting = true; | ||
} | ||
|
||
void update(float deltaTime) { | ||
checkEdges(); | ||
|
||
velocity.add(acceleration); | ||
|
||
velocity.limit(speedLimit); | ||
|
||
location.add(velocity); | ||
|
||
acceleration.mult(0); | ||
|
||
angularVelocity += angularAcceleration; | ||
angle += angularVelocity; | ||
|
||
angularAcceleration = 0.0; | ||
} | ||
|
||
float size = 20; | ||
|
||
void display() { | ||
pushMatrix(); | ||
translate (location.x, location.y); | ||
rotate (heading); | ||
|
||
fill(200); | ||
noStroke(); | ||
|
||
beginShape(TRIANGLES); | ||
vertex(0, -size); | ||
vertex(size, size); | ||
vertex(-size, size); | ||
endShape(); | ||
|
||
if (thrusting) { | ||
fill(200, 0, 0); | ||
} | ||
rect(-size + (size/4), size, size / 2, size / 2); | ||
rect(size - ((size/4) + size/2), size, size / 2, size / 2); | ||
|
||
popMatrix(); | ||
} | ||
|
||
void pivote(float angle) { | ||
heading += angle; | ||
} | ||
|
||
void noThrust() { | ||
thrusting = false; | ||
} | ||
} |
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
int currentTime; | ||
int previousTime; | ||
int deltaTime; | ||
|
||
boolean saveVideo = false; | ||
|
||
Vaisseau v; | ||
|
||
void setup () { | ||
size (800, 600); | ||
currentTime = millis(); | ||
previousTime = millis(); | ||
|
||
v = new Vaisseau(); | ||
v.location.x = width / 2; | ||
v.location.y = height / 2; | ||
|
||
} | ||
|
||
void draw () { | ||
currentTime = millis(); | ||
deltaTime = currentTime - previousTime; | ||
previousTime = currentTime; | ||
|
||
|
||
update(deltaTime); | ||
display(); | ||
|
||
savingFrames(5, deltaTime); | ||
} | ||
|
||
PVector thrusters = new PVector(0, -0.02); | ||
|
||
/*** | ||
The calculations should go here | ||
*/ | ||
void update(int delta) { | ||
if (keyPressed) { | ||
switch (key) { | ||
case ' ': | ||
v.thrust(); | ||
break; | ||
case CODED: | ||
if (keyCode == LEFT) v.pivote(-.03); | ||
if (keyCode == RIGHT) v.pivote(.03); | ||
break; | ||
} | ||
} | ||
|
||
v.update(delta); | ||
} | ||
|
||
/*** | ||
The rendering should go here | ||
*/ | ||
void display () { | ||
background(0); | ||
|
||
v.display(); | ||
} | ||
|
||
//Saving frames for video | ||
//Put saveVideo to true; | ||
int savingAcc = 0; | ||
int nbFrames = 0; | ||
|
||
void savingFrames(int forMS, int deltaTime) { | ||
|
||
if (!saveVideo) return; | ||
|
||
savingAcc += deltaTime; | ||
|
||
if (savingAcc < forMS) { | ||
saveFrame("frames/####.tiff"); | ||
nbFrames++; | ||
} else { | ||
println("Saving frames done! " + nbFrames + " saved"); | ||
saveVideo = false; | ||
} | ||
} | ||
|
||
|
||
|
||
void keyReleased() { | ||
switch (key) { | ||
case ' ': | ||
v.noThrust(); | ||
break; | ||
} | ||
} |
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
interface IGraphicObject { | ||
|
||
abstract void update(int deltaTime); | ||
abstract void display(); | ||
} |
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
abstract class Mover implements IGraphicObject { | ||
PVector location; | ||
PVector velocity; | ||
PVector acceleration; | ||
|
||
color strokeColor; | ||
color fillColor; | ||
} |
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
class Particle extends Mover { | ||
|
||
int diameter = 5; | ||
float lifespan; | ||
|
||
PVector initialPosition; | ||
|
||
float intensity; | ||
|
||
Particle (PVector loc) { | ||
location = loc.copy(); | ||
acceleration = new PVector (0f, 0.05f); | ||
intensity = 1; | ||
velocity = new PVector (randomGaussian() * intensity, random (-2, 0) * 3); | ||
initialPosition = location.copy(); | ||
|
||
lifespan = random (200, 255); | ||
|
||
strokeColor = 255; | ||
fillColor = color (200, 0, 0); | ||
} | ||
|
||
void update (int delta) { | ||
velocity.add (acceleration); | ||
location.add (velocity); | ||
|
||
lifespan -= 2.0; | ||
} | ||
|
||
void display() { | ||
stroke (strokeColor, lifespan); | ||
fill (fillColor, lifespan); | ||
|
||
pushMatrix(); | ||
translate (location.x, location.y); | ||
ellipse (0, 0, diameter, diameter); | ||
popMatrix(); | ||
} | ||
|
||
boolean isDead () { | ||
return lifespan <= 0.0; | ||
} | ||
|
||
void reset () { | ||
location.x = initialPosition.x; | ||
location.y = initialPosition.y; | ||
velocity.x = randomGaussian() * intensity; | ||
velocity.y = random (-2, 0); | ||
lifespan = random (200, 255); | ||
} | ||
} |
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
class ParticleSystem implements IGraphicObject { | ||
ArrayList<Particle> particles; | ||
int nbParticles = 100; | ||
|
||
ParticleSystem () { | ||
|
||
particles = new ArrayList<Particle>(); | ||
for (int i = 0; i < nbParticles; i++) { | ||
particles.add (new Particle(new PVector (width / 2, 100))); | ||
} | ||
} | ||
|
||
ParticleSystem (PVector loc) { | ||
|
||
particles = new ArrayList<Particle>(); | ||
for (int i = 0; i < nbParticles; i++) { | ||
particles.add (new Particle(loc)); | ||
} | ||
|
||
} | ||
|
||
|
||
|
||
void update(int delta) { | ||
for (Particle p : particles){ | ||
if (p.isDead()){ | ||
p.reset(); | ||
} | ||
|
||
p.update (delta); | ||
} | ||
} | ||
|
||
void display() { | ||
for (Particle p : particles){ | ||
p.display(); | ||
} | ||
} | ||
|
||
} |
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
int currentTime; | ||
int previousTime; | ||
int deltaTime; | ||
|
||
ParticleSystem ps; | ||
|
||
void setup () { | ||
size (640, 480); | ||
currentTime = millis(); | ||
previousTime = currentTime; | ||
|
||
ps = new ParticleSystem(new PVector(width / 2, height / 2)); | ||
} | ||
|
||
void draw () { | ||
currentTime = millis(); | ||
deltaTime = currentTime - previousTime; | ||
previousTime = currentTime; | ||
|
||
update(deltaTime); | ||
display(); | ||
} | ||
|
||
color fillColor = 0; | ||
int alpha = 2; | ||
|
||
/*** | ||
The calculations should go here | ||
*/ | ||
void update(int delta) { | ||
ps.update(delta); | ||
} | ||
|
||
/*** | ||
The rendering should go here | ||
*/ | ||
void display () { | ||
background (0); | ||
//fill (fillColor, alpha); | ||
//rect (0, 0, width, height); | ||
|
||
//fill (0); | ||
//rect (width / 2 - 128, 100, 256, 300); | ||
ps.display(); | ||
|
||
} | ||
|
||
void mousePressed() { | ||
if (mouseButton == LEFT) { | ||
ps = new ParticleSystem(new PVector (mouseX, mouseY)); | ||
} | ||
} |
This file contains 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 characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
abstract class GraphicObject { | ||
|
||
PVector location; | ||
PVector velocity; | ||
PVector acceleration; | ||
|
||
PVector size; | ||
|
||
abstract void update(int deltaTime); | ||
abstract void display(); | ||
} |
Oops, something went wrong.