Created
July 1, 2018 15:38
-
-
Save josephtaylor/89f963c81c85af1d1c9ac1b74a58c485 to your computer and use it in GitHub Desktop.
Processing Noise Experiment
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.time.LocalDateTime; | |
private ArrayList<Point> points; | |
private final int NUM_POINTS = 20000; | |
private final float NOISE_INCREMENT = 0.01; | |
void setup() { | |
size(700,700); | |
background(0); | |
stroke(255,255,255,10); | |
points = new ArrayList<Point>(); | |
for(int i = 0; i < NUM_POINTS; i++) { | |
PVector loc = new PVector(250, 250); | |
float r = random(20); | |
float theta = random(2 * PI); | |
PVector vel = new PVector(r * cos(theta), r * sin(theta)); | |
points.add(new Point(loc, vel)); | |
} | |
} | |
void draw() { | |
for (Point point : points) { | |
line(point.prevLoc.x, point.prevLoc.y, point.loc.x, point.loc.y); | |
point.update(); | |
} | |
} | |
void mousePressed() { | |
saveFrame(LocalDateTime.now() + ".png"); | |
} | |
public class Point { | |
public PVector loc; | |
public PVector vel; | |
public PVector prevLoc; | |
public float noiseCounter = 0; | |
public Point(PVector loc, PVector vel) { | |
this.loc = loc; | |
this.vel = vel; | |
this.prevLoc = loc.get(); | |
} | |
public void update() { | |
prevLoc.set(loc.x,loc.y,0); | |
float noiseVal = noise(loc.x * NOISE_INCREMENT, loc.y * NOISE_INCREMENT, noiseCounter += NOISE_INCREMENT); | |
float angle = noiseVal * 2 * PI; | |
loc.set(loc.x + (vel.x * cos(angle)), loc.y + (vel.y * sin(angle)), 0); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment