Using processing

profileMaxYao198
exercise_8-5.pdf

// Simple gravity example

// (x,y) location float x = 100; float y = 0;

// Starting speed float speed = 0; // Gravity float gravity = 0.1;

void setup() { size(200, 200); }

void draw() { background(255);

// Display the circle fill(175); stroke(0); ellipse(x, y, 10, 10);

// Add speed to y location y = y + speed; // Add gravity to speed speed = speed + gravity;

// If square reaches the bottom // Reverse speed if (y > height) { speed = speed * -0.95; y = height; } }

Exercise 8-5: Rewrite the gravity example from Chapter 5 using objects with a Ball class. The original example is included here for your reference with a framework to help you get started. Once you get one object working, make two without changing the class! Can you add variables for color or size in your class?

_________ __________; float gravity = 0.1;

void setup() { size(200, 200); ball = new _______(50, 0); }

void draw() { background(255); ball.display();

__________________________ }

_______________ { float x; __________________ float speed; ______(______,______,______) { x = ______; ___________ speed = 0; }

void ___________() {

_____________________________

_____________________________

_____________________________ }

Lesson 3: Organization154