package mixViewer
{
import flash.display.Sprite;
import flash.display.Bitmap;
import flash.display.Stage;
import flash.geom.Rectangle;
import flash.geom.Point;
import flash.filters.BlurFilter;
import flash.geom.ColorTransform;
import flash.utils.ByteArray;
import flash.display.Bitmap;
import flash.utils.setTimeout;
import flash.events.MouseEvent;
import flash.events.Event;
import flash.media.SoundMixer;
import flash.display.BitmapData;
public class MixViewer extends Sprite
{
public static var stage:Stage;
private var ins:MixViewer;
private var speedA:Number = 5.5;
private var speedLine:Number = 4.7;
private var ange:Number = 0;
private var visScale:Number = 1;
/***粒子斜度*** xl= ***0、1、0.6、-0.5、1.5***/
private var xl:Number = 1;
private var showW:int = 1024;
private var showH:int = 360;
private var halfShowW:int = 512;
private var scaleA:Number = 1.5;
private var scaleB:Number = 1;
private var _mode:int = 0;
private var mode:uint = 0;
private var frameCount:int = 0;
private var lineScaleValue:Number = 3.53;
private var mixBP:Bitmap;
private var mixBP2:Bitmap;
private var mixBD:BitmapData;
private var bdFilleRect:Rectangle= new Rectangle();
private var alwaysShow:Boolean = false;
private var isOn:Boolean = false;
private var _isHalf:Boolean = false;
private var _isMute:Boolean = false;
private var sinArr:Vector.<Number > ;
private var scaArr2:Vector.<Number > ;
private var toArr2:Vector.<Number > ;
private var bytes:ByteArray;
private var pus:Array;
private var filterRect:Rectangle;
private var filterPoint:Point = new Point(0,0);
private var _color:ColorChange=new ColorChange();
private var _transform:ColorTransform=new ColorTransform();
private var color:uint = 0xFFFF0000;
public function MixViewer()
{
sinArr = new Vector.<Number > (360,true);
filterRect = new Rectangle(0,0,256,80);
ins = this;
bytes = new ByteArray();
setTimeout(startThis, 1000);
for (var i:int=0; i<360; i++)
{
sinArr[i] = Math.sin(i/ 180* Math.PI);
}
pus = new Array();
pus.y = 50;
scaArr2 = new Vector.<Number > (512,true);
toArr2 = new Vector.<Number > (512,true);
for (var j:uint=0; j <512; j++)
{
scaArr2[j] = 1;
toArr2[j] = 1;
}
mixBP = new Bitmap(mixBD);
mixBP2 = new Bitmap(mixBD);
setTimeout(initMix, 1000);
addChild(mixBP);
mixBP.y = showH;
mixBP2.scaleY = -1;
mixBP2.y = showH;
addChild(mixBP2);
initValues();
MixViewer.stage.addEventListener(Event.RESIZE, onStageReSize);
MixViewer.stage.addEventListener(Event.ACTIVATE, onStageActive);
MixViewer.stage.addEventListener(Event.DEACTIVATE, onStageDeActive);
addEventListener(Event.ADDED_TO_STAGE, onStageReSize);
}
private function active():void
{
alwaysShow = ! alwaysShow;
}
private function initMix():void
{
//mixBP.alpha = .8;
onOff();
}
private function onStageActive(_arg_1:Event):void
{
isOn = true;
}
private function onStageDeActive(_arg_1:Event):void
{
isOn = false;
}
private function onStageReSize(event:Event=null):void
{
showW = int(MixViewer.stage.stageWidth * visScale);
showH = int(MixViewer.stage.stageHeight / 2 * visScale);
halfShowW = showW / 2;
if (mixBD)
{
mixBD.dispose();
}
mixBD = new BitmapData(showW,showH,true,0);
mixBP.bitmapData = mixBD;
mixBP2.bitmapData = mixBD;
mixBP.y = showH / visScale;
mixBP2.y = showH / visScale;
mixBP.scaleY = 1 / visScale;
mixBP.scaleX = 1 / visScale;
mixBP2.scaleY = 1 / visScale;
mixBP2.scaleX = 1 / visScale;
mixBP2.scaleY = - mixBP2.scaleY;
lineScaleValue = showW / 200 / visScale;
if (visScale == 1)
{
mixBP2.smoothing = false;
mixBP.smoothing = false;
}
else
{
mixBP2.smoothing = true;
mixBP.smoothing = true;
}
initValues();
}
private function startThis():void
{
addEventListener(Event.ENTER_FRAME, updateMix);
}
private function onOff():void
{
isOn = true;
}
private function initValues():void
{
filterRect = new Rectangle(0,0,showW,showH);
}
private function updateMix(event:Event):void
{
var n:int = 0;
var k:int = 0;
var m:int = 0;
var stpo:int = 0;
if (isOn == true|| alwaysShow == true)
{
color = 0xFFFF0000;
for (n = 0; n <512; n++)
{
scaArr2[n] = scaArr2[n] + (toArr2[n] - scaArr2[n]) / speedA;
}
mixBD.lock();
mixBD.fillRect(filterRect, 0xFFFFFF);
for (n = halfShowW + 1; n < showW; n += 2)
{
k =showH * scaArr2[int(n / showW * 512)];
for (m = 0; m < k; m+=2)
{
if (m < showH)
{
mixBD.setPixel32(n, m, color + int(m / k * 256) * 16777216);
}
}
mixBD.setPixel32(n,k, color);
}
mixBD.applyFilter(mixBD, filterRect, filterPoint,new BlurFilter(2,2,1));
mixBD.colorTransform(filterRect, new ColorTransform(1,1,1,0.975));
for (n = 0; n < halfShowW; n+=2)
{
k = showH * scaArr2[int(n / showW * 512)];
for (m = 0; m < k; m+=2)
{
if (m < showH)
{
mixBD.setPixel32(halfShowW - n + m * xl, m, color);
}
}
mixBD.setPixel32(halfShowW - n, k, color);
}
/*****************弧线**************/
ange +=speedLine +(((scaleB * (scaArr2[5] + scaArr2[10] + scaArr2[15] + scaArr2[20] + scaArr2[25] + scaArr2[30] + scaArr2[35] + scaArr2[40] + scaArr2[45] + scaArr2[50] + scaArr2[55] + scaArr2[60] + scaArr2[70] + scaArr2[90] + scaArr2[110] + scaArr2[130] + scaArr2[150] + scaArr2[170] + scaArr2[190] + scaArr2[210] + scaArr2[230])) / 21) * (1 + (Math.random() * 10))) / 2;
stpo += 1;
if (stpo > 9)
{
stpo = 0;
}
for (n = 0; n < showW; n+=3)
{
mixBD.setPixel32(n +stpo / 3, (sinArr[int((n / lineScaleValue + ange)) % 360] * showH) / 2 + showH / 2, color);
}
mixBD.unlock();
}
/*****************bytes********************/
frameCount += 1;
if (frameCount == 2)
{
SoundMixer.computeSpectrum(bytes, true, 2);
for (n = 0; n <512; n++)
{
toArr2[n] = bytes.readFloat() * scaleA;
}
frameCount = 0;
}
/******************颜色变换*****************/
_color.enterFrameHandler();
_transform.color = _color.color_number;
//_transform.color =0x9900cc
this.transform.colorTransform = _transform;
}
}
}
class ColorChange
{
private var colorNumber:Number = 0xf09000;
private var colorArray:Array;
private var color_index:Number = 1;
private var mz:int = 1;
public function ColorChange()
{
colorArray = color_arr();
}
public function enterFrameHandler():void
{
var i:Number;
var j:Number;
i = Math.random();
if (i> 0.99)
{
mz *= -1;
}
j = Math.round(mz * i * 5);
color_index += j;
if (color_index < 0)
{
color_index = colorArray.length - 1;
}
else
{
if (color_index >= colorArray.length)
{
color_index = 0;
}
}
colorNumber = colorArray[color_index];
}
private function color_arr():Array
{
var n:int = 0;
var color1:Array = [];
var color2:Array = [];
var color3:Array = [];
var color4:Array = [];
var color5:Array = [];
var color6:Array = [];
var color7:Array;
while (n < 0xFF)
{
color1.push(0xFF0000 + n * 256);
color2.push((0xFF - n) * 65536 + 0xFF00);
color3.push(0xFF00 + n);
color4.push((0xFF - n) * 256 + 0xFF);
color5.push(0xFF + n * 65536);
color6.push(0xFF - n + 0xFF0000);
n += 3;
}
color7 = [];
color7 = [].concat(color1).concat(color2).concat(color3).concat(color4).concat(color5).concat(color6);
return color7;
}
public function get color_number():Number
{
return colorNumber;
}
}
评论