first of all im sorry for my english, it isnt that good.
im gonna catch up with my problem:
what i try to do is creating objects(ellipses) random on the stage.
these ellipses are growing from 0 to "maxSize".
what i want to do is, if one ellipse touches another it should recoil.
i tried so much. till now im trying to find a solution with PVector.
dont be to hard with me, im not a professional - just a student.
this is my code:
Code:int stageWidth = 1200;
int stageHeight = 800;
int maxBalls = 50;
PVector[] v2 = new PVector[maxBalls];
MagneticBall[] balls = new MagneticBall[maxBalls];
void setup() {
size(stageWidth, stageHeight);
background(40);
smooth();
frameRate(60);
for(int i = 0; i < balls.length; i++) {
v2[i] = new PVector(random(-1, 1), random(-1, 1));
balls[i] = new MagneticBall(1, 1, random(-200, 200), random(-200, 200), random(40, 255), 0.1, random(20, 60));
balls[i].allBalls = balls;
}
}
void draw() {
background(40);
translate(stageWidth/2, stageHeight/2);
for(int i = 0; i<balls.length; i++) {
balls[i].drawMagneticBall(v2[i]);
};
}
and the BallsClass
Code:class MagneticBall {
float ballSize;
float ballSizeGrow;
float ballSizeMax;
float ballPositionX;
float ballPositionY;
float ballSpeed;
float ballSpeed2;
float d;
float g1;
int moveDirection;
int moveThis;
MagneticBall[] allBalls;
float strokeWidth;
float strokeColor;
PVector v1;
PVector vPos;
MagneticBall(float tempBallSize, float tempStrokeWidth, float tempBallPositionX, float tempBallPositionY, float tempStrokeColor, float tempBallSizeGrow, float tempBallSizeMax) {
ballSizeMax = tempBallSizeMax;
ballSizeGrow = tempBallSizeGrow;
ballSize = tempBallSize;
strokeWidth = tempStrokeWidth;
ballPositionX = tempBallPositionX;
ballPositionY = tempBallPositionY;
strokeColor = tempStrokeColor;
vPos = new PVector(tempBallPositionX, tempBallPositionY);
}
void drawMagneticBall(PVector tempV2) {
g1++;
v1 = tempV2;
noFill();
stroke(strokeColor);
if(ballSize < ballSizeMax) {
ballSizeGrow += 0.01;
ballSize += ballSizeGrow;
}
strokeWeight(strokeWidth);
for(int i = 0; i<maxBalls; i++) {
if(ballPositionX != allBalls[i].ballPositionX) {
d = dist(ballPositionX, ballPositionY, allBalls[i].ballPositionX, allBalls[i].ballPositionY);
if(d < ballSize/2+allBalls[i].ballSize/2) {
v1 = allBalls[i].v1;
}
}
}
v1.div(1.1);
vPos.add(v1);
ellipse(vPos.x, vPos.y, ballSize, ballSize);
}
}
any questions and answers are welcome. thank you
blaufasan