Archive for the ‘Flash AS2’ Category

Box2D Javascript test

Thursday, March 13th, 2014


I’ve just indulged myself in some physics therapy. I *FINALLY* managed to get a few hours to play with the JavaScript port of the infamous Box2D.js physics library. Not fantastically exciting, but at least it’s a start!

Why is this even remotely interesting? Well, I’ve had a bit of a history with physics engines. Way back in the early days of Flash 5 and AS2, I was pulling together a team to make a pinball game to promote a new Disney movie. A contractor took on the job of writing the physics engine but half way through, he decided his work was too ‘valuable’ and wanted to license it to us instead. Honour and morals are pretty high on my list so that approach didn’t go down too well. So I did what any Creative Director (with barely a C-grade in O-level maths) would do… I decided to make one myself. How hard could it be? Turns out it was quite hard, took lots of “vector maths for dummies” research and annoying my ‘real coder’ colleague Jop with random circles and lines scribbled on napkins. But we got there. I think I OD’d on vector maths a little, hence haven’t been near a physics engine since.

The engine I made was quite ‘creative’ in its approach. It had all sorts of optimisations to make it run on slower computers, especially given how bad browsers where back then. I’ve managed to dig out a debug version (excuse the dead fonts). This version has the visualisation of my “hit zone optimisation” turned on. As the game starts up, it registers every element of the table and every section of curve. It only bothers to work out which areas to properly calculate based on the ball’s immediate surroundings. It sped the calculations up something like 400% when I switched it on for the first time. Click on the image below to launch it in good old-fashioned Flash and you’ll see how it highlights first the quarter of the table to concentrate on, then the individual areas within. Just click yo get started and use the cursors (down arrow to pull the spring back). Have fun!



How many days until Christmas? Here’s a timer…

Monday, October 17th, 2011

Get Adobe Flash player

I created this little puppy a while back, maybe 2004. Just found it on my hard drive and thought I’d add a post with it in. It dynamically updates the stats based on daily averages I set up at the beginning. It also takes the year from the current system clock, so should just tick over into the next year on New Year. The bit in-between will go a bit strange, but I’m not that fussed about fixing it. Feel free to do it yourself.

The source is here, but it’s a bit old skool. It’ll give you a few ideas though if you’re brave enough to open it.

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 :)

Stitched up by my own webcam!

Friday, March 27th, 2009

Another strange webcam experiment! Click the image to launch it.

I take the raw cam feed, find what changes between frames and add a threshold filter to colour the bits that change to a solid red. I then simply loop through the pixels to see if any are red then use the pixel position to draw lines to and from, sampling the original image to get the correct line colour. Completely no use to anyone… but looks nice enough.

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

function checkVid() {
//grab live cam
// grab 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, 0x00000000, 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);
// cache the resulting mask and apply it to the live feed
mask_mc.cacheAsBitmap = result_mc.cacheAsBitmap = true;


Source is here. Have fun!