使用Actionscript 3/Flash进行流体/果冻(ish)模拟
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了使用Actionscript 3/Flash进行流体/果冻(ish)模拟相关的知识,希望对你有一定的参考价值。
Description & download at http://adamcoulombe.info/lab/as3/jellybox.html
import traer.physics.Attraction; import traer.physics.Particle; import traer.physics.ParticleSystem; import traer.physics.Spring; import com.cartogrammar.drawing.CubicBezier; import flash.geom.Vector3D; var s:ParticleSystem = new ParticleSystem(new Vector3D(0, 0, 0), .2); //var waterMolecules = new Array(); var waterParticles = new Array(); var sky = new Array(); var earth = new Array(); var magnet = s.makeParticle(20, new Vector3D(0, 0, 0)); var hover=new Molecule(); var points = new Array(); var water = new Sprite(); init(); function init(){ magnet.makeFixed(); for (var i=0; i<20; i++){ sky[i]=s.makeParticle(10, new Vector3D(90+(i*20), 100, 0)); sky[i].makeFixed(); waterParticles[i]=s.makeParticle(0.5, new Vector3D(90+(i*20), 200, 0)); earth[i]=s.makeParticle(10, new Vector3D(90+(i*20), 300, 0)); earth[i].makeFixed(); //waterMolecules[i]=new Molecule(); //addChild(waterMolecules[i]); if(i>0){ s.makeSpring(waterParticles[i-1], waterParticles[i], 0.1 , .05, 0); s.makeSpring(sky[i], waterParticles[i], 0.05 , .05, 0); s.makeSpring(earth[i], waterParticles[i], 0.05 , .05, 0); if(i<19){ s.makeAttraction(magnet, waterParticles[i], -500 , 0); } } } waterParticles[0].makeFixed(); waterParticles[19].makeFixed(); addChild(water); water.alpha = 0.8 stage.addEventListener(Event.ENTER_FRAME,loop); } function loop(e){ s.tick(1); magnet.position.x = hover.x = mouseX; magnet.position.y = hover.y = mouseY; water.graphics.clear(); water.graphics.beginFill(0x007693); for(var i in waterParticles){ points[i] = new Point(waterParticles[i].position.x, waterParticles[i].position.y); //waterMolecules[i].x = points[i].x, //waterMolecules[i].y = points[i].y } CubicBezier.curveThroughPoints(water.graphics,points); water.graphics.lineTo(points[0].x,stage.stageHeight-50); water.graphics.lineTo(points[19].x,points[19].y); water.graphics.lineTo(points[19].x,stage.stageHeight-50); water.graphics.lineTo(points[0].x,stage.stageHeight-50); }
以上是关于使用Actionscript 3/Flash进行流体/果冻(ish)模拟的主要内容,如果未能解决你的问题,请参考以下文章
ActionScript 3 Actionscript 3 / Flash中的半色调效果
ActionScript 3 Flash:使用AS3参数添加编译器设置
动画未在 actionscript 3.0 (flash cc) 中启动