SilverDraw Library

About a year ago I started work on a set of Silverlight libraries providing controls and classes that implement the primary features of a drawing application. Some of the results of that effort made their way into demos on this site, i.e. the ColorTools and GradientMaker demos. Eventually I also posted a partially complete demo of a drawing program, however not long after that I joined the J. Becker team, and have been heads down working with a small, creative group on some cool Silverlight media management stuff. The upshot of it all is that the drawing libraries, and the application they were designed to support, have been gathering dust.

This morning I received a request from Sweden for the source to GradientMaker, which I’m happy to share. I had previously released the source for the color controls in ColorTools, but the GradientEditor control hadn’t been added at that point. When I got around to implementing it I created a dependency on another small library which I hadn’t released, and so I put off adding the GradientEditor to what was publicly available. Prompted by this morning’s request I have whipped it all into shape and uploaded it to the site. See the download links at the end of the post.

The code is released under a new BSD license. In order to package it I ripped the projects for the two libraries out of the solution I created for the app last year, and placed them into a solution called SilverDraw. It’s a little aspirational at the moment, but I hope to add in some of the other drawing code I have written and release some updates to it soon. There is no documentation, but the code is pretty well-commented. If you have any questions feel free to email me.

Downloads: SilverDraw Assemblies, SilverDraw Source

Still Lost

Ok, I admit I have been in the middle of a really unproductive cycle for the last couple of weeks. I’m not talking about work. I’m talking about the other 50% of my life, or more specifically the 50% of that 50% that is available for liesure, and which for some strange reason I can’t explain continues to be devoted in large part to watching old episodes of Lost. I can’t stop. I need help. There is no reason for me to be watching this show. Actually, I did have a sort of rational goal in mind, which was to catch up before the start of the final season. But I’m not sure I’ll make it.

Lost has a great premise, but a tough one to get a long run out of. Gilligan’s Island only made it for three seasons, and that feels like some sort of cosmic constant because I have just started in on Lost’s fourth season on Netflix and it’s just getting ridiculous. There must have been at least some members of the cast and crew looking at those scripts each week and thinking “what the hell?” So far my favorite example of how ludicrous it gets involves the “Looking Glass” underwater station.

First, and maybe funniest, is the moment when Sayid unfurls a blueprint of the station at the Beach Camp, and the title on the document is “Looking Glass Hatch.” Why is this hilariously stupid? The blueprint was created by Dharma, and is a document that pre-dated the castaways’ arrival. The castaways referred to these installations as “hatches” because the first thing Locke found was a metal hatch. The rooms below it then became known as the hatch, and the other rooms they found were by extension hatches. There’s no reason to think any of the original builders would have thought of an underwater habitat and lab as a “hatch” or labelled it that way on a blueprint.

Then there is the whole series of events leading up to Charlie’s checking out. If the Looking Glass station were the source of the jamming signals don’t you think that, before paddling out and trying to dive on it and get inside without SCUBA equipment, you might try, oh, I don’t know, cutting that fat cable leading down to it from the beach? Yes, there could be backup power. It might not work. But I would try it before I got wet, and so would any other rational person. As an aside, what builder sophisticated enough to create an underwater habitat and lab would just leave that cable lying on the damn beach?

Then we get to Charlie in the communications room, where he has just turned off the jamming signal. He knew he was supposed to drown there, and it looks like he has cheated fate. But wait! The Russian guy who got shot in the chest with a speargun is swimming outside the porthole, and he has a grenade! The grenade goes off, the porthole shatters, water is pouring in. What does Charlie do? Does he step through the door he is standing right next to and pull it shut after him? No, he closes it and locks himself in the room. Yea, I get to die!

This is just bad writing. It’s lazy writing. You could rewrite that entire sequence of events, preserve every ounce of drama and mystery, and have it all make sense from start to finish. But to do that you have to think about it, and maybe that’s a luxury television writers don’t have anymore. Or maybe the absurdity itself has some larger meta-purpose that I don’t get yet. I have no idea. But it’s hard to imagine people watching this stuff without laughing.

Getting Lost

Given the title and what I often write about here, you might think this post is about either losing one’s way, or becoming hopelessly mired in the documentation for some arcane class library. It’s about neither of those things, nor is it concerned with any other variation on the theme of not knowing where you are. Rather, it’s about writing, and the title reflects that I got to thinking about writing while watching a billion episodes of ABC’s drama “Lost.” Well, perhaps not a billion. Anyway, let me explain.

I hardly watch television. I have an HDHomerun on our network and can get 120+ channels at my desktop, but frankly it’s 99% crap. Pick a channel at random and you have a 75% chance of hitting a commercial. Wait the commercial through and you have an 85% chance of finding yourself watching Cops. The remaining 15% of the time is split between informercials and a show on the “History Channel” entitled “Mega-awesome Disasters III: The Earth is Overwhelmed by Ice and then Explodes!” Most of the time I turn it on after work and fall asleep waiting for dinner to be ready.

So I missed the whole “Lost” phenomenon. I was aware of it like a distant cultural carrier-wave, but up until two weeks ago I hadn’t watched a single episode. Then my wife got a Netflix account and I discovered their on-demand streaming library and Windows 7 Media Center integration. If you have a job and responsibility do not sign up for this service. It should be a schedule II controlled substance. Once you start watching there is no reason to stop. An intervention will require physically removing you from your couch with a large putty knife. The service is fast, the quality of the video and audio excellent, and if the library isn’t massive yet, there is still enough to keep you supine for a year. It should be illegal.

One of the titles in the Netflix streaming library is all of “Lost.” I always wondered what the buzz was all about, so I decided to watch a few episodes. I’ve now watched about 35 of them, and will probably watch the remainder of Season 2, at least. But as I have watched it an interesting thing has happened: I’ve transitioned from watching to see where the story goes, to waiting for the next completely absurd plot twist to unfold so I can laugh and launch derisive comments at the monitor. What prompted me to write this post is not that I have been watching “Lost” devolve into a comedy of writing horror, but rather that it seems to me like so much writing these days has succumbed to the same fate.

Making a good story is very hard. I know because I keep trying and failing. Aside from all the other well-cataloged elements a good story requires, its events must be constructed on a foundation of plausibility. You have to get the little things right in order to make the world feel believable and real. Not to say that a good story cannot contain the incredible. The incredible and otherworldly make great story elements. But the incredible has to spring from the credible. When the big incredible thing happens, it has to happen in the context of a world that is wholly credible in all the small details. That’s what allows the reader to disregard reason and leap that small gap from the mundane to the wonderful.

The problem with “Lost” is that virtually nothing about it is plausible. It could have been. There’s no reason why it shouldn’t have been. The big incredible things that happen work very well. It’s just that they happen in a world that is itself absurd. It falls apart the minute you start to think about it. Yet the show is hugely popular and won an Emmy. It makes me wonder if most of the audience ever does think about it. Clearly some get it, and the evident absurdities and incongruities have even led fans to speculate that all the characters actually died on the plane and that they are in purgatory. I don’t think they are, but the viewers might be.

Start with the basic premise of the show. The writers needed to get a group of people into an exotic, isolated location without hope of rescue or recourse to any of the normal amenties of civilization. How did they choose to do that? They had an airliner break up at altitude and dump its three sections onto a mountainous island in the South Pacific, relatively intact and with a substantial number of living humans aboard. Every single aspect of this series of events is implausible in the extreme.

The pilots were on their way to Los Angeles from Sydney when they “lost all communication” and “turned back toward Fiji.” First, airliners don’t lose all communication unless they lose all power. The average airliner has something like four independent radios, as well as satellite communication with the fleet home office. Second, when an airliner breaks up at altitude at full cruise speed (the airliner in Lost was actually in a dive and would have been exceeding cruise speed) it doesn’t come down gently, or in very large pieces. People don’t live through that, or at least not often. There is one case I am aware of where a stewardess was tossed into the tail section of an aircraft after it was split by a bomb. The tail impacted on a forested slope and bounced to a stop and she lived, although very seriously injured. Everyone else on the aircraft was killed. In “Lost” some of the passengers are tossed into the water, some into the jungle, but at least 60-80 of them get up and walk away.

Yeah, right. Was that really the best the writers could come up with? There was no other way to get this group of people into the situation they wanted? I can think of at least three. “Lost” doesn’t really get any better after the passengers are deposited at the edge of the jungle and struggling to survive. One of my favorite chuckle-inducing scenes was when Sayid turns on a handheld VHF radio and exclaims breathlessly “We have a bar!” It’s as if all the writers are 20 year-olds who think every communications device works like an IPhone. Later he takes that same, single transceiver and by setting up some aluminum antennas in various places he uses that same, single transceiver to attempt to triangulate the position of a radio signal they intercepted. The producers should have hired some of the team that created MacGiver. At least some of the science would be sound.

The silliness just continues to multiply the longer you keep punching up that next episode, from hunting wild boar with a knife, to making use of dynamite that has been sitting in a humid jungle for 90 years. We don’t even have to get into the illogical, irrational way most of the characters behave. And yet I keep watching those episodes on Netflix, and from this and the series persistent popularity the writers might conclude that they have done a bang-up job. And so, from a business perspective, I guess they have. But in terms of quality there is quite a large difference between watching something out of appreciation for its merits, and watching something else out of the morbid fascination of witnessing a trainwreck.

Stripping HTML Comments

Over the last couple of days I was working on a system that generates HTML emails. The email content is created by loading and rendering ascx controls that perform the value substitutions into a template, and comments had been included in the templates describing what data items each email required. This morning I realized that the comments were being included in the email bodies, so that using ‘View Source’ would display them. Not a huge deal, but it would be better not to have them in there, so I went looking for a method to strip the HTML comments. Everything I found seemed more cumbersome than necessary, so I threw together this simple recursive method to remove HTML comments from a string. It’s naive with respect to the question “what is a comment in HTML?” For my purposes a comment is the text between the <!– and –> tags, and that’s it. Posting this in case someone finds it useful.

private string StripHtmlComments(string html)
	int open = html.IndexOf("<!--"); 	if (open > -1)
		int close = html.IndexOf("-->");
		if (close > open)
			string newHtml = html.Remove(open, (close - open) + 3);
			return StripHtmlComments(newHtml);
		else throw new FormatException("The input HTML contains mismatched comment tags");
	else return html;