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

チョコ・ハート

////////////////////////////////////////////////////////////////////////////////
// チョコ・ハート
//
// 線でマスク
// http://www.project-nya.jp/modules/weblog/details.php?blog_id=596
// [AS3.0] ぼよよんと出る
// http://www.project-nya.jp/modules/weblog/details.php?blog_id=1058
//
// zahir's hart [http://wonderfl.net/c/k6dm]
////////////////////////////////////////////////////////////////////////////////
Get Adobe Flash player
by ProjectNya 14 Feb 2011
/**
 * Copyright ProjectNya ( http://wonderfl.net/user/ProjectNya )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/fdmv
 */

////////////////////////////////////////////////////////////////////////////////
// チョコ・ハート
//
// 線でマスク
// http://www.project-nya.jp/modules/weblog/details.php?blog_id=596
// [AS3.0] ぼよよんと出る
// http://www.project-nya.jp/modules/weblog/details.php?blog_id=1058
//
// zahir's hart [http://wonderfl.net/c/k6dm]
////////////////////////////////////////////////////////////////////////////////

package {

    import flash.display.Sprite;
    import flash.display.BlendMode;
    import flash.events.Event;
    import flash.display.LineScaleMode;
    import flash.display.CapsStyle;
    import flash.display.JointStyle;
    import flash.filters.BlurFilter;

    [SWF(backgroundColor="#FFFFFF", width="465", height="465", frameRate="30")]

    public class Main extends Sprite {
        private var heart:Sprite;
        private static var blur:BlurFilter = new BlurFilter(32, 32, 3);
        private static var baseScale:Number = 0.4;
        private static var targetScale:Number = 0.7;
        private var scale:Number = baseScale;
        private var amplitude:Number = 0;
        private static var deceleration:Number = 0.85;
        private static var friction:Number = 0.8;
        private static var acceleration:Number = 0.4;

        public function Main() {
            //Wonderfl.capture_delay(1);
            init();
        }

        private function init():void {
            var chocolate:Chocolate = new Chocolate(465, 465);
            addChild(chocolate);
            chocolate.x = int(465 - chocolate.width)/2;
            chocolate.y = int(465 - chocolate.height)/2;
            var label:Label = new Label(400, 50, 40, Label.CENTER);
            addChild(label);
            label.x = 32;
            label.y = 192;
            label.textColor = 0xFFFFFF;
            label.text = "チョコ♥注入!";
            label.blendMode = BlendMode.OVERLAY;
            //
            heart = new Sprite();
            heart.graphics.lineStyle(256, 0x000000, 1 , false, LineScaleMode.NORMAL, CapsStyle.ROUND, JointStyle.MITER);
            heart.graphics.moveTo(-80, -60);
            heart.graphics.lineTo(0, 20);
            heart.graphics.lineTo(80, -60);
            heart.x = 232;
            heart.y = 232;
            addChild(heart);
            heart.cacheAsBitmap = true;
            cacheAsBitmap = true;
            mask = heart;
            heart.filters = [blur];
            heart.scaleX = heart.scaleY = baseScale;
            addEventListener(Event.ENTER_FRAME, elastic, false, 0, true);
        }
        private function elastic(evt:Event):void {
            amplitude += targetScale - scale;
            scale += amplitude*friction;
            amplitude *= deceleration;
            heart.scaleX = heart.scaleY = scale;
            if (Math.abs(targetScale - scale) < 0.005 && Math.abs(amplitude) < 0.001) {
                removeEventListener(Event.ENTER_FRAME, elastic);
                amplitude = 0;
                scale = targetScale;
                heart.scaleX = heart.scaleY = targetScale;
                addEventListener(Event.ENTER_FRAME, slide, false, 0, true);
            }
        }
        private function slide(evt:Event):void {
            scale += (baseScale - scale)*acceleration;
            heart.scaleX = heart.scaleY = scale;
            if (Math.abs(baseScale - scale) < 0.005) {
                removeEventListener(Event.ENTER_FRAME, slide);
                scale = baseScale;
                heart.scaleX = heart.scaleY = baseScale;
                addEventListener(Event.ENTER_FRAME, elastic, false, 0, true);
            }
        }

    }

}


//////////////////////////////////////////////////
// Chocolateクラス
//////////////////////////////////////////////////

import flash.display.Sprite;

class Chocolate extends Sprite {
    private var _width:uint;
    private var _height:uint;

    public function Chocolate(w:uint, h:uint) {
        _width = w;
        _height = h;
        draw();
    }

    private function draw():void {
        var rows:uint = Math.ceil(_width/124);
        var cols:uint = Math.ceil(_height/64);
        for (var r:uint = 0; r < rows; r ++) {
            for (var c:uint = 0; c < cols; c ++) {
                var block:Block = new Block();
                addChild(block);
                block.x = 124*r;
                block.y = 64*c;
            }
        }
    }

}


//////////////////////////////////////////////////
// Blockクラス
//////////////////////////////////////////////////

import flash.display.Shape;
import frocessing.color.ColorHSV;

class Block extends Shape {
    private var color:ColorHSV;

    public function Block() {
        draw();
    }

    private function draw():void {
        color = new ColorHSV();
        color.h = 20;
        color.s = 1;
        color.v = 0.6;
        graphics.beginFill(color.value);
        graphics.drawRect(0, 0, 124, 64);
        graphics.endFill();
        color.s = 0.5;
        color.v = 0.7;
        graphics.beginFill(color.value);
        graphics.moveTo(0, 0);
        graphics.lineTo(10, 10);
        graphics.lineTo(110, 10);
        graphics.lineTo(120, 0);
        graphics.endFill();
        color.s = 0.75;
        color.v = 0.7;
        graphics.beginFill(color.value);
        graphics.moveTo(0, 0);
        graphics.lineTo(10, 10);
        graphics.lineTo(10, 50);
        graphics.lineTo(0, 60);
        graphics.endFill();
        color.s = 1;
        color.v = 0.5;
        graphics.beginFill(color.value);
        graphics.moveTo(0, 60);
        graphics.lineTo(10, 50);
        graphics.lineTo(110, 50);
        graphics.lineTo(120, 60);
        graphics.endFill();
        color.s = 1;
        color.v = 0.4;
        graphics.beginFill(color.value);
        graphics.moveTo(120, 0);
        graphics.lineTo(110, 10);
        graphics.lineTo(110, 50);
        graphics.lineTo(120, 60);
        graphics.endFill();
    }

}


//////////////////////////////////////////////////
// Labelクラス
//////////////////////////////////////////////////

import flash.display.Sprite;
import flash.text.TextField;
import flash.text.TextFieldType;
import flash.text.TextFieldAutoSize;
import flash.text.AntiAliasType;
import flash.text.TextFormat;
import flash.text.TextFormatAlign;

class Label extends Sprite {
    private var txt:TextField;
    private static var fontType:String = "_ゴシック";
    private var _width:uint = 20;
    private var _height:uint = 20;
    private var size:uint = 12;
    public static const LEFT:String = TextFormatAlign.LEFT;
    public static const CENTER:String = TextFormatAlign.CENTER;
    public static const RIGHT:String = TextFormatAlign.RIGHT;

    public function Label(w:uint, h:uint, s:uint = 12, align:String = LEFT) {
        _width = w;
        _height = h;
        size = s;
        draw(align);
    }

    private function draw(align:String):void {
        txt = new TextField();
        addChild(txt);
        txt.width = _width;
        txt.height = _height;
        txt.autoSize = align;
        txt.type = TextFieldType.DYNAMIC;
        txt.selectable = false;
        //txt.embedFonts = true;
        //txt.antiAliasType = AntiAliasType.ADVANCED;
        var tf:TextFormat = new TextFormat();
        tf.font = fontType;
        tf.size = size;
        tf.align = align;
        txt.defaultTextFormat = tf;
        textColor = 0x000000;
    }
    public function set text(param:String):void {
        txt.text = param;
    }
    public function set textColor(param:uint):void {
        txt.textColor = param;
    }

}