我以前用AS3.0做的,
给大家分享一下:
package
{
import flash.display.*;
import flash.events.*;
import flash.geom.*;
import flash.media.*;
import flash.text.*;
import flash.ui.*;
import flash.utils.Timer;
import flash.filters.*;
public class firework extends Sprite
{
var con:ConvolutionFilter;
var rect:Rectangle;
var bitmap1:BitmapData;
var bitmap2:BitmapData;
var bitmapShow1:Bitmap;
//粒子的显示画布
var bitmapShow2:Bitmap;
//白色闪光点的显示画布
var m_mouseX:int;
//鼠标x坐标
var m_mouseY:int;
//鼠标y坐标
var sound1:Sound1;
//上升过程的声音
var sound2=Sound2;
//爆炸声音
var bit_px:Array;
//爆炸过程的x坐标
var bit_py:Array;
//爆炸过程的y坐标
var bit_vx:Array;
//爆炸过程的x速度
var bit_vy:Array;
//爆炸过程的y速度
var bit_sx:Array;
//上升过程的x坐标
var bit_sy:Array;
//上升过程的y坐标
var bit_l:Array;
//粒子的生命时间
var bit_f:Array;
//是上升还是爆炸的标志
var bit_p :Array;
//随机出现白色闪光点的标志
var bit_c :Array;
//粒子颜色
var myTimer:Timer;
var myContextMenu:ContextMenu;
function firework()
{
init();
stage.scaleMode=StageScaleMode.NO_SCALE;
addEventListener(Event.ENTER_FRAME, enterFrameHandler);
stage.addEventListener(MouseEvent.CLICK, clickHandler);
myContextMenu = new ContextMenu();
myContextMenu.hideBuiltInItems();
var defaultItems:ContextMenuBuiltInItems = myContextMenu.builtInItems;
contextMenu=myContextMenu;
addCustomMenuItems('绚丽烟花',false);
addCustomMenuItems('送给我的高中同桌',false);
addCustomMenuItems('制作者:QQ:237075463',true);
addCustomMenuItems('Email:zhangmingfu_163@163.com',false);
}
function init()
{
bits = 500;
//总的最大粒子数
bit_max = 50;
//一次出现的粒子数
bit_sound = 2;
con = new ConvolutionFilter(3, 3, [1, 1, 1, 1, 30, 1, 1, 1, 1], 38);
rect= new Rectangle(0, 0, 500, 200);
bitmap1 = new BitmapData(rect.width, rect.height, false, 0x000000);
bitmap2 = new BitmapData(rect.width, rect.height, true, 0x00000000);
bitmapShow1 = new Bitmap(bitmap1);
addChild(bitmapShow1);
bitmapShow2 = new Bitmap(bitmap2);
addChild(bitmapShow2);
sound1 = new Sound1();
sound2 = new Sound2();
bit_px = new Array(bits);
bit_py = new Array(bits);
bit_vx = new Array(bits);
bit_vy = new Array(bits);
bit_sx = new Array(bits);
bit_sy = new Array(bits);
bit_l = new Array(bits);
bit_f = new Array(bits);
bit_p = new Array(bits);
bit_c = new Array(bits);
for (var j:int = 0; j<bits; j++)
{
bit_f[j] = 0;
}
}
private function enterFrameHandler(event:Event):void
{
//event.updateAfterEvent();
bitmap2.fillRect(new Rectangle(0, 0, rect.width, rect.height), 0x00000000);
//白色闪光点清除
//bitmap2.applyFilter(bitmap, bitmap.rectangle, new Point(0, 0), con);
rend();
bitmap1.applyFilter(bitmap1, bitmap1.rect, new Point(0, 0), con);
//模糊滤镜
}
function rend() {
var flag:Boolean = false;
var flag1:Boolean = false;
var flag2:Boolean = false;
for (var k = 0; k<bits; k++) {
switch (bit_f[k]) {
case 1 :
// 爆炸过程
bit_vy[k] += Math.random()/100;
bit_px[k] += bit_vx[k];
bit_py[k] += bit_vy[k];
bit_l[k]--;
if (bit_l[k] == 0 || !rect.contains(bit_px[k], bit_py[k]))
{
bit_c[k] = 0x000000;
bit_f[k] = 0;
} else if (bit_p[k] == 0)
{
if (Math.floor(Math.random()*2) == 0)
{
bit_setwhite(int(bit_px[k]), Math.floor(bit_py[k]), 0xFFFFFFFF);
}
bit_set(Math.floor(bit_px[k]), Math.floor(bit_py[k]), bit_c[k]);
} else
{
bit_set(Math.floor(bit_px[k]), Math.floor(bit_py[k]), bit_c[k]);
}
break;
case 2 :
// 上升过程
bit_sy[k] -= 5;
if (bit_sy[k]<=bit_py[k])
{
bit_f[k] = 1;
flag2 = true;
}
if (Math.floor(Math.random()*20) == 0)
{
var i:int = Math.floor(Math.random()*2);
var j:int = Math.floor(Math.random()*5);
bit_set(bit_sx[k]+i, bit_sy[k]+j, 0xFFFFFF);
}
break;
}
}
if (flag2)
{
sound2.play();
}
}
private function clickHandler(event:MouseEvent):void
{
m_mouseX = event.stageX;
m_mouseY = event.stageY;
if (rect.contains(m_mouseX, m_mouseY))
{
var k:uint = Math.floor(Math.random()*0xFF);
var l:uint = Math.floor(Math.random()*0xFF);
var i1:uint = Math.floor(Math.random()*0xFF);
var j1:uint = k << 16 | l << 8 | i1;
var k1:uint = 0;
for (var l1:int = 0; l1<bits; l1++)
{
if (bit_f[l1] != 0)
{
continue;
}
bit_px[l1] = m_mouseX;
bit_py[l1] = m_mouseY;
var d:Number = Math.random()*6.28;
var d1:Number = Math.random();
bit_vx[l1] = Math.sin(d)*d1/2;
bit_vy[l1] = Math.cos(d)*d1/2;
bit_l[l1] = Math.floor(Math.random()*100)+100;
bit_p[l1] = Math.floor(Math.random()*3);
if (Math.floor(4*Math.random()) == 0)
{
bit_c[l1] = 0xFFFFFF;
} else
{
bit_c[l1] = j1;
}
bit_sx[l1] = m_mouseX;
bit_sy[l1] = rect.height-5;
bit_f[l1] = 2;
if (++k1 == bit_max)
{
break;
}
}
sound1.play();
}
}
function bit_set(i:int, j:int, k:uint)
{
bitmap1.setPixel(i, j, k);
}
function bit_setwhite(i:int, j:int, k:uint)
{
bitmap2.setPixel32(i, j, k);
//白色闪光点
}
public function addCustomMenuItems(menuLabel:String,spr:Boolean):void {
var item:ContextMenuItem = new ContextMenuItem(menuLabel);
if(spr==true)
{
item.separatorBefore=true;
}
myContextMenu.customItems.push(item);
item.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, menuItemSelectHandler);
}
private function menuItemSelectHandler(event:ContextMenuEvent):void {
//trace("menuItemSelectHandler: " + event);
var s:String=new String(event.target.caption);
}
}
}
Word教程网 | Excel教程网 | Dreamweaver教程网 | Fireworks教程网 | PPT教程网 | FLASH教程网 | PS教程网 |
HTML教程网 | DIV CSS教程网 | FLASH AS教程网 | ACCESS教程网 | SQL SERVER教程网 | C语言教程网 | JAVASCRIPT教程网 |
ASP教程网 | ASP.NET教程网 | CorelDraw教程网 |