flash on 2010-5-12
/**
* Copyright omochieater ( http://wonderfl.net/user/omochieater )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/zsgW
*/
package {
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.Graphics;
import flash.display.Shape;
import flash.display.Sprite;
import flash.geom.Point;
public class FlashTest extends Sprite {
public function FlashTest() {
// write as3 code here..
addChild(mBG);
addChild(mCanvas);
mCanvas.bitmapData.copyPixels(mImage, mImage.rect, mPoint);
}
private function createShape():Shape {
var shape:Shape = new Shape();
var g:Graphics = shape.graphics;
g.beginFill(0x00AAAA, 0.5);
g.drawCircle(80, 80, 80);
g.beginFill(0x55EEFF, 1.0);
g.drawCircle(80, 80, 40);
g.endFill();
return shape;
}
private function createBitmapData(shape:Shape):BitmapData {
var bmd:BitmapData = new BitmapData(shape.width, shape.height, true, 0x0);
bmd.draw(shape);
return bmd;
}
private var mPoint:Point = new Point();
private var mImage:BitmapData = createBitmapData(createShape());
private var mCanvas:Bitmap = new Bitmap(new BitmapData(stage.stageWidth, stage.stageHeight, true, 0x0));
private var mBG:CheckedBitmap = new CheckedBitmap(stage.stageWidth, stage.stageHeight, 10, 0xAAAAAA, 0x666666);
}
}
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.geom.Rectangle;
internal class CheckedBitmap extends Bitmap {
public function CheckedBitmap(stageWidth:uint, stageHeight:uint, split:Number, color1:uint, color2:uint) {
super(new BitmapData(stageWidth, stageHeight, false, 0x0));
drawChecked(split, color1, color2);
}
private function drawChecked(split:uint, color1:uint, color2:uint):void {
var i:uint, _i:Number;
var j:uint, _j:Number;
fillRect(0, 0, width, height, color1);
for (j = 0, _j = height/split; j < _j; ++j) {
for (i = 0, _i = width/split; i < _i; ++i) {
if ((i & 0x01) == 1) {
if ((j & 0x01) == 0) fillRect(i*_i, j*_j, _i, _j, color2);
}
else {
if ((j & 0x01) == 1) fillRect(i*_i, j*_j, _i, _j, color2);
}
}
}
}
private function fillRect(x:Number, y:Number, width:Number, height:Number, color:uint):void {
mRectangle.x = x;
mRectangle.y = y;
mRectangle.width = width;
mRectangle.height = height;
bitmapData.fillRect(mRectangle, color);
}
private static const mRectangle:Rectangle = new Rectangle();
}