import controlP5.*;
ControlP5 mySliders;
int n;
int d;
float myPosX = 5;
float myPosY = 3;
float KnobR, KnobG, KnobB;
float xx = 120;
float dim = 25;
float yy = 100;
Ball[] b;
Ball[] c;
Ball[] balls = new Ball[1];
//----------
void setup() {
size(500, 500);
frameRate(90);
n = 10;
d = int(random(10, 60));
c = new Ball[n];
balls[0] = new Ball(64, 5, 5, 150);
for (int i = 0; i < n; i++) {
c[i] = new Ball(random(dim/2, dim), 5, 5, random(255));
balls = (Ball[]) append(balls, c[i]);
}
mySliders = new ControlP5(this);
mySliders.addSlider("myPosX", 0, 6, myPosX, width/2, height/2, width/4, 10);
mySliders.addSlider("myPosY", 0, 6, myPosY, width/2, height/2 -20, width/4, 10);
mySliders.addSlider("dim", 1, 50, 25, width/2, height/2 + 20, width/4, 10);
mySliders.addKnob("xx", 50, 255, 120, width/2+50, height/2+50, 50);
mySliders.addKnob("yy", 0, 255, 120, width/2+150, height/2+50, 50);
}
//----------
void draw() {
//println("this scrip allow for 20 balls only!!!" + ", " + str(balls.length));
background(yy);
for (int i = 0; i < balls.length; i++) {
balls[i].move();
balls[i].display();
Ball Ba;
Ball Bb;
for (int g = 0; g < balls.length -1; g++) {
for (int u = g + 1; u < balls.length; u++) {
}
}
}
stroke(255);
fill(xx);
//if (balls.length > 20){
//exit();
//}
}
//-----------
void mousePressed() {
Ball b = new Ball(random(dim/2, dim), myPosX, myPosY, xx);
balls = (Ball[]) append(balls, b);
}
//---------
void keyPressed(){
if ( key == 'e'){
exit();
}
}
//----------
class Ball {
float r;
float x, y;
float xspeed, yspeed;
float fillZ;
float randomt1, randomt2;
PVector p, v, a;
int radius, hits;
float m;
boolean col;
//---------
Ball(float tempR, float randomz1, float randomz2, float fillz) {
r = tempR;
randomt1 = randomz1;
randomt2 = randomz2;
fillZ = fillz;
x = mouseX;
y = mouseY;
//x = random(width);
//y = random(height);
xspeed = random(-randomt1, randomt1);
yspeed = random(-randomt2, randomt2);
}
//-----------
void move() {
x += xspeed;
y += yspeed;
if ( x < r && xspeed < 0) {
xspeed *= -1;
}
if (y < r && yspeed < 0) {
yspeed *= -1;
}
if ( x > (width - r) && xspeed > 0) {
xspeed *= -1;
}
if ( y > (height - r) && yspeed > 0) {
yspeed *= -1;
}
}
//-----------
void bounce() {
Ball Ba;
Ball Bb;
}
//-----------
void display() {
fill(255-yy);
text(str(int(r)), x-10, y);
//fill(255-yy,255-yy,255-yy);
//text(str(balls.length), x-10, y+12);
stroke(255-yy);
fill(fillZ, 100);
ellipse(x, y, r * 2, r * 2);
}
//-----------
}