a core of lettuce
こういうのってmatrixで縮小するよりbitmapのscaleで縮小したほうがきれいになるんですね
/**
* Copyright matacat ( http://wonderfl.net/user/matacat )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/djs1
*/
package
{
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.Shape;
import flash.display.Sprite;
import flash.events.Event;
public class lettuce extends Sprite
{
private const WZ:int = stage.stageWidth;
private const HI:int = stage.stageHeight;
private const SIDE:int = WZ <= HI ? WZ : HI;
private const RADIUS:Number = SIDE / 2 - MAX;
private const D2R:Number = Math.PI / 180;
private const THETA:Number = 5;
private const MAX:Number = 30;
private const MIN:Number = 16;
private const THRESHOLD:Number = 18;
private const DELTA:Number = 1;
private const REDUCION:Number = 0.995;
private const BG_COLOR:uint = 0x104020;
private const CORE_COLOR:uint = 0x90F0B0;
private var background:Sprite = new Sprite();
private var canvas:Shape = new Shape();
private var displayBmd:BitmapData = new BitmapData(SIDE, SIDE, false, BG_COLOR);
private var captureBmd:BitmapData = displayBmd.clone();
private var degree:Number = 0;
private var thickness:Number = THRESHOLD;
private var isIncreasing:Boolean = true;
public function lettuce()
{
graphics.beginFill(BG_COLOR);
graphics.drawRect(0, 0, WZ, HI);
background.graphics.beginFill(BG_COLOR);
background.graphics.drawRect(0, 0, SIDE, SIDE);
background.x = (WZ - SIDE) / 2;
background.y = (HI - SIDE) / 2;
addChild(background);
var bmp:Bitmap = new Bitmap(displayBmd, "auto", true);
bmp.scaleX = REDUCION;
bmp.scaleY = REDUCION;
bmp.x = SIDE * (1 - REDUCION) / 2;
bmp.y = SIDE * (1 - REDUCION) / 2;
background.addChild(bmp);
canvas.graphics.beginFill(CORE_COLOR);
canvas.graphics.drawCircle(0, -RADIUS, thickness);
canvas.x = SIDE / 2;
canvas.y = SIDE / 2;
background.addChild(canvas);
addEventListener(Event.ENTER_FRAME, update);
}
private function update(e:Event):void
{
captureBmd.draw(background);
displayBmd.copyPixels(captureBmd, captureBmd.rect, captureBmd.rect.topLeft);
degree += THETA;
if (isIncreasing) thickness += DELTA;
else thickness -= DELTA;
if (thickness >= MAX || thickness <= MIN) isIncreasing = !isIncreasing;
canvas.graphics.clear();
if (thickness >= THRESHOLD) {
canvas.graphics.beginFill(CORE_COLOR);
canvas.graphics.drawCircle(
Math.sin(degree * D2R) * RADIUS,
Math.cos(degree * D2R) * -RADIUS,
thickness
);
}
}
}
}