By Zevan | December 31, 2009
Actionscript:
-
var one:Array = [1,2,3];
-
var two:Array = [10, 20, 30];
-
-
var zipOneTwo:Array = zip(one, two);
-
-
// trace each tupple
-
for each (var tuple:Array in zipOneTwo){
-
trace(tuple);
-
}
-
-
/* outputs:
-
1,10
-
2,20
-
3,30
-
*/
-
-
function zip(a:Array, b:Array):Array{
-
var longest:Array = (a.length>= b.length) ? a : b;
-
var zipped:Array = [];
-
for (var i:int = 0; i<longest.length; i++){
-
zipped.push([a[i], b[i]]);
-
}
-
return zipped;
-
}
This snippet shows a function called zip that takes two arrays and returns a two dimensional array of tuples. Just imagine that each array is one side of a zipper and you'll sort of get the idea...
I do wish flash would trace this:
[[1, 10], [2, 20], [3, 30]]
We shouldn't have to write a utility function to see the real array structure...
I've been messing with haskell for a few days now... just for fun I thought I'd write a few functions inspired by it... this is the first one...
Posted in arrays | Tagged actionscript, as3, flash |
By Zevan | December 30, 2009
Actionscript:
-
var boxA:Shape = Shape(addChild(new Shape()));
-
with (boxA.graphics) beginFill(0), drawRect(-10,-10,20,20);
-
-
var boxB:Shape = Shape(addChild(new Shape()));
-
with (boxB.graphics) beginFill(0), drawRect(-10,-10,20,20);
-
-
boxA.x = 100;
-
boxA.y = 100;
-
-
boxB.x = 200;
-
boxB.y = 100;
-
-
var rot:Number = 32750;
-
-
addEventListener(Event.ENTER_FRAME, onLoop);
-
function onLoop(evt:Event):void {
-
rot += 1
-
// will stop rotating
-
boxA.rotation = rot
-
// will keep rotating
-
boxB.rotation = rot % 360;
-
}
I recently became aware of a strange aspect of the rotation property on DisplayObjects. For some reason, once it's value goes a little beyond ~32750 the DisplayObject will simply stop rotating. If you read the rotation property it is still changing, but there is no visual update - a quick check on the DisplayObject.transform.matrix property will show that the value has stopped.
The easy fix is to use mod before applying the value to the rotation property. Surprised I've never come across this one before. Maybe someone can shed some light on this.
// for people searching google for solutions to this problem I'll add the following key words:
MovieClip stops rotating, DisplayObject stops rotating, rotation property broken, not rotating
By Zevan | December 17, 2009
I took some pictures of Four by Four last night:
Have a look at them over at flickr...
Posted in binary | Tagged misc |
By Zevan | December 14, 2009
Two years ago I had an idea for a programming experiment. After writing a proof of concept in Processing, I never did anything else with it. A few weeks back I decided to revisit the project and I created a finalized version. Have a look at it here (the instructions are important so be sure to read them):