xxxxxxxxxx
float[] rots;//rotations
float[] rads;//radii
float[] rss;//rotation speeds
float cc;//color
PVector center, prev1, prev2;
PVector[] circles;
int nbSym = 3;
int nbCircles;
boolean lines = true;
void setup() {
size(550, 550, P2D);
colorMode(HSB, 1);
noFill();
center = new PVector(width/2, height/2);
initValues();
}
void initValues() {
background(0);
nbCircles = (int)random(2, 5);
cc = random(.05, 1);
stroke(cc, 1, 1, .2 + .4/nbSym);
prev1 = null;
prev2 = null;
rots = new float[nbCircles];
rads = new float[nbCircles];
rss = new float[nbCircles];
for (int i = 0; i < nbCircles; i ++) {
rots[i] = random(123);
rads[i] = random(10, 130);
rss[i] = random(.02, .12) * (random(1) < .5 ? 1 : -1);
}
}
void draw() {
for (int i = 0; i < nbCircles; i ++) {
rots[i] += rss[i];
}
PVector pv = new PVector(0, 0), pv1, pv2;
PVector tmp = new PVector(0, 0);
if (frameCount % 20 == 0) {
fill(0, .04);
noStroke();
rect(0, 0, width, height);
}
stroke(cc, 1, 1, .4 + .2/nbSym);
for(int i = 0; i < nbCircles; i ++){
tmp = new PVector(rads[i], 0);
tmp.rotate(rots[i]);
pv.add(tmp);
}
pv1 = pv.get();
pv.sub(tmp);
tmp.rotate(PI);
pv.add(tmp);
pv2 = pv.get();
translate(center.x, center.y);
for (int i = 0; i < nbSym; i++) {
rotate(TWO_PI/nbSym);
line(pv1.x, pv1.y, pv2.x, pv2.y);
if (lines && prev1 != null) {
line(prev1.x, prev1.y, pv1.x, pv1.y);
line(prev2.x, prev2.y, pv2.x, pv2.y);
}
}
prev1 = pv1.get();
prev2 = pv2.get();
}
void mousePressed() {
initValues();
}
void keyPressed() {
if (key == CODED) {
if (keyCode == LEFT && nbSym > 1) {
nbSym --;
initValues();
} else if (keyCode == RIGHT) {
nbSym ++;
initValues();
}
}else {
lines = !lines;
}
}