Need someone who is proficient in the program called “processing.” Looking for repeat business.

1 answer below »
Need someone who is proficient in the program called “processing.” Looking for repeat business.
Answered 2 days AfterSep 30, 2021

Answer To: Need someone who is proficient in the program called “processing.” Looking for repeat business.

Amar Kumar answered on Oct 01 2021
140 Votes
Ball[] balls = {
new Ball(100, 400, 05),
new Ball(700, 400, 05)
};
void setup() {
size(640, 360);
}
void draw() {
backgr
ound(51);
for (Ball b : balls) {
b.update();
b.display();
b.checkBoundaryCollision();
}

balls[0].checkCollision(balls[1]);
}
class Ball {
PVector position;
PVector velocity;
float radius, m;
Ball(float x, float y, float r_) {
position = new PVector(x, y);
velocity = PVector.random2D();
velocity.mult(3);
radius = r_;
m = radius*.1;
}
void update() {
position.add(velocity);
}
void checkBoundaryCollision() {
if (position.x > width-radius) {
position.x = width-radius;
velocity.x *= -1;
} else if (position.x < radius) {
position.x = radius;
velocity.x *= -1;
} else if (position.y > height-radius) {
position.y = height-radius;
velocity.y *= -1;
} else if (position.y < radius) {
position.y = radius;
velocity.y *= -1;
}
}
void checkCollision(Ball other) {
// Get distances between the balls components
PVector distanceVect = PVector.sub(other.position, position);
// Calculate magnitude of the vector separating the balls
float distanceVectMag = distanceVect.mag();
// Minimum distance before they are touching
float minDistance = radius + other.radius;
if...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here