Created
August 16, 2010 17:28
-
-
Save mataspetrikas/527348 to your computer and use it in GitHub Desktop.
Processing: Crystals
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
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