Skip to content

Instantly share code, notes, and snippets.

@ramayac
Last active December 16, 2015 22:19
Show Gist options
  • Save ramayac/5506298 to your computer and use it in GitHub Desktop.
Save ramayac/5506298 to your computer and use it in GitHub Desktop.
Brownian noise movement sketch
class Gusano {
int cantidad = 100;
int rango = 6;
PVector[] linea = new PVector[cantidad];
Gusano() {
for (int i = 0; i < cantidad; i++) {
linea[i] = new PVector(width/2, height/2);
}
}
void update() {
for (int i = 1; i < cantidad; i++) {
linea[i-1].x = linea[i].x;
linea[i-1].y = linea[i].y;
//linea[i-1]= linea[i]; //no sirve
}
linea[cantidad-1].x += noise(linea[cantidad-1].x)*2; //random(-rango, rango);
linea[cantidad-1].y += noise(linea[cantidad-1].y)*2; //random(-rango, rango);
boolean fuerapantalla = false;
if (linea[cantidad-1].x > width) {
linea[cantidad-1].x = linea[cantidad-1].x-width;
}
if (linea[cantidad-1].y > height) {
linea[cantidad-1].y = linea[cantidad-1].y-height;
}
}
void draw() {
for (int i = 1; i < cantidad; i++) {
float val = float(i)/cantidad * 204.0 + 51;
stroke(val);
float d = dist(linea[i-1].x, linea[i-1].y, linea[i].x, linea[i].y);
if (d < rango) {
line(linea[i-1].x, linea[i-1].y, linea[i].x, linea[i].y);
}
}
}
}
Gusano gusanito;
void setup() {
size(640, 360);
gusanito = new Gusano();
frameRate(30);
}
void draw() {
background(51);
gusanito.update();
gusanito.draw();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment