注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

无痕影音音乐空间

我的空间我做主 音乐无极限

 
 
 

日志

 
 
关于我

哥的世界不需要太多人懂。带上耳机.用音樂和麦克风驱赶悲傷,一声长叹何为缘?劳燕分飞两重天。泪眼作别转身去,柔情昨夜已成眠。尘世间的尘缘、以不再为红颜 无痕影音群号87433011 欢迎喜欢唱歌跳舞的你加入

网易考拉推荐

【转载】频谱-003原文件(双声道)  

2017-01-03 13:56:45|  分类: FLASH教程 |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |

效果浏览:




调用方法:
import spectrum.Spectrum
var _spectrum:Spectrum=new Spectrum(720,480)
addChild(_spectrum)

/**********spectrum.Spectrum类:*****************/
package spectrum
{
import flash.display.MovieClip;
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.TimerEvent;
import flash.filters.BlurFilter;
import flash.filters.ColorMatrixFilter;
import flash.geom.Point;
import flash.geom.Rectangle;
import flash.media.SoundMixer;
import flash.utils.ByteArray;
import flash.utils.Timer;
import flash.display.PixelSnapping;

public class Spectrum extends MovieClip
{
private var byteArray:ByteArray;
private var _sprite:Sprite;
private var sprite:Sprite;
private var timer:Timer;
private var thisW:Number;
private var thisH:Number;
private var bitmapData:BitmapData;
private var bitmap:Bitmap;
private var blur:BlurFilter;
private var colorMatrixFilter:ColorMatrixFilter;
private var _color:ColorChange = new ColorChange();

public function Spectrum(width:Number=550,height:Number=400)
{
thisW = width;
thisH = height;
byteArray = new ByteArray  ;
_sprite = new Sprite();
sprite = new Sprite();

/*位图是否透明true/false*/
bitmapData = new BitmapData(thisW,thisH,true,0);

bitmap = addChild(new Bitmap(bitmapData)) as Bitmap;
colorMatrixFilter = new ColorMatrixFilter([1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,.96,0]);

timer = new Timer(30);
timer.addEventListener(TimerEvent.TIMER,timerHandler);
timer.start();

}

private function timerHandler(event:TimerEvent):void
{
SoundMixer.computeSpectrum(byteArray,true,0);
                        _color.enterFrameHandler()
_sprite.graphics.clear();
sprite.graphics.clear();

_sprite.graphics.beginFill(_color.color_number,1);
sprite.graphics.beginFill(0xffffff,1)

var num:Number;
var n:Number=thisW/2/256
/*left*/
for (var i:int =0; i <256; i++)
{
num =byteArray.readFloat()

_sprite.graphics.drawRect(i*n+thisW/2,thisH,n-1,-(thisH*num/1.4-4));
sprite.graphics.drawRect(i*n+thisW/2,thisH-(thisH*num/1.4),n-1,1);

}
/*right*/
for (i=256; i>0; i--)
{
num = byteArray.readFloat();

_sprite.graphics.drawRect(i*n-n,thisH,n-1,-(thisH*num/1.4-4));
sprite.graphics.drawRect(i*n-n,thisH-(thisH*num/1.4),n-1,1);


}


_sprite.graphics.endFill();
sprite.graphics.endFill()

bitmapData.lock();

/*是否使用ColorMatrixFilter*/
bitmapData.applyFilter(bitmapData,bitmapData.rect,new Point(),colorMatrixFilter);
bitmapData.applyFilter(bitmapData, bitmapData.rect, new Point(), new BlurFilter(8, 8,2));
bitmapData.draw(_sprite);
bitmapData.draw(sprite);
bitmapData.unlock();
}

}
}

import flash.display.Sprite;
import flash.events.Event;

class ColorChange 
{
private var colorNumber:uint = 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;
}

}
  评论这张
 
阅读(57)| 评论(0)
推荐 转载

历史上的今天

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2017