Return to Snippet

Revision: 28214
at October 2, 2010 03:26 by adamcoulombe


Updated Code
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);
	
}

Revision: 28213
at July 3, 2010 23:43 by adamcoulombe


Updated Code
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  = mouseX;
	magnet.position.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,stage.stageHeight-50);
	
	water.graphics.lineTo(points[19].x,points[19].y);
	
	
}

Revision: 28212
at July 3, 2010 23:42 by adamcoulombe


Initial Code
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,stage.stageHeight-50);
	
	water.graphics.lineTo(points[19].x,points[19].y);
	
	
}

Initial URL
http://adamcoulombe.info/lab/as3/jellybox.html

Initial Description
Description & download at http://adamcoulombe.info/lab/as3/jellybox.html

Initial Title
Fluid/Jelly (ish) Simulation using Actionscript 3 / Flash

Initial Tags
actionscript, flash

Initial Language
ActionScript 3