Shooting music
forked from: Shooting star on the attractor road
with music
/**
* Copyright Andy.Huber ( http://wonderfl.net/user/Andy.Huber )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/lPGY
*/
// forked from matsu4512's Shooting star on the attractor road
/*
Full Screenで見ると見やすいかと思います。
3D酔いには注意!
*/
//http://www.chaoscope.org
package {
import __AS3__.vec.Vector;
import flash.media.*;
import flash.net.URLRequest;
import flash.system.Security;
import flash.events.Event;
import flash.filters.*;
import frocessing.color.ColorHSV;
import org.papervision3d.cameras.*;
import org.papervision3d.core.geom.Lines3D;
import org.papervision3d.core.geom.renderables.Line3D;
import org.papervision3d.materials.ColorMaterial;
import org.papervision3d.materials.special.LineMaterial;
import org.papervision3d.objects.primitives.*;
import org.papervision3d.view.BasicView;
[SWF(width=465, height=465, backgroundColor=0xffffff)]
public class Papervision_Line3D_rainbow extends BasicView
{
// adding for sound
private var channel:SoundChannel;
private var channelA:SoundChannel;
private var trans:SoundTransform;
private var transA:SoundTransform;
private var mySound:Sound;
private var mySoundA:Sound;
private var maxRadius:Number=0;
//カメラが追う球
private var sphere:Sphere;
//描く線
private var line:Lines3D;
//ここを変更すると描かれる線が変わる
// private const A:Number = 9.5340, B:Number = 11.7350, C:Number = 19.9210, D:Number = 0.0830;
private const A:Number = 10.0, B:Number = 25.0, C:Number = 8.0/3.0, D:Number = 0.01;
//向かう座標
private var xx:Number, yy:Number, zz:Number;
//HSV->RGB変換用の変数
private var hsv:ColorHSV;
private var glow:GlowFilter;
//Planeを格納するためのVector
private var particles:Vector.<Plane>;
public function Papervision_Line3D_rainbow()
{
super(465, 465, true, false, CameraType.SPRING);
graphics.beginFill(0);
graphics.drawRect(0, 0, 465, 465);
graphics.endFill();
//初期化
hsv = new ColorHSV(0, 1, 1);
glow = new GlowFilter(0, 1, 8, 8, 2);
particles = new Vector.<Plane>();
xx = yy = zz = 1;
//球の生成
sphere = new Sphere(new ColorMaterial(0xffffff), 3);
sphere.x = sphere.y = sphere.z = 1;
scene.addChild(sphere);
//フィルターを有効にする
sphere.useOwnContainer = true;
sphere.filters = [new BlurFilter(8,8,4), glow];
//カメラが追うものを球に設定
camera.target = sphere;
//各パラメータの設定
SpringCamera3D(camera).mass = 80;
SpringCamera3D(camera).damping = 30;
SpringCamera3D(camera).stiffness = 8;
line = new Lines3D(null);
scene.addChild(line);
startRendering();
// adds for the sound
// Security.loadPolicyFile("http://mutast.heteml.jp/crossdomain.xml");
channel = new SoundChannel();
channelA = new SoundChannel();
mySound = new Sound();
mySoundA = new Sound();
trans = new SoundTransform(0.1, 0);
transA = new SoundTransform(0.1, 0);
mySound.addEventListener(Event.COMPLETE, play);
mySound.load(new URLRequest("http://freedownloads.last.fm/download/555370508/I%25E2%2596%25BCYou.mp3"));
mySoundA.load(new URLRequest("http://freedownloads.last.fm/download/477541996/Your%2BFirst%2BLight%2BMy%2BEventide.mp3"));
// mySound.play(0, 1, trans);
addEventListener(Event.ENTER_FRAME, onFrame);
}
public function play(e:Event):void {
// var channel:SoundChannel = new SoundChannel();
// channel.soundTransform = new SoundTransform(-0.8, 0);
// trans = new SoundTransform(0.1, 0);
// transA = new SoundTransform(0.9, 0);
channel = mySound.play(0, 1, trans);
channelA = mySoundA.play(0, 1, transA);
channel.addEventListener(Event.SOUND_COMPLETE, play);
}
private function soundSphere(x:Number, y:Number, z:Number):void {
var help:Number = 0;
// is at
help = Math.abs(x+0);
help += Math.abs(y+0);
help += Math.abs(z+0);
// trans.pan = 1 / help; // 1/...
trans.volume = 1 / help; // 1/...
// A is at
help = Math.abs(x-10);
help += Math.abs(y-10);
help += Math.abs(z-10);
transA.volume = 1 / help; // 1/...
// transA.pan = 1 / help; // 1/...
// trans = new SoundTransform(trans.volume, 0);
// transA = new SoundTransform(transA.volume, 0);
channel.soundTransform = trans;
channelA.soundTransform = transA;
// channel = mySound.play(0, 1, trans);
// channel = mySoundA.play(0, 1, transA);
}
private function onFrame(event:Event):void{
//from
var preX:Number = sphere.x;
var preY:Number = sphere.y;
var preZ:Number = sphere.z;
//進む距離
var dx:Number, dy:Number, dz:Number;
dx = A*(yy-xx);
dy = xx * (B - zz) - yy;
dz = xx * yy - C * zz;
//to
xx += D*dx;
yy += D*dy;
zz += D*dz;
sphere.x = xx*80;
sphere.y = yy*80;
sphere.z = zz*80;
//sound
if ( sphere.x > maxRadius ) maxRadius = sphere.x;
if ( sphere.y > maxRadius ) maxRadius = sphere.y;
if ( sphere.z > maxRadius ) maxRadius = sphere.z;
// sound change to
soundSphere( xx, yy, zz );
// trace("Maximal radius: " + maxRadius + " at all.");
//線を描画
line.addNewLine(2, preX, preY, preZ, sphere.x, sphere.y, sphere.z);
//HSV->RGBの変換
var color:uint = hsv.toRGB().value;
//glowフィルターの色変更
glow.color = color;
//線の色を変更
(line.lines[line.lines.length-1] as Line3D).material = new LineMaterial(color);
//球から出るパーティクルの生成
for(var j:int = 0; j < 3; j++){
var mat:ColorMaterial = new ColorMaterial(color);
mat.doubleSided = true;
var p:Plane = new Plane(mat, 1, 1);
p.x = sphere.x;
p.y = sphere.y;
p.z = sphere.z;
p.useOwnContainer = true;
p.filters = [new BlurFilter(4,4,2)];
p.extra = {vx:Math.random()*6-3, vy:Math.random()*6-3, vz:Math.random()*6-3};
scene.addChild(p);
particles.push(p);
}
var i:int = particles.length;
//パーティクルの管理
while(i--){
p = particles[i];
p.x += p.extra.vx;
p.y += p.extra.vy;
p.z += p.extra.vz;
p.material.fillAlpha -= 0.05;
if(p.material.fillAlpha <= 0){
particles.splice(i,1);
scene.removeChild(p);
}
}
i = line.lines.length;
//線を徐々に透明にしていく
while(i--){
var l:Line3D = line.lines[i];
l.material.lineAlpha -= 0.001;
if(l.material.lineAlpha <= 0)
line.removeLine(l);
}
hsv.h += 1;
}
}
}