AS3 Plinko with APE 2D Flash Physics Engine

I rarely mention stuff I have worked on here but I got a chance to use APE and AS3 on the online Plinko game at the site for the Price is Right videogame for the famed pink Plinko Board.  Who doesn’t love Plinko?

I did the programming on this back when I still worked at emarketing/prizelogic.

I will be featuring a small iteration to APE with draggable particles and how I did it.  In the end I didn’t use the draggable particles but they are fun (i ended up changing my collision/border particles after testing).  I ended up controlling the drop location by swapping out a wheel particle after they dropped it.  So that it got the famous Plinko disc bounce and roll.

Why did I use APE? Well it is the least complex physics engine.  I started off with Box2dFlashAS3 and will post that one maybe as well but ended up going with APE mainly for integration it was easier that it was a less intensive codebase.  Box2DFlashAS3 can scare non C++ coders with it’s style let alone AS2 coders moving to AS3.

It is slower with all the other animation going on in the site but you can also play on my server here just the Plinko part.

Can you get 10,000?

Google Tech Talk: Simple interactive 3D modeling for all – VideoTrace

3D models from basic video… This can be huge in all sorts of ways.  For exponential growth you need to go virtual.

  • This is a technology called VideoTrace from Australia
  • The Siggraph paper describing VideoTrace is available here (pdf 6MB)
  • Larger videos available here, with a more compressed version here.

Box2DFlashAS3 Version 2 Released – AS3 2D Physics Engine

Box2dFlashAS3 has been updated to version 2.0 complete with ragdolls and Theo Jansen walkers ala APE fame.

Physaxe 2D Flash Physics Kit for haXe and List of Flash Flex Actionscript Physics Engines for AS3

Nicolas Cannasse, a virtual machine genius (maker of MTASC compiler, Neko and haXe (haXe compiles to target flash 6-9 but really only flash 9 is used anymore unless you are making banners)) released the Physaxe 2D Physics kit for haXe today.

It is heavily based on Glaze (demos) and Box2D which the Motor2, Glaze and Box2DFlashAS3 physics kits are all based on. Box2D is a great C++ 2D physics engine, it is simple which lended itself to being ported to AS3 quite easily. It is also a testament to AS3 that C++ kits are being ported into the language, not once, but many times. Also C ports like Chipmunk and other signs point to == AS3 is of fun.

Physaxe is quite amazing you must see the demos (very similar to Glade demos), it will get the inspirational wheels turning in your idea machines.

2D Physics in Flash and AS3 are extremely hot and can be used for many, many things from game development to promotions to simulations to user interface or visualizations and even modeling natural systems. It is nice to have a port of Box2D and similar to glade capabilities with Chipmunk like Glade has.

A game and physics engine for Flash including:

  • Rigid Body Dynamics
  • Scene management
  • Line of sight
  • User Input
  • Scrolling
  • AI

Core parts of the physics solver and collision system are based on the C physics engine Chipmunk

Notes about Physaxe:

Physaxe is a 2D Rigid Body Library written in haXe. It’s been highly optimized for the Flash 9 Player, with the best optimizations available.

Physaxe is based on several existing physics engines, mainly :

  • Box2D, the reference open source physics engine
  • Glaze, an AS3 engine which is a port of Chipmunk, itself based on Box2D

Physaxe features are :

  • rigid body consisting in several shapes
  • shapes supported are circles, segments (with rounded edges) and arbitrary convex polygons
  • customizable broadphase (currently bruteforce and y-sorted list are available)
  • island resolution and sleeping (allow ~0 CPU to be spent when groups are sleeping)
  • constraint solver based on Box2D sequential impulses
  • customizable body properties, such as linear/angular friction and maximized motion

Updated list of physics engines are like this:

AS3 3D Physics Engines (Open Source)

AS3 2D Physics Engines (Open Source)

haXe 2D Physics Engines

Get your game on! It is best to get them out early and often. I need to take my own advice.

AS3, Convert Python Code to Flex AS3 with flex-pypy

I have officially been sucked into the Python vortex. I recently have really been digging IronPython, Jython and good old plain Python but have not ventured here yet. Google (They employ Guido), Microsoft (IronPython) and Sun (Jython) are all becoming infected pythonistas as well. But this is just too cool, Python to AS3 code with flex-pypy. This project is very young but could be fun, source at Google Code.

Haxe has a similar premise where it can compile to Flash6-9 versions of actionscript 2-3 which makes for a system with better reach. Python code for this is lots of fun and very flexible. Python is becoming a baseplane language and one great language for transcending platform lock-in.

Check out this snippet pulled from here (click to see sample game)

#/usr/bin/env python
This simple example has very little to do with the pygame
chimp example, except that it will act the same (more or less)
and it uses the same resources, only they got converted to
mp3s, pngs.

#Import Modules
from pypy.translator.flex.modules.flex import *

class MyRect:
def __init__(self,x,y,w,h):
self.x, self.y,self.w,self.h = x,y,w,h

SCREEN_W = 468

class Game:
def __init__(self):pass

def init(self,screen):
self.screen = screen
screen.layout = ‘absolute’
screen.setActualSize(SCREEN_W, SCREEN_H)

screen.addEventListener(‘click’,chimp_whip) = load_sprite(“py_background_png”);

self.chimp = load_sprite(“py_chimp_png”);

self.orig_y = self.chimp.y

img2 = self.fist = load_sprite(“py_fist_png”)
self.move = 1
self.spin = 0
self.hit = 0
self.hit_move = 1

self.sfx = {}
self.sfx[‘whip’] = load_sound_resource(“py_punch_mp3”)
self.sfx[‘nohit’] = load_sound_resource(“py_whiff_mp3”)

def loop(self):
img = self.chimp
if self.spin:
self.spin -= 1
img.rotation = self.spin*24
img.x += self.move * 8
if img.x > SCREEN_W-img.width:
self.move = -1
if img.x < 0: self.move = 1 if self.hit: self.hit -= 1 self.fist.y += 6 * self.hit_move if self.hit SCREEN_W - img_halfw: newx = SCREEN_W - img.width if newx img.x and e.stageX < img.x+img.width: game.sfx['whip'].play() game.spin = 20 else: game.sfx['nohit'].play() def flash_main( x=1 ): game.init(castToWindow(x))[/sourcecode]

AS3 First Open Source 3d Flash Physics Engine Released – WOWEngine

Seraf, True to the word WOWEngine was released today. It is still a work in progress but it is the first 3d physics engine out of the gate. It is built with many open source kits that are emerging. It can use any of the 3 major flash 3d engines (pv3d, sandy, away3d) and it is built on APE AS3 2d physics engine.

WOW-Engine use Sandy library for all the 3D mathematical computations (matrix, 3D vector, plane). The inner architecture of the engine is also inspired by Sandy’s one.

Collisions and physical reactions are possible thanks to the AS3 physic engine made by Alec Cove, named APE(version 0.2.).. Even if APE is a 2D physic engine, it is possible to extend the contraints on volumes, and that’s the purpose of WOW-engine. WOW-engine extends APE, and allows to simulate physics on 3D volumes.

WOW-Engine is capable to handle positions and rotations of abstract objects, which need to be linked to some visual objects (2D or 3D). The visual objects can be drawn thanks to another library (Sandy3D , Papervision3D, Away3D for 3D).

WOW-Engine use and depend of the Data Structures classes written by polygonal labs.

Basic technical Demos :

Advanced technical Demos:


Motion Detection In Flash (AS2 and AS3) and C#

Currently working on some motion detection with flash/c# and webcams right now. Here’s a basic overview of some motion detection source files and tricks. Most motion detection is based on snapshots and finding brightness of a pixel with all combined colors, then comparing that to previous snapshots to detect enough variance and thus movement. If you have a webcam hooked up, this sample in Flash AS3 highlights this well showing the camera on the left, then the brightness snapshots on the right. It also has an indicator to the amount of movement due to much brightness.


Here is a nice example of motion detection using various motion detection algorithms in C#. This is built on the very slick AForge.NET Computer Imaging Library.

If you ever wanted your own motion detection or recording it is all possible with the basics of checking brightness and snapshots in the most simple form checking how much change or variance their was to bright pixels or the count of bright pixels compared to previous snapshots.

// Calculate white pixels

private int CalculateWhitePixels( Bitmap image )
    int count = 0;
    // lock difference image
    BitmapData data = image.LockBits( new Rectangle( 0, 0, width, height ),
        ImageLockMode.ReadOnly, PixelFormat.Format8bppIndexed );
    int offset = data.Stride - width;
        byte * ptr = (byte *) data.Scan0.ToPointer( );
        for ( int y = 0; y < height; y++ )
            for ( int x = 0; x < width; x++, ptr++ )
                count += ( (*ptr) >> 7 );
            ptr += offset;

    // unlock image
    image.UnlockBits( data );
    return count;

Flash AS2

In Flash this is also possible here is a good article from Flash8 that explains cycling through each pixel to compare the image data and implement motion detection from a webcam.

For instance the basics here show how you can compare each pixel and the change in the brightness for each pixel:


//color of the current pixel in the current snapshot

//red channel

//green channel

//blue channel

nl=Math.sqrt(nr*nr + ng*ng + nb*nb)

//color of the same pixel in the previous snapshot

//red channel

//green channel

//blue channel

bl=Math.sqrt(br*br + bg*bg + bb*bb);

//difference in brightness between now and before

//there was a change in this pixel

Flash AS3

Here is a link to grab a conversion of the AS2 Flash motion detection above to AS3.

Source of AS3 motion detection here.

Grant Skinner has done some interesting things with motion detection with Flash and webcams in the past in the incomplet gallery.

C# or other hardware accelerated capable kits are faster but AS3 and Flash with the new AVM2 virtual machine  should be about 10 times faster than AS2 as much of the improvement in performance and the virtual machine is on iteration speed increases such as loops (i.e. pixel loop).

JSTweener: Javascript Tweener for Animation

Zeh Fernando’s AS2 and AS3 Flash Animation Kit Tweener has inspired a JSTweener port to javascript, why thanks Yuichi Tateno (secondlife).

This actually could be used quite easily with Silverlight and an AgTweener could be very easily created from this. The Tweener like syntax with an object and adding tweens of available properties as an object or array is very simple and could make animation systems much more standard if everything used this not to mention easier for developers to animate in any presentation layer. The syntax makes for the best of the Animation Packages currently available for AS3. If this could be used in other kits it would make animation pretty standard and simple when changing platforms.

JQuery is very lightweight and has a similar syntax on their animate() call. There are many animation javascript kits such as mootools, jquery, dojokit and prototype and others that have similar functionality but it is all handled differently.


JSTweener.addTween(, {
time: 3,
transition: 'linear',
onComplete: function() {},
width: 200,
height: 200,
left: 500,
top: 300

JSTweener Source



Found via Zeh

AS3 Content Aware Resizing or Image Seam Carving

Flash9 AS3 Lisp Interpreter

Well, one thing is for sure AS3 is inspiring programmers and Solve et Coagula made a Lisp interpreter for Flash9/AS3 as proof. Silverlight has some programming advantages over Flash due to the fact that many languages can be used for it and the DLR. But AS3 is a very fun language and inspires lots of great libraries through it’s simplicity. AS3 is based on the Javascript2 ECMA spec and it proves well that it might really take off and is worth your time to learn, you can make toys at least.

Try the AS3 Lisp intepreter 

Use the commands available here 

Some notes from the author:

AS3 Lisp Source

So I got asked a few times to post the source for the AS3 Lisp. I have and it’s here. Please keep in mind:

  • I wrote this a year and a half ago and didn’t know AS3 or Lisp very well
  • I never intended to release the source so I apologize if anyone is offended by any class names, variable names, function names or comments (such as a function call named getGUI.LoadInterface();)
  • I have since figured out a way better way to handle symbols in the system and it would really clean up a ton of stuff
  • Some one over at YCombinator News noticed that closures don’t seem to work and for that I apologize, if I were rewriting this (which I kinda am just in a different form) I would definitely make closures works since I now realize how important they are to Lisp

Dojo Adds Silverlight Effects Support

Dojo Toolkit, a robust javascript library similar to my favorite js kit mootools, recently update and added some support for Silverlight effects. This is one really cool aspect of Silverlight in that it allows you to script/code it in many languages in the DLR (Dynamic Language Runtime) including ironpython, C#, IronRuby, javascript and others. Where as with Flash you only have Actionscript3 available.

Check out the Silverlight demos here:

butterfly.html 20-Aug-2007 18:19 33K
circles.html 20-Aug-2007 18:19 4.0K
clock.html 20-Aug-2007 18:19 7.3K
lion.html 20-Aug-2007 18:19 22K
tiger.html 20-Aug-2007 18:19 100K


  • high quality implementations of previously experimental features: gfx (portable 2D drawing), data wires, offline, storage, cometd, etc.
  • dojox.gfx now includes Sliverlight support
  • many more features and improvements than there’s room for here.


  • unified look and feel for all widgets
  • ambitious a11y and i18n features in every Dijit widget
  • a mature CSS-driven theme system with multiple, high-quality themes
  • huge improvements in system performance
  • data-bound widgets
  • Declarations for lightweight widget writing
  • a new page parser that allows instances of any class, not just widgets
  • no magic


  • reduced API surface area (easier to remember and use)
  • dojo.query() always available, returns real arrays
  • from-scratch high-performance DnD system
  • Base (dojo.js) is 25K on the wire (gzipped)
  • APIs finalized
  • new build system
  • new test harness for both CLI and browser use
  • dojo.behavior now marked stable and based on dojo.query
  • excellent animation APIs with Color animations in Base (always available)
  • all the features you’ve come to count on from Dojo (RPC, JSON-P, JSON, i18n, formatting utilities, etc.)

[ source ]

HAXE Flash9 Assembler Library and Compiling SWF

is a very interesting project that is a scripting language that can create SWF for Flash.

Haxe has now added Flash9 Assembler library called hxASM and released version 1.1.4 that includes performance updates for Flash9 SWFs compiled using Haxe scripting.

I have to compile SWFs dynamically right now in a service and this is a very attractive solution with the new version and the performance improvements. Previously there was some slow down and only static content really worked well but if this is equal or a 30% improvement that is excellent.

Flex 2 can also compile at the command line you can compile flash9 swf with or without the flex2 libraries, when using mxml the flex libraries are included which add 100k or so minimum. It is not required to compile with flex 2 libraries though.

Flex 2 command compiler options

Haxe command compiler tutorial

Using Haxe with Flex 2

Using Haxe hxASM

Full Haxe API (includes all flash libraries)

IronRuby Released, and the Dynamic Language Rising

Microsoft has been busy pushing the DLR (Dynamic Language Runtime) and there is many interesting developments from C# 3.0 to IronPython and now Microsoft released IronRuby public alpha.

Will these languages be treated like J# and JScript.NET? We shall see.

If they perform better than their counterparts it might make python and ruby coders able to take on more platforms and capabilities.

It is still only pre-alpha and missing much but like, it can have an impact when platforms and languages merge.

Earlier this year, Microsoft assured developers that it would be continuing to build languages on top of the Dynamic Language Runtime (DLR). Considering that IronPython had been a success in terms of implementation, the company decided that it would make an attempt at bringing Ruby into the world of .NET. With the help of Ruby expert John Lam, today the company announced that a pre-alpha build of IronRuby is now available. You heard it right, this release is pre-alpha—many Ruby features and libraries have not yet been implemented.

One very interesting aspect of all these DLR languages is that Silverlight Alpha 1.1 supports IronPython. Will it support IronRuby? Silverlight is very fun to code in C# and can be coded in Python as well. This over just AS3 in Flash. However, AS3 is very fun and is based very closely to the Javascript2 spec. Javascript can be argued that it is the most dynamic language and functional language there is that is so widespread in, Javascript 2 could be a big thing. Languages seem to be converging on this point.

For IronRuby fun ScottGu has a great blog post on getting started with IronRuby.