xxxxxxxxxx
Agent[] agents;
int numAgents = 100;
int a = 1;
float theta = 0;
PVector center, vertex;
void setup() {
size(650,650);
colorMode(HSB,360,100,100,100);
background(0,0,100,100);
noStroke();
fill(0,0,0,50);
center = new PVector( width/2.0, height/2.0);
float radius = width/20.0;
float scale = width/25.0;
agents= new Agent[numAgents];
for (int i = 0; i< numAgents; i++) {
vertex = goldenPoint(i+1);
vertex.mult(scale);
vertex.add(center);
agents[i] = new Agent(vertex.x,vertex.y,2*PI*i/float(numAgents) ,radius);
}
}
void draw() {
background(0,0,100);
for (int i =0; i< numAgents; i++){
agents[i].display();
agents[i].evolve(0.02);
}
}
PVector goldenPoint(int n){
float theta = 2.39996*n;
float r=sqrt(n);
return new PVector(r*sin(theta),r*cos(theta));
}
class Agent {
float x, y, agentTime;
float radius,d1,d2;
Agent() {
x=1;
y=1;
radius=10;
}
Agent(float x_pos, float y_pos,float t,float r) {
x = x_pos;
y = y_pos;
agentTime=t;
radius=r;
d1 = radius*sin(t);
d2 = radius*cos(t);
}
void evolve(float dt) {
agentTime += dt;
d1 = radius*sin(agentTime);
d2 = 2.618*radius*sin(agentTime);
// x = x + p_x;
// y = y + p_y;
}
void display() {
noStroke();
h = 60*sin(agentTime);
fill(240 + h ,100,70,100);
rect(x-0.5*d1,y-0.5*d1,d1,d1);
//ellipse(x,y,d1,d1);
stroke(280+h,50,100,100);
noFill();
//ellipse(x,y,d2,d2);
rect(x-0.5*d2,y-0.5*d2,d2,d2);
}
}