This would be cool,
Anyway this a bit off topic but heres my code i have written so far
the buttons havent been sorted yet so just ignore that
it seems to be measuring where collisions take place incorrectly,
if you run the code it draws a black circle where it thinks a collision occurs
Quote://Librarys
import guicomponents.*;
//guicomponents library, declaring buttons and sliders
GButton btnclear, btnreset, btnstroke, btnfill, btntrails;
GVertSlider alphaslider, diameterslider, numslider;
//Declare arraylist
ArrayList balls;
//declare integers
int numcircles = 10; //number of circles created
//integer for the array index
void setup() {
balls = new ArrayList(); //Create and empty array list
background(255);
size(1000,600);
for ( int i = 0; i < numcircles; i++ )
{
Circle ball = new Circle(800/2,height/2,random(-5,5),random(-5,5));//Create ball objects
balls.add(ball); //add ball to the array list
}
smooth();
//Button shit
GComponent.globalColor = GCScheme.getColor(this, GCScheme.BLUE_SCHEME);
GComponent.globalFont = GFont.getFont(this, "Arial", 12);
btnclear = new GButton(this,"Clear",825,25,70,10);
btnreset = new GButton(this,"Reset",825,50,70,10);
btnstroke = new GButton(this,"Stroke",825,490,70,10);
btnfill = new GButton(this,"Fill",825,515,70,10);
btntrails = new GButton(this,"Trails",825,540,70,10);
//Slider shit
alphaslider = new GVertSlider(this,825,75,20,400);
alphaslider.setLimits(10,0,200);
diameterslider = new GVertSlider(this,850,75,20,400);
diameterslider.setLimits(10,0,300);
numslider = new GVertSlider(this,875,75,20,400);
numslider.setLimits(10,0,50);
}
void draw(){
background(255);
for (int i = balls.size()-1; i >=0 ;i--)
{
ball.moveCircle();
ball.drawCircle();
}
checkCollision();
}
void checkCollision(){
for (int i = balls.size()-1; i >=0 ;i--){
float CollisionCheckX = (((Circle)balls.get(i)).x);
float CollisionCheckY = (((Circle)balls.get(i)).y);
float BallDiameter = (((Circle)balls.get(i)).diameter);
for (int j = balls.size()-1; j >=0 ;j--) {
float CollisionCheckX2 = (((Circle)balls.get(j)).x);
float CollisionCheckY2 = (((Circle)balls.get(j)).y);
float BallDiameter2 = (((Circle)balls.get(j)).diameter);
if (i != j){
if (dist(CollisionCheckX,CollisionCheckX2,CollisionCheckY,CollisionCheckY2) <= (BallDiameter/2) + (BallDiameter/2)){
println("Ball "+i+" X "+CollisionCheckX+", Y "+CollisionCheckY+", Diameter "+BallDiameter+" || Ball "+j+" X "+CollisionCheckX2+", Y "+CollisionCheckY2+" Diameter "+BallDiameter2);
fill(0,0,0);
ellipse((CollisionCheckX+CollisionCheckX2)/2,(CollisionCheckY+CollisionCheckY2)/2,10,10
);
}
}
}
}
}
void handleButtonEvents(GButton button) {
if (btnreset == button && button.eventType == GButton.CLICKED) {
setup();
}
}