首页 > 网络安全 > 媒体动画

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

admin 媒体动画 2022-02-20 21:45:27 3D设计   Flash   as3代码"
这篇教程是向潘少俊衡的朋友介绍利用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代码打造漂亮的轻纱般变幻线效果过程,希望对大家有所帮助!

版权声明

本文仅代表作者观点,不代表本站立场。
本文系作者授权发表,未经许可,不得转载。
本文地址:/3Dsheji/167851.html

留言与评论(共有 0 条评论)
   
验证码:

潘少俊衡

| 桂ICP备2023010378号-4

Powered By EmpireCMS

爱享小站

中德益农

谷姐神农

环亚肥料

使用手机软件扫描微信二维码

关注我们可获取更多热点资讯

感谢潘少俊衡友情技术支持