Created
July 8, 2013 23:23
-
-
Save studioijeoma/5953338 to your computer and use it in GitHub Desktop.
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
import java.util.ArrayList; | |
import java.util.Vector; | |
import processing.core.PApplet; | |
import processing.core.PVector; | |
public class NoisePathTest4 extends PApplet { | |
// ParticlePath pathParticle; | |
ArrayList<ParticlePath> particlePaths; | |
public void setup() { | |
size(400, 400); | |
smooth(); | |
stroke(0); | |
background(255); | |
cursor(CROSS); | |
// pathParticle = new ParticlePath(); | |
setupPaths(); | |
} | |
public void setupPaths() { | |
particlePaths = new ArrayList<ParticlePath>(); | |
for (int i = 0; i < 1; i++) | |
particlePaths.add(new ParticlePath()); | |
} | |
public void draw() { | |
background(255); | |
stroke(0); | |
PVector p1 = new PVector(mouseX, mouseY); | |
PVector p2 = new PVector(pmouseX, pmouseY); | |
// pathParticle.draw(); | |
for (int i = 0; i < particlePaths.size(); i++) | |
particlePaths.get(0).draw(); | |
} | |
public void mousePressed() { | |
setupPaths(); | |
} | |
public void mouseDragged() { | |
Particle mp = new Particle(mouseX, mouseY); | |
// pathParticle.addParticle(mp); | |
for (int i = 0; i < particlePaths.size(); i++) { | |
Particle rp; | |
if (i == 0) | |
rp = new Particle(mp.x, mp.y); | |
else | |
rp = new Particle(mp.x + random(-25, 25), mp.y | |
+ random(-25, 25)); | |
particlePaths.get(i).addParticle(rp); | |
} | |
} | |
public void mouseReleased() { | |
} | |
public void keyPressed() { | |
setupPaths(); | |
} | |
class Particle extends PVector { | |
public Particle(float x, float y) { | |
super(x, y); | |
} | |
} | |
class ParticlePath { | |
public ArrayList<Particle> particles; | |
int particleCountMax = 50; | |
int color; | |
public ParticlePath() { | |
particles = new ArrayList<Particle>(); | |
color = color(random(255), random(255), random(255)); | |
} | |
public void addParticle(Particle p) { | |
if (particles.size() > particleCountMax) | |
particles.remove(0); | |
particles.add(p); | |
println(p); | |
} | |
public void draw() { | |
Particle pp = null; | |
noFill(); | |
stroke(color); | |
beginShape(LINES); | |
for (Particle p : particles) { | |
if (pp != null) { | |
vertex(pp.array()); | |
vertex(p.array()); | |
} | |
pp = p; | |
} | |
endShape(); | |
for (Particle p : particles) | |
ellipse(p.x, p.y, 5, 5); | |
pp = null; | |
stroke(255, 0, 0); | |
beginShape(); | |
for (Particle p : particles) { | |
if (pp != null) { | |
// PVector pd = PVector.sub(p, pp); | |
// pd.mult(5); | |
// pd.add(pp); | |
float angle = PVector.sub(pp, p).heading(); | |
float d = (angle < 0) ? -1 : 1; | |
println(angle); | |
PVector pd = new PVector(cos(angle - HALF_PI), sin(angle | |
- HALF_PI)); | |
pd.mult(sin(angle)); | |
pd.add(pp); | |
// line(pp.x, pp.y, pd.x, pd.y); | |
vertex(pd.array()); | |
} | |
pp = p; | |
} | |
endShape(); | |
} | |
public void removeAll() { | |
particles.clear(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment