ActionScript 3 使用Actionscript 3 / Flash进行流体/果冻(ish)模拟
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ActionScript 3 使用Actionscript 3 / Flash进行流体/果冻(ish)模拟相关的知识,希望对你有一定的参考价值。
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 使用Actionscript 3 / Flash进行流体/果冻(ish)模拟的主要内容,如果未能解决你的问题,请参考以下文章
ActionScript 3:字符命中测试对象,所有对象都在数组中
ActionScript 3 使用ActionScript 3暂停框架
ActionScript 3 clickTag使用ActionScript 3
ActionScript 3 全屏使用ActionScript 3
ActionScript 3 使用ActionScript 3异步读取文件
ActionScript 3 使用Actionscript 3的onEnterFrame事件