Esempio n. 1
0
 static FishTankApplication()
 {
     Window.AddEventListener("load", delegate(ElementEvent e) {
         FishTank fishtank = new FishTank();
         fishtank.Run();
     }, /* useCapture */ false);
 }
Esempio n. 2
0
 static FishTankApplication()
 {
     Window.AddEventListener("load", delegate(ElementEvent e) {
         FishTank fishtank = new FishTank();
         fishtank.Run();
     }, /* useCapture */ false);
 }
Esempio n. 3
0
        public Fish(FishTank tank, double x, double y, double z, ImageElement fishStrip, CanvasContext2D context) {
            _tank = tank;

            _x = x;
            _y = y;
            _z = z;
            _zFactor = 1;
            _species = Math.Floor(Math.Random() * FishTank.FishSpecies);
            _cellIndex = Math.Floor(Math.Random() * (FishTank.CellsInFishStrip - 1));
            _cellReverse = -1;

            _angle = 2 * Math.PI * Math.Random();
            _xAngle = Math.Cos(_angle);
            _yAngle = Math.Sin(_angle);
            _zAngle = 1 - 2 * Math.Round(Math.Random());
            _scale = 0.1;
            _flip = 1;
            _velocity = 100;

            // Stop fish from swimming straight up or down
            if ((_angle > Math.PI * 4 / 3) && (_angle < Math.PI * 5 / 3) ||
                (_angle > Math.PI * 1 / 3) && (_angle < Math.PI * 2 / 3)) {
                _angle = Math.PI * 1 / 3 * Math.Random();
                _xAngle = Math.Cos(_angle);
                _yAngle = Math.Sin(_angle);
            }

            // Face the fish the right way if angle is between 6 o'clock and 12 o'clock
            if ((_angle > Math.PI / 2) && (_angle < Math.PI / 2 * 3)) {
                _flip = -1;
            }

            _fishStrip = fishStrip;
            _context = context;
        }
Esempio n. 4
0
        public Fish(FishTank tank, double x, double y, double z, ImageElement fishStrip, CanvasContext2D context)
        {
            _tank = tank;

            _x           = x;
            _y           = y;
            _z           = z;
            _zFactor     = 1;
            _species     = Math.Floor(Math.Random() * FishTank.FishSpecies);
            _cellIndex   = Math.Floor(Math.Random() * (FishTank.CellsInFishStrip - 1));
            _cellReverse = -1;

            _angle    = 2 * Math.PI * Math.Random();
            _xAngle   = Math.Cos(_angle);
            _yAngle   = Math.Sin(_angle);
            _zAngle   = 1 - 2 * Math.Round(Math.Random());
            _scale    = 0.1;
            _flip     = 1;
            _velocity = 100;

            // Stop fish from swimming straight up or down
            if ((_angle > Math.PI * 4 / 3) && (_angle < Math.PI * 5 / 3) ||
                (_angle > Math.PI * 1 / 3) && (_angle < Math.PI * 2 / 3))
            {
                _angle  = Math.PI * 1 / 3 * Math.Random();
                _xAngle = Math.Cos(_angle);
                _yAngle = Math.Sin(_angle);
            }

            // Face the fish the right way if angle is between 6 o'clock and 12 o'clock
            if ((_angle > Math.PI / 2) && (_angle < Math.PI / 2 * 3))
            {
                _flip = -1;
            }

            _fishStrip = fishStrip;
            _context   = context;
        }