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: dots2

Get Adobe Flash player
by _toppo 21 Apr 2011
/**
 * Copyright _toppo ( http://wonderfl.net/user/_toppo )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/tKU5
 */

// forked from Scmiz's dots2
// forked from Scmiz's dots
package {
    import flash.display.Sprite;
    public class FlashTest extends Sprite {
        public function FlashTest() {
            var recipe:Recipe = new Recipe();
            recipe.width = 16;
            recipe.height = 16;
            recipe.scale = 8.0;
            recipe.data.push(0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0);
            recipe.data.push(0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 0, 0, 0, 0, 0);
            recipe.data.push(0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 0, 0, 0, 0);
            recipe.data.push(0, 0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 0, 0, 0);
            recipe.data.push(0, 0, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 1, 1, 0, 0);
            recipe.data.push(0, 1, 1, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0);
            recipe.data.push(0, 1, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 0);
            recipe.data.push(1, 1, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 2, 2, 1, 1);
            recipe.data.push(1, 1, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 2, 2, 2, 1);
            recipe.data.push(1, 1, 1, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 2, 2, 1);
            recipe.data.push(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1);
            recipe.data.push(0, 1, 2, 2, 2, 3, 3, 3, 3, 3, 3, 2, 2, 2, 1, 0);
            recipe.data.push(0, 0, 0, 0, 3, 3, 3, 3, 3, 3, 3, 3, 0, 0, 0, 0);
            recipe.data.push(0, 0, 0, 0, 3, 3, 3, 3, 3, 3, 1, 3, 0, 0, 0, 0);
            recipe.data.push(0, 0, 0, 0, 3, 3, 3, 3, 3, 3, 1, 3, 0, 0, 0, 0);
            recipe.data.push(0, 0, 0, 0, 0, 3, 3, 3, 3, 1, 3, 0, 0, 0, 0, 0);
            recipe.pallet.push(0x000000, 0xde9c39, 0xbd3939, 0xffffff);
            recipe.transparent = 0;
            recipe.outline = 1;
            
            var d:DotDraw = new DotDraw(recipe);
            d.x = 232.5 - (8 * 8);
            d.y = 232.5 - (8 * 8);
            this.addChild(d);
        }
    }
}
import flash.display.Sprite;

class Recipe
{
    public var width:uint = 0;
    public var height:uint = 0;
    public var scale:Number = 1.0;
    public var data:/*uint*/Array = new Array();
    public var pallet:/*uint*/Array = new Array();
    public var transparent:int = -1;
    public var outline:uint = 0;
}

class DotDraw extends Sprite
{
    public function DotDraw(recipe:Recipe) {
        for (var index:uint = 0; index < recipe.width * recipe.height; ++index) {
            var x:uint = index % recipe.width;
            var y:uint = uint(index / recipe.width);
            
            var datum:uint = recipe.data[x + (y * recipe.width)];
            var color:uint = recipe.pallet[datum];
            var scale:Number = recipe.scale;
            var alpha:Number = (datum == recipe.transparent) ? 0.0 : 1.0;
            
            this.graphics.beginFill(color, alpha);
            this.graphics.drawRect(x * scale, y * scale, scale, scale);
            this.graphics.endFill();
            
            if (datum != recipe.transparent) {

                this.graphics.beginFill(0x000000);
                if (x == 0
                    || ((x > 0) && (recipe.data[(x - 1) + (y * recipe.width)] == recipe.transparent))) {
                        this.graphics.drawRect(x * scale - recipe.outline, y * scale, recipe.outline, scale);
                }
                if (x == recipe.width - 1
                    || ((x < recipe.width - 1) && (recipe.data[(x + 1) + (y * recipe.width)] == recipe.transparent))) {
                        this.graphics.drawRect((x + 1) * scale, y * scale, recipe.outline, scale);
                }
                if (y == 0
                    || ((y > 0) && (recipe.data[x + ((y - 1) * recipe.width)] == recipe.transparent))) {
                        this.graphics.drawRect(x * scale, y * scale - recipe.outline, scale, recipe.outline);
                }
                if (y == recipe.height - 1
                    || ((y < recipe.height - 1) && (recipe.data[x + ((y + 1) * recipe.width)] == recipe.transparent))) {
                        this.graphics.drawRect(x * scale, (y + 1) * scale, scale, recipe.outline);
                }
                
                this.graphics.endFill();
                
            }

        }
    }

}