xxxxxxxxxx
int m = 67;
float [] xc = new float[m];
float [] yc = new float[m];
float [] r = new float[m];
float [] dx = new float[m];
float [] dy = new float[m];
int [] cr = new int[m];
int [] cg = new int[m];
int [] cb = new int[m];
float x,y;
float w = 3.5;
void setup(){
size(600,600);
background(0);
noStroke();
fill(127);
x = width/2;
y = height/2;
for(int i = 0; i <m ; i++){
r[i] = random(20,30);
xc[i] = random(2*r[i],width-2*r[i]);
yc[i] = random(2*r[i],height-2*r[i]);
dx[i]=random(-w,w);
dy[i]=random(-w,w);
cr[i] = int(random(256));
cg[i] = int(random(256));
cb[i] = int(random(256));
}
}
void draw(){
background(0);
for(int i = 0; i <m; i++)
{
float d = dist(xc[i],yc[i],x,y);
float alpha = PI/2 - asin(r[i]/d);
float theta=PI+atan((yc[i]-y)/(xc[i]-x));
if(xc[i]<x) theta= atan((yc[i]-y)/(x-xc[i]));
fill(color(cr[i],cg[i],cb[i]),80);
if(xc[i]<x){
// line(xs1,ys1,x,y);
float xs2=xc[i]+r[i]*cos(-(theta+alpha));
float ys2=yc[i]+r[i]*sin(-(theta+alpha));
//line(xs2,ys2,x,y);
float xs3=xc[i]+r[i]*cos(-(theta-alpha));
float ys3=yc[i]+r[i]*sin(-(theta-alpha));
//line(xs3,ys3,x,y);
triangle(xs2,ys2,xs3,ys3,x,y);
}
else
{
//line(xs1,ys1,x,y);
float xs2=xc[i]+r[i]*cos(theta+alpha);
float ys2=yc[i]+r[i]*sin(theta+alpha);
//line(xs2,ys2,x,y);
float xs3=xc[i]+r[i]*cos(theta-alpha);
float ys3=yc[i]+r[i]*sin(theta-alpha);
//line(xs3,ys3,x,y);
triangle(xs2,ys2,xs3,ys3,x,y);
}
xc[i]+=dx[i];
yc[i]+=dy[i];
if((xc[i]>=width-r[i])||(xc[i]<=r[i])) dx[i]*=-1;
if((yc[i]>=height-r[i])||(yc[i]<=r[i])) dy[i]*=-1;
}
for(int i = 0; i <m;i++){
fill(color(cr[i],cg[i],cb[i]));
ellipse(xc[i],yc[i],2*r[i],2*r[i]);
}
for(int i = 0; i <m-1; i++){
for(int j = i+1; j<m; j++){
int mr = (cr[i]+cr[j]);
if (mr > 255) mr = 255;
int mg = (cg[i]+cg[j]);
if (mg > 255) mg = 255;
int mb = (cb[i]+cb[j]);
if (mb > 255) mb = 255;
float d = dist(xc[i],yc[i],xc[j],yc[j]);
if(d +r[i] < r[j])
{
fill(color(mr,mg,mb));
ellipse(xc[i],yc[i],r[i]*2,r[i]*2);
}
if (d +r[j] < r[i])
{
fill(color(mr,mg,mb));
ellipse(xc[j],yc[j],r[j]*2,r[j]*2);
}
if((d<=(r[i]+r[j])) && (d +r[i] > r[j]) && (d +r[j] > r[i])){
//println("überschneidet");
if(xc[j]>xc[i]){
float beta = acos((sq(r[i])+sq(d)-sq(r[j]))/(2*r[i]*d));
float dxx = xc[j]-xc[i];
float dyy = yc[j]-yc[i];
float theta= atan(dyy/dxx);
pushMatrix();
translate(xc[i],yc[i]);
rotate(theta);
fill(color(mr,mg,mb));
arc(0,0,2*r[i],2*r[i],-beta,beta,CHORD);
popMatrix();
noFill();
beta = acos((sq(r[j])+sq(d)-sq(r[i]))/(2*r[j]*d));
dxx = xc[i]-xc[j];
dyy = yc[i]-yc[j];
theta= atan(dyy/dxx);
pushMatrix();
translate(xc[j],yc[j]);
rotate(PI+theta);
fill(color(mr,mg,mb));
arc(0,0,2*r[j],2*r[j],-beta,beta,CHORD);
popMatrix();
noFill();
}
else
{
float beta = acos((sq(r[j])+sq(d)-sq(r[i]))/(2*r[j]*d));
float dxx = xc[i]-xc[j];
float dyy = yc[i]-yc[j];
float theta= atan(dyy/dxx);
pushMatrix();
translate(xc[j],yc[j]);
rotate(theta);
fill(color(mr,mg,mb));
arc(0,0,2*r[j],2*r[j],-beta,beta,CHORD);
popMatrix();
noFill();
beta = acos((sq(r[i])+sq(d)-sq(r[j]))/(2*r[i]*d));
dxx = xc[j]-xc[i];
dyy = yc[j]-yc[i];
theta= atan(dyy/dxx);
pushMatrix();
translate(xc[i],yc[i]);
rotate(PI+theta);
fill(color(mr,mg,mb));
arc(0,0,2*r[i],2*r[i],-beta,beta,CHORD);
popMatrix();
noFill();
}
}
}
}
}