Flash教程:用AS3代码实现鼠标跟随喷枪涂鸦效果
2008-11-23 19:18:01 来源:WEB开发网核心提示:var wallCanvas:BitmapData = new BitmapData(stage.stageWidth,stage.stageHeight - 100,true, 0x00ffffff); var bitmap:Bitmap = new Bitmap(wallCanvas); addChild (bit
var wallCanvas:BitmapData = new BitmapData(stage.stageWidth,stage.stageHeight - 100,true, 0x00ffffff);
var bitmap:Bitmap = new Bitmap(wallCanvas);
addChild (bitmap);
drawingArea.addEventListener (MouseEvent.MOUSE_DOWN, mouseDownHandler);
stage.addEventListener (MouseEvent.MOUSE_UP, mouseUpHandler);
var color:uint;
var maxRadius:Number;
var density:Number;
function mouseDownHandler (event:MouseEvent):void {
addEventListener (Event.ENTER_FRAME, onEnterFrame);
}
function mouseUpHandler (event:MouseEvent):void {
removeEventListener (Event.ENTER_FRAME, onEnterFrame);
}
function onEnterFrame (event:Event):void {
maxRadius = sizeSlider.value;
color = myColorPicker.selectedColor + 0xff000000;
density = densitySlider.value;
for (var i:int = 0; i < density; i++) {
var angle:Number = Math.random() * Math.PI * 2;
var radius:Number = Math.random() * maxRadius;
var xPos:Number = mouseX + Math.cos(angle) * radius;
var yPos:Number = mouseY + Math.sin(angle) * radius;
wallCanvas.setPixel32 (xPos, yPos, color);
}
}
var bitmap:Bitmap = new Bitmap(wallCanvas);
addChild (bitmap);
drawingArea.addEventListener (MouseEvent.MOUSE_DOWN, mouseDownHandler);
stage.addEventListener (MouseEvent.MOUSE_UP, mouseUpHandler);
var color:uint;
var maxRadius:Number;
var density:Number;
function mouseDownHandler (event:MouseEvent):void {
addEventListener (Event.ENTER_FRAME, onEnterFrame);
}
function mouseUpHandler (event:MouseEvent):void {
removeEventListener (Event.ENTER_FRAME, onEnterFrame);
}
function onEnterFrame (event:Event):void {
maxRadius = sizeSlider.value;
color = myColorPicker.selectedColor + 0xff000000;
density = densitySlider.value;
for (var i:int = 0; i < density; i++) {
var angle:Number = Math.random() * Math.PI * 2;
var radius:Number = Math.random() * maxRadius;
var xPos:Number = mouseX + Math.cos(angle) * radius;
var yPos:Number = mouseY + Math.sin(angle) * radius;
wallCanvas.setPixel32 (xPos, yPos, color);
}
}
- ››ASP.NET及JS中的cookie基本用法
- ››ASP.NET获取MS SQL Server安装实例
- ››asp.net实现调用百度pai 在线翻译英文转中文
- ››ASP.NET页面选项进行提示判断
- ››Asp.net定时执行程序
- ››ASP.NET中利用DataList实现图片无缝滚动
- ››ASP.NET验证控件RequiredFieldValidator
- ››ASP.NET中使用System.Net.Mail发邮件
- ››ASP.NET中获取用户控件中控件的ID
- ››ASP.NET中FileBytes写成文件并存档
- ››asp获取毫秒数
- ››asp.net报“INSERT INTO 语句的语法错误解决
更多精彩
赞助商链接