← All lessons/Objects· Lesson 27 of 32

Drawing from an object

Feed an object's properties into a drawing function to put it on the canvas.

About 6 min

Properties are just values

Anywhere you'd write a number, you can write a property instead. So ellipse(ball.x, ball.y, ball.size, ball.size) draws a circle exactly where the ball says it should be, and at the size the ball says it should be.

The ball draws itself from its own data.

NOTE

Change one property, say size: 200, and the drawing updates everywhere it's used. That's the payoff of keeping the data in one place.

Your turn

A ball object is already started for you. Finish it by drawing the ball: call ellipse using ball.x, ball.y, and ball.size (use ball.size for both the width and the height).

Hints