2x mod 1 map

Actionscript:
  1. [SWF(width=800, height=600)]
  2. var xn1:Number;
  3. var xn:Number = Math.random() * Math.random() * .2;
  4. var inc:int = 0;
  5. var xp:Number = 10;
  6. var yp:Number = 10;
  7. var count:int = 1;
  8. scaleX = scaleY = 2;
  9. graphics.lineStyle(0,0x00000);
  10. addEventListener(Event.ENTER_FRAME, onLoop);
  11. function onLoop(evt:Event):void {
  12.    
  13.      xn1 = 2 * xn % 1;
  14.      xn = xn1;
  15.      if (inc == 0){
  16.           graphics.moveTo(xp + inc, yp + 30 - xn1 * 30);
  17.      }else{
  18.          graphics.lineTo(xp + inc, yp + 30 - xn1 * 30);
  19.      }
  20.      inc++
  21.      if (inc == 50){
  22.          inc = 0;
  23.          xp = 10 + count % 6 * 60;
  24.          yp = 10 + int(count / 6) * 60;
  25.          xn = Math.random() * Math.random() * .2;
  26.          trace(xn);
  27.          count++;
  28.      }
  29. }

This snippet plots 2x mod 1 maps with random starting values for xn. More info over at wikipedia and mathworld.

This entry was posted in Math, misc, motion and tagged , , . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*