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

forked from: forked from: native 3D is good for anything?

かっこよかったのでforkした
文字をかけるようにする
/**
 * Copyright Albert ( http://wonderfl.net/user/Albert )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/wcU4
 */

// forked from Albert's forked from: native 3D is good for anything?
// forked from Albert's native 3D is good for anything?
// forked from Albert's forked from: forked from: forked from: Pixels
// forked from Albert's forked from: forked from: Pixels
// forked from shohei909's forked from: Pixels
// forked from Saqoosha's Pixels

//かっこよかったのでforkした
//文字をかけるようにする

package {
    import flash.events.Event;
    import frocessing.color.ColorHSV;

    import flash.display.Sprite;
    import flash.display.StageAlign;
    import flash.display.StageQuality;
    import flash.display.StageScaleMode;
    import flash.events.MouseEvent;
    import flash.geom.PerspectiveProjection;
    import flash.utils.getTimer;
    import flash.text.TextField;
    import flash.text.TextFieldType;

   [SWF(backgroundColor="#000000", frameRate="60", width="475", height="475")]
    
    
    public class Pixels extends Sprite {

        private var _canvas:Canvas;

        private var _color:ColorHSV;
        private var _px:int;
        private var _py:int;
        
        private var _x:int;
        private var _y:int
        private var drawing:Boolean;
        
        public function Pixels() {
            stage.scaleMode = StageScaleMode.NO_SCALE;
            stage.align = StageAlign.TOP_LEFT;
            //stage.quality = StageQuality.LOW;
            
            var pp:PerspectiveProjection = root.transform.perspectiveProjection;
            //pp.focalLength = 2000;
            root.transform.perspectiveProjection = pp;
            
            _canvas = addChild(new Canvas()) as Canvas;
            _color = new ColorHSV();
            _px = _py = -1;
            

            addEventListener(Event.ENTER_FRAME, _onEnterFrame);
            addEventListener(MouseEvent.MOUSE_DOWN, _onMouseDown);
            addEventListener(MouseEvent.MOUSE_UP, _onMouseUp);
            addEventListener(MouseEvent.MOUSE_MOVE, _onMouseMove);            
        }



        private function _onEnterFrame(event:Event):void {

        }
       
        
        private function _onMouseDown(event:MouseEvent):void {
            _draw();
            drawing = true;
        }
    
        
        private function _onMouseMove(event:MouseEvent):void {
            if (drawing)
                _draw();
            else
           { 
                x += mouseX - 470;
                y += mouseY - 470;
            }
        }
    
        
        private function _onMouseUp(event:MouseEvent):void {
            _px = _py = -1;
            drawing = false;
        }
        
        
        private function _draw():void {
            _color.h = getTimer() / 20 + Math.random() * 50;
            var cx:int = mouseX / 5/5;
            var cy:int = mouseY / 5/5;
            if (_px >= 0) _canvas.drawLine(_px, _py, cx, cy, _color.value);
            _px = cx;
            _py = cy;
        }
    }
}

import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.PixelSnapping;
import flash.display.Shape;
import flash.display.Sprite;


class Canvas extends Sprite {
    
    private const _height:int = 150;
    private var _image:Bitmap;
    private var _floor:Sprite;
    private var _ceil:Sprite;
    //private var _grid:Bitmap;
    
    private var _px:int;
    private var _py:int;

    
    public function Canvas() {
        init();
    }
    public function init():void{
        mouseChildren = false;
        
        var b:BitmapData = new BitmapData(95 + 1, 95, false, 0x0);
        _image = addChild(new Bitmap(b, PixelSnapping.ALWAYS, false)) as Bitmap;
        _image = addChild(new Bitmap(b)) as Bitmap;
        _image.scaleX = _image.scaleY = 5;
        _floor = new Sprite();
        addChild(_floor);
        _ceil = new Sprite();
        addChild(_ceil);
        _ceil.z=0;
        scaleX=scaleY=5;
        
        b = new BitmapData(475 + 5, 475, true, 0x0);
        
        _px = _py = -1;
        
    }


    public function drawLine(x0:int, y0:int, x1:int, y1:int, color:int):void {
        var steep:Boolean = Math.abs(y1 - y0) > Math.abs(x1 - x0);
        var tmp:int;
        if (steep) {
            tmp = x0;
            x0 = y0;
            y0 = tmp;
            tmp = x1;
            x1 = y1;
            y1 = tmp;
        }
        if (x0 > x1) {
            tmp = x0;
            x0 = x1;
            x1 = tmp;
            tmp = y0;
            y0 = y1;
            y1 = tmp;
        }
        var deltax:int = x1 - x0;
        var deltay:int = Math.abs(y1 - y0);
        var error:int = deltax / 2;
        var ystep:int;
        var y:int = y0;
        if (y0 < y1) {
            ystep = 1;
        } else {
            ystep = -1;
        }
        for (var x:int = x0; x <= x1; x++) {
            if (steep) {
                setPixel(y, x, color);
            } else {
                setPixel(x, y, color);
            }
            error = error - deltay;
            if (error < 0) {
                y = y + ystep;
                error = error + deltax;
            }
        }
    }
    
    public function drawDataPoint(d:BitmapData, x:int, y:int, color:uint):Boolean{
        if( d.getPixel(x,y) < 0xFFFFFF){
            setPixel(x, y, color);
            return true;
        }
        return false;
    }
    
    public function drawWall(x:int, y:int, color:uint, rot:int):void{
        var s:Shape = new Shape();
        s.graphics.beginFill(color);
        s.graphics.drawRect(0, 0, _height, 5);
        s.graphics.endFill();
        s.rotationY = 90;
        s.rotationZ = rot;
        s.x=x;
        s.y=y;      
        s.alpha = 0.5;
        _floor.addChild(s);        
    }
 
    public function drawCeil(x:int, y:int, color:uint):void{
        var s:Shape = new Shape();
        s.graphics.beginFill(color);
        s.graphics.drawRect(0, 0, 5, 5);
        s.graphics.endFill();
        s.z = -_height;
        s.x=x;
        s.y=y;      
        _ceil.addChild(s);
    } 
    
    public function setPixel(x:int, y:int, color:uint):void {
        if (x == _px && y == _py) return;
        _px = x;
        _py = y;
        
        _image.bitmapData.setPixel32(x, y, 0x333333);
        drawWall(x*5,y*5,color, 0);
        drawWall(x*5,y*5,color, -90);
        drawWall(x*5+5,y*5,color, 0);
        drawWall(x*5,y*5+5,color, -90);
        drawCeil(x*5,y*5, 0x202020); //0xffffff);
    }
}