Flash as3代码打造漂亮的轻纱般变幻线效果
平面设计 2021-07-03 14:35www.168986.cn平面设计培训
这篇教程是向狼蚁SEO的朋友介绍利用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 .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(-bWidthratio, bHeight0.5));
for (var n:uint = 1; n <= segments+1; n++) {
var xPos:Number = nbWidthratio;
var yPos:Number = perlin.noise(n0.25, t)bHeight;
points.push(new Point(xPos-bWidthratio, yPos));
}
t += 0.01;
points.push(new Point(bWidth(1+ratio), bHeight0.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();
}
}
}
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 .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(-bWidthratio, bHeight0.5));
for (var n:uint = 1; n <= segments+1; n++) {
var xPos:Number = nbWidthratio;
var yPos:Number = perlin.noise(n0.25, t)bHeight;
points.push(new Point(xPos-bWidthratio, yPos));
}
t += 0.01;
points.push(new Point(bWidth(1+ratio), bHeight0.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代码打造漂亮的轻纱般变幻线效果过程,希望对大家有所帮助!
上一篇:教你用CAD把分散的线段合并成一个整体
下一篇:3D常用专业名词解释大汇总
平面设计师
- 平面设计图怎么画 小学生画平面图
- 平面设计内容怎么写 平面设计的求职意向怎么写
- 平面设计图手绘 平面设计图手绘家具
- 平面设计多久能出师 平面设计要多久
- 女生做ui设计师有多累 女生为什么学ui的人很惨
- 哪里有学平面设计的学校 想学平面设计去哪里学
- 初学平面设计用哪个软件 平面设计初学者必备的
- 0基础学平面设计要多久 0基础自学平面设计
- 平面设计手绘培训 平面设计师培训班学费多少钱
- ui工作好找工作吗 ui好不好找工作
- 女生学室内设计吃香吗
- ps平面设计自学教程 平面设计ps入门教程
- 平面设计基础知识大全 平面设计基本常识
- 平面设计基础教学视频 平面设计教学零基础入门
- 平面设计基础教学 平面设计基础教学平时作业
- ui设计主要是学什么 ui设计一般是学什么