• as3.0声音波形频谱系列_03


    as3.0声音波形频谱系列_03

    package 
    {
    	import flash.display.Sprite;
    	import flash.display.BitmapData;
    	import flash.display.Bitmap;
    	import flash.geom.Point;
    	import flash.utils.ByteArray;
    	import flash.filters.BlurFilter;
    	import flash.geom.ColorTransform;
    	import flash.display.PixelSnapping;
    	import flash.events.Event;
    	import flash.media.SoundMixer;
    	import flash.geom.Rectangle;
    
    	public class Spectrum extends Sprite
    	{
    		var thisW:Number;
    		var thisH:Number;
    		var parBd:BitmapData;
    		var bitmapData:BitmapData;
    		var parBit:Bitmap;
    		var bitmap:Bitmap;
    		var point:Point;
    		var bytes:ByteArray;
    		var blur:BlurFilter;
    		var colorTransform:ColorTransform;
    		var list:Vector.<Point>= new Vector.<Point>();
    
    		public function Spectrum(w:Number=550,h:Number=400)
    		{
    			thisW = w;
    			thisH = h;
    			init();
    		}
    		function init():void
    		{
    			parBd = new BitmapData(thisW,thisH,true,0);
    			bitmapData = new BitmapData(thisW,thisH,true,0);
    			parBit = addChild(new Bitmap(parBd,PixelSnapping.AUTO,false)) as Bitmap;
    			bitmap = addChild(new Bitmap(bitmapData,PixelSnapping.AUTO,false)) as Bitmap;
    			parBit.scaleX = parBit.scaleY = -1;
    			colorTransform = new ColorTransform(1,11,24,0.95,0,0,0,0);
    			blur = new BlurFilter(6,5,8);
    			parBit.filters = [blur];
    
    			for (var i:int=0; i<768; i++)
    			{
    				point= new Point();
    				point.x = thisW * 0.5 + Math.cos(i) * 50;
    				point.y = thisH * 0.5 + Math.sin(i) * 50;
    				list.push(point);
    			}
    			bytes=new ByteArray();
    			addEventListener(Event.ENTER_FRAME, enterFrameHandler);
    
    		}
    
    		private function enterFrameHandler(event:Event):void
    		{
    			var newPoint:Point=new Point();
    			SoundMixer.computeSpectrum(bytes,false,0);
    			parBd.colorTransform(new Rectangle(0, 0,thisW,thisH),colorTransform);
    			bitmapData.colorTransform(new Rectangle(0, 0,thisW,thisH),colorTransform);
    			for (var i:int=0; i<list.length; i++)
    			{
    				newPoint=list[i]
    				if (i< 256)
    				{
    					newPoint.x = thisW * 0.5 + Math.cos(i* 1.40625 * Math.PI / 180) * (thisW * 0.3 + bytes.readFloat() * 55);
    					newPoint.y = thisH * 0.5 + Math.sin(i* 1.40625 * Math.PI / 180) * (thisH * 0.3 + bytes.readFloat() * 55);
    				}
    				else if (i!= 256)
    				{
    					if (i> 256)
    					{
    						newPoint.x = (list[i- 256].x + list[i- 255].x) * 0.5;
    						newPoint.y = (list[i- 256].y + list[i- 255].y) * 0.5;
    					}
    				}
    				else
    				{
    					newPoint.x = (list[256].x + list[0].x) * 0.5;
    					newPoint.y = (list[256].y + list[0].y) * 0.5;
    				}
    				parBd.setPixel32(newPoint.x, newPoint.y, 5278190080);
    				bitmapData.setPixel32(newPoint.x, newPoint.y,2278190080);
    			}
    
    
    		}
    
    
    
    
    
    
    
    
    
    	}
    
    }
    

      

  • 相关阅读:
    安装solr
    Linux下安装mysql
    SQL JOIN
    SQL之TCL
    SQL之DCL
    SQL之DML
    SQL之DDL
    Mysql 常用查询语句
    Java-Poi 读取excel 数据
    工作中的第一份LoadRunner脚本
  • 原文地址:https://www.cnblogs.com/fengziwu/p/14555952.html
Copyright © 2020-2023  润新知