Archive

Monthly Archives: June 2014

Images are often stored with their pixels formatted as RGBA values, with each channel taking 8 bits. Together, these 4x eight-bit numbers make up a 32-bit integer. The color dark red, for example, would be 0x990000FF. The 0x99 denotes a reddish color (as it is in the red channel) and the 0xFF indicates that the color is not transparent. 0x99000000 would not be visible, as its opacity is 0x00. Every time I find myself working with images in Java, the problem of always-signed numbers arises. 0xFF000000, when the top-most channel is extracted, sometimes will return -1, as 0xFF can be interpreted in a few ways if you're not explicit. This is the code I've been using to extract colors from channels.


/*** getChannel
 * Returns a byte from the pixel by channel.
 * @param pixel
 * @param channel
 * @return
 */
public static int getChannel(int pixel, char channel) {
	if(channel == 'r' || channel == 'R') {
		return byteToUInt((byte)((pixel & 0xFF000000) >>> 24));
	} else if(channel == 'g' || channel == 'G') {
		return byteToUInt((byte)((pixel & 0x00FF0000) >>> 16));
	} else if(channel == 'b' || channel == 'B') {
		return byteToUInt((byte)((pixel & 0x0000FF00) >>> 8));
	} else if(channel == 'a' || channel == 'A') {
		return byteToUInt((byte)(pixel & 0x000000FF));
	} else {
		System.err.println("Unrecognized channel: " + channel);
		return 0;
	}
}

This week's Freakonomics unpacked the idea of stigmatizing failure. In short, don't be afraid to fail. Failure shows you something that didn't work. If at all possible, it's better to fail to hit a deadline than complete something incorrectly. Among the techniques discussed in the podcast was the 'pre-mortem'. Unlike a post-mortem, which investigates the things that went wrong and caused a patient to die/project to fail/rocket to explode, the pre-mortem asks everyone on a team to pull together an imagine that the date is three months after the spectacular failure of a project. "Assume the project has indeed failed, and it has failed completely. When people whisper to one another bitterly in the halls about it, what's the narrative? How did it fail? Give as many details as possible." This approach cleverly repositions the team naysayer/skeptic/demoter as someone who is trying to help the team. Really, the team as a whole now has a valid channel for predicting the failures of a project. In much the same way, I'd like to share my concerns about what's going to happen in SAGJ9.

1) Deployment issues. It's hard enough to get people to play your game without asking them to download Java. Worst case scenario will have judges going through the trouble of pulling down the JRE and the game, only to finally have it crash on startup because the shell is sitting one directory level below the library folder.

2) Gameplay issues. Is this going to be fun? The idea of an angry Bob Ross was amusing and charming, but neither is on its own a sufficient condition for a good game. When the prototype is done on week 1, will it be at all fun?

3) Development issues. The image comparison function could completely fail to correctly/effectively score user submissions, frustrating the users or, worse still, completely breaking forward progression in the game. Will I be able to maintain my enthusiasm when I get to the boring parts?

Number three has been a problem for my entire life. I have a surplus of attentional deficit, and leap from interesting project to interesting project as the boring bits surface. This means a lot of smoke and a lot of spinning tires, but little in the way of forward movement. A thousand half-finished projects don't look as good as one finished project.

Lastly, I'd like to give a shout out to SA forumgoer, IRC poster, and all around chill dude, Poemdexter. He gave a talk recently on finishing projects. The slides are available here: http://bit.ly/AoGJSlides and his website is http://poemdexter.com It's hard to think of anyone who is more capable of getting stuff done, so you should listen to his advice.

This rant is more stream of consciousness than normal. Tune in next time for a return to our regularly scheduled rant.

It's been a little over a week since the commencement of the competition (and subsequent decision to make The Rage of Painting), so I've had some time to mill over the idea of the main character. Since the theme draws upon the charming hokeyness of public access, it seems now unwise to outright rip-off Bob Ross. Instead, in the sprit of PATV, the main character should be strongly influenced by, but entirely distinct from, Bob Ross.

I'm having trouble making a character from the components of my friends thus far. Instead , I'll try and pick out generic people, add a personality quirk, and fast forward their lives.

Ross Franko
Truck driver turned painter who is convinced the CIA is recording video from his eyeballs.

Mike Newsman
A friendly and personable guy who was generally well liked as a kid. He aspired to be a correspondent in his adolescence, a dream he carried through to a degree in journalism. He joined the military in the early-mid stages of Vietnam to try and get a first-hand view of the situation. In keeping with his childhood tendencies, he befriends and units the huge plurality of his unit. The horrors of war start to chip away at their camaraderie, and after a particularly horrifying battle, they're collectively hospitalized. He's left distant and traumatized. The suicides of several of his brothers in arms only serves to amplify the damage to his psyche. He starts to paint as a way to escape from the reality of his situation. After discharge, he's returned to a society that despises him. He starts teaching art and history at a local community college. One of his students recommends painting on public access television, "Like that guy!" He views the activity as a compromise between journalism and the easy escapism of painting. Gradually, he considers dusting off his dream. (Fuck that's depressing.)

Buck Rossers
Rockstar physicist who is trying to earn money for his experiments by painting. This is a blatant rip of Buckaroo Bonsai.

Moss Ross
A sapient green ball of moss which acts like a combination of Groot and Meatwad.

Rob Moss
A deranged millionaire who loves painting and being on television. Kinda' like John Hodgeman. Strong anti-government and strong anti-corporate sentiments. Believes he is a direct male descendant of Ghengis Khan, who he repeatedly confuses with Khan from Star Trek II.

Robot Boss
An honest to god robot from the future who is attempting to pass off as completely human. Can't decide if it should be more panicky or Bender-esque + Aaron Stack. Should quote the Dalek and Cybermen.

I ended up throwing away the genetic algorithm and instead implementing a basic flood-fill selection with a twist.

Basically, the algorithm iterates through the image doing flood fill. The difference is, instead of four or eight connectivity, the algorithm selects a window of size n around the pixel. Additionally, instead of filling in the paint in those regions, it instead selects the pixels and pushes them onto a list. This collection of pixels of a similar color is called a step. The steps are then sorted by their length, from largest (longest, really) to smallest. In doing so, it looks as if fake Bob Ross is painting the big regions first, then filling in the details. It's far from perfect. The foreground is obviously painted in, rather than over. It looks good enough, though, and it was fun.

Like a Ross

For the up-coming Rage of Painting game, I really wanted to automate the creation of the intermediate steps of painting a picture. Doing so would mean I could upload only the finished steps and have the system automatically compute the intermediates. More compellingly, it would mean in a future version users could upload their own photos and have Ross paint them. The method I tried was simulated annealing.

Kiiiillllll Meeee

Kiiiillllll Meeee

The results were unspectacular. Summarily, after computing the 16-bit palette, I'd generate a set of n rectangles with X,Y,W,H, and palette index values. Each rectangle was one 'gene' in the organism. Fitness was defined as the number of pixels which don't match between the 'painted' image and the target image. (Really, 1.0/(1.0 + number of mismatched pixels).) Generations were bred, mutated, and selected. Wash, rinse, repeat.

I'm not sure what I'll try next. Maybe loosen the painting order a bit. Maybe select regions to paint by biggest area or most pixels.