Bar Trivia

Trivia night is all the rage at local bars, and I’ve been enjoying the challenge. It’s about as much fun as people who are old enough to drink legally but are not working on a postgraduate degree until their eyes bleed can have on a weeknight. Plus, it’s a chance to win free beer, and therefore not end up spending disposable income on alcohol! Perhaps not a great chance, but a chance nevertheless.

This framing device isn’t arbitrary – the bar trivia fad is a great example of the things that people of my generation are doing with their college knowledge. Our great-grandparents designed bridges, uncovered the secrets of atomic physics, and argued for a universal declaration of human rights. We can write down Avogadro’s number and come up with vulgar team names to offend any sensibility.

Ha ha! Of course I’m exaggerating. Everyone knows that only the better aspects of popular culture are remembered. Still, it’s kind of funny that a bachelor’s degree in the humanities used to mean a real opportunity to find a good job and earn a good salary. These days, if you pay attention in class, you might win a free pitcher of ale.

NSA Snoops

This whole NSA melodrama is rather interesting. Once again a disgruntled government employee has leaked juicy top secret documents, and the fallout has divided politicians roughly along that quirky libertarian/authoritarian axis. Meanwhile, the public is freaking out because privacy online is an illusion, and Big Brother has been watching all along. George Orwell was right! We didn’t listen!

Along with several other people, I’m not exactly surprised by this revelation. What does the NSA even do if not this? How else does a company like Palantir make money? Are people actually surprised that planning crimes on Facebook is not a solid business plan?

Less obviously, why would anyone expect an ad-supported media company to stand up for privacy rights or whatever the libertarians want? People are acting like this is the cyberspace equivalent of strong-arming banks in order to search everyone’s safety deposit boxes. I’d suggest that it’s closer to reading people’s mail and rooting through their garbage. If someone invented a cheap stealth robot to do exactly that, do you really think the NSA wouldn’t be their top customer?

Signals intelligence is a sketchy business, whether or not you agree with the tactics. Most contractors who are not fleeing the country probably figured that out a long time ago.

Thrift Shops

Secondhand markets combine several great aspects of capitalism. Unlike much of that feel-good environmentalist nonsense, reusing manufactured products actually saves energy. Plus the revenue goes to enterprising resellers and charitable causes.

The problem is that this trend has turned into a mainstream fashion movement, which I suppose must please some people to no end. How could it be a problem? Well, the secondhand market obeys the laws of supply and demand just like any other market, so with increased demand either the price of goods will go up or the supply will dwindle. If you’re shopping for exclusive secondhand deals to stick it to corporations and show solidarity with the lower classes, somehow I can see that plan backfiring.

It’s fair to argue that if the secondhand store is run by a charity, increased business will divert more capital to a worthy cause. However, direct charity is not the only service that these organizations provide. And buying unnecessary new clothes does nothing for society beyond indulging our need to stand out or fit in, no matter where the transaction happens. Still, that is not necessarily a bad thing.

Look, if you’re all about the whole anti-consumerist underpaid Starbucks employee thing, there’s nothing wrong with getting a good deal on clothes. But taking your parents’ money to Goodwill so that you can buy beer and cigarettes with the change is a whole different story. If you’re not even going to donate some overpriced khakis or whatever, you’re actually making life that much harder for many of the unglamorous poor.

I’m getting awfully tired of products dubiously marketed as pre-packaged ethics, but that’s a topic for another time.

Fractals

Last time we plotted a Mandelbrot set using a small Python script. This set is interesting because an unexpectedly large amount of detail emerges from the iteration of a relatively simple function. Even more interesting is the fact that this detail is not limited to any particular resolution. The Mandelbrot set exhibits fractal geometry, meaning that tiny areas of the set share features with the whole thing. If we zoom in, smaller details are visible no matter how far we choose to zoom.

But you don’t have to believe me – let’s modify our Python script and see what happens. Basically we have to map 600 pixels in each direction to arbitrary sections of the real and imaginary axes. We can have our script read in the desired ranges and calculate appropriate mappings. First, store the inputs in decimal variables:

def get_decimal(m):
    while True:
        try:
            x = float(input(m))
            return x
        except ValueError:
            print('Enter a decimal number.')

loX = get_decimal('Minimum X: ')
hiX = get_decimal('Maximum X: ')
loY = get_decimal('Minimum Y: ')
hiY = get_decimal('Maximum Y: ')

Divide 600 by the range in each direction to compute scale coefficients:

scaleX = 600.0/(hiX - loX)
scaleY = 600.0/(hiY - loY)

Now modify the drawing code to use our designated ranges:

for x in range(0,600):
    real = loX + x / scaleX
    for y in range(0, 600):
        imag = loY + y / scaleY
        c = complex(real, imag)
        p = mandel(c)
        w.create_line(x, 600-y, x+1, 601-y, fill=colors[p])
        w.pack()

With these changes we can zoom in and see some interesting features. Try using -0.15, -0.05, 0.9, and 1.0 as input values. More detail is visible, but it looks like some of the boundaries are smoothing out! Interestingly, that’s because our mandel() function only checks whether each candidate c escapes within 20 iterations. Points close to the boundary often take more than 20 iterations to escape, but they don’t actually belong in the set. Therefore, as the zoom level increases we have to test each candidate c for more iterations in order to maintain an accurate image. This is left as an exercise for the reader.

The Mandelbrot Set

Last year we considered complex numbers, quantities with two degrees of freedom. These numbers have many important applications in engineering, but can we immediately use them to do something interesting?

Well, we can draw the Mandelbrot set with a computer and a bit of ingenuity. This set includes every complex number for which the following recurrence equation never produces a result with an absolute value (distance from the complex origin) greater than two:

mandelbrotequation

For any complex number, we start with z = 0, square it, add our complex candidate c, then repeat the process with z equal to the new (complex) value. As long as z stays close to the origin after many iterations, our candidate is probably in the Mandelbrot set. Since complex numbers behave like points in a 2D plane, we can draw an image where each pixel is colored by testing a candidate c related to its horizontal and vertical position.

So let’s make a drawing! This program is based on Prez Jordan’s Python code, but we’ll add a gradient to show how many iterations each candidate takes to escape. First we set up a 600×600 canvas with Tkinter:

from Tkinter import Tk, Canvas, mainloop

tk = Tk()
w = Canvas(tk, width=600, height=600)

Next we define our mandel() function which takes a complex number and tests whether it escapes in twenty iterations. If so the function returns the last iteration number, otherwise it returns 99:

def mandel(c):
    z = 0
    i = 0
    for h in range(0,20):
        z = z*z + c
        if abs(z) > 2:
            break
        else:
            i+=1
    if abs(z) >= 2:
        return i
    else:
        return 99

In order to draw a gradient, let’s use a dictionary to map iterations to colors. We’ll need entries for keys 0-20 and 99:

colors = {
    0: 'white',
    1: 'white',
    2: 'light yellow',
    3: 'light yellow',
    4: 'lemon chiffon',
    5: 'lemon chiffon',
    6: 'yellow',
    7: 'yellow',
    8: 'gold',
    9: 'gold',
    10: 'orange',
    11: 'orange',
    12: 'orange red',
    13: 'orange red',
    14: 'red',
    15: 'red',
    16: 'red',
    17: 'dark red',
    18: 'dark red',
    19: 'dark red',
    20: 'dark red',
    99: 'black'
}

Finally we loop over each pixel, convert its x and y coordinates to a complex number, test that number by passing it to the mandel() function, and use the returned key to look up the appropriate color in our dictionary:

print "Drawing..."

for x in range(0,600):
    real = x / 200.0 - 2.2
    for y in range(0, 600):
        imag = y / 200.0 - 1.5
        c = complex(real, imag)
        p = mandel(c)
        w.create_line(x, 600-y, x+1, 601-y, fill=colors[p])
        w.pack()

print "Complete!"
mainloop()

Run this code in your Python interpreter and see a picture of the Mandelbrot set!

Hobgoblins

Here’s a quote from H.L. Mencken that caught my attention:

The whole aim of practical politics is to keep the populace alarmed (and hence clamorous to be led to safety) by menacing it with an endless series of hobgoblins, all of them imaginary.

I guess I’ve always been a bit amused by hobgoblins, having seen quite a lot of them influence American pop culture firsthand. This isn’t to say that none of these scare stories have any basis in reality, or that I have always seen through the hype. However, it will be fun to maintain an official List of Hobgoblins that this millenial remembers. Here it is:

Nuclear Winter, Pollution, Japanese Manufacturing, Ozone Depletion, Saddam Hussein, Ecological Collapse, Skynet, Global Warming, Y2K, Terrorists, SARS, Russian Hackers, Nazi George Bush, Mexicans, Illuminati Bankers, Genetically Modified Food, Hyperinflation, Climate Change, Nazi Barack Obama, Ocean Acidification, Chinese Hackers, Nuclear Meltdowns, Bath Salts, Climate Disruption, Planet X, Budget Cuts…

The list approximates a chronology, and it will be updated.

The Pixar Princess

A surprising number of animated classics have been created during my lifetime. Two important revolutions happened in America at the end of the 20th century: the “Disney Renaissance” and the arrival of computer-based animation. While the explosive impact of 3D was hard to miss, another important factor was subtle and sociopolitical.

The Little Mermaid was a regression in one sense, to the animated Broadway-musical royal romances that defined early Disney animation. In another sense, it broke new ground for the format. Ariel is the titular 19th-century ocean-dwelling heroine who makes a faustian deal to win the heart of Prince Eric, a boring but beautiful human. As only the fourth official Disney Princess, she does something other than be in distress, which is notable. The box office returns were impressive, and the royal romance was back in a big way. However, that whole singing princess trope hasn’t transcended its gendered appeal to this day. Consider that Pixar out-earned Disney at the box office without featuring a princess for 17 years. Or consider Halloween costume sales.

Anyway, let’s continue. Belle is also an “interesting princess” with all the book learning and such, but her character has more depth in that she learns to love a hideous creature. There’s not much else that needs to be said here, but imagine if the genders were switched!

Jasmine is the bride of Aladdin. She is notable for being non-European and owning a tiger. Perhaps because boys would balk at Beauty and the Beast, the action in that movie revolves around the illegitimate title prince. The Lion King doesn’t actually marry an official Disney Princess, which is just as well because lions are polygynous cannibals.

Pocahontas is next, featuring a quasi-historical (Native) American. The wheels were coming off the royal romance gravy train by this time, and her movie was slightly overshadowed by Pixar’s explosive debut. Animation would be changed forever; 2D was suddenly old-fashioned and unmarketable (see The Iron Giant). While its shiny new rendering process got a lot of attention, Toy Story was also at the vanguard of a different narrative technique. Gone were the musical numbers and pretty princesses – the only romance in Toy Story is between Woody and Bo Peep, and the framing device literally casts them as role-playing toys.

That stroke of genius allowed the franchise to explore mature themes like jealousy, existential angst, and the social contract, while basing all the action around a child and his possessions. Perhaps there is some significance to Andy’s gender and the fact that his pretend play always involves aggressive conflict between good and evil. The neighbor Sid takes this to a perverted extreme, obliterating and mutilating toys, while his sister Hannah has them share idle gossip over tea.

In any case, Pixar’s movies have avoided the royal romance trope almost entirely. Shrek absolutely wallowed in fairy-tale nonsense, and eventually The Princess and the Frog and Tangled introduced Tiana and Rapunzel as the first Black and 3D Disney Princesses, respectively. Meanwhile, Finding Nemo celebrated guardianship and adventure, The Incredibles focused on ability and the family unit, and Ratatouille studied ambition and creative expression. The latter did have a romantic subplot and a peerage aspect which was subversive at best.

To get to the point, Merida the Brave is scheduled to become the first official Pixar Princess in July. This is interesting for several reasons: First, she stays single until the end of the movie! Her three would-be suitors are not very charming, to say the least. Second, she doesn’t sing, except for one Gaelic lullaby. Finally, Merida isn’t actually the first romantic female lead in a Pixar movie. That honor goes to EVE, a machine with a fusion reactor and a minimalist design supervised by Jony Ive. Clever.

I’m leaving out several other animated features of note, like Wallace and Gromit, Persepolis, and Coraline, and that isn’t even mentioning Miyazaki or the rest of Japan. Here’s to all these great artists, and congratulations to Princess Merida!