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

EmitParticle (4)

////////////////////////////////////////////////////////////////////////////////
// EmitParticle (4)
//
// 音はTsabeat より拝借
// http://www.ektoplazm.com/free-music/tsabeat-warp-speed-ep/
////////////////////////////////////////////////////////////////////////////////
Get Adobe Flash player
by ProjectNya 06 Oct 2010
    Embed
/**
 * Copyright ProjectNya ( http://wonderfl.net/user/ProjectNya )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/7P6n
 */

////////////////////////////////////////////////////////////////////////////////
// EmitParticle (4)
//
// 音はTsabeat より拝借
// http://www.ektoplazm.com/free-music/tsabeat-warp-speed-ep/
////////////////////////////////////////////////////////////////////////////////

package {

    import flash.display.Sprite;
    import flash.events.MouseEvent;

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

    public class Main extends Sprite {
        private var emit:EmitParticle;

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

        private function init():void {
            graphics.beginFill(0x000000);
            graphics.drawRect(0, 0, 465, 465);
            graphics.endFill();
            //
            emit = new EmitParticle();
            addChild(emit);
        }

    }

}


//////////////////////////////////////////////////
// EmitParticleクラス
//////////////////////////////////////////////////

import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.net.URLRequest;
import flash.media.Sound;
import flash.media.SoundChannel;
import flash.media.SoundLoaderContext;
import flash.media.SoundMixer;
import flash.utils.ByteArray;
import flash.system.Security;

class EmitParticle extends Sprite {
    private static var max:uint = 4;
    private var id:uint = 0;
    private var particles:Array;
    private static var acceleration:Number = 1.04;
    private static var gravity:Number = 0.5;
    private var sound:Sound;
    private static var policyPath:String = "http://mutast.heteml.jp/crossdomain.xml";
    private static var soundPath:String = "http://mutast.heteml.jp/works/music/music.mp3";

    public function EmitParticle() {
        if (stage) init();
        else addEventListener(Event.ADDED_TO_STAGE, init, false, 0, true);
    }

    private function init(evt:Event = null):void {
        removeEventListener(Event.ADDED_TO_STAGE, init);
        particles = new Array();
        //
        Security.loadPolicyFile(policyPath);
        sound = new Sound();
        sound.addEventListener(Event.COMPLETE, complete, false, 0, true);
        sound.load(new URLRequest(soundPath), new SoundLoaderContext(10, true));
    }
    private function complete(evt:Event):void {
        evt.target.removeEventListener(Event.COMPLETE, complete);
        start();
    }
    private function start():void {
        var channel:SoundChannel = sound.play(0, 5);
        addEventListener(Event.ENTER_FRAME, create, false, 0, true);
        addEventListener(Event.ENTER_FRAME, update, false, 0, true);
    }
    private function create(evt:Event):void {
        var bytes:ByteArray = new ByteArray();
        SoundMixer.computeSpectrum(bytes, false, 1);
        for (var n:uint = 0; n < 2; n++) {
            for (var t:uint = 0; t < 256; t++) {
                var rf:Number = bytes.readFloat();
                if (t%8 == 0 && rf > 0.25) {
                    var particle:Particle = new Particle(id);
                    particle.id = id;
                    addChild(particle);
                    particle.vx = (n*2 - 1)*10*rf;
                    particle.vy = 0;
                    particle.x = 232;
                    particle.y = 32 + 400*t/256;
                    particles.push(particle);
                }
            }
        }
        id ++;
    }
    private function update(evt:Event):void {
        for (var n:uint = 0; n < particles.length; n++) {
            var particle:Particle = particles[n];
            particle.x += particle.vx;
            particle.y += particle.vy;
            particle.vx *= acceleration;
            particle.vy *= acceleration;
            //particle.vy += gravity;
            if (particle.x < - 20 || particle.x > stage.stageWidth + 20) {
                removeChild(particle);
                particles.splice(n, 1);
                particle = null;
            }
        }
    }

}


//////////////////////////////////////////////////
// Particleクラス
//////////////////////////////////////////////////

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

class Particle extends Shape {
    public var id:uint;
    private static var radius:uint = 8;
    private static var inner:uint = 4;
    public var vx:Number = 0;
    public var vy:Number = 0;
    private var color:ColorHSV;

    public function Particle(hue:Number = 0) {
        color = new ColorHSV(hue, 0.6);
        draw();
        blendMode = BlendMode.ADD;
    }

    private function draw():void {
        graphics.beginFill(color.value);
        graphics.drawCircle(0, 0, radius);
        graphics.drawCircle(0, 0, inner);
        graphics.endFill();
    }

}