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

无痕影音音乐空间

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

 
 
 

日志

 
 
关于我

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

网易考拉推荐

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

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

  下载LOFTER 我的照片书  |
效果浏览:

调用方法:
import spectrum.Spectrum
/*Spectrum(720,480)频谱宽、高*/
var _spectrum:Spectrum=new Spectrum(720,480)
addChild(_spectrum)

Spectrum类:
/*
*author:疯子
*Date:17/12/2016
*根据正弦、余弦、SoundMixer.computeSpectrum()控制_spriteX、Y坐标
*BitmapData
*BlurFilter
*/
package spectrum
{
import colorNum.ColorChange;
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 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();

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

bitmap = addChild(new Bitmap(bitmapData,PixelSnapping.AUTO,false)) as Bitmap;
colorMatrixFilter = new ColorMatrixFilter([1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,.9,0]);

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

}

private function timerHandler(event:TimerEvent):void
{
SoundMixer.computeSpectrum(byteArray,true,0);

_sprite.graphics.clear();
for (var i:int= 0; i < 512; i++)
{
var num:Number = byteArray.readFloat() + 0.1;

var a:uint = i;
if (i <256)
{
a +=  256;
}
var n:Number = Math.ceil((thisH * 0.7/2)*(num+0.5));
var xPos:Number = -Math.sin(i/256*Math.PI)*n*num*4 + thisW/2;
var yPos:Number = Math.cos(a/256*Math.PI)*n*num*2 + thisH*0.8;
if (i%2==0)
{
_sprite.graphics.lineStyle(0,_color.color_number);
_sprite.graphics.drawCircle(xPos, yPos,14*num);
}
}
_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, null, null, "add");
bitmapData.unlock();
}

}
}

ColorChange类:
/*
*颜色转换
*65536
*color_number
*/
package colorNum
{
import flash.display.Sprite;
import flash.events.Event;

public class ColorChange extends Sprite
{
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();
this.addEventListener(Event.ENTER_FRAME,enterFrameHandler);
}
private function enterFrameHandler(event:Event):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;
}

}

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

历史上的今天

在LOFTER的更多文章

评论

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

页脚

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