Brian Shaler

Occasionally Interesting

Gravity is for chumps

Archive for the ‘Projects’ Category

The THX Sound and Random Numbers

I recently stumbled upon a 7 year old article detailing the creation of the THX sound in the 1980s. It was apparently generated by 250,000 ASP commands that were generated from a program that consisted of 20,000 lines of C code.

While entirely impressed by the work and result, this part stuck out to me.

>> There are many, many random numbers involved in the score for the piece. Every time I ran the C-program, it produced a new “performance” of the piece. The one we chose had that conspicuous descending tone that everybody liked. It just happened to end up real loud in that version.
>> “Some months after the piece was released (along with “Return of the Jedi”) they lost the original recording. I recreated the piece for them, but they kept complaining that it didn’t sound the same. Since my random-number generators were keyed on the time and date, I couldn’t reproduce the score of the performance that they liked. I finally found the original version and everybody was happy.

In visualization, I’ve come across instances in the past where I’ve needed random numbers to get a desired look, but needed repeatable results.

Take these two cases:

1.) I was re-rendering grid-like portions of a scatter-plot where data could be added but not removed. If I had 100 randomly placed points in a grid cell and needed to redraw it with 101 points, I needed the first 100 to be redrawn in the same positions they were in, plus the new one. (This one was in Flash)

2.) I was rendering a video with hundreds of thousands of “people” scattered around a floor in 3D space, but needed to be able to zoom in on particular people. If they were positioned in a truly random formation, the hard-coded positions I zoomed into would no longer show the specific people I was targeting. I needed to be able to re-render the video, position the people randomly, but have them in the same random positions they were in previously. (This one was in Processing)

For both of those cases, I came up with similar solutions. I created an alternate random() function that accepted an input parameter—a seed—and returns a random-ish floating point number between 0 and 1. For example, if you send it a seed of 123456, you might get a value back of 0.382919. If you send 123457, you might get 0.716254. What’s most important, however, is that sending 123456 again would result in the same value, 0.382919.

There are many ways to accomplish this, and I certainly didn’t set out to find the most optimal/scalable method. Within my seeded random function, I simply used the value for pi, performed some arithmetic using the seed, and returned only the digits after the decimal. That resulted in a very random-looking floating point number between 0 and 1, just like basic, non-ranged random() methods tend to provide.

In Case #1 above, I used the grid cell’s static X and Y coordinates plus the UID of the dot being rendered, and then generated a second random number with a slight variation in order to have two values—X and Y coordinates. In Case #2, all I needed was the UID of the person, also varied for a second random number to retrieve a random X and a random Y position.

As for the THX sound, they could have used a similar approach with a single hard-coded base seed value (e.g. the number 1) that is used in all subsequent seeded random function calls. This would result in the same sound being played every time. If they wanted to “compose” a new, randomized piece, the would simply change that base seed value (e.g. 1 becomes 2). To go back to a previous version, change that number back. Upon finding a composition they want to keep, simply leave that base seed in the code. The only way to lose the sound would be to lose the entire codebase, at which point your hopes of recreating the sound would obviously be slim, even if no random (or random-ish) numbers were involved.

Ludum Dare #23 48h Compo

Until Friday night, I had never heard of Ludum Dare, a global game development event celebrating its 10th anniversary. I found it via Reddit or Hacker News or Twitter or something, and discovered the event had kicked off 4 hours prior. Everyone participating in the Compo was given 48 hours to create a game from scratch around a theme announced that night. An alternate Jam competition has more relaxed rules, allowed teams, and ran for 72 hours. The theme was “Tiny Worlds,” which can be tricky when coming up with a compelling game idea. Fortunately, the theme and rules allow for pretty broad interpretation.

I wasn’t sure I would participate, but an idea popped into my head. Inspired in part by a segment of Dragon Ball Z Kai, I pondered what it would be like to jump from tiny planet to tiny planet. Mainly, what would happen to your perspective of “up” and “down” if you jump from the top of one planet to the bottom of another? The concept of “down” essentially just means “in the direction of the pull of gravity.” What drove me to want to build the game was the idea of making a 2D platformer where the directions up, down, left, and right are completely fluid and based on the gravitational pull of planets around the character.

Even though I haven’t used CoffeeScript or Processing.js before, I decided to try them out. Probably not a good idea on such a short timeline, but oh well.

The result was an auto-orienting 2D puzzle game where you have to jump from tiny planet to tiny planet to get to your goal before your oxygen runs out. You can walk around on planets and jump, but after leaving a planet’s surface, there is no longer any control over the character. That means if you miss a planet, you can drift off into space forever!

I finished an hour before the deadline and set up the game at (a play on “pico” meaning one one-millionth, or 0.000001) and made the source code available on GitHub. You can also see screenshots and blog posts about the progress (“making of”) here on my Ludum Dare author page.

R.I.P. Kerplunk 2008-2009

A few years ago, I put together an alpha version of an AIR-based Twitter desktop client, called “Kerplunk!” It deserved its alpha status. It was little more than a proof of concept, focusing solely on displaying a new way of looking at and interacting with streams of tweets. I ran out of time and momentum on the project in mid-2009 and never got around to updating it while the Twitter API evolved (OAuth, id_str, etc).

If I had that primitive alpha version of Kerplunk! today, it would still be able to improve my Twitter experience. Twitter has only gotten noisier, and Kerplunk was the only application to provide ways of suppressing certain types of content—craptweets—either partially or entirely. To deemphasize craptweets, Kerplunk! would simply reduce the screen real estate available for that tweet and truncate it after a certain number of characters. If it turned out to be interesting, despite tricking Kerplunk! into thinking it was crap, you could still spot it and expand it. Simple, yet amazeballs. I miss it.

What’s more, Kerplunk! was designed from Day Zero to go beyond Twitter (in fact, the core application included ZERO references to Twitter or tweets, aside from a command to download and install a plug-in called “Twitter”). You see, I don’t give a damn about tweets or Twitter. I care about what my friends are posting and sharing online, be it on Twitter, Facebook, blogs/RSS, etc.

While the prototype source code lay abandoned collecting dust, the idea and desire remained. The idea grew beyond Kerplunk!, though. Beyond a desktop application, at least. Since 2009, I’ve used my phone more and more to see what my friends are up to, probably up to 50% of my social media usage. I also came up with concepts that would benefit from my application to talk directly to another application, rather than communicating only through social network APIs.

The nice thing about ideas is that they can evolve and change entirely. Over the last 3 years, I’ve wanted different tools to solve different problems I had with my disparate social graph. Kerplunk! evolved into something else entirely. I’ll share what the new project is all about in a subsequent blog post. Stay tuned!

The Curse of Capability

I had an interesting realization recently when discussing funding options for a web site I built. For some background, I’ve worked on it occasionally on weekends (and a few multi-week sprints) throughout the last 4 years. It has slowly grown up to be a pretty robust lump of technology. For it to have a chance at taking off, it will need serious attention from a bunch of different angles: design, user experience, back-end optimization, sysadmin/devops, content acquisition, moderation, and marketing.

There are always valid arguments in favor of and in opposition to raising capital. After a couple of years of having no intention to seek funding for this project, I started to lean in favor of it. Part of it is manpower and not spreading myself too thin. Another part is skill set—my skills are too broad.

I’m pretty good at a few things (interactive development; “making stuff move with code”), but much less so at a bunch of other things. I can do various things under the “big D Design” umbrella (from product to user experience to graphic design), but that doesn’t mean I should. My design work is definitely inferior to those who specialize in it. I can do database administration and query optimization, but that doesn’t mean I should. My low-level systems prowess is definitely inferior to those who specialize in it. Basically, I have the ability to build a fully functional and fairly usable proof of concept, but not an all around amazing product. I can bring an idea to life, but beyond that, it’s best to let specialists take it from there.

Throughout most of my career, I’ve always worked alongside complementary specialists, allowing me to focus my attention to my own specialty. My best work has always been the work I’ve done with good teams. My best solo work, while sometimes being technologically innovative, is nowhere near as well-rounded or impressive.

So, I hit a roadblock. If I were talking to investors with an idea, a plan, some slides, and no ability to pull it off myself, an investors answer would simply be, “Yes,” or, “No.” However, because I technically can build everything from front to back, the answer becomes, “No,” or, “Come back after you launch it and start getting some traction.” If an investor has the option to see the product in action and gauge real-world interest, why not wait and see?

Well, I need to get back to my client work now…

Stranding Yourself


Half way up the mountain, overlooking downtown Charlotte Amalie to the South, along the highway that takes you to Magens Beach on the North side of St. Thomas, rests a cozy hotel with a marvelous view. Mafolie Hotel.

I landed in St. Thomas, U.S. Virgin Islands on a Saturday afternoon, after a long, three-leg, red-eye trip from San Francisco. Friday afternoon, I was trying to come up with a place to sleep in San Francisco when I just got the urge to jettison myself to some island somewhere. My friend Chrystall had said I could crash at her place in the British Virgin Islands any time. Out of the blue, I send her a direct message via Twitter to the effect of, “Hey, mind if I crash on your couch? Like, soon?” She said yes, so I double-checked flights.

“Okay, I’ll be there tomorrow!”

Sunday worked better for her, so I ended up having a day to kill in St. Thomas. I booked my flight with a half dozen hours of notice and decided that was enough planning for one day.

Fortunately, I got adequate cell phone coverage in St. Thomas. Upon landing, I asked myself, “What now?” I searched online for a hotel. Something cheap. Near downtown. But not too ghetto, so I opted for something that was $20 above the cheapest.

Book it. “Taxi!”

Couch surfing is tough, especially considering I only stay with friends and I hate feeling like I’m intruding. I’ve been wasting too much time and energy figuring out where to sleep each night, and decided I should just get away from it all so I can focus on me and my work.

While at the hotel bar, I asked the bartender if she knew of any cheap weekly or monthly rentals in the area. I was in luck, because the peak travel season hadn’t picked up yet and the hotel was still offering long term leases for a few more weeks. Instead of $125 per night, which is way too expensive for a month, they offered me $350 per week ($50 per night) if I stayed for at least 3-4 weeks.

Book it. “Ferry!”

A few nights couch surfing, with Chrystall in the BVIs, a short ferry ride away, and then I’d be back in St. Thomas for 3 weeks.

I thought it would be nice to lock myself away for a while and work full-time on my own thing. A bunch of people have told me this is a common desire. I was living their dream.

Honestly, it wasn’t that great. Good, but not great.

Despite becoming more reclusive during the last couple years, the biggest thing I was missing was socializing with fellow technologists, and all the excitement, motivation, and inspiration that comes with it.

I struggled to put in fully productive days, but luckily forced myself to take breaks and get some sun. I hardly left the hotel, pool, or hotel bar, mostly because going into town was an expensive hassle and almost nothing down there interests me.

The food at the hotel was way too expensive for my budget, so I made use of the mini-fridge and microwave. I drank a lot of fruit juice and ate a lot of microwavable ‘healthy choice’ type crap. (#startuplife)

The view from the hotel really was spectacular. The list of applicable adjectives could go on and on. Being able to work with such a magnificent backdrop is amazing and very fulfilling, especially when the seaplanes were taking off and landing. But ultimately, the isolation was rough, draining, challenging, and I realized I need to come up with a better way to work. I definitely need more balance and a better atmosphere.

You are currently browsing the archives for the Projects category.