Logo
  Sunday, May 20, 2012
Sign-In  |  Sign-Up  |  Contact Us  | Bookmark |  RSS Feed

HTML5 Tutorial FeedBurner

HTML5 Fill Styles  
HTML5 canvas allows you to fill paths and subpaths. The Fill Styles are used for this purpose and you can do it with the help of fillStyle command.

Example of how it is done in HTML5 is displayed below

<script>

    function fillExample(context) {

        context.fillStyle = '#662244'

        context.Fill

    }

</script>

It is also possible to set gradient for your fill color or image pattern. Make sure that while you applying fill styles, all you paths and subpaths are closed.

There is one important point that you need to be aware of. In order for you to make your fill crisp, you need to apply fill style before stroking the path. Otherwise, your fill will overlap with your path border images and will be little bit blurry.

Fill Styles work with other objects besides paths and subpaths. They work with rectangles too. In order to fill in rectangle object we need to set fill style first and they call on fillRect command as shown in the example below

<script>

    function fillExample(context) {

        Context.fillStyle = '#553322'

        Context.fillRect(-1, -10, 1, 10)

    }

</script>

As you can see from the example above, we fill in rectangle which we defined with our coordinates and then filled it with the help of fillStyle command.

In case you need to clear rectangle, you can always call of clearRect command. This is mostly used if you want to create animation on your canvas.

Print HTML5 Fill Styles Bookmark HTML5 Fill Styles

Related Articles  
Drawing Curves in HTML5
HTML5 allows you to draw curves on HTML5 canvas. They way to do it is with the help of paths.
HTML5 Canvas Transforms context.rotate(x) function
HTML5 provides several transform operations: scale, translate, rotate and others. Let’s look at the context.rotate(x) ...
Creating Shadow Effect with HTML5
HTML5 shadows are controlled by several operations available in HTML5 arsenal of operations. The shadow effect can be ...
Adding and drawing on canvas in HTML5
You can add canvas to your HTML5 page with the help of HTML5 tag called canvas.
HTML5 Gradient
Applying HTML5 gradient requires three steps to be completed. Creation of the gradient object, applying colors and call ...
Using HTML5 Stroke Styles
HTML5 provides with new styling capabilities when it comes to canvas. We can improve the way lines are drawn on canvas ...
More