Wednesday, January 7th, 2009

Archive for October, 2008

Pumpkin stuff

Tonight, my wife (and our neighbors) carved a few jack o'lanterns (however it's punctuated). After searching in vain for almost forever (read: seven or eight minutes) for a totally sweet dragon head or something, I decided I'd tackle vintage, old school 8-bit NES sprites.

What a kick in the pants that turned out to be. I was originally going to attempt Warmech from Final Fantasy I. But he had too many colors (4, I think) and too many pixels. My second choice was Mario from Super Mario Brothers 3. That jerk has eyes in the middle of his face! (Because of the nature of carving with negative space, anything "white" gets tossed; anything gray or black remains.

This was our first time toying with varying levels of opacity: in hindsight, I should have scraped more material from the inside of the pumpkin before hacking and slashing; that said, however, I think the result is a moderate success!

Gooma o'lantern

Key.isDown is gone!

Those of you familiar with ActionScript 1.0 (and even ActionScript 2.0) may have, on occasion, employed the ever-so-helpful flag Key.isDown when testing for the "downness" of a key.

In Actionscript 3.0, you no longer have that luxury!

Here's what I've been doing to fake it:

import flash.events.KeyboardEvent;
import flash.ui.Keyboard;
 
var keys:Object=new Object();
 
stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyboardDown);
stage.addEventListener(KeyboardEvent.KEY_UP, onKeyboardUp);
 
function onKeyboardDown (evt:KeyboardEvent):void
{
keys[evt.keyCode]=evt.keyCode;
}
 
function onKeyboardUp (evt:KeyboardEvent):void
{
delete keys[evt.keyCode];
}

Then, if you need to test for key combinations, add to the relevant handler; for example, if I wanted to make sure the Ctrl, W, and Z keys were all currently down, I'd add this to the onKeyboardDown listener:

if (keys[Keyboard.CONTROL] && keys[87] && keys[90]) {
// do stuff
}

(87 is the key code for "W," and 90 is the key code for "Z". Don't want to memorize key codes? There's always this handy-dandly little thingy!)

It's pretty straightforward, which is probably why lots of people have already written their own routines for handling Key.isDown. If you're one of the ones who hadn't written such statements, feel free to steal them from here!

Further adventures in colorspaces

Update: Here's a slightly modified version of the colorspace adventure! In this iteration, you can also adjust sliders for R, G, and B. Regardless of which "space" you make changes to, the other space will update accordingly:

(Either JavaScript is not active or you are using an old version of Adobe Flash Player. Please install the newest Flash Player.)

If you read my last entry, you know I'm in the process of reinventing the wheel! I mean creating a color picker.

In preparation, I did some additional research on the HSV colorspace. The Wikipedia article contains all kinds of totally awesome math stuff -- some of which I actually understand! (I also found another site that, while replete with pictures and explanations, etc., left me scratching my head, though I think if I read through it again, I could figure it out...)

Anyway, after looking over the formulae (and only understanding a handful of them), I created the following thingy:

(Either JavaScript is not active or you are using an old version of Adobe Flash Player. Please install the newest Flash Player.)

Either drag the HSV sliders around or click the color chip in the lower left corner to modify the displayed color. The HSV values are (roughly) reflected in fields next to their respective sliders; the RGB values are displayed in fields to the right of the color chip in decimal, hexadecimal, and percentages.

So what's the point? I'm not entirely sure. I guess in a lot of ways, I think HSV is a more intuitive method for choosing a color than RGB, and the ultimate purpose for this color picker was (is?) a "game" for the unwashed (read: non-designer-y) masses My previous experiments (conducted back in the olden days) were coarse hacks compared to this iteration -- although, in fairness, they (mostly) worked, even if somewhat "particular." I guess I'm just excited to see that after all these years, I'm still capable of learning and improving. Or something.

If you want the source, it's right here!