最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
pure as3创造一个线条曲线效果实例
时间:2022-06-28 22:16:30 编辑:袖梨 来源:一聚教程网
粒子有x,y,vx,vy属性,vx,vy为速度。
色彩变换用colortransform的参数变换实现
飘影用位图的appleTransform
代码如下 | 复制代码 |
package { import flash.display.Bitmap; import flash.display.BitmapData; import flash.display.Shape; import flash.display.Sprite; import flash.events.Event; import flash.events.MouseEvent; import flash.geom.ColorTransform; /** * ... * @author lizhi http://www.111com.net/ */ [SWF(width=465,height=465,backgroundColor=0xffffff,frameRate=60)] public class Main extends Sprite { private var w:int; private var h:int; private var ps:Array; private var pen:Shape = new Shape; private var bmd:BitmapData; private var ct:ColorTransform = new ColorTransform(0.999, 0.95, 0.99); private var max:Number = ct.redMultiplier; private var min:Number = ct.blueMultiplier; private var vr:Number = 0.0001; private var vg:Number = vr; private var vb:Number = vr; public function Main():void { w = stage.stageWidth; h = stage.stageHeight; bmd = new BitmapData(w, h, false, 0); addChild(new Bitmap(bmd)); var c:int = 10; ps = []; while (c-->0) { ps.push(new Particle(w * Math.random(), h * Math.random(),(Math.random()-0.5)*2,(Math.random()-0.5)*2)); } addEventListener(Event.ENTER_FRAME, init); } private function init(e:Event = null):void { for each(var p:Particle in ps) { p.x += p.vx; p.y += p.vy; if (p.x<0) { p.x = 0; p.vx = Math.abs(p.vx); } if (p.y<0) { p.y = 0; p.vy = Math.abs(p.vy); } if (p.x>w) { p.x = w; p.vx = -Math.abs(p.vx); } if (p.y>h) { p.y = h; p.vy = -Math.abs(p.vy); } } pen.graphics.clear(); pen.graphics.lineStyle(0,0xffffff); pen.graphics.moveTo(ps[0].x/2+ps[1].x/2,ps[0].y/2+ps[1].y/2); for (var i:int = 1; i < ps.length; i++ ) { p = ps[i + 1]; if (p == null) p = ps[0]; pen.graphics.curveTo(ps[i].x, ps[i].y, ps[i].x / 2 + p.x / 2, ps[i].y / 2+ p.y / 2); } pen.graphics.curveTo(ps[0].x, ps[0].y, ps[0].x/2+ps[1].x/2,ps[0].y/2+ps[1].y/2); ct.redMultiplier += vr; ct.greenMultiplier += vg; ct.blueMultiplier += vb; if (ct.redMultiplier > max) { ct.redMultiplier = max; vr = -Math.abs(vr); } if (ct.redMultiplier vr = Math.abs(vr); } if (ct.greenMultiplier > max) { ct.greenMultiplier = max; vg = -Math.abs(vg); } if (ct.greenMultiplier vg = Math.abs(vg); } if (ct.blueMultiplier > max) { ct.blueMultiplier = max; vb = -Math.abs(vb); } if (ct.blueMultiplier vb = Math.abs(vb); } bmd.colorTransform(bmd.rect, ct); bmd.draw(pen); } } } import flash.geom.Point; class Particle extends Point { public var vx:Number; public var vy:Number; public function Particle(x:Number,y:Number,vx:Number,vy:Number) { super(x, y); this.vx = vx; this.vy = vy; } } |
相关文章
- 绝区零月城柳怎么配装 11-28
- 浪漫餐厅兑换码11.22 11-28
- 光遇中国绊爱联动直播怎么玩 11-28
- 光遇11.25每日任务怎么做 11-28
- 光遇11.28每日任务怎么做 光遇11月28日每日任务做法攻略 11-28
- 以闪亮之名砰砰寻礼怎么玩 以闪亮之名月光长诗套装活动介绍 11-28