Author Archives: Zevan

Static Stage and More…

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 [...]

Posted in DisplayObject, OOP, variables | Tagged , , | Leave a comment

Not a Snippet (wandering robots)

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;

  [...]

Posted in Events, OOP, arrays, motion | Tagged , , | 3 Comments

Canonical Representation of XOR

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 [...]

Posted in Operators, one-liners | Tagged , | 2 Comments

NAND

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 [...]

Posted in Operators, misc | Tagged , | Leave a comment