+

Auge mit haXe, AS2

Das sieht zwar genauso aus, wie die Actionscript 3 Version, aber hier in dieser ersten Variante hatte ich das Auge noch nicht in eine eigene Klasse gepackt. Was zum Problem werden könnte, wenn ich mehr als ein Auge haben will.

Ausserdem musste man bei AS2 die Kreise noch mit Splines zeichnen (siehe function kreis() ganz unten auf dieser Seite) und überhaupt ist AS3 besser und performanter und so! Jedenfalls war das einer meiner ersten Versuche mit haXe, ende 2008.


import flash.MovieClip;

class Auge {

    static var mc : MovieClip; // der gesamte film
    static var auge : MovieClip;
    static var pupille : MovieClip;
    static var radius:Int =  50;
    static var hoehe:Int = 200;

    static var zentrumX : Int = 200; // zentrum der Buehne
    static var zentrumY : Int = 200;

    static function main() {
      mc = flash.Lib.current;
      augeMalen();
      mc.onEnterFrame = augeBewegen;
    } // main()

    static function augeBewegen() {
      var xm: Float = mc._xmouse-zentrumX;
      var ym: Float = mc._ymouse-zentrumY;
      var abstand : Float = Math.sqrt((xm*xm)+(ym*ym));

      if (ym >= 0) {
        auge._rotation = Math.acos(xm/abstand )*57.29578; // 180/PI
      } else {
        auge._rotation = -Math.acos(xm/abstand )*57.29578;
      }

      var alpha:Float = Math.atan(hoehe/abstand);
      var rpol:Float = Math.cos(alpha) *radius;

      pupille._xscale = Math.sin(alpha) *100; // 200/PI
      pupille._x = rpol;

    } // augeBewegen()

    static function augeMalen() {
      auge = mc.createEmptyMovieClip ("auge", mc.getNextHighestDepth());
      var pupillenradius :Float = 3;
      kreis(auge, 0, 0, Math.sqrt( radius*radius + (radius/pupillenradius)*(radius/pupillenradius) )  ); // augenradius geht bis zum Pupillenrand und nicht nur bis zum Pupillenmittelpunkt (radius)
      auge._alpha = 10;
      pupille = auge.createEmptyMovieClip ("pupille", mc.getNextHighestDepth());
      kreis( pupille, 0, 0, radius/pupillenradius );
      kreis( pupille, 0, 0, radius/pupillenradius/1.5 );
      pupille._alpha = 300;
      auge._x = zentrumX;
      auge._y = zentrumY;
    } // augeMalen()

    static function kreis(mc, x, y, r:Float) {
      mc.beginFill(0x234090,90);
      mc.moveTo(x+r, y);
      mc.curveTo(r+x, Math.tan(Math.PI/8)*r+y, Math.sin(Math.PI/4)*r+x, Math.sin(Math.PI/4)*r+y);
      mc.curveTo(Math.round( Math.tan(Math.PI/8)*r+x ), r+y, x, r+y);
      mc.curveTo(Math.round( -Math.tan(Math.PI/8)*r+x ), r+y, -Math.sin(Math.PI/4)*r+x, Math.sin(Math.PI/4)*r+y);
      mc.curveTo(-r+x, Math.tan(Math.PI/8)*r+y, -r+x, y);
      mc.curveTo(-r+x, -Math.tan(Math.PI/8)*r+y, -Math.sin(Math.PI/4)*r+x, -Math.sin(Math.PI/4)*r+y);
      mc.curveTo(Math.round( -Math.tan(Math.PI/8)*r+x ), -r+y, x, -r+y);
      mc.curveTo(Math.round( Math.tan(Math.PI/8)*r+x ), -r+y, Math.sin(Math.PI/4)*r+x, -Math.sin(Math.PI/4)*r+y);
      mc.curveTo(r+x, -Math.tan(Math.PI/8)*r+y, r+x, y);
      mc.endFill();
    } // kreis()

} // class Auge