Moving clouds

A moving version of the Perlin noise clouds. Noise generation is pretty hard on the processor, though Gnash needs only about half as much CPU as the Adobe Flash player for the same result.

ActionScript code follows:

BitmapData = flash.display.BitmapData;

MovieClip.prototype.drawCircle = function(r, x, y) {

   this.moveTo(x + r, y);

   var segments = 8;
   var radians = Math.PI * 2 / segments;

   var a = Math.tan(Math.PI / segments); 

   for (var i = 0; i < segments; ++i) {
      var k = i + 1;
      var endx = r * Math.cos(k * radians);
      var endy = r * Math.sin(k * radians);
      var ax = endx + r * a * Math.cos((k * radians) - Math.PI / 2);
      var ay = endy + r * a * Math.sin((k * radians) - Math.PI / 2);
      this.curveTo(x + ax, y +  ay, x + endx, y + endy); 
   };

};

var w = 200;
var h = 200;

mc1 = _root.createEmptyMovieClip("mc1", 1); 
mc2 = _root.createEmptyMovieClip("mc1", 2); 

mc1.beginFill(0xaaaaff);
mc1.lineTo(w, 0);
mc1.lineTo(w, h);
mc1.lineTo(0, h);
mc1.endFill();

mc1.beginFill(0xeeeecc);
mc1.drawCircle(15, 120, 40);

bd2 = new BitmapData(w, h, true);
mc2.attachBitmap(bd2, 4);

mc2.o1 = { x:0, y:0 };
mc2.o2 = { x:0, y:0 };
mc2.o3 = { x:0, y:0 };
offsets = [ mc2.o1, mc2.o1, mc2.o2, mc2.o2, mc2.o3 ];

mc2.onEnterFrame = function() {
    this.o1.x -= 0.5;
    this.o2.x -= 1.5;
    this.o3.x -= 3.0;
    bd2.perlinNoise(350, 60, 5, 47, false, true, 8, true, offsets);
};