Sunday, October 16, 2011

I translated Alexander Boswell's toy REYES renderer from C++ to Google's new Dart programming language.

Here's what the output looks like:



Try It Yourself

If your browser supports the canvas tag and JavaScript, you can see the sphere being rendered here:

Render a REYES bumpy sphere in your browser.

And the source is here: http://code.google.com/p/reyes-dart/

Translating C++ to Dart

It was pretty easy to translate the original code from C++ to Dart.
  • The original code made use of classes and overloaded operators, both of which are also in the Dart language.
  • The original code used the SDL library to display output. It was easy to switch to the HTML5 CANVAS tag.

I used an early version of the "Dart Editor" IDE. The Dart Editor IDE was helpful because of the compiler warnings and errors.

Debugging

I used a variety of techniques to debug the code:
  • print() Dart has a built-in print function that logs to the JavaScript console. This was good for logging small amounts of data.
  • write() This is a utility function I wrote that appended the argument text to the document body of my HTML document. This has several advantages over "print":
    • Easier to see output during development.
    • Much easier to search and copy/paste large amounts of text.
  • Dumping 3D geometry as text. At one point I wanted to check whether or not my geometry was correct. The easiest way to check it was to dump the geometry out as a 3D text file using "write()", and then copy-and-paste that code into a file and view it in the blender3d.org Blender app.
  • Using Chrome to step through the compiled app.js code. This was pretty painful, but was occasionally useful. The stack crawls for exceptions usually gave good hits as to what was going wrong.
Dart Limitations
  • The Dart "dom" library is not yet complete. Currently it can't write to canvas imageData. As a work-around I draw each pixel of output as a little filled rectangle.
Dart Editor Limitations

I wish the Dart Editor would support:
  • Formatting code.
  • Stripping whitespace from ends of lines on save.
  • Converting tabs to spaces on save.

Sunday, September 11, 2011

A script to upload files to Picasa Web Albums

Today I backed up all my family pictures and videos to Picasa Web Albums.

For several months I have been thinking of ways to backup my pictures to somewhere outside my house. I wanted something simple, scalable and inexpensive.

When I read that Google+ users can store unlimited pictures sized <= 2048 x 2048 and videos <= 15 minutes long, I decided to try using Google+ to back up my media.

Full disclosure: I work for Google, which probably predisposes me to like and use Google technologies.

Unfortunately I had my pictures in so many folders that it wasn't very convenient to use either Picasa or Picasa Web Albums Uploader to upload them.

Luckily, I'm a programmer, and Picasa Web Albums has a public API for uploading images. Over the course of an afternoon, I wrote a Python script to upload my pictures and videos from my home computer to my Picasa Web Album account. I put it up on GitHub: picasawebuploader

Good things:
  • The Google Data Protocol is easy to use.
  • Python's built-in libraries made file and directory traversal easy.
  • OSX's built-in "sips" image processing utility made it easy to scale images.
Bad things:
  • The documentation for the Google Data Protocol is not well organized or comprehensive.
  • It's undocumented how to upload videos. Luckily I found a Flicker-to-Picasa-Web script that showed me how.
To do:
  • Use multiple threads to upload images in parallel.
  • Prompt for password if not supplied on command line.

Saturday, August 20, 2011

What am I up to?

I'm mostly posting on google+ these days, sorry!