Posts Tagged ‘as2’

Do Penguins use Flash AS2?

Tuesday, September 14th, 2010

Looks like those penguins down at Club Penguin are being put to good use. Just noticed this little Easter egg… Go to the homepage of Club Penguin, click Play Now and zoom into the lower part of the screen (expand your browser window). Looks like they are using AS2 though… god help us when they figure out HTML5! Still, I assume they are working on Linux :)

A simple Flash 3D engine from my past…

Tuesday, February 10th, 2009

Just trawling through a few old Flash folders on my mac and found this little fella’ sitting there all unloved. Came up with the 3D engine in 1998 using Director and made a quick hack to get it into Flash. It’s not particularly neat, hence why there’s no source posted, but suffice to say the heart of he 3D bit is that old ‘fake-doodle-dandy’ equation…

var x = (worldLens*pointX)/(pointZ+worldScale)+xOffset;
var y = (worldLens*pointY)/(pointZ+worldScale)+yOffset;

Like so…

Launch it to fill the browser

If you really want the code, let me know, but I’m secretly ashamed of it… :)

Webcam background removal in Flash

Thursday, November 27th, 2008

If you’re a fan of the EyeToy or you’ve just got You’re In the Movies on Xbox 360, you’ll know what this is all about. How to remove yourself from a web cam image and superimpose you on another background.

The mighty Jop had a bit of a testbed working and I thought I’d get the old brain working again and have a tinker. It’s not pretty code but it’s available below if you’re interested in a few pointers. It’s also not that good, but if it inspires you to do it better (I.e. properly) then it’s done its job.

If the web cam doesn’t initailise. Try this link:

In a nutshell:

1: Grab camera feed

2: Take a snap of the background

3: Use a ‘difference’ filter on them both to fighure out which pixels have changed the most

4: Use a ‘threshold’ filter to remove all the pixels that haven’t changed much

5: ColourTransform the resulting pixels to black

6: Apply a slight blur to help make it less jagged

7: Cache the resulting image as a bitmap (so it can be used as a mask) and put it over a copy of the live feed

8: Cache the live feed as a bitmap and apply the mask

9: And repeat using an interval or similar

Here’s the main function:

function takeSnapshot() {
//grab the cam and render it into a snapshot bitmapData obj
snapshot.draw(output_vid);
}

function checkVid() {
//grab live cam
liveData.draw(output_vid);
// grab snapshot
maskData.draw(snapshot);
// apply difference to 2 images
maskData.draw(liveData, new Matrix(), new ColorTransform(), ‘difference’);
// remove all unchanged pixels. Make them transparent
maskData.threshold(maskData, new Rectangle(0, 0, output_vid.width, output_vid.height), new Point(0, 0), “<=”, (threshVal/100)*0x00ffffff, 0×00000000, 0x00ffffff, true);
// colour what’s left black
maskData.draw(maskData, new Matrix(), new ColorTransform(0, 0, 0, 1, 0, 0, 0, 0))
// Blur to improve quality
maskData.applyFilter(maskData, maskData.rectangle, new Point(0, 0), blurFiltr);
resultData.draw(liveData);
// cache the resulting mask and apply it to the live feed
mask_mc.cacheAsBitmap = result_mc.cacheAsBitmap = true;
result_mc.setMask(mask_mc);

}

Source is here. Have fun!