Skip to content

Instantly share code, notes, and snippets.

@mataspetrikas
Created August 16, 2010 17:28
Show Gist options
  • Save mataspetrikas/527348 to your computer and use it in GitHub Desktop.
Save mataspetrikas/527348 to your computer and use it in GitHub Desktop.
Processing: Crystals
int oWidth = 20;
int oHeight = oWidth;
int oX;
int oY;
void setup() {
size(800,600);
background(0);
oX = floor(random(width/oWidth)) * oWidth;
oY = floor(random(height/oHeight)) * oHeight;
}
void draw() {
int bX = oX;
int bY = oY;
fill(200,random(1, 25));
int o = floor(random(oWidth * 4));
noStroke();
rect(oX, oY, o, o);
oX = constrain(oX + randomDirection(oWidth, 1), 0, width - oWidth);
oY = constrain(oY + randomDirection(oHeight, 1), 0, height - oHeight);
stroke(255, 45);
line(bX,bY,oX, oY);
}
int randomDirection(int step, int factor) {
int r = round(random(-factor,factor));
return step * r;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment