int nsides = 4;
int trailLength = 15;
int nForms = 2;
 
int bright = 0;
 
Vector forms = new Vector();
 
 
void setup(){
 
size(550,700,P3D);
 
makeForms();
frameRate(30);
background(0);
colorMode(HSB,100);
}
 
void makeForms(){
forms = new Vector();
for (int i =0; i < nForms; i++){
forms.add(new Form());
}
 
}
 
void draw(){
 
noStroke();
fill(0,0,100*bright,trailLength);
rect(0,0,width,height);
noFill();
Form form;
Point pt;
float x=0,y=0;
for (int i =0; i < forms.size(); i++){
form = (Form)forms.elementAt(i);
form.shift();
stroke(form.c);
beginShape();
for (int j =0; j < form.points.size(); j++){
 
pt = (Point)form.points.elementAt(j);
if (j == 0){
x = pt.x;
y = pt.y;
}
vertex(pt.x,pt.y);
pt.physics();
}
 
vertex(x,y);
 
 
endShape();
}
 
}
 
 
void keyPressed(){
 
if (key =='a') trailLength ++;
else if (key =='z') trailLength --;
constrain(trailLength,0,50);
 
if (key == 's' || key == 'x'){
if (key =='s') nsides ++;
else if (key =='x') nsides--;
if (nsides < 3) nsides = 3;
makeForms();
}
 
if (key == 'd' || key == 'c'){
if (key =='d') nForms ++;
else if (key =='c') nForms--;
if (nsides < 1) nsides = 1;
makeForms();
}
 
if (key == ' ') bright = 1- bright;
 
}
 
class Form{
 
color c;
float h = random(0,100);
float s = random(0,100);
float b = 100;
Vector points;
float dh = random(-2,2);
float ds = random(-2,2);
//colorshifting
void shift(){
b = 100 - 50*bright;
h += dh;
if (h < 0 || h > 100) dh = -dh;
 
s += ds;
if (s < 0 || s > 100) ds = -ds;
 
c = color(h,s,b);
}
Form(){
c = color(h,s,b);
points = new Vector();
for (int i = 0; i < nsides; i++){
points.add(new Point(random(0,width), random(0,height),random(-7,7),random(-7,7)));
}
}
 
}
 
class Point{
float x,y,dx,dy;
Point(float x, float y, float dx, float dy){
this.x = x;
this.y = y;
this.dx = dx;
this.dy = dy;
}
void physics(){
x += dx;
y += dy;
//dy += 1;
if (x > width || x < 0) dx = -dx;
if (y > height || y < 0) dy = -dy;
}
 
}