欢迎来到山村网

as3打造轻纱般的变幻线效果

2019-03-31 06:03:40浏览:959 来源:山村网   
核心摘要:详细代码:package{ importflash.display.Sprite; importflash.display.Bitmap; importflash.display.BitmapData; importflash.e

详细代码:

package{



importflash.display.Sprite;

importflash.display.Bitmap;

importflash.display.BitmapData;

importflash.events.MouseEvent;

importflash.events.Event;

importflash.geom.Point;

importfrocessing.math.PerlinNoise;

importfrocessing.color.ColorHSV;

//importorg.libspark.utils.GeomUtil;



[SWF(backgroundColor="#000000",width="465",height="465",frameRate="30")]



publicclassMain13extendsSprite{

privatevarcanvas:Sprite;

privatevarbitmap:Bitmap;

privatevarbitmapdata:BitmapData;

privatestaticvarbWidth:uint=600;

privatestaticvarbHeight:uint=600;

privatestaticvarsegments:uint=5;

privatestaticvarratio:Number=1/segments;

privatestaticvarcolors:uint=360;

privatevarperlin:PerlinNoise;

privatevarcolor:ColorHSV;

privatevart:Number=0;

privatevarc:uint=0;

privatestaticvartightness:uint=40;



publicfunctionMain13(){

//Wonderfl.capture_delay(30);

stage.frameRate=120;

init();

}



privatefunctioninit():void{

graphics.beginFill(0x000000);

graphics.drawRect(0,0,465,465);

graphics.endFill();

canvas=newSprite();

bitmapData=newBitmapData(bWidth,bHeight,true,0x00000000);

bitmap=newBitmap(bitmapData);

addChild(bitmap);

bitmap.y=uint((bWidth-bHeight)/2);

perlin=newPerlinNoise();

color=newColorHSV();

addEventListener(Event.ENTER_frame,draw,false,0,true);

stage.addEventListener(MouseEvent.CLICK,reset,false,0,true);

}

privatefunctiondraw(evt:Event):void{

canvas.graphics.clear();

color.h=c;

canvas.graphics.lineStyle(0,color.value,0.2);

c++;

c%=colors;

bitmapData.lock();

varpoints:Array=newArray();

points.push(newPoint(-bWidth*ratio,bHeight*0.5));

for(varn:uint=1;n<=segments+1;n++){

varxPos:Number=n*bWidth*ratio;

varyPos:Number=perlin.noise(n*0.25,t)*bHeight;

points.push(newPoint(xPos-bWidth*ratio,yPos));

}

t+=0.01;

points.push(newPoint(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(varp:uint=0;p<points.length-3;p++){

varp0:Point=points[p];

varp1:Point=points[p+1];

varp2:Point=points[p+2];

varp3:Point=points[p+3];

for(vars:uint=1;s<tightness+1;s++){

//varpx:Number=GeomUtil.spline(p0.x,p1.x,p2.x,p3.x,s/tightness);

//varpy:Number=GeomUtil.spline(p0.y,p1.y,p2.y,p3.y,s/tightness);

varpx:Number=spline(p0.x,p1.x,p2.x,p3.x,s/tightness);

varpy: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();

}

privatefunctionspline(p0:Number,p1:Number,p2:Number,p3:Number,t:Number):Number{

varv0:Number=(p2-p0)*0.5;

varv1:Number=(p3-p1)*0.5;

vart2:Number=t*t;

vart3:Number=t2*t;

return(2*p1-2*p2+v0+v1)*t3+(-3*p1+3*p2-2*v0-v1)*t2+v0*t+p1;

}

privatefunctionreset(evt:MouseEvent):void{

bitmapData.lock();

bitmapData.fillRect(bitmapData.rect,0x00000000);

bitmapData.unlock();

}



}



}
(责任编辑:豆豆)
下一篇:

去除Dreamweaver表格宽度辅助线

上一篇:

DreamWeaver巧用模板工具批量制作网页

  • 信息二维码

    手机看新闻

  • 分享到
打赏
免责声明
• 
本文仅代表作者个人观点,本站未对其内容进行核实,请读者仅做参考,如若文中涉及有违公德、触犯法律的内容,一经发现,立即删除,作者需自行承担相应责任。涉及到版权或其他问题,请及时联系我们 xfptx@outlook.com