Posts

Showing posts from January, 2015

Create an interactive HTML5 Canvas using event handlers.

Image
You can use HTML5 Canvas as an alternative approach designing info graphics, branding graphics etc. Using the example in my previous blog post, I will add a clickable area on the canvas and use a JavaScript event handler to execute some logic. This is the result of the previous example. I want to pop an alert Box when clicking inside the logo. I need to create an object reflecting the coordinates I want my clickable zone to have. I’m also throwing in an id/name. var CustFigure = function (x, y, height, width, name ) { this.x = x; this.y = y; this.height = height; this.width = width; this.name = name; }; In this case I just create a global Array that I can pop the objects on to.   var custFigures = []; At some point (I choose to include it in the function drawing  the logo) we create the object with the desired coordinates and push it on to the array. var custFigure = new CustFigure(50, 50, 75+50, 75+50, " Hello

Painting using Canvas and JS.

Image
Lately I've been playing around with HTML5 and Canvas trying to render icons and graphics without the use of image files. This blog post is simply showing how to render the HTML5 logo using only code. First up, we create a HTML5 canvas-tag where our logo will live. I’ll add some simple CSS to it for good measure, creating a circular form for our logo. We make sure to call our function rendering the logo as the page is loaded. <canvas id="xpCanvasWeb" class="testblock" width="175" height="175"></canvas> <style type="text/css"> .testblock { background: none repeat scroll 0 0 #2a2a2e; border: 1px solid #2a2a2e; border-radius: 115px; margin: 10px; } </style> Now, for the rendering-function, please see my inline code. My approach towards this is to paint the logo in «layers», starting with the background and adding on layer by layer until the logo is complete. By using semi-transpare