In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

Chapter 36 Example 10

/**
 * Copyright actionscriptbible ( http://wonderfl.net/user/actionscriptbible )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/x4yq
 */

package {
  import flash.display.*;
  import flash.events.Event;
  import flash.media.Camera;
  import flash.media.Video;
  [SWF(width="500",height="500",frameRate="20")]
  public class ch36ex10 extends Sprite {
    protected const COLORS:Vector.<uint> = new <uint>[0xff0000, 0xff00, 0xff];
    protected const SCALE:Number = 200 / 256;
    protected var bmp:BitmapData;
    protected var video:Video;
    protected var hstR:Shape, hstG:Shape, hstB:Shape;
    protected var allHstShapes:Vector.<Shape>;
    public function ch36ex10() {
      bmp = new BitmapData(stage.stageWidth, stage.stageHeight);
      video = new Video(stage.stageWidth, stage.stageHeight);
      video.attachCamera(Camera.getCamera());
      addChild(video);
      stage.addEventListener(Event.ENTER_FRAME, onEnterFrame);
      var hstbox:Sprite = new Sprite();
      addChild(hstbox);
      hstbox.x = stage.stageWidth - 270 - 10;
      hstbox.y = 10;
      hstbox.graphics.lineStyle(0, 0xffffff);
      hstbox.graphics.beginFill(0, 0.5);
      hstbox.graphics.drawRect(0, 0, 270, 150);
      hstR = new Shape(); hstG = new Shape(); hstB = new Shape();
      allHstShapes = new <Shape>[hstR, hstG, hstB];
      for each (var hstShape:Shape in allHstShapes) {
        hstbox.addChild(hstShape);
        hstShape.y = hstbox.height - 10;
        hstShape.blendMode = BlendMode.ADD;
        hstShape.rotationY = 35;
        hstShape.scaleY = -1;
      }
      hstR.x = 10; hstG.x = 30; hstB.x = 50;
    }
    protected function onEnterFrame(event:Event):void {
      bmp.draw(video);
      var allHstData:Vector.<Vector.<Number>> = bmp.histogram(bmp.rect);
      var PIXELCOUNT:int = bmp.width*bmp.height;
      for (var i:int = 0; i < allHstShapes.length; i++) {
        var hstData:Vector.<Number> = allHstData[i];
        var g:Graphics = allHstShapes[i].graphics;
        g.clear();
        g.beginFill(COLORS[i]);
        for (var x:int = 0; x < hstData.length; x++) {
          g.drawRect(x*SCALE, 0, SCALE, hstData[x]/PIXELCOUNT * 1500*SCALE);
        }
      }
    }
  }
}