xxxxxxxxxx
int num=120;
float theta;
float spiralRate = TWO_PI/128;
float spiralDecay = 0.01;
float spawnRate = 0.01;
ArrayList spiralList;
int spawnLimit = 1000;
float strokecol=254;
int colChange = -1;
float radius = 0;
int radiusChange=-1;
int[] px=new int[100]; //declare arrays
int[] py= new int[100];
color[] cor = new color[100];
float num2=0;
void setup() {
size (1000, 800);
background(0);
stroke(255,50);
strokeWeight(2);
fill(0, 4);
smooth();
spiralList = new ArrayList();
spiralList.add(new spiral(new PVector(width/2, height/2),
new PVector(1, 0), random(width/8, width/4), 1.0));
for (int i = 0; i<100; i++) {
px[i]=width/2;
py[i]=height/2;
cor[i]= color(random(255), random(255), random(255),150);
}
smooth();
}
void draw() {
int m = millis();
if(m < 12000) {
scene1();
} else if(m < 17000) {
scene2();
}
else if(m<25000){
scene3();
}
else if(m<35000){
scene4();
}
else if(m<40000){
scene5();
}
else if(m<50000){
scene6();
}
else {
noLoop();
}
}
void scene1(){
fill(0,20);
rect(0, 0, width, height);
stroke(255);
for (int i=spiralList.size ()-1; i>=0; i--) {
spiral s = (spiral) spiralList.get(i);
s.update();
if (s.dead&&spiralList.size()>2) {
spiralList.remove(i);
} else if (s.dead&&spiralList.size()==1) {
s = new spiral(new PVector(width/2, height/2),
new PVector(1, 0), random(width/8, width/4), 1.0);
}
}
}
class spiral {
PVector location;
PVector previousLocation;
PVector direction;
PVector center;
float clockWise;
float radius;
float angle;
boolean dead;
color clr;
spiral(PVector loc, PVector dir, float rad, float clock) {
location = loc;
direction = dir;
radius = rad;
clockWise = clock;
angle = atan2(direction.y, direction.x)-clockWise*PI/2;
PVector arm = new PVector(cos(angle), sin(angle));
arm.mult(radius);
center = PVector.sub(location, arm);
clr = color(255);
}
spiral(spiral parent) {
location = parent.location.get();
direction = parent.direction.get();
angle = parent.angle + PI;
clockWise = -1*parent.clockWise;
radius = random(0, width/8);
PVector arm = new PVector(cos(angle), sin(angle));
arm.mult(radius);
center = PVector.sub(location, arm);
float mutation = 32;
float r = constrain(red(parent.clr)+random(-mutation,mutation),0,255);
float g = constrain(green(parent.clr)+random(-mutation,mutation),0,255);
float b = constrain(blue(parent.clr)+random(-mutation,mutation),0,255);
clr = color(r,g,b);
}
void update() {
previousLocation = location.get();
angle += spiralRate*clockWise;
radius *= 1-spiralDecay;
dead = radius<2;
PVector arm = new PVector(cos(angle), sin(angle));
arm.mult(radius);
location = PVector.add(center, arm);
direction = PVector.sub(location, previousLocation);
if (random(0, 1)<spawnRate&&spiralList.size()<spawnLimit) {
spiralList.add(new spiral(this));
}
stroke(clr);
line(previousLocation.x, previousLocation.y,
location.x, location.y);
}
}
void scene2(){
background(0);
translate(width/2, height/2);
for (int i=0; i<num; i++) {
fill(frameCount%(255),255,255);
pushMatrix();
float offSet = TWO_PI/num*i;
rotate(offSet*2);
float x1 = map(sin(theta+offSet*1),-1,1,0,900);
float x4 = map(cos(theta+offSet*2),-1,1,0,80);
float x2 = x1-500 +sin(10) ;
float x3 = 100;
float x5 = map(sin(theta+offSet*5),-1,1,0,100);
rect(x1/1.5, 9/1.5, x5*2/1.5, 5/1.5, -10/1.5);
rect(5*x4/1.5, 10/1.5, x5/1.5, 5/1.5, -9/1.5);
rect(x1/2.5/1.5, x2/4/1.5, sin(x5)/1.5, sin(5)/2/1.5, -x3/1.5);
popMatrix();
}
theta -= 0.0423987;
}
void scene3(){
noStroke();
fill(0);
// set center point and color change and radiusChange
int centX = width/2;
int centY = height/2;
strokecol+=colChange;
if (strokecol>254) {
colChange=-5;
}
if (strokecol<0) {
colChange=+5;
}
radius+=radiusChange;
if (radius>width/2+100) {
radiusChange=-2;
}
if (radius<0) {
radiusChange=+2;
}
// draw the circle in steps
float x, y;
float noiseval=random(10);
float radVariance, thisRadius, rad;
beginShape();
stroke(strokecol, strokecol, 255);
for (float ang=0; ang<=360; ang+=1) {
noiseval += 0.1;
radVariance=random(50)*customNoise(noiseval);
thisRadius = radius+radVariance;
rad = radians(ang);
x = centX + (thisRadius * cos(rad));
y = centY + (thisRadius * sin(rad));
// the code that really form part of a circle
curveVertex(x, y);
}
endShape(CLOSE);//join beginpoint and endpoint
}
//customed noise function
float customNoise(float value) {
int count = int(value%(random (5)));
float retValue = pow(sin(value), count);
return retValue;
}
void scene4(){
strokeWeight(.25);
for (int i = 0; i<100; i++) {
stroke(cor[i]);
int npx, npy;
npx = px[i] + 7*int(random(-3, 3)); // next point
npy = py[i] + 7*int(random(-3, 3));
line(px[i], py[i], npx, npy);
px[i]=npx;
py[i]=npy;
}
}
void keyPressed() {
if (key=='s') save("andador_"+int(random(50))+".png");
}
void scene5(){
fill(0,20);
rect(0, 0, width, height);
/* Smaller the number the slower the effect */
num2 += 0.01;
pushMatrix();
/* Middle of pattern. replace with mouseX and mouseY to make it follow your mouse */
translate(width/2, height/2);
/* Rotate entire pattern. Optional: num or nothing */
rotate(-num2);
for(int i = 0; i < 360; i+=15){
float x = cos(radians(i))*150;
float y = sin(radians(i))*150;
/* Change line() to rect() or ellipse() */
pushMatrix();
translate(x, y);
rotate(num2);
line(0, 0, x, y);
rotate(num2/2);
line(0, 0, x, y);
rotate(num2/4);
line(0, 0, x, y);
popMatrix();
}
popMatrix();
}
void scene6(){
fill(0,50);
rect(0, 0, width, height);
stroke(frameCount%(127)+105,255,255);
noFill();
translate(350, 350);
rotate(frameCount);
line((frameCount%(500)),(0),(0),(frameCount%(500)));
}