欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

Flash as3代码打造漂亮的轻纱般变幻线效果

程序员文章站 2023-11-13 11:45:58
本教程是向脚本之家的Flash学习者介绍利用Flash as3代码打造漂亮的轻纱般变幻线效果,教程比较简单,全部都是代码,喜欢的朋友一起来学习吧... 14-10-30...
这篇教程是向的朋友介绍利用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(0x000000);
graphics.drawrect(0, 0, 465, 465);
graphics.endfill();
canvas = new sprite();
bitmapdata = new bitmapdata(bwidth, bheight, true, 0x00000000);
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, 0x00000000);
bitmapdata.unlock();
}
}
}

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