Ben Galbraith’s Blog

HTML 5 Canvas Lessons: Zooming and Reusing

leave a comment »

I noticed an interesting bug today while working on a browser-based user interface rendered with the HTML 5 <canvas> element. A little rectangle was appearing fuzzy:

nib4

Let me zoom in a bit:

nib3

Whereas it should have appeared crisp, as in this:

nib2

My first thought was that it would be due to fractional coordinates. I have years of experience with drawing APIs that force integer coordinates, so I’m used to relying whacking off the fractional part of a coordinate and making up the difference when necessary in a second pass. Canvas, on the other hand, supports fractional coordinates, which I’m told is the fancy thing to do these days. (How the fraction is converted to an actual pixel is depenendent on whatever drawing system is doing the heavy lifting somewhere down the stack.) When your coordinates are fractional, you can get this kind of fuzziness.

Because the interface I’m working with involves a few layers of rendering code, ensuring that integers ruled the roost took some time. But after quite a bit of poking around, I found no evidence of fractional coordinates. It was around this time I saw Vlad (Mozilla’s graphics guru) walking around the office and asked for some help.

We started looking for evidence of transforms that would introduce fractional coordinates–but ultimately came up empty handed. As we went through this process, he pointed out that the <canvas> context instances are reused, so it’s a really good idea to save() and restore() when obtaining a canvas to avoid polluting the context:

var ctx = canvas.getContext("2d");
ctx.save();
// painting here
ctx.restore();

I had assumed each call produced a fresh, stateless context, so this was welcome news indeed.

But, we didn’t find a source for the fractional coordinates. And then we noticed when right-clicking and selecting “View Image” from the context menu produced an image that was physically smaller than the browser window.

And that’s when we noticed that I had zoomed in a click using Firefox 3’s fancy full page zoom feature. And that was causing the image the be scaled up, and the blurriness.

May you avoid a similar fate.

Written by Ben Galbraith

January 6, 2009 at 5:25 pm

Posted in Technology

Thoughts on the Rise and Fall of the Third Reich

with 12 comments

Rise and Fall of the Third Reich

For as long as I can remember, my family has spent time each year in Cedaredge, a small little town in western Colorado. During our most recent visit, I was caught unprepared in a rain shower and, seeking cover wherever it could be found, I stumbled upon a library book sale. The combination of ridiculous prices, an eclectic selection, and nothing else to do with the rain about me conspired to fill many bags with good old books. Among them was an old edition of William Shirer’s classic Rise and Fall of the Third Reich.

At over 1200 pages, it’s not a quick read–but it’s not a difficult one, either. The author is a journalist rather than a historian, and to the great credit of the book, he was a first-hand witness of many of the events chronicled in the book. The result is a rather interesting account of a pivotal period of the past century.

But then, there is a natural drama and grandeur to these events that transcends the pages. We see Hitler’s rise from a penniless wretch on the streets of Vienna to the most powerful man in Europe; we witness the shame of Nevill Chamberlain’s “leadership” contrasted with the breathtaking courage and splendor of Winston Churchill; we marvel as Fate herself seems to conspire to keep Hitler alive against all odds as he survives many would-be assassins only to topple from power due to countless bungled decisions for which only he can take blame.

As I plowed through the book as fast as I could manage, I was fascinated by how much of the history was readily applicable to our own time and place. Let me share some of the points that most resonated with me.

Religion and Wars

Some make the argument that religion is the primordial source of conflict in the world and were we but unshackled from our silly delusions of God’s existence, peace and harmony would break out across the land. (In an era of terrorists blowing up thousands of innocents under the banner of religion, it’s easy to be sympathetic to that position.)

The horrors of the war waged by the Nazis should give pause to that assertion. While not as hostile towards religion as the Communists, the Nazi Party’s leadership openly disdained organized religion and crushed any religious leaders unwilling to support the Party. To replace religion as the moral core of society, the Nazis established a new set of values anchored in the faux-science of their philosophers–and managed to get a significant portion of the populace to embrace them.

The sheer evil of the Nazis is breath-taking. The holocaust, of course. Their half-executed plan to simply starve the Russians and Ukranians–to ship their food to Germany and let them all die. Their reign of terror over all of their occupied territories.

And then, there was Stalin who had guns mounted behind his own front lines to shoot any of his men who retreated; who interned his own country’s POWs when they were liberated because he expected them to fight to the death; who killed thousands of his own people as they fled Moscow when it seemed clear that the Nazis would occupy the city (he wanted them to stay as a show of support).

Religious extremists have no monopoly on evil.

Media Propaganda

The Nazi’s exploited a basic human flaw with great success: we are heavily influenced by repetition. In a particularly memorable passage, the author describes how he personally witnessed countless people from educated backgrounds adopting the silly and baseless ideas of the Nazi party only because they were repeated so constantly through every medium. Even otherwise respectable, credentialed scientists and academics fell victim to the echo chamber.

Are there shared beliefs in our zeitgeist based on shabby science oft-repeated that we no longer question, that even our men-and-women-of-letters champion or fail to challenge? How much original research is in place before the media machine takes over, repeating it a thousand times until many or all believe?

We must question everything and have an anchor in something more than the fashion of the moment.

Deception in Foreign Relations

It is tempting to believe President Ahmadinejad of Iran when he asserts publicly that his government is seeking for nuclear technology only to provide power for his people. Especially when he is courteous and photogenic.

The Nazis bluntly lied shamelessly to any member of the press or foreign statesmen they could find. The sheer audacity of their deception is impressive. They lied about invading every country they eventually crushed. If rhetoric was not enough, they created fake events upon which to base their rhetoric. Yet their actions betrayed their true intentions; it was only the world’s willingness to accept seemingly innocent explanations for their war preparations and their troop movements and their alliances, etc. that led to disaster.

Effective foreign policy must simply ignore rhetoric and focus relentlessly on action.

Records of History

Rise and Fall would have been impossible to write had it not been for the voluminous records kept by the Nazis–the same records that contributed so well to their executions and imprisonments at the trials at Nuremberg. Some of the most interesting revelations were made possible by the odd memo here or the random piece of correspondence there. These threads would have been impossible for history’s actors to have seen as they were woven in time; historians had to discern the pattern. All thanks to meticulously filed and archived documents, preserved for us.

There is something about the Truth that is larger than any of us, or all of us. We owe it to our successors to clearly present their legacy. As tempting as it may be to manipulate facts and control the narrative–to emulate the totalitarian regimes in their absolute control of the facts–we cannot indulge in this desire.

We need to work out how to effectively archive digital information and how to balance the need for Truth with the right to avoid self-incrimination. I hope we get that figured out before many of us succumb to the temptation to shred a part of our society’s story.

Justice

The man at the head of the machine which caused the deaths of countless millions and further hardships upon most of the entire world never had to face justice. Hitler died on his own terms, so completely that his remains were never recovered. He left behind his belief that the Third Reich fell because the German people did not deserve him.

Some others in positions of authority were executed after the war following the various Nuremberg trials, but so many of these oversaw or directly committed mass murders. To kill one who has killed another is itself hardly justice–for the second killing cannot begin to undo the first–but it has a certain symmetry that feels to some like justice. But you cannot kill such criminals more than once. How do you extract justice from such monsters? Of course, you cannot.

And yet, shortly after sentencing many such to jail terms and executions, the sentences were commuted and the criminals were set free. Men who killed defenseless prisoners of war. Men who burned little children. Terrible people.

Still, the Nazi regime had a gangster element to it–via the SS and its derivatives–that successfully prevented dissent. Had these men refused to fulfill their dreadful orders, they would have reason to fear brutal torture of themselves and their families. Of course, the right thing to do is take a moral stand regardless of the outcome, but then, thanks to the propaganda built on “science” mentioned above, on what moral ground do you stand? Moral relativists at this point must eat their cake as we realize that, without immutable moral anchors, there can for some be no stand to take.

There is no justice in this world, though we try our best.

Written by Ben Galbraith

December 30, 2008 at 12:49 am

Posted in Life

Tech Luminaries: Brendan Eich

with 3 comments

Ben and Brendan

Dion and I have been wanting to do a podcast series for a long time that is a more casual “Charlie Rose-ish” format–just chatting with some of the luminaries in tech about their careers and such. We collected some content quite a ways back and have finally gotten around to releasing some of it over on TechLuminaries.com.

In our first episode, we interview Brendan Eich, Mozilla’s CTO. We recorded this long before we ever considered coming to Mozilla, which casts a weird perspective on the interview. Hope you enjoy it.

Written by Ben Galbraith

December 15, 2008 at 6:10 pm

Posted in Technology

Usability Hall of Shame: Excel

with 3 comments

Since May of this year, I’ve been trying to snap screenshots and videos of those special moments when my software (or hardware) interactions have been… less than stellar.

Would you believe Microsoft bits have accounted for more than a few of these? Sure, but you have to go way back in time to find them. All the way back to Excel 2008 for the Mac, in fact.

I opened a spreadsheet and was treated to this modal dialog:

Excel File Error

Genius.

Written by Ben Galbraith

December 6, 2008 at 10:52 pm

Posted in Usability

A Quick Tweak

leave a comment »

I’ve moved my blog from my crusty old virtual server to WordPress.com; apologies if I’ve munged the mod_rewrite rules and for some missing images here and there.

Written by Ben Galbraith

December 3, 2008 at 11:47 pm

Posted in Technology

A New Direction

with 9 comments

My friend Dion Almaer and I started Ajaxian.com a few years back out of an intense enthusiasm to track the nascent Ajax movement, a community-driven discovery of new techniques to wring better user interfaces out of old browser technologies. Our earliest role at Ajaxian was to help spread the word that whole new worlds of experiences were possible with the current browsers; as time passed, this role has largely evolved into tracking the latest news in the Ajax community.

In parallel with these efforts, Dion and I have had separate careers, in each of which we’ve had the opportunity to use the techniques we’ve covered at Ajaxian (and in some cases do entirely different kinds of development work). As we compared notes along the way (with ourselves and others in the industry), both of us noticed ample opportunities to make Web development more productive than it is today. Eventually, the size of this opportunity became so distracting that we started exploring how we might pursue efforts to address it full-time.

To make a long story short, we’re announcing today that Mozilla has hired both of us to lead an initiative to create Web development tools–to make life better for Web developers. Over the coming weeks, we’ll be building up a team and sharing more details with the community.

I have immense respect for the crew at Moz; I couldn’t be more thrilled that they’ve invited us to join them and for the opportunity at hand.

Read more at:
- Ajaxian.com
- Mozilla Labs

Written by Ben Galbraith

October 13, 2008 at 11:15 am

Posted in Technology

Engage 2008: eBay

with one comment

eBay released their AIR application last night. It’s a cool, flashy way to interact with eBay. If you’ve been to an Adobe event in the past year, you’ve seen this demo.

We didn’t go to the desktop to do off-line, we did it because browsers were not built for applications, and AIR is a platform that *is* built for applications. It’s amazing that we’ve been able to build complex applications in the content platform that is the Web.

In a Web environment, there are constraints to what users expect in terms of the user interface (e.g., bookmarkability). With the AIR app, we could start over and invent our own conventions. (He presented this as an advantage.)

They have all kinds of usability enhancements for the eBay Desktop application that dramatically improve the website’s usability. They had tons of examples. Plus, eye candy!

They also have desktop widgets for tracking key auctions.

Written by Ben Galbraith

February 25, 2008 at 7:22 pm

Posted in Technology, engage08

Engage 2008: Nick.com

leave a comment »

Nick.com is talking about their platform for off-line gaming. They wanted to bridge the off-line piece with their website, so they created a dealio where you have to find puzzle pieces on the website and drag-and-drop them into the AIR application. Once you find all the pieces, you get a 2 minute video and then a link to a full-length video.

They’re also showing something called neopets. It’s a Populous clone that lets you build colonies of “pets”. He’s going into great detail on how the game works. It’s got a lot of hooks that make players want to go back to the website, like the ability to craft your own breeds of pets.

“It’s been a pleasure to work with Adobe, they were great to work with, gave us tons of access”, blah blah. :-)

This was created with two full-time developers, along with supporting folks.

Written by Ben Galbraith

February 25, 2008 at 6:48 pm

Posted in Technology, engage08

Engage 2008: BusinessObjects

with one comment

BusinessObjects/SAP is on. They’re talking about their desire to create more engaging products. Once again they repeat the theme that the move to the Web cost theme in terms of their user experience and with Flex/AIR they can recapture some of that.

They’ve got a new application–Polestar–that helps casual users generate reports. The first feature they demonstrate is a simple Google Search style interface to the system. Enter “sweaters” and it finds the data you want.

When you choose a search result, you’re given a very intuitive way to query the data. Having used BusinessObjects and hated it in the past, this is very interesting stuff. The UI actually looks… usable.

The UI is built dynamically based on the data in the system. They’re spending a lot of time on specific use cases for the UI. One of the cooler things about the charting system is that the charts transition in meaningful ways. When you transition chart types or change chart scopes, you can see the data move to the appropriate part of the screen.

They also have widgets. Everyone has widgets. Goodness. They have a widget “factory” that can be used to generate new widgets on demand. Neat.

We are very interested in social networking and our products, especially to learn about the types of people in the company and bring them the right data.

Written by Ben Galbraith

February 25, 2008 at 6:41 pm

Posted in Technology, engage08

Engage 2008: Yahoo!

leave a comment »

Yahoo! is up talking. They’re talking about their increased use of Flash (including a new AS3 Maps API). They’re here to show two AIR apps they’ve written.

They’re showing a widget–what they call a “sidebar” application–written in AS2 wrapped as an AS3/AIR application. The widget has four different areas all pulling data. Wrapping the AS2 app took very little effort, so all of their old AS2 code can be ported to AIR very easily.

They feel putting this stuff on the desktop as a “sidebar” will drive a lot of traffic to their web property; people can interact with the widget to get more detail on stock information, more info on a news story, and so forth.

Now they’re showing a Music Blog Remixers. The developer is talking about how much he loves the Flex tools and is a Java/PHP convert.

Apparently, music blogs are the new distribution channel for music on the web, especially indie music. Their app helps you navigate the music blogosphere and remix them; take the best parts of music blogs and combine them into a custom playlist. You can then export the playlist and post it on your blog.

Now available on next.yahoo.com.

Now we’re seeing Yahoo! Live, which lets you view live video feeds. It’s currently a Flex 2 app but they have plans to upgrade it to Flex 3 / AIR. They let you embed the live video feed all over the place. They want to use AIR so the video feed stays live even if you close the browser and so they can do alerts in the native OS.

We’ve been very happy with how rapidly we can build solutions with Flex and AIR. We built Live in 6 months with 4 full-time people. Software development moves slower the more developers you add to the project, so it’s important for us to choose technologies that let us build software rapidly with small teams.

Written by Ben Galbraith

February 25, 2008 at 5:15 pm

Posted in Technology, engage08