O'Reilly logo

iPhone JavaScript Cookbook by Arturo Fernandez Montoro

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Applying colors

In the last recipe, you learned how to draw geometric figures on the screen using paths through lines and movements. You can go further by applying some styles such as colors. Fortunately, Safari Mobile provides a few JavaScript functions for applying these styles, making our job easier.

This recipe describes how to apply background colors to figures inside a canvas element.

Getting ready

In order to make things easier, we're going to use our code generated for the previous recipe as a starting point. This means we'll need to have the iWebKit framework installed in our computer.

How to do it...

  1. We'll start by saving the file generated for the previous file as colors.html. Then, let's go to the line ctx.stroke() for the first figure. ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required