Skip to main content

Posts

Showing posts from October, 2010

Drawing Dashed Lines on an HTML5 Canvas

The canvas element in HTML is great, but has one strange shortcoming: it cannot draw dashed lines (natively). However, dashed lines seem like a pretty common thing to draw, which only highlights the problem.

Looking around, I've noticed several solutions to this problem. Some use trig, and others use their own libraries that must be imported. So in the end, I decided to create my own method.

This code will add the function to all canvas elements, both those already on the page, and any that are dynamically added later.

Here is the code:
CanvasRenderingContext2D.prototype.dashedLine = function(x1, y1, x2, y2, dashLen) { if (dashLen == undefined) dashLen = 2; this.beginPath(); this.moveTo(x1, y1); var dX = x2 - x1; var dY = y2 - y1; var dashes = Math.floor(Math.sqrt(dX * dX + dY * dY) / dashLen); var dashX = dX / dashes; var dashY = dY / dashes; var q = 0; while (q++ < dashes) { x1 += dashX; y1 += dashY; this[q …

What Google's Relationship with Vendors Should be like in Regards to Android

I've been watching Android since it was first released, and got myself a Nexus One about half a year ago. The potential this platform has is very nice, and not just for smartphones. I would really like to see the tablets that will come with Android. But this isn't about me discussing Android itself. It's about the vendors who sell Android handsets and tablets, and their relationship with Google.

Android is great for its customizability. Unfortunately, vendors have taken this too far and made a perversion of the platform with forced apps, home screens, missing features, etc.

Forced Apps

If I don't use/want an app on my phone, I should be able to remove it at will, unless it is a system app (e.g. removing the Dialer app would be plain stupid). But carriers and manufacturers insist on putting apps on the users' phones that cannot be removed unless the user roots their phone (which will void the warranty). Why? If the app really is good, I will keep it, use it, and not …