Posted By

alexaivars on 07/29/09


Tagged


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

MacEvelly


anaglyph 3d


 / Published in: ActionScript 3
 

  1. package {
  2. import flash.display.Bitmap;
  3. import flash.display.BitmapData;
  4. import flash.display.BitmapDataChannel;
  5. import flash.display.BlendMode;
  6. import flash.display.Sprite;
  7. import flash.display.StageAlign;
  8. import flash.display.StageScaleMode;
  9. import flash.geom.ColorTransform;
  10. import flash.geom.Matrix;
  11. import flash.geom.Point;
  12. import flash.geom.Rectangle;
  13.  
  14. public class Work extends Sprite
  15. {
  16. [Embed(source="image.jpg")]
  17. private var Image1:Class;
  18.  
  19. [Embed(source="alpha.jpg")]
  20. private var Image2:Class;
  21.  
  22.  
  23. private var tx:Number = 10;
  24. private var ty:Number = 10;
  25.  
  26. public function Work()
  27. {
  28. stage.scaleMode = StageScaleMode.NO_SCALE;
  29. stage.align = StageAlign.TOP;
  30. test1();
  31. test2();
  32. test3();
  33. }
  34.  
  35. private function test1():void
  36. {
  37. var source:BitmapData = (new Image1() as Bitmap).bitmapData;
  38.  
  39. var offset:Matrix = new Matrix();
  40.  
  41. var bmd:BitmapData = new BitmapData(source.width-tx,source.height-ty,source.transparent,0xFF0000);
  42.  
  43. bmd.copyChannel(source,new Rectangle(tx,ty,source.width,source.height),new Point(0,0), BitmapDataChannel.RED,BitmapDataChannel.RED);
  44. bmd.draw(source,offset, new ColorTransform(0),BlendMode.DIFFERENCE );
  45.  
  46. addChild( new Bitmap(bmd) );
  47. }
  48.  
  49.  
  50. private function test2():void
  51. {
  52. var source:BitmapData = (new Image1() as Bitmap).bitmapData;
  53.  
  54. var offset:Matrix = new Matrix();
  55. offset.translate(tx,ty);
  56.  
  57. var bmd:BitmapData = source.clone();
  58.  
  59. bmd.copyChannel(source,source.rect,new Point(0,0), BitmapDataChannel.BLUE,BitmapDataChannel.RED);
  60. bmd.copyChannel(source,source.rect,new Point(0,0), BitmapDataChannel.GREEN,BitmapDataChannel.RED);
  61.  
  62. bmd.copyChannel(source,source.rect,new Point(-tx,-ty), BitmapDataChannel.ALPHA,BitmapDataChannel.ALPHA);
  63. bmd.copyChannel(source,source.rect,new Point(-tx,-ty), BitmapDataChannel.RED,BitmapDataChannel.RED);
  64.  
  65. addChild( new Bitmap(bmd) ).y = 200;
  66. }
  67.  
  68. private function test3():void
  69. {
  70. var source:BitmapData = (new Image2() as Bitmap).bitmapData;
  71.  
  72. var offset:Matrix = new Matrix();
  73. offset.translate(tx,ty);
  74.  
  75. var bmd:BitmapData = source.clone();
  76.  
  77. bmd.copyChannel(source,source.rect,new Point(0,0), BitmapDataChannel.BLUE,BitmapDataChannel.RED);
  78. bmd.copyChannel(source,source.rect,new Point(0,0), BitmapDataChannel.GREEN,BitmapDataChannel.RED);
  79. bmd.copyChannel(source,source.rect,new Point(-tx,-ty), BitmapDataChannel.ALPHA,BitmapDataChannel.ALPHA);
  80. bmd.copyChannel(source,source.rect,new Point(-tx,-ty), BitmapDataChannel.RED,BitmapDataChannel.RED);
  81.  
  82. addChild( new Bitmap(bmd) ).y = 400;
  83. }
  84.  
  85. }
  86. }

Report this snippet  

You need to login to post a comment.