Category Archives: motion

Sine Cosine Walk

Actionscript:
  1. stage.frameRate = 30;
  2. var footA:MovieClip = makeFoot(0);
  3. var footB:MovieClip = makeFoot(Math.PI);
  4.  
  5. addEventListener(Event.ENTER_FRAME, onLoop);
  6. function onLoop(evt:Event):void {
  7.      graphics.clear();
  8.      graphics.lineStyle(0,0x000000);
  9.      graphics.moveTo(footA.x, footA.y);
  10.      graphics.curveTo(footA.x + 20, footA.y - 50, 200, 100);
  11.      graphics.curveTo(footB.x + 20, footB.y - 50, footB.x, footB.y);
  12. }
  13.  
  14. function makeFoot(startAngle:Number):MovieClip {
  15.     var mc:MovieClip = MovieClip(addChild(new MovieClip()));
  16.     with(mc.graphics) beginFill(0x000000), curveTo(10,-10, 20, 0);
  17.     mc.x = 200;
  18.     mc.y = 200;
  19.     mc.sx = mc.x;
  20.     mc.sy = mc.y;
  21.     mc.t = startAngle;
  22.     mc.r = 50;
  23.     mc.addEventListener(Event.ENTER_FRAME, onRunFoot);
  24.     return mc;
  25. }
  26. function onRunFoot(evt:Event):void {
  27.     var mc:MovieClip = MovieClip(evt.currentTarget);
  28.      with(mc){
  29.         x = sx + r * Math.cos(t);
  30.         y = Math.min(sy, sy + r * Math.sin(t));
  31.         rotation = sy - y;
  32.         t += .15;
  33.      }
  34. }

This is a funny looking snippet that creates a very primitive walk cycle with the Graphics class and sine and cosine.

Posted in motion | Tagged , | Leave a comment