A trip down Alka-Seltzer Lane

Hey everyone; here’s my first entry! :sc: I need to fix a few things, like it getting slower once it’s left sitting for awhile, but other than that, it’s done.

See it in Action:
http://masterfidgeter.com/2009/01/flashas-experiment-a-trip-down-alka-seltzer-lane/

The guts:
[AS]
_root.createEmptyMovieClip(“container”,1);

var d = 1;
var cam_z = 0;
var cam_x = 0;
var cam_y = 0;
var maxdepth = 40;
var HALF_WIDTH = 500/2;
var HALF_HEIGHT = 300/2;

MovieClip.prototype.setHue = function(x, mc) {
x = Math.max(x2Math.PI, 0.01);
r = Math.floor(128+128Math.cos(x));
g = Math.floor(128+128
Math.cos(x+Math.PI2/3));
b = Math.floor(128+128
Math.cos(x+Math.PI*4/3));
var hex = r << 16 | g << 8 | b;
this.hue = x;
this.colorobj.setRGB(hex);
return hex;
};

MovieClip.prototype.update3D = function() {
var normalizedz = 1-(this.z-cam_z)/maxdepth;
if (normalizedz <= 0) {
this._visible = false;
} else {
this._x = (this.x-cam_x)*normalizedz + HALF_WIDTH;
this._y = (this.y-cam_y)normalizedz + HALF_HEIGHT;
this._xscale = this._yscale=100
(normalizedz)this.scaleFactor;
this._visible = true;
this._alpha = Math.max(0, maxdepth - Math.abs(this.z - cam_z)) / (maxdepth
0.5) * 100;
}
};

function addCircle®{
var mc = container.attachMovie(“circle”,“c”+d,d++);
mc.vx = mc.vy=0;
mc._x = mc._y = -100;
mc._width = mc._height=r*2;
mc.colorobj = new Color(mc.coloroverlay);
var hex = mc.setHue(.4);
mc.filters=[new flash.filters.GlowFilter(hex,.3,30,30)];
return mc;
}

var f = 0;
_root.onEnterFrame = function(){
cam_x += ((_root._xmouse - HALF_WIDTH)*0.2 - cam_x)*0.1;
cam_y += ((_root._ymouse - HALF_HEIGHT)*0.2 - cam_y)*0.1;
if (f++ % 10 == 0){
spawn();
}
};

function spawn(){
var mc = addCircle(19);
var spread = 150;
mc.x = random(spread) - random(spread);
mc.y = random(spread) - random(spread)
mc.z = cam_z - maxdepth;
mc.scaleFactor = Math.random()2;
mc.targetX = (random(spread) - random(spread))
(mc.scaleFactor/2);
mc.targetY = (random(spread) - random(spread))(mc.scaleFactor/2);
mc.jumpDistance = mc.scaleFactor * 10 + 10;
mc.targetZ = mc.z + mc.jumpDistance;
mc.easingFactor = 0.4
Math.random() + 0.1;
mc.update3D();
mc.visitedPt = false;
mc.onEnterFrame = function(){
if (Math.abs(this.z - this.targetZ) <= 0.1 && !this.visitedPt){
//take out the trash
if (this.z > max_depth + cam_z){
this.removeMovieClip();
return;
}
//ease this main particle to a new location
this.targetZ = this.z + this.jumpDistance;
this.targetX = (random(spread) - random(spread))(this.scaleFactor/2);
this.targetY = (random(spread) - random(spread))
(this.scaleFactor/2);
this.visitedPt = true;
//esplode
var sCount = 2 + random(5);
for (var i = 0; i < sCount; i++){
var shrapnel = addCircle(this._width * 0.2 * Math.random());
shrapnel.theta = i/sCount * Math.PI * 2;
shrapnel.speed = Math.random()*2 + 1;
shrapnel.zSpeed = Math.random()*2 - Math.random()*2;
shrapnel.x = this.x;
shrapnel.y = this.y;
shrapnel.z = this.z;
shrapnel.alpha = 100;
shrapnel.setHue(this.hue + Math.random()/6 - Math.random()/6);
shrapnel.onEnterFrame = function(){
this.z += this.zSpeed;
this.x += Math.cos(this.theta)*this.speed;
this.y += Math.sin(this.theta)*this.speed;
this.alpha *= 0.9;
if (this.alpha <= 1){
this.removeMovieClip();
return;
}
this.update3D();
};
}
}else{
this.visitedPt = false;
//ease to the target z (we’re at an intermediate location now)
this.z += (this.targetZ - this.z) * this.easingFactor;
this.x += (this.targetX - this.x) * this.easingFactor;
this.y += (this.targetY - this.y) * this.easingFactor;
}
this.update3D();
}
}
[/AS]
-Brian :slight_smile:

(ps. the zipped version is the correct dimensions and doesn’t have the button)