Have you ever wanted to spice up your website with some interactive elements, but didn’t know which library to use or where to start?
An increasing number oftop websites are leveraging the power of HTML5 Canvas elements to render some pretty cool effects.
If, like me, you’ve always wanted to create something cool with canvas , keep reading.
You might be asking these questions:
What is the best way to get started with HTML5 Canvas ?
Should I use a library or the native API ?
PixiJS , Three.js or CreateJS ?
Which one should I learn and why?
1. HTML5 Canvas API
Before you dive straight into any of theI encourage you to look at the native HTML5 Canvas API .
In this Mozilla tutorial you will discover how to draw simple shapes, apply styles and colors, work with text, images, compositing, clipping and animations .
Here, we draw a few rectangles on the canvas. We define the background color for each rectangle fillStyle and position them where we want.
fillRect(25, 25, 150, 150) renders a 150×150 rectangle, 25
pixels from the top left corner of our canvas element.
Follow the whole tutorial to get familiar with the HTML5 Canvas API.
Knowing what beginPath() , stroke() , fill() and lineTo() commands will give you a good overview of what lies under the hood of the following libraries.
Now let’s have a look at the most popular libraries when it comes to HTML5 Canvas rendering.
Write less, do more…in other words they let you write less code and be more creative.
Or at least that’s what I think about them.
The motto of PIXI.js is “ Create beautiful digital content with the fastest, most flexible 2D WebGL renderer ”.
I think that sums it up pretty nicely.
Pixi.js by Goodboy Digital has recently (September 2016) been updated to version v4.0.1, this is a good sign of active development !
The last thing you want is to spend hours or weeks learning something new that won’t be supported anymore.
Looks like Pixi.js will be around for a while.
There are plenty of outstanding PIXI.js projects . Browse the following projects to get an idea of when to use Pixi.js.
Quechua Lookbook is a powerful combination of Pixi.js and GreenSock . If you never heard about GreenSock, you can learn the basics in 60 minutes here .