forked from: forked from: うにょうにょ
forked from forked from: うにょうにょ (diff: 1)
ActionScript3 source code
/**
* Copyright bradsedito ( http://wonderfl.net/user/bradsedito )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/4nRD
*/
// forked from makc3d's forked from: うにょうにょ
// forked from saharan's うにょうにょ
package {
import flash.ui.*;
import fl.controls.*;
import flash.text.*;
import flash.geom.*;
import flash.events.*;
import flash.display.*;
[SWF(width = 465, height = 465, frameRate = 60)]
public class PixelArt extends Sprite {
private const WIDTH:int = 465;
private const HEIGHT:int = 465;
private var prevMouseX:int;
private var prevMouseY:int;
private var world:BitmapData;
private var bitmap:Bitmap;
private var count:int;
private var mousePressed:Boolean;
public function PixelArt() {
initialize();
}
private function initialize():void {
count = 0;
world = new BitmapData(WIDTH, HEIGHT, false, 0);
world.draw(stage);
bitmap = new Bitmap(world);
addChild(bitmap);
stage.addEventListener(MouseEvent.MOUSE_DOWN,
function():void {
mousePressed = true;
});
stage.addEventListener(MouseEvent.MOUSE_UP,
function():void {
mousePressed = false;
});
addEventListener(Event.ENTER_FRAME, frame);
stage.quality = StageQuality.LOW;
}
private function frame(e:Event):void {
//TODO
var s:Sprite = new Sprite();
world.lock();
if(mousePressed) {
s.graphics.beginFill(0xffffff);
s.graphics.drawEllipse(mouseX - 20, mouseY - 20, 40, 40);
s.graphics.endFill();
s.graphics.lineStyle(20, 0xffffff);
s.graphics.moveTo(prevMouseX, prevMouseY);
s.graphics.lineTo(mouseX, mouseY);
world.draw(s);
}
world.fillRect(new Rectangle(0, 0, WIDTH, 1), 0);
world.fillRect(new Rectangle(0, 0, 1, HEIGHT), 0);
world.fillRect(new Rectangle(0, HEIGHT - 1, WIDTH, 1), 0);
world.fillRect(new Rectangle(WIDTH - 1, 0, WIDTH, HEIGHT), 0);
prevMouseX = mouseX;
prevMouseY = mouseY;
var i:int;
var j:int;
for(i = 1; i < WIDTH - 1; i++) {
for(j = 1; j < HEIGHT - 1; j++) {
doPixel(i, j);
}
}
count++;
world.unlock();
}
private function doPixel(x:int, y:int):void {
var c:int = 4.00000018 * world.getPixel(x, y) -
world.getPixel(x - 1, y) - world.getPixel(x, y - 1) -
world.getPixel(x + 1, y) - world.getPixel(x, y + 1);
if (c < 0) c = 0;
world.setPixel(x, y, c);
}
}
}