Public feed #888927

Something

public text v1 · immutable
Raw Edit
·published 2008-02-02 15:04 UTC
rendered paste body
var g:Number = 600;
var f:Number = 600;
var t:Number = 0.02;
var radius:Number = 20;
var xStart:Number = 100;
var yStart:Number = 100;
var nc:Number = 50;

for (i=1; i<nc; i++) {
	node = attachMovie("node", "n"+i, _root.getNextHighestDepth());
	node._x = radius*Math.cos(i/(nc-1)*Math.PI*2) + xStart;
	node._y = radius*Math.sin(i/(nc-1)*Math.PI*2) + yStart;
	node.mass = 5;
	node.vx = 0;
	node.vy = 0;
	
	node.sForceX1 = 0;
	node.sForceX2 = 0;
	node.sForceX3 = 0;
	node.sForceX4 = 0;
	node.sForceY1 = 0;
	node.sForceY2 = 0;
	node.sForceY3 = 0;
	node.sForceY4 = 0;
	node.cake = 0;
}

for (i=1; i<nc; i++) {
	spring = createEmptyMovieClip("spring"+i, _root.getNextHighestDepth());
	spring.lineStyle(2, 0xFFFFFF);
	spring.moveTo(_root["n"+i]._x, _root["n"+i]._y);
	spring.p1 = i;
	if (i != (nc-1)) {
		spring.lineTo(_root["n"+(i+1)]._x, _root["n"+(i+1)]._y);
		spring.p2 = (i+1);
		spring.xDist = _root["n"+i]._x - _root["n"+(i+1)]._x;
		spring.yDist = _root["n"+i]._y - _root["n"+(i+1)]._y;
	} else {
		spring.lineTo(_root["n"+1]._x, _root["n"+1]._y);
		spring.xDist = _root["n"+i]._x - _root["n"+1]._x;
		spring.yDist = _root["n"+i]._y - _root["n"+1]._y;
		spring.p2 = 1;
	}
	spring.nm = i;
	spring.f = 600;
	spring.restl = Math.sqrt(spring.xDist*spring.xDist + spring.yDist*spring.yDist);
}


_root.onEnterFrame = function(){
	
	if(Key.isDown(Key.RIGHT)){
		n1.cake = 2000;
	}
	
	for(i=1;i<nc;i++){
		_root["spring"+i].clear();
		_root["spring"+i].lineStyle(2, 0xFFFFFF);
		_root["spring"+i].moveTo(_root["n"+i]._x, _root["n"+i]._y);
		if (i != (nc-1)) {
			_root["spring"+i].lineTo(_root["n"+(i+1)]._x, _root["n"+(i+1)]._y);
		} else {
			_root["spring"+i].lineTo(_root["n"+1]._x, _root["n"+1]._y);
		}
	
		
		_root["n"+i].onEnterFrame = function(){
			this.xForce = this.sForceX1 + this.sForceX2 + this.sForceX3 + this.sForceX4 + this.cake;
			this.yForce = this.sForceY1 + this.sForceY2 + this.sForceY3 + this.sForceY4;
			
			this.vx += t*this.xForce/this.mass;
			this.vy += t*this.yForce/this.mass;
			
			if(this.xForce == 0){
				this.vx = 0;
			}
			if(this.yForce == 0){
				this.vy = 0;
			}
			
			this._x += this.vx*t + this.xForce/this.mass/2*t*t;
			this._y += this.vy*t + this.yForce/this.mass/2*t*t;
		}
		
		_root["spring"+i].onEnterFrame = function(){
			this.xDist = _root["n"+this.p1]._x-_root["n"+this.p2]._x;
			this.yDist = _root["n"+this.p1]._y-_root["n"+this.p2]._y;
			this.dist = Math.sqrt(this.xDist*this.xDist+this.yDist*this.yDist);
			this.angle = Math.atan2(this.yDist, this.xDist);
			
			
			if(this.dist < (this.restl+1) && this.dist > (this.restl-1)){
				_root["n"+this.p1]["sForceX"+this.nm] = 0;
				_root["n"+this.p1]["sForceY"+this.nm] = 0;
				_root["n"+this.p2]["sForceX"+this.nm]= 0;
				_root["n"+this.p2]["sForceY"+this.nm] = 0;
			}else{
				if(this.dist < this.restl){
					this.error = this.restl - this.dist;
					_root["n"+this.p1]["sForceX"+this.nm] = (Math.cos(this.angle)*f*this.error)/2;
					_root["n"+this.p1]["sForceY"+this.nm] = (Math.sin(this.angle)*f*this.error)/2;
					_root["n"+this.p2]["sForceX"+this.nm] = (Math.cos(this.angle)*-f*this.error)/2;
					_root["n"+this.p2]["sForceY"+this.nm] = (Math.sin(this.angle)*-f*this.error)/2;
				}else{
					this.error = this.dist - this.restl;
					_root["n"+this.p1]["sForceX"+this.nm] = (Math.cos(this.angle)*-f*this.error)/2;
					_root["n"+this.p1]["sForceY"+this.nm] = (Math.sin(this.angle)*-f*this.error)/2;
					_root["n"+this.p2]["sForceX"+this.nm] = (Math.cos(this.angle)*f*this.error)/2;
					_root["n"+this.p2]["sForceY"+this.nm] = (Math.sin(this.angle)*f*this.error)/2;
				}				
			}
		}
	}
}