shinyblog

Friday, December 31, 2004

most obfuscated code I've ever seen

I'm porting something from java to C#. I'm pretty sure what I'm trying to figure out at the moment is the Bresenham line drawing algorithm, which tells you how to draw a line on a bitmap. But then I get to this line, where it actually sets the pixel value in the buffer:

int rand8 = Shade3D.nextRandom8Bit();
pbuf[offset] = (n > nMid?(rand8 < 85?argb1Dn:(rand8 > 170?argb1Up:argb1)):(rand8 < 85?argb2Dn:(rand8 > 170?argb2Up:argb2)));

So first it gets a random 8 bit integer, if the method name can be trusted, and then
it decides what value to put in the pixel by whether the random is less than 85, less than 170, or greater than 170.

Okay, wait -- I might actually understand this. This might actually be antialiasing. Or it might be utter witchcraft.

This section also includes code that shifts bits left and right, and a lot of code that pays a lot of attention to 8 bit vs 16 bit vs 32 bit integers. As a rule, something is harder to port the closer it is to hardware. Bit-shifts and paying attention to the bit-width of types is rather close to the hardware, for my taste.

So have I just spent two day's on a fool's errand? Perhaps. I'm probably going to have to throw away the last two days of work, and re-start the port with another approach. Damn it. At least I get to keep the lessons learned.

And yes, it is new year's eve and I'm programming. It's not exactly fun, but it's what makes my life better.

Wednesday, December 29, 2004

weather

This is just an idea; it might be horrible in some ways.

This year we had the worst hurricane season ever. Last year was the coldest winter in ages, and the year before I think was the snowiest winter in ages. Significant portions of the Antarctic Ice Shelf are falling off and melting into the sea. I'm talking about rapid global climate change. I think it's real, and it's here, and it's just going to get worse.

Eleven countries around the rim of the Indian Ocean are suffering the worst natural disaster ever because of one tsunami: the waters rose quickly, then receded. A tectonic shift caused the earthquate which caused the tsunami, but think about this: the flood waters receded this time. What's going to happen when the water rises, and rises, and doesn't recede for hundreds of thousands of years? It won't be sudden; there will be time to plan for it, but it will be permanent. People won't just be homeless; the actual land they live on will disappear.

Let's use this disaster as a preview of the coming floods. Let's encourage the nations to rebuild at higher elevations, and leave the lowlands for the sea's inevitable encroachment. Most of all, let's use these horrible images to keep up the fight against global warming. A tsunami early warning system won't save us from global warming; we've already got a global warming detection system, and the alarms have been ringing off the hook for twenty years. We ignore them at our peril.

Monday, December 27, 2004

"significant enhancements"

I've been working on migrating Jmol to Microsoft Visual J# so that I can use it in a C# program. I ran into a problem with the javax.vecmath library -- it falls into the set of "technologies with no automatic migration." The Moving Java Applications to .NET instructions include this ridiculous bit of "it's not a bug it's a feature" and generally everything that's wrong with Microsoft's worldview when it comes to Java:
To finish the migration, you replace the unmigrated Java technology with comparable .NET technology. Because .NET provides a richer set of classes than what is available in Java, often you can make some significant enhancements when performing the technology replacement.

*splutters* But I don't want to re-work Jmol to use .NET's vector math library. There's already a perfectly good java vector library that I want to use.

What this *actually* means is that if I want to use vecmath, I have to "upgrade" it to J#. I think it will be worth it for Jmol though -- the whole point of using Jmol is to save me from having to write a complete molecule viewer in Direct3D/C#.

...arg. It turns out to be rather difficult to sane-ify the output of the "upgrade" wizard. And in fact, it seems to upgrade to C# rather than J#. I know C#, so I don't mind that.

I'm still in love with open source. Very much in love.

Monday, December 20, 2004

I love cross-platform open source.

I'm so in love with open source. And unix. And cygwin.
./configure
make
make install

Those three commands lead to such goodness. At the moment I'm installing FreeType2, a free, high-quality, portable font engine. I'm installing it on my windows tablet, but I'm entirely certain that I'll be able to compile and install it on the linux system at work with those same three commands... and that code I write on my PC will work under linux.

And, my favorite firefox feature: type anything into the firefox address bar. Hit return. You get the google "I'm-Feeling-Lucky" result. It's just... so... perfect.

Sunday, December 19, 2004

I'm a hobbit!

Janet Bruesselbach painted me last night, as Frodo. She's a RISD student who's into sci-fi and fantasy and geeks. She was my partner in cs137 this fall. She asked if she could paint me as a fictional character... I took a look at my hair, which is at its curly, overgrown stage, and decided to be a hobbit. So last night I pulled on some heavy felt pants and a cloak, took off my shoes and socks, and posed on Janet's couch... while watching Return of the King, no less. Janet started with an empty canvas, and then three hours later, there was an actual painting there. Of me! As a hobbit! I look like me and also like a hobbit at the same time. I was worried that I wouldn't like the way I look, but I really do... something about how hobbits are supposed to be chubby.

I did try to watch the whole ROTK extended edition, but that's just too long to sit still for me!

Now I"m off to the cave for some hacking on screen, which I'm re-implementing in IS3D. I want to finish a project. For once.

Maybe that's what's so amazing about Janet's painting last night -- she produced a complete, finished work. Also that she did it on a Saturday night, at the end of the semester... it reminded me that artists make art for fun, not just for coursework. I code for fun, too, sure, but this was still somehow surprising, I suppose after all semester of hearing the RISD kids saying things like "I have to go finish a painting now."

Zebediah and I are planning to build a space ship and fly to the moon, or Mars, or Saturn. We will bring Hugo and Phineas in special kitty space suits, and we will return to earth when we need to go to a cat food store. Darling and Isabel just want to lie on the couch; they don't want to go to space.

Wednesday, December 15, 2004

Barney Cam 2004

The white house has made a film starring the most visible memebers of the Bush cabinet and Barney, W's scottish terrier. CNN just played the whole film. The plot seems to be that Barney has lost Mrs. Beasley, who is the new puppy. It actually features W down on one knee in the white house explaining to Barney what his job is for the holiday season, and why Barney didn't get any cabinet appointments.
People! There's a war on in Iraq. American children don't have enough to eat and they're certainly not getting enough education. We're accumulating a gigantormous deficit, and the dollar is sliding. Why are they spending the time and money on this silliness?

Monday, December 13, 2004

just like 1995

oh my god it's late and i'm at the cave and i'm programming and it's just like 1995. except there wasn't a cave then. instead we had the VR lab, which is now the editing room, but which also had no windows and a giant sgi.

Thursday, December 09, 2004

geek survival kit

Lately I have been having entirely too much fun with duct tape, velcro, and surplus electronics. I've been connecting everything to everything else. The two best examples of the last 24 hours:
-- a wireless keyboard duct-taped to a belt, making a wearable keyboard for use in vr. We took some pretty silly pictures of this; apparently it has a glam-rock aspect that RISD students can't get enough of.
-- a super-cheap dvd player, my ipod, and an walkman radio hooked up to my tv -- a complete home entertainment system that would just about fit in a backpack.

I think I should make it a point to always have the following supplies on hand:
* velcro
* duct tape
* utility knife or leatherman
* cable ties
* blank cd-r's
* earbud headphones
* dark chocolate
* aa batteries
* an unread issue of the ny times magazine, harper's digest, the economist, science news, or the atlantic monthly
* aleve