Sections

  • Search Chrome Cow

Design a Day



Use a Cellphone Camera to Check Remote Control Batteries

Use the hidden secrets of the cosmos to impress your friends and family, see things otherwise hidden to the human eye! All this is within your grasp with  an astounding new tutorial.

Head on over to the How-To section and learn the secret of checking the batteries in your remote control with nothing but a cellphone camera.

A movie is included for your edification and enjoyment.


World’s simplest how-to: Use your cellphone camera to check the batteries in that pile of remote controls you have strewn around the living room:

 

Why does it work? Your remote controls communicate with your entertainment system with an infrared LED. You can’t see it, because, sorry to break the news, the human eye isn’t built to see infrared light, which sits in the rainbow just below red.

Your camera has the opposite problem. The CCD sensor in your camera is too good at picking up infrared. So good in fact that it requires a special filter to screen out most of the infrared light. Without the filter, your pictures would look very odd. But the filter’s aren’t perfect, and when a strong IR source (like the LED on your remotes) shines at your camera, the camera "sees" the IR source as a white light.

Added Bonus: If you own a Nintendo Wii, point your camera at the sensor bar on top of your TV to see what it looks like in IR:

Click to Enlarge


I’ve collected together all of my various experiments with Flash on this page. Most of what you will find here are snippets of code and small movies that test certain features of Flash, or solve some small, specific problems. There are also a few game-like projects.

Each of the movies posted here also show the source code (or at least the important bits). The goal is to create a resource for other people who are learning Flash, especially ActionScript . All of the exercises below are created in Flash 8. Some of them will work in earlier versions, some will not.

<

 Drawing Regular NGons

Game Prototype: Drunken Seek

  Here’s a Flash prototype I did to test a gameplay question in my last game, "Destroy All Humans: Big Willy Unleashed" for the Wii. [ Link ]


 Drawing Regular NGons

Documentation: Palabre 0.6

I am in need of a Flash compatible Socket Server, and found a great open source project, Palabre, with poor docs. This is info gather from docs, forums, etc. [ Link ]


 Drawing Regular NGons

Drawing Regular NGons

I have a project in progress that require me to draw regular NGons (Pentagons, Hexagons, Octagons, etc). I’ve posted the Flash movie and the source code for drawing them, using a simple rotation equation. [ Link ]


Learning Flash

Learning Flash

Since returning from GDC, I have been fired up to learn Flash as a tool for doing some simple gameplay prototyping. It has been rewarding, and at times fairly frustrating, as Flash has some interesting quirks of implementation. It has…personality.

  • Loading Text as Unicode
  • Create and Format a Dynamic Text Field
  • Write-On Text in a Fixed Amount of Time
  • Using Checkboxes
  • The Game Loop

  [ Link ]


Radial Solo Ball

Radial Solo Ball

Flash game number one. Basic goal, build a game with a main execution loop.

First experimentation with collision detection in Flash. [ Link ]


eRadiRace

eRadiRace

A simple wall avoidance game.

First iteration using built-in collision handling in Flash.
[ Failed ]

Second iteration using Flash 8’s Draw API. [ Somewhat Final ]


 


Regular nGons. We’ve all wanted to draw them at some time, right? Look no further, seeker of knowledge, I’ve got just what you’re looking for.

The method I’m using is pretty simple.

  • Assume we are drawing our nGon with its center at 0,0
  • Start with a point at
    • x = 0
    • y = nGon radius
  • for an nGon with n sides
    • rotate the point 360/n degrees
    • do this n+1 times
      • to close the polygon
    • add 360/n degrees each time we iterate

So assume we want a 12 sided nGon. We rotate the first point 30 degrees, the next point 60 degrees, 90 degrees and so on.

For the rotation, I’m using:

x’ = x cos Φ - y sin Φ
y’ = y cos Φ + x sin Φ

Where:
x and y are the original position
x’ and y’ are the new position
Φ is the degree of rotation

And because Flash uses radians instead of degrees, we have to convert from degrees to radians when doing this calculation:

radians = (degrees * Π/180)

Add in an x and y offset to each point to place the polygon in the center of the screen.

Here the code that run the movie:

// Drawing Regular Ngons
// Sean Hyde-Moyer
// April 2007
//
// Initialize variables

xOffset = 350
yOffset = 200
var xArray:Array = new Array();
var yArray:Array = new Array();

vert.text = 5;
radius.text = 120;

this.createEmptyMovieClip("planet_mc", this.getNextHighestDepth());

this.onEnterFrame = function() {
    incrementalRot = 0.0
    updateFlag = 0
    startVerts = Number(vert.text)           
    ngonRadius = Number(radius.text)
   
        //sanity check user values
        if (ngonRadius >180) {
            ngonRadius = 180
            //radius.text = 180;
        }
        if (ngonRadius <= 20) {
            ngonRadius = 20
            //radius.text = 1;
        }

        if (startVerts >512) {
            startVerts = 512
           
        }
        if (startVerts <= 3) {
            startVerts = 3

        }       
   
    // If values change, redraw poly
    if (oldStartVerts != startVerts ){
        updateFlag = 1
    }
    if (oldngonRadius != ngonRadius) {
        updateFlag = 1
    }
    if (updateFlag == 1) {

        degreeRot = 360/startVerts
   
        // Resize the demo circle
       
        circle_mc._height = ngonRadius*2
        circle_mc._width = ngonRadius*2
        circle_mc._x = xOffset
        circle_mc._y = yOffset
   
        // Draw the Ngon
       
        planet_mc.clear()

        planet_mc.lineStyle(1, 0xFFFF00, 100, true, "normal", "square", "miter", 3);
        planet_mc.moveTo(xOffset,ngonRadius+yOffset);
       
        for (i=0; i<=startVerts; ++i) {
            radianRot = (incrementalRot * Math.PI/180)
            xArray[i] = ((0*Math.cos(radianRot)) - (ngonRadius*Math.sin(radianRot)))
            yArray[i] = ((ngonRadius*Math.cos(radianRot)) - (0*Math.sin(radianRot)))
            xArray[i] += xOffset
            yArray[i] += yOffset
            incrementalRot = incrementalRot + degreeRot
            planet_mc.lineTo(xArray[i],yArray[i]);
        }
    }
oldStartVerts = startVerts
oldngonRadius = ngonRadius
}


I’ve dabbled in macro photography for a number of years, most recently I’ve taken to spiders, insects and other tiny creatures as my main focus. It’s a great way to take yourself out of the world for a moment, and visit someplace completely alien. With the advent of really nice digital cameras, it’s also cheap entertainment..};^)

(After the the camera itself has been depreciated over a few thousand photos).

Many insects have the decency to pose for photos in the great (and generally well-lit) outdoors, like the fellow pictured above.

This is not always the case, however. Every so often a photogenic creature wanders into the house, in the shade, at night. Using the built in flash (I’m using a Nikon Coolpix 5700) gives acceptable results, but often, as pictured below, the really small critters get lost in the shadow cast by the camera’s own lens. See the picture below.

I recently received a small, high-output flashlight [G2 Nitrolon] as a gift. It has a halogen bulb, runs on a pair of Lithium batteries, and is very, very bright. I have tried using this as a lighting instrument for macro photography, but it is extremely awkward to hold the flashlight in one hand, the camera in the other and coordinate their movements.

The only successful test was made with an extra set of hands. But it is tough (not to mention socially unacceptable) to pack an extra set of hands in your camera bag …or is it?

This can mean only one thing: Project!

The goal is to build a small rig that screws into the tripod mount on the bottom of the camera. It has a flexible armature that can be bent into position to point a mounted flashlight where needed to light a macro photo.

Gathering the Materials

I had almost everything I needed lying around the house. Your mileage and actual materials may vary, as the content our junk boxes may differ. I suggest reading the project description all the way through, and then substituting parts as fits your situation.

  • Tripod with broken leg, check.
  • Old pill bottle, check.
  • Hose from useless exercise-ball foot-pump, check
  • Fairly stiff but bendable wire…hmmm.

The wire was a lucky find. I was at the craft store stocking up for another project, and I stumbled across "armature wire." This is thick wire made of soft aluminum. It’s used to make a skeleton for sculptural projects, but it is the perfect material for the boom arm, stiff, but easily bent into position. As an added bonus, it is actually designed to be frequently bent and rebent, so it should last for a while without breaking. It is approximately 1/8th inch in diameter.

Again: read through the project first. I had to make some mid-course corrections, so don’t follow this step by step.

Let’s get to it!



Since returning from GDC, I have been fired up to learn Flash as a tool for doing some simple gameplay prototyping. It has been rewarding, and at times fairly frustrating, as Flash has some interesting quirks of implementation. It has…personality.

So this is to be a dumping ground for bits and bobs of code and information that I’ve learned, and might help others over some rough spots. No particular order or theme. Just nuggets of Flashy goodness.



Loading Text as Unicode

Use the standard loadVars method:

myLoadVars = new LoadVars( );
myLoadVars.load("unicodeSample.utx");

myLoadVars.onLoad = function (success) {
    if (success) {
        textWindow_txt.text = myLoadVars.quote1;
    } else {
        trace("Load Failed");
    }
}

 

 

The trick is to save the  text out as UTF-8 or UTF-16, with the *.utx file extension. I use JEdit for this, though there are a number of other free unicode text editors available.

Download the Flash File
Flash unicode.fla


Create and Format a Dynamic Text Field

This code creates a dynamic text field, creates a text formatting object, and applies the text format to the newly created text object.

createTextField("display_txt", getNextHighestDepth(), 20, 10, 460, 200);
//createTextField(textObjectName, Zdepth, X, Y, width, height)

my_txt.autoSize = true;
display_txt.text = "Twas brillig, and the slithy toves\nDid gyre and gimble in the wabe\nAll mimsy were the borogoves,\nAnd the mome raths outgrabe.";

var my_fmt:TextFormat = new TextFormat();
    my_fmt.font = "Times"
    my_fmt.size = 33;
    my_fmt.bold = false;
    my_fmt.color = 0×0055CC;
    my_fmt.kerning = true;
   

display_txt.selectable = false;
display_txt.antiAliasType = "normal";

this.onEnterFrame = function() { // Update Format Every Frame (for button update)
    display_txt.setTextFormat(my_fmt);
}

Download the Flash File
Flash dynamicText.fla


Write-On Text in a Fixed Amount of Time

This code writes a text string into a dynamic text field, left-to-right, one or more characters at a time, in a fixed amount of time.

This was created for the Design-A-tron, to write-on a text string of arbitrary length, in the amount of time it took to play the gears running animation and sound. It is completely dependent on the framerate of your movie.

var displayMe = "This was created for the Design-A-tron, to write-on a text string of arbitray length, in the amount of time it took to play the gears running animation and sound. It is completely dependent on the framerate of your movie."
displaySize = displayMe.length;

delay = 70;  // The larger, the slower the write on
displayLoop = 0;
endFlag = 0;
displayRate = displaySize/delay;
   
onEnterFrame = function() {  // Runs this loop every frame
   
    if (endFlag == 0) {  // Only Done for Duration of Write-On
   
        // Text Write-On
        tmp = displayMe.substr(0, displayLoop);
        display_txt.text = tmp;
        displayLoop = displayLoop + displayRate;

        if (displayLoop > displaySize) {
            // This writes on the last few characters
            // if the math doesn’t come out right
            // And sets the end condition for the loop
            endFlag = 1;
            display_txt.text = displayMe;
        }
    }
}

 

Download the Flash File
Flash TextWriteOn.fla


A Beginner’s Guide

Developed with Sonja Hyde-Moyer


Disclaimer: These are all tricks and techniques Sonja and I developed while driving in New Zealand. They worked for us, but none of the comments here should take the place of your own common sense, and we do not vouch for the correctness of the information contained herein. You should familiarize yourself with the traffic laws and customs of any country you will be spending time in.

See also our standard Terms of Service


NZ Road

We’ve been on-and-off planes and in airports for the last 24 hours. Sleep has been more of a goal than an accomplishment. Stepping off the plane in New Zealand (6 AM Local Time, Personal Time…anybody’s guess), our first stop is the rental car agency. Half-an-hour later, we’re on the road. The wrong side of the road. The learning begins.

This short guide to driving in mirror-lands is written from the point of view of righties learning to drive lefty, but the principles should also apply to those coming the other direction. Just flip directions, where appropriate.

The Buddy System

Most of these tips can be practiced alone, but it really helps to have another person in the car to help with sanity checks. But know this: as nerve-wracking as it can sometimes be driving in mirror-lands, the toughest job by far is being the passenger.

Inside the Car

We were very clever (we thought), and rented the same make of car that we drive at home to help ease the transition. This was a mistake. Instead of things feeling obviously wrong, and thus easy to remember, things were subtly wrong, and generally plagued us the entire trip. Left turns were consistently signaled by turning on the windshield wipers.

We felt bad about that, until we noticed the behavior in other cars, at which point it helped foster a sense of community. We were a band of clean-screened brothers, driving dangerously close to the curb. To avoid embarrassment, always try to drive in the rain.

The first thing to realize is that you have a lot more car on your left than you are used to, and far less car on the right. The practical effect of this is that you tend to give wide berth to the center-line, and hug the curb/ditch/400 foot drop-to-certain-death.

Which brings us to the first use of the buddy system. The passenger can help with this, with panicked shouts of “Too close! Too close!”

There are two less tortuous ways to help monitor the curb-side situation:

  • Tilt the passenger-side rear-view mirror down enough to see the curb.
  • Buy one of those little convex stick-on objects-may-be-larger-than-they-appear mirrors.

The stick-on mirrors shouldn’t be a problem in New Zealand, where the main concern of the rental car companies was that both halves of the car be returned intact.

Ahh, yes. Mirrors. Years of ingrained mirror-checking reflexes are for naught. All the mirrors are in the wrong place. So develop a little OCD and check left-middle-right whenever you do…almost anything.

IMPORTANT: All your reflexes are working against you. Driving is now a deliberate act. Forget this at your peril.

Early on in the learning curve, try to find a low-traffic highway with rumble strips on the median and reflectors embedded down the centerline. Wait until you are clear of other traffic, then within your lane, drift slowly left and right, and listen for the audio-tactile feedback that will tell you when your tires are hitting left and right boundaries.

There is a difference between drifting and weaving. This is left as an exercise for the reader.

You need to relearn your car’s bounding box. A few repetitions of this will help calibrate your sense of where the extents of your car lie.

The Buddy System: Perils of Passengering

As the passenger, you will be in constant fear for your life. This is normal.

Remember, short descriptive warnings are more effective than shouts of panic, no matter how heartfelt they may be:

  • Too close! (Usually in relation to curb/ditch/400-foot drop to certain death)
  • Slow down! (Usually in relation to the suddenly revealed switchback curve around the 400-foot drop to certain death)
  • Wrong lane! (Usually in relation to the lane you are in, which is wrong)
  • Giant Concrete Hedgehog! (Nothing more to say here)

As the passenger, you should take on the job of navigator, and act as a safety check for the driver. This is an active partnership.

Develop a habit of verbal confirmation. The driver should identify upcoming maneuvers, including their non-intuitive component:

  • I’m taking a tight left
  • I’m taking a wide right
  • Roundabout ahead. I’m going to look and yield right, then go left.

The passenger then confirms, or shouts “No, no, no!” in a loud, steady voice.

The passenger can also identify upcoming maneuvers, depending on the relationship’s power dynamics.

Frequently, this kind of mirror-land driving happens as an element of a vacation. As such, there will likely be time in the schedule for spontaneous events and roadside attractions ranging from fresh strawberries, to restrooms, to a 30-foot high concrete hedgehog (with restrooms).

This is all good fun, but remember that the driver’s reaction times are probably not as swift as they would be on a familiar (side of the) road. Give plenty of lead-time for these callouts, and don’t be afraid to go past the Hedgehog and turn around a half-mile down the road to circle back. The Hedgehog will wait. That’s what he does.

Finally, you will reach your destination, if all has gone well. If the handbrake is mounted on the center column, the passenger will frequently set the hand brake by habit. This is funny, if you are parked at the time.

Some More Rules of Thumb

When in doubt, the visitor yields.

After a couple of days, you’ll start to get comfortable and relaxed on the road. Knock it off! You have a lifetime of habits and reflexes just waiting to betray you.

I shouldn’t have to say this, but there’s one in every crowd. No drinking and driving. I have enough to keep track of without having to look out for your drunken ass.

Pedestrian advice: Look both ways before crossing the street; otherwise you’re probably looking the wrong way. Good advice all the time, really. I forget who said, “You can be killed just as easily be a car going the wrong way down a one way street as by one going the right way.”

New Zealand Specific Tips

There are very few stop signs in New Zealand. Intersections are frequently marked with “Give Way” signs. These are strong yield signs, like Yield, no kidding!

New Zealand is full of beautiful scenery, connected largely by two-lane highways, with occasional passing lanes. When you edge over to let someone pass you on the right (remember, that’s the normal side for passing), they may honk as they go by.

Take a deep breath, smile and wave. They are using the horn to say “Thanks!”
Unimaginable, but true! New Zealanders use the horn to convey a variety of friendly messages, from “Thanks for letting me pass,” to “Buddy, you’re driving on the wrong side, just thought you should know!”



Next Page »