# A trip down Alka-Seltzer Lane

**URL:** <https://forum.kirupa.com/t/a-trip-down-alka-seltzer-lane/279673>\
**Category:** Uncategorized\
**Created:** [January 17, 2009, 11:31am UTC](https://forum.kirupa.com/t/a-trip-down-alka-seltzer-lane/279673 "2009-01-17T11:31:43Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![bigmtnskier](https://avatars.discourse-cdn.com/v4/letter/b/a4c791/32.png) [@bigmtnskier](https://forum.kirupa.com/u/bigmtnskier)\
**Post date:** [January 17, 2009, 11:31am UTC](https://forum.kirupa.com/t/a-trip-down-alka-seltzer-lane/279673/1 "2009-01-17T11:31:43Z")

</div>

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/](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(x_2_Math.PI, 0.01);  
r = Math.floor(128+128_Math.cos(x));  
g = Math.floor(128+128_Math.cos(x+Math.PI_2/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 🙂

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