diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..2b47517 Binary files /dev/null and b/.DS_Store differ diff --git a/week1/.DS_Store b/week1/.DS_Store new file mode 100644 index 0000000..b7f32bd Binary files /dev/null and b/week1/.DS_Store differ diff --git a/week1/BouncingBalls/Ball.pde b/week1/BouncingBalls/Ball.pde new file mode 100644 index 0000000..8dd006e --- /dev/null +++ b/week1/BouncingBalls/Ball.pde @@ -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); + } +} \ No newline at end of file diff --git a/week1/BouncingBalls/BouncingBalls.pde b/week1/BouncingBalls/BouncingBalls.pde index 4cb6b96..3e85eba 100644 --- a/week1/BouncingBalls/BouncingBalls.pde +++ b/week1/BouncingBalls/BouncingBalls.pde @@ -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(); }