Snowflake Formation

I had to one up kirupa’s example :stuck_out_tongue:


_root.createEmptyMovieClip("container",1);
var d = 1;
var radius = 5;
wind = 0;
function addCircle(x, y, scale) {
    var mc = container.attachMovie("Circle", "circle"+d, d++);
    mc._x = x;
    mc._y = y;
    mc.vx = Math.random()-.5;
    mc.vy = Math.random()-.5;
    mc.t = 0;
    mc._xscale = mc._yscale=scale;
    mc.colorobj = new Color(mc.coloroverlay);
    return mc;
}
function makeSnowParticle(x, y) {
    mc = addCircle(x, y, 3+Math.random()*2);
    mc.growthi = -1;
    mc.track = -1;
    mc.falling = false;
    mc.isSeed = false;
    mc.setHue(.3);
    mc.onEnterFrame = function() {
        dx = 250-this._x;
        dy = 150-this._y;
        this._x += this.vx+wind;
        this._y += this.vy;
        if (!this.falling) {
            this.vx += dx/80000;
            this.vy += dy/80000;
        } else {
            this.vy += .02;
            if (this._y>300+this._width/2 && this.parent != null) {
                this.removeMovieClip();
            }
        }
        if (!this.isSeed) {
            dx = seed._x-this._x;
            dy = seed._y-this._y;
            d2 = (dx*dx+dy*dy);


            if (this.track == -1) {
                if (d2<3500) {
                    this.growthi = -2;
                    this.colorobj.setRGB(0xFFFFFF);
                    this.track = seed.growthi;
                    this.parent = seed;
                    seed.growthi++;
                    this.filters = [];
                    makeSnowParticle(random(500),random(300));
                    if (seed.growthi>=36) {
                        seed = null;
                        setSeed();
                    }
                }
            } else {
                this._xscale = this._yscale += (10-this._yscale)/15;
                this.p = getParticlePosition(this.track, this.parent.t);
                dx = (this.parent._x+this.p.x-this._x);
                dy = (this.parent._y+this.p.y-this._y);
                d2 = (dx*dx+dy*dy);
                var fx = .01*dx-.08*this.vx;
                var fy = .01*dy-.08*this.vy;
                this.vx += fx;
                this.vy += fy;
                if (seed != this.parent) {
                    this.parent.falling = true;
                    this.falling = true;
                }
            }
        } else {
            this.t += .01;
        }
    };
    return mc;
}
function getParticlePosition(i, rotation) {
    if (i<18 || i>=30) {
        var normalizedi = i>=30 ? i-12 : i;
        var ri = 1+Math.floor(normalizedi/6);
        return {x:ri*radius*Math.cos(rotation+Math.PI/3*normalizedi), y:ri*radius*Math.sin(rotation+Math.PI/3*normalizedi)};
    } else {
        var normalizedi = i-18;
        var t = Math.PI/3*normalizedi;
        var s = normalizedi<6 ? 1 : -1;
        return {x:3*radius*Math.cos(rotation+t)+s*radius*Math.cos(rotation+t+Math.PI/2), y:3*radius*Math.sin(rotation+t)+s*radius*Math.sin(rotation+t+Math.PI/2)};
    }
}
MovieClip.prototype.setHue = function(x, mc) {
    //x = 0 - 1
    x = Math.max(x*2*Math.PI, 0.01);
    r = 128+128*Math.cos(x);
    g = 128+128*Math.cos(x+Math.PI*2/3);
    b = 128+128*Math.cos(x+Math.PI*4/3);
    var hex = r << 16 | g << 8 | b;
    this.colorobj.setRGB(hex);
};

function setSeed() {
    seed = makeSnowParticle(250, 150);
    seed.setHue(.1);
    seed.growthi = 0;
    seed.isSeed = true;
    seed._visible = false;
    seed.t = Math.random()*Math.PI*2;
    seed._x = 250;
    seed._y = 150;
}

for (i=0; i<=180; i++) {
    makeSnowParticle(random(500),random(300));
}
setSeed();
var windt = 0;
onEnterFrame = function () {
    wind = .2*Math.sin(windt += .05);
};

> Preview Here <