masthead

No More Posts On This Blog

TwitS***

I am self-censoring myself here, since this is RIT’s network and I’m sure they wouldn’t want me cursing and whatnot. But the title to this project includes a word that rhymes with “Twit” and begins with an S. Moving on…

My first project for Physical Computing was to find a creative way to turn an LED on and off using Arduino. A while ago, I said that the only way I’ll use Twitter (which I think is beyond pointless) was if I could hook it up to our cat’s litterbox and have it “Tweet” every time the cat takes a poop. An LED would light up to signal “the litterbox is occupied” or start flashing to signal “warning: it may smell awful.” And that’s exactly what I did!

I had first planned to install an ultrasonic sound emitter inside the litterbox to detect if there was something inside. When I went to Jason to look through his box-o-sensors, however, I found the flex sensor which was not only much easier to use than the ultrasonic emitter, but it would be much easier to code for as well. The flex sensor outputs a number which tells me if it is bending one way or another.

p3170089

Once I had wired up the board, I took to writing the code. The Arduino code checks three times a second to get the value of the sensor. If it is bending into the litterbox, it signals the LED to turn on. If it is bending out of the litterbox, it tells the LED to flash for a few minutes. The Processing code is responsible for posting the Twitter updates, which works like this: the Arduino board is able to broadcast information via the USB port back up to the computer, which Processing listens for — this is called a serial event. Depending on what the event parameters are, I can tell which direction the sensor is flexed in and post the appropriate tweet using a nifty library called JTwitter. Here’s a screenshot of the programs running on my laptop (technically, Arduino doesn’t have to be open for it to work, but it looks cool with them both there):

screenshot1

And here is a picture of the installed “device:”

p3170090

If you’re interested, you can follow our beloved cat Reptar on Twitter here.

New Portfolio Site! sjbrenner.com

Go check it out! A brief bit about the site: It’s built in AS3 and XML; I also used swffit so I could use the browser’s scroll bar instead of making one in AS3 (see how the height changes on each page! I think that’s pretty slick). There are a few bugs and missing features (a way to display progress work, a more integrated way to view still image projects) and those changes will be made soon. I’ll also be moving this blog over to the new domain sometime this week.

Of course, now I have to bump that page up in Google for my name to maintain my hard-earned number one spot: Sam Brenner New Media Design Portfolio.

Sankey Diagram Generator, Final Print

sankey_final_01

It was more fun than I thought to read through the entire stimulus bill, and even more so to do it again, with a different version, when the bill was signed into law. Fortunately, I stumbled across the website stimuluswiki.com, which made the second readthrough considerably easier. After turning all the numbers into XML, I ran it through Processing, fixed whatever errors I had (including an extremely perplexing error involving Processing not liking my XML file generated in FlashDevelop, but having no problem with the exact same code copied and pasted into Dreamweaver) and went to the printers. I’ll take a picture of the print itself later, but for now you can click on the image above for the whole thing or see some actual-size details below.

sankey_final_02

sankey_final_03

Sankey Diagram Test Run

The unfortunate thing about choosing stimulus package (officially the American Recovery and Reinvestment Act of 2009) as my dataset is that it gets updated quite frequently. So when I started gathering data, the latest version was the one passed by the House. Now the latest version is the one passed by the Senate, and soon it will be the one signed into law. So I stuck with my original version, which means eventually I’ll have to go back in and find whatever changes have been made. The good news is that the generator works like a charm! There are some design obstacles for me to overcome: a more graceful way to handle the text will be necessary, and the overlapping branches aren’t exactly what I wanted the diagram to look like. I’m swiftly converting all of my data to XML, but here is what I have so far: the Depts. of Agriculture, Commerce, Defense and Education.

test

Sankey Generator v0.3 and 0.4

picture-1

Fourth time’s a charm! It took a while and a lot of mistakes, but I have my Sankey Generator working with a theoretically infinite number of XML nodes. Here’s how it went down.

While version 0.2 looked exactly how I wanted to, it didn’t work exactly how I wanted it to. It ran through the values, generated all the arrays I needed for the drawing, and plotted them accordingly. However it didn’t keep track of values like where each branch ends, which are very important if I wanted to plot a sub-level (which I did). I knew that I would need to use some sort of recursion to achieve the handling of infinitely-nested XML values, so I decided to rewrite my code from scratch to make it completely recursive. This was version 0.3. It read through the XML file as it is written, line by line, checking for any child nodes before moving on to a sibling node. This made quick work of handling an infinite amount of data, but I encountered a new problem: because it went to children before going to the next sibling, I again could not keep track of the end position of each branch. So once I ran through all the children of a node and needed to draw the next sibling, I would need to get the coordinates of the end of the parent node. My code quickly became cluttered with a ton of offsets and confusing numbers, driving me crazy! I am no fan of ugly code, for one, but most importantly, this wasn’t working. I solved this by creating a middle ground, a combination between recursive and level-by-level XML handling.

In version 0.4, I created a class called BranchGroup. BranchGroup takes three parameters:

  1. The XML element containing the siblings that need to be drawn, plus any potential child nodes, their children, etc.
  2. How deep in the XML the node is, for calculating the curve’s X position
  3. The Y position of the end of the branch from which this BranchGroup branches. (Got it?)

It is also responsible for performing two functions:

  1. Drawing the curves for all the children (and only the children, not grandchildren or anything deeper). This works much the same way version 0.2 does.
  2. Going back through the children and seeing if they have any children. If they do, I send that child element into a new BranchGroup, which repeats the same process until there are no more children. This works much the same way version 0.3 does.

And voila! Now an infinite number of values with an infinite number of children can be drawn in beautiful Sankey form. My next task is to go through some data (I have chosen Obama’s economic stimulus bill, which so far has been a thrilling read), put it into XML and see how my program handles it. I anticipate having to make a few tweaks to make sure that branches don’t cross over and node labels show up properly. That’s all for now!

Groundhog’s Day

It’s my birthday! But more importantly, it’s Groundhog’s Day. Let’s appreciate some lesser-known prognosticators, and their predictions (as of when I wrote this):

Blog Redesign

You may have noticed that I redesigned my blog to match my pending portfolio change. Nothing major – I just changed the colors and the masthead. I also implemented sIFR so my post titles match the rest of the design. Enjoy!

Portfolio Comp Revision

After getting some suggestions on my portfolio, I have changed the color scheme and the top slightly. Here it is:

comp_top_alternatives

I’m still working with some more options for the top, but this is the one that feels the most complete.

Sankey Generator v0.2

UPDATE: Here’s the final piece. Due to a few requests for it, I will soon be releasing my code. (Caveat: it’s ugly.)

Here is the next step forward in my Sankey diagram generator. While it is still far from a finished product, it actually looks like it’s supposed to, which is quite rewarding! Quite simply, I take the point in the middle of each trunk’s Y axis, map all of those values to a larger scale (to create the fanning out effect) and draw a bezier curve from the original point to the end point.

sankeywithbranches1

The curves are looking weird in a few spots, for instance with the largest values at the top, it appears to be more of a bulge than a curve. This may just be a matter of giving the curve more room to breathe on the X axis. Eventually I will need to come up with a nicer way to display the monetary values as well.

My next task is to gather more detailed data (specific Federal grants, for example), and draw those on to the graph as well. This should prove more of a challenge, but most of that code is already written.