This is a bit of an unusual blog post for me, but I've been using oCanvas recently and thought it deserved a mention!
If you don't know it, oCanvas is a library for HTML5 canvas drawing, intended to make it easier to draw by thinking in terms of objects, like shapes. It also offers you an easy way to do animation, which I wanted to use for creating a small header graphic over at Happyrelay.
Drawing using oCanvas is great, it helps keep the different components in the drawing organized in a nice way (that the code ended up looking like something the cat dragged in is my fault entirely).
I can absolutely see myself using this library going forward, especially for things like drawing charts etc.
So speaking of charts, to try it out, I set myself a task to write a simple "moving line" chart in under an hour using oCanvas. Here is what I came up with.
While oCanvas has functionality for running a loop to change the drawing and doing animation, I opted for something simpler, keeping track of the elements, changing them periodically and redrawing the whole thing.
It consists of a run-loop that will generate a new integer data-point, and add it to an array of integers, before passing it to a draw function that plots the data points on the canvas and connects them using lines.
When we run it we get a line chart moving from right to left, looking something like this.
There are plenty of libraries for canvas drawing out there, and I can't really claim to know any of them well, including oCanvas. But doing some basic drawing with oCanvas was a fun experience. A great little JS library to check out if you are planning on doing any drawing or animation in the browser!