int n = (int)random(5, 20); //number of lines
float[] x1 = new float[n];
float[] y = new float[n];
float[] r = new float[n];
float[] xspeed = new float[n];
float[] yspeed = new float[n];
color[] c = new color[n];
float [] circles ;
boolean[] direction = new boolean[n];
//boolean[] overlap = new boolean[n];
boolean stop = false;
void initialize() {
for (int i=0; i < n; i++) { //for each line
// circles = {x1[i],y[i],r[i]};
//randomize all attributes
r[i] = random(10, 50);
x1[i] = random(r[i], width-r[i]);
// x2[i] = random(width);
y[i] = random(r[i], height-r[i]);
c[i] = color(random(0, 255),random(0, 255),random(0, 255));
//by default direction[i] = false
if (random(1) < 0.5) { //with 50% probablity
direction[i] = true; //flip it
xspeed[i] = random(0.5, 2);
} else { //50% probability
xspeed[i] = random(-2, -0.5);
}
if (random(1) < 0.5) { //with 50% probablity
direction[i] = true; //flip it
yspeed[i] = random(0.5, 2);
} else { //50% probability
yspeed[i] = random(-2, -0.5);
}
}
}
void drawLines() {
for (int i=0; i < n; i++) {
for (int j=0; j < n; j++) {
boolean overlap=false;
float d= dist(x1[i],y[i],x1[j],y[j]);
if (d< r[i]+r[j]){
overlap =true;
}
if (!overlap) {
count++;
}
}
//draw the line
noStroke();
fill (255);
ellipse (x1[i], y[i], r[i]*3, r[i]*3);
fill(c[i]);
ellipse(x1[i], y[i], r[i]*2, r[i]*2);
collide (i,i);
}
keyPressed();
//overlapping (random(width)) ;
}
/*
void overlapping () {
int count = 0;
boolean overlap=false;
for (int j=0;j<circles.length;j++) {
float other = circles[j];
float d= dist(circles.x1[j],circles.y,other.x1,other.y);
if (d< circle.r+other.r){
overlap =true;
}
if (!overlap) {
count++;
}
}
*/
void keyReleased () {
if (key== 'r') {
stop=!stop;
}
}
void keyPressed () {
for (int idx=0; idx < n; idx++) {
if (stop== true) {
if (key=='r') {
x1[idx]=x1[idx]+xspeed[idx];
y[idx]=y[idx]+yspeed[idx];
if (direction[idx] == true) { //right
//move
if (x1[idx] >= width - r[idx] || x1[idx] <= r[idx] ) {
xspeed[idx] = -xspeed[idx];
//direction[idx] = false;
}
//else {
//move
// x1[idx]--;
// y[idx]--;
//y[idx]=y[idx]+yspeed[idx];
//x2[idx]--;
//if reached left border
if (y[idx] >= height -r[idx] || y[idx] <= r[idx]) {
yspeed[idx] = -yspeed[idx];
//direction[idx] = true; //set it up to move right next time
}
} else {
direction[idx]=!direction[idx] ;
}
}
}
}
}
void collide (int d1,int d2) {
// if () {
// }
}
void setup() {
size(500, 300);
background(255);
initialize();
/*
for (int i=0; i<25;i++){
circles = new float [25];
float r = random(10, 50);
float x1= random(r, width-r);
// x2[i] = random(width);
float y = random(r, height-r);
}
int count = 0;
boolean overlap=false;
for (int j=0;j<circles.length;j++) {
float other = circles[j];
float r = random(10, 50);
float x1= random(r, width-r);
// x2[i] = random(width);
float y = random(r, height-r);
float d= dist(circles.x1,circles.y,other.x1,other.y);
if (d< circles.r+other.r){
overlap =true;
}
if (!overlap) {
count++;
}
}
*/
}
void draw() {
background(255);
drawLines();
}