flash as3代码制造漂亮的轻纱般变幻线效果

更新时间:15-10-24 14:31 热度:431
 

这篇教程是向脚本代码之家的朋友绍介利用flash as3代码制造漂亮的轻纱般变幻线效果,教程制造出来的效果十分漂亮,也很简单,适应生手学习,引荐过来,一块儿来学习吧!变幻线效果:

周密代码:

复制代码

代码如下所述:

package {
import flash.display.sprite;
import flash.display.bitmap;
import flash.display.bitmapdata;
import flash.events.mouseevent;
import flash.events.event;
import flash.geom.point;
import frocessing.math.perlinnoise;
import frocessing.color.colorhsv;
//import org.libspark.utils.geomutil;
[swf(backgroundcolor="#000000", width="465", height="465", framerate="30")]
public class main13 extends sprite {
private var canvas:sprite;
private var bitmap:bitmap;
private var bitmapdata:bitmapdata;
private static var bwidth:uint = 600;
private static var bheight:uint = 600;
private static var segments:uint = 5;
private static var ratio:number = 1/segments;
private static var colors:uint = 360;
private var perlin:perlinnoise;
private var color:colorhsv;
private var t:number = 0;
private var c:uint = 0;
private static var tightness:uint = 40;
public function main13() {
//wonderfl.capture_delay(30);
stage.framerate = 120;
init();
}
private function init():void {
graphics.beginfill(0×000000);
graphics.drawrect(0, 0, 465, 465);
graphics.endfill();
canvas = new sprite();
bitmapdata = new bitmapdata(bwidth, bheight, true, 0×00000000);
bitmap = new bitmap(bitmapdata);
addchild(bitmap);
bitmap.y = uint((bwidth – bheight)/2);
perlin = new perlinnoise();
color = new colorhsv();
addeventlistener(event.enter_frame, draw, false, 0, true);
stage.addeventlistener(mouseevent.click, reset, false, 0, true);
}
private function draw(evt:event):void {
canvas.graphics.clear();
color.h = c;
canvas.graphics.linestyle(0, color.value, 0.2);
c ++;
c 百分之百= colors;
bitmapdata.lock();
var points:array = new array();
points.push(new point(-bwidth*ratio, bheight*0.5));
for (var n:uint = 1; n <= segments+1; n++) {
var xpos:number = n*bwidth*ratio;
var ypos:number = perlin.noise(n*0.25, t)*bheight;
points.push(new point(xpos-bwidth*ratio, ypos));
}
t += 0.01;
points.push(new point(bwidth*(1+ratio), bheight*0.5));
points.unshift(points[0]);
points.push(points[points.length-1]);
canvas.graphics.moveto(points[0].x, points[0].y);
for (var p:uint = 0; p < points.length-3; p++) {
var p0:point = points[p];
var p1:point = points[p+1];
var p2:point = points[p+2];
var p3:point = points[p+3];
for (var s:uint = 1; s < tightness+1; s++) {
//var px:number = geomutil.spline(p0.x, p1.x, p2.x, p3.x, s/tightness);
//var py:number = geomutil.spline(p0.y, p1.y, p2.y, p3.y, s/tightness);
var px:number = spline(p0.x, p1.x, p2.x, p3.x, s/tightness);
var py:number = spline(p0.y, p1.y, p2.y, p3.y, s/tightness);
canvas.graphics.lineto(px, py);
}
}
bitmapdata.draw(canvas);
bitmapdata.scroll(0,1);
bitmapdata.unlock();
}
private function spline(p0:number, p1:number, p2:number, p3:number, t:number):number {
var v0:number = (p2 – p0) * 0.5;
var v1:number = (p3 – p1) * 0.5;
var t2:number = t * t;
var t3:number = t2 * t;
return (2 * p1 – 2 * p2 + v0 + v1) * t3 + ( -3 * p1 + 3 * p2 – 2 * v0 – v1) * t2 + v0 * t + p1;
}
private function reset(evt:mouseevent):void {
bitmapdata.lock();
bitmapdata.fillrect(bitmapdata.rect, 0×00000000);
bitmapdata.unlock();
}
}
}

以上就是flash as3代码制造漂亮的轻纱般变幻线效果过程,期望对大家有所帮忙!