1. Introduction
  2. Draw a Circle
  3. Add Some Color
  4. Action
  5. Library: an Interlude
  6. Bounce
  7. Add a Paddle
  8. The Keyboard
  9. The Mouse
  10. The Bricks
  11. Finishing Touches
  12. Coda

Add Some Color

We can also turn our ball different colors. Changing the value of ctx.fillStyle will change the canvas' current color; we can set its value to a hex string of the format '#rrggbb' or to a string 'rgba(r, g, b, a)' where a is a value between 0 and 1 representing the transparency of the color.

Play around a bit with the colors and the rectangle's alpha value and see how the objects respond.

next prev