Flash制作音乐频谱的效果
作者 佚名技术
来源 服务器技术
浏览
发布时间 2012-07-07
|
_Sp = new Sprite();
drawMaskRect();
addChild(mask_Sp);
square_Sp = new Sprite();
drawSquareRect();
square_Sp.y = 99;
square_Sp.addEventListener(Event.ENTER_FRAME, _enterframe);
addChild(square_Sp);
//设置遮罩
BG_Sp.mask = mask_Sp;
oldNum = 0;
myTimer = new Timer(200, 1);
myTimer.addEventListener("timer", onTimer);
canDrop = false;
}
//使小方块下落
private function _enterframe(e:Event):void {
if (canDrop) {
square_Sp.y += 4;
}
if (square_Sp.y > 99) {
square_Sp.y = 99;
}
if (square_Sp.y < -1) {
square_Sp.y = -1;
}
}
//绘制渐变图形
private function drawGradualRect():void {
var fillType:String = GradientType.RADIAL;
var colors:Array = [top_color, middle_color, bottom_color];
var alphas:Array = [1, 1, 1];
var ratios:Array = [0x00, 0x7f, 0xff];
BG_Sp.graphics.beginGradientFill(fillType, colors, alphas, ratios);
BG_Sp.graphics.drawRect(0,-1,100,1);
BG_Sp.rotation = 90;
}
//绘制遮罩图形
private function drawMaskRect():void {
mask_Sp.graphics.lineStyle();
mask_Sp.graphics.beginFill(0);
mask_Sp.graphics.drawRect(0,-100,1,100);
mask_Sp.graphics.endFill();
mask_Sp.y = 100;
}
//绘制小方块
private function drawSquareRect():void {
square_Sp.graphics.lineStyle();
square_Sp.graphics.beginFill(square_color);
square_Sp.graphics.drawRect(0,0,1,1);
square_Sp.graphics.endFill();
}
//接收频谱数据
public function getSpectrum(num:Number):void {
if (oldNum > num) {
oldNum -= 7;
} else {
oldNum = num;
if (oldNum != 0) {
//调用小方块运动的函数
squareMove(oldNum);
}
}
if (oldNum<0) {
oldNum = 0;
}
mask_Sp.height = oldNum;
}
//控制小方块运动的函数
private function squareMove(num:Number):void {
if (square_Sp.y > 99 - oldNum) {
square_Sp.y = 99 - num;
canDrop = false;
myTimer.reset();
myTimer.start();
}
}
public function onTimer(e:TimerEvent):void {
canDrop = true;
}
}
}
Waveform类,波形的类,用一条线条来绘制的,加入了逐渐消失的轨迹的效果。
-
- /*
- 类功能:波形。
- */
- package net.cdipan.spectrum{
- import flash.display.*;
- import flash.filters.*;
- import flash.geom.*;
- public class Waveform extends Sprite {
- //线条颜色
- private const line_color:uint = 0x07f7ff;
- //创建用来绘制线条的精灵对象
- private var Line:Sprite;
- //用于逐渐消失的轨迹的位图对象
- private var bmpData:BitmapData;
- private var bmp:Bitmap;
- //滤镜的各项参数
- private var colorM:ColorMatrixFilter;
- private var blur:BlurFilter;
- private var r:Rectangle;
- private var point;
- //通过数字使滤镜处理慢一步
- private var num:int;
- public
|
凌众科技专业提供服务器租用、服务器托管、企业邮局、虚拟主机等服务,公司网站:http://www.lingzhong.cn
为了给广大客户了解更多的技术信息,本技术文章收集来源于网络,凌众科技尊重文章作者的版权,如果有涉及你的版权有必要删除你的文章,请和我们联系。以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!
|