Skip to content

Instantly share code, notes, and snippets.

@takawo
Created December 23, 2015 07:31
Show Gist options
  • Save takawo/2ceb146f407390785e7d to your computer and use it in GitHub Desktop.
Save takawo/2ceb146f407390785e7d to your computer and use it in GitHub Desktop.
float angleStep;
Motif myMotif;
int numH = 16;//NUMBER OF COLUMNS
int numV = 12; //NUMBER OF ROWS
float res = 100;
int timer;
void setup() {
size(960, 540);
background( 0 );
smooth();
noStroke();
timer = 175;
myMotif = new Motif(0, 0);
frameRate(12);
// Noise
int octave = (int)random(1, 4);
float fallOff = random(0.01, 0.9);
noiseDetail(octave, fallOff);
//Angles
int dice = (int)random(3);
if (dice == 0) {
angleStep = 60;
}
if (dice == 1) {
angleStep = 90;
}
if (dice == 2) {
angleStep = 120;
}
}
/////////////////////////// DRAW ////////////////////////////
void draw() {
float sv = 0;
sv = sqrt(3) / 2 * res;
float offsetX = res * (numH-1)/2;
float offsetY = sv * (numV-1)/2;
if (timer<=0) {
restart();
} else
{
for (int j=0; j<numV; j++) {
for (int i=0; i<numH; i++) {
float x = i * res - offsetX + width/2.1;
float y = j * sv - offsetY + height/2;
if (j%2==0) x += res/2;
pushMatrix();
translate(x, y);
for (float theta=0; theta<360; theta+=angleStep) {
myMotif.render();
myMotif.move2();
rotate(radians(-angleStep));
}
popMatrix();
}
}
}
timer -= 1;
}
/////////////////////////// FUNCTIONS ////////////////////////////
void restart() {
background( 0 );
timer = 475;
setup();
}
/////////////////////////// CLASS ////////////////////////////
//Simple class to draw our pattern.
class Motif {
float x, y;
float angle;
Motif(float x, float y) {
this.x = x;
this.y = y;
}
void render() {
fill(255);
ellipse(x, y, 1, 1);
}
void move() {
angle += random(-0.2, 0.2);
x += cos(angle) * 0.17;
y += sin(angle) * 0.17;
}
void move2() {
float nFactX = cos(frameCount*0.09)*300;
float nFactY = sin(frameCount*0.05)*300;
float nZ = noise(x/abs(nFactX), y/abs(nFactY)) * 50;
x += cos(nZ) * 0.00195;
y += sin(nZ) * 0.00195;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment