Skip to content

Instantly share code, notes, and snippets.

@adacable
Created May 7, 2014 17:57
Show Gist options
  • Save adacable/542e91fe57b934565882 to your computer and use it in GitHub Desktop.
Save adacable/542e91fe57b934565882 to your computer and use it in GitHub Desktop.
void drawStep(int xStepIn){
drawGrid(8,xStepIn);
};
//helpers
void drawGrid(int xnum, int xOffset){
//draws xnum by ynum modules on the canvas, sperated by xgutter and ygutter
int yOffset = (height % ( width / xnum ))/2 ;
int ynum = (height/( width / xnum ));
for (int w = -1; w < xnum; w++) {
for (int d = -1; d < ynum; d++){
float xCenter = (((w+0.5)*(width/xnum) + xOffset % (width/xnum)) + width*(chaoticNumber()))%(width*1.1);
float yCenter = (((d+0.5)*(width/xnum) + yOffset) + height*(chaoticNumber()))%(height*1.1);
float shapeRadius = (2*(width/xnum)/3)*(1-chaoticNumber());
int verticies = int(4 + (chaoticNumber())*10);
color polygonColor = color((chaoticNumber())*50,(chaoticNumber())*40,(chaoticNumber())*40);
polygon(xCenter,yCenter,shapeRadius,verticies,polygonColor);
};
};
};
void polygon(float x, float y, float radius, int npoints, color fillColor) {//draws a polygon at x,y within radius r, with npoints verticies. Function nabbed from the processing docs.
float angle = TWO_PI / npoints;
beginShape();
fill(fillColor);
stroke(fillColor);
for (float a = TWO_PI/8; a < TWO_PI; a += angle) {
float sx = x + cos(a) * radius;
float sy = y + sin(a) * radius;
vertex(sx, sy);
}
endShape(CLOSE);
}
float updateChaosIntensity(float chaosIntensityIn){
float chaosIntensityOut;
if (chaosOn) {//if chaos is on
if (chaosIntensityIn <= 1){//and the chaosInternisty is less than 1
if (chaosIntensityIn < 0.01){
chaosIntensityOut = 0.01;
} else{
chaosIntensityOut = chaosIntensityIn*1.01;//increment the chaosIntensity
}
} else {//Otherwise(if the chaos intensity is one
chaosIntensityOut = 1;
}//leave it as one
} else {//Otherwise(if chaos is off)
chaosIntensityOut = 0.99*chaosIntensityIn;
};
return chaosIntensityOut;
};
float chaoticNumber(){ //a mathematically chaotic algorithm which returns a float between 0 and 1, multiplied by chaosItensity,
float num = ((sqrt(lastChaoticNumber) * 10.0) % 1.0);
lastChaoticNumber = num;
return num * chaosIntensity;
};
//begin main fucntions
void setup() {
size(displayWidth -1, displayHeight - 1,OPENGL);
stroke(000);
fill(000);
background(#ffffff);
xStep = 0;
frameRate(100);
};
void draw() {
background(color(255-(chaoticNumber()*100),255-(chaoticNumber()*100),255-(chaoticNumber())*100));
xStep = xStep + 1;
chaosIntensity = updateChaosIntensity(chaosIntensity);
drawStep(xStep);
;
}
void keyPressed(){
chaosOn = !chaosOn;
}
boolean chaosOn = false;
float chaosIntensity = 0;
float lastChaoticNumber = random(1.0);
int xStep;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment