By Zevan | February 1, 2009
CLICK HERE TO COPY
Actionscript:
package {
import flash.display.*;
public class Main extends MovieClip{
private static var _display:MovieClip;
private static var _stage:Stage;
// use getters instead of public static vars so they
// cannot be reset [...]
By Zevan | January 31, 2009
CLICK HERE TO COPY
Actionscript:
package {
import flash.display.Sprite;
[SWF(width=500, height=500, backgroundColor=0xEFEFEF, frameRate=30)]
public class Main extends Sprite{
private var _robotManager:RobotManager;
public function Main(){
_robotManager = new RobotManager(this, 12);
}
}
}
class RobotManager{
private var _robots:Array;
[...]
By Zevan | January 30, 2009
CLICK HERE TO COPY
Actionscript:
// xor
trace(0 ^ 0);
trace(0 ^ 1);
trace(1 ^ 0);
trace(1 ^ 1);
trace("canonical representation of xor");
trace(xor(0, 0));
trace(xor(0, 1));
trace(xor(1, 0));
trace(xor(1, 1));
function xor(a:int, b:int):int{
//1-a is the same as int(!a)
return 1-a & b | a & 1-b;
}
/*
outputs:
0
1
1
0
canonical representation of xor
0
1
1
0
*/
I learned about this from reading The Elements of Computing Systems: Building a [...]
By Zevan | January 29, 2009
CLICK HERE TO COPY
Actionscript:
var a:int, b:int;
a = 0;
b = 0;
trace(int(!(a & b)));
a = 0;
b = 1;
trace(int(!(a & b)));
a = 1;
b = 0;
trace(int(!(a & b)));
a = 1;
b = 1;
trace(int(!(a & b)));
/*
outputs:
1
1
1
0
*/
/*
NAND
00 1
01 1
10 1
11 0
*/
I started reading "The Elements of Computing Systems: Building a Modern Computer from First Principles" By Noam Nisan [...]