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 uniq's ニコニコテレビちゃんを描いてみた
// ニコニコテレビちゃんを動かしてみた
package{
import flash.display.Sprite;
import flash.utils.*;

public class DrawNicotvchan1 extends Sprite {
    public function DrawNicotvchan1() {
        y = 100;
        var bodies:Array = [];
        for(var i:int = 0; i < 10; i++){
            var body:Body = new Body(i);
            body.scaleX = body.scaleY = Math.pow(0.9, i - 1);
            body.y = -i * Math.pow(0.9, i - 1) * 10;
            addChildAt(body, 0);
            bodies.push(body);
        }

        addEventListener("enterFrame", function(event:*):void{
            for(i = 0; i < bodies.length; i++){
                body = bodies[i];
                body.x = (body.x * (i * 2 + 1) + stage.mouseX) / (i * 2 + 2);
            }
        });
    }
}
}


import flash.display.Sprite;
import flash.filters.GlowFilter;

class Body extends Sprite{
    public function Body(num:int){
        var color:uint = 0x000000 + 0x111111 * num;

        var l1:Leg = new Leg();
        l1.x = -30; l1.y = 150
        addChild(l1);

        var l2:Leg = new Leg();
        l2.x = 30; l2.y = 150
        addChild(l2);

        // アンテナを描く
        var antena:Sprite = new Sprite();
        antena.graphics.lineStyle(4, color);
        antena.graphics.moveTo(-30, 40);
        antena.graphics.lineTo(  0, 60);
        antena.graphics.lineTo( 30, 40);
        antena.filters = [new GlowFilter(0xffffff)];
        addChild(antena);
  
        // 外側四角を描く
        var s2:Sprite = new Sprite();
        s2.graphics.lineStyle(6, color);
        s2.graphics.beginFill(0xffffff);
        s2.graphics.drawRect(-60, 0, 120, 90);
        s2.graphics.endFill();
        s2.y = 60;
        addChild(s2);
  
        // 内側四角を描く
        var s3:Sprite = new Sprite();
        s3.graphics.lineStyle(4, color);
        s3.graphics.beginFill(0xffffff);
        s3.graphics.drawRect(-50, 0, 100, 70);
        s3.graphics.endFill();
        s3.y = 70;
        addChild(s3);
  
        // 左目を描く
        var eye1:Sprite = new Sprite();
  	  eye1.graphics.beginFill(color);
        eye1.graphics.drawCircle(0, 0, 5);
        eye1.x = -30;
        eye1.y = 100;
        addChild(eye1);
  
        // 右目を描く
        var eye2:Sprite = new Sprite();
        eye2.graphics.beginFill(color);
        eye2.graphics.drawCircle(0, 0, 5);
        eye2.x = 30;
        eye2.y = 90;
        addChild(eye2);
  
        // 口を描く
        var s8:Sprite = new Sprite();
        s8.graphics.lineStyle(1, color);
        s8.graphics.beginFill(color);
        s8.graphics.moveTo(  0, 120);
        s8.graphics.lineTo(-10, 130);
        s8.graphics.lineTo( 15, 130);
        s8.graphics.endFill();
        addChild(s8);

        var count:int = num * 2;
        addEventListener("enterFrame", function(event:*):void{
            l1.rotation = 15 * Math.cos(count / 10 * Math.PI);
            l2.rotation = -l1.rotation;
            antena.scaleX = Math.cos(count / 30 * Math.PI);
            eye1.y = 95 + Math.cos(count / 30 * Math.PI) * 5;
            eye2.y = 95 - Math.cos(count / 30 * Math.PI) * 5;
            count = (count + 1) % 360;
        });
    }
}

class Leg extends Sprite{
    public function Leg(){
        graphics.lineStyle(4, 0x000000);
        graphics.beginFill(0xffffff);
        graphics.moveTo( 20, -12);
        graphics.lineTo(  0,  12);
        graphics.lineTo(-20, -12);
        graphics.endFill();
    }
}