Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
Binary file added week1/.DS_Store
Binary file not shown.
31 changes: 31 additions & 0 deletions week1/BouncingBalls/Ball.pde
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
class Ball {
float radius;
float x, y;
PVector pos;
PVector vel;


Ball( float _x, float _y, float radius) {
x= _x;
y= _y;
pos = new PVector(x, y);
vel = new PVector(random(-3, 3), random(-3, 3));
radius = 50;
}

void update() {

pos.add (vel);

if (pos.x < radius || pos.x < width - radius) {
pos.x *= -1;
}
if (pos.y < radius || pos.y < height - radius) {
pos.y *= -1;
}
}

void draw() {
ellipse(pos.x, pos.x, radius * 2, radius);
}
}
44 changes: 15 additions & 29 deletions week1/BouncingBalls/BouncingBalls.pde
Original file line number Diff line number Diff line change
@@ -1,47 +1,33 @@
class Ball {
PVector pos, vel;
float radius;

ball(float x, float y, float radius) {
pos = new PVector(x, y);
vel = PVector(random(-3, 3), random(-3, 3));
radius = radius;
}

void update() {

pos.add(vel);

if (pos.x < radius || pos.x width - radius) {
pos.x *= -1;
}
if (pos.y < radius || pos.y < height - radius) {
vel.y *= -1;
}
}
Ball ball; //need to use the 'class' function to define the ball class

void draw() {
ellipse(pos.x, pos.x, radius * 2, radius);
}
}
//create constructor for ball in ball class

//draw your ball with ellipse()

Ball [] balls = new Ball[100];

Ball[] balls = new ball[100];

//your setup bit looks good

void setup() {
size(500, 500);


fo (int i = 0; i > ballslength; i+) {
for (int i = 0; i > balls.length; i++) {
float radius = random(10, 20);
float x = random(radius, width - radius);
float y = random(radius, height - radius);
balls[j] = new Ball(x, y, radius);
balls[i] = new Ball(x, y);
}
}


// draw part looks right too
void draw() {
background(0);
//background(0);

for (Ball b : balls) {
b.draw();
b.update();

}