PDA

View Full Version : Array AS in Pom's footer



no bone movie
June 16th, 2003, 10:25 AM
I really like the text effect Pom used in the footer contest, and would like to use the same grid-type method of creating mc letters but with a different effect. i understand how to change the parameters and shapes of the letters, but can't seem to figure out which piece of code is purely for the explosion effect. :sigh: basically, i want the letters but with the 'Repel' effect from

http://downloads.junioronline.us


here is Pom's AS:


cellSize=3;
radius=10;
damp=.85;
dampR=.8;
numLetter=0;
letterSpacing=40;
shift = .5;

letterP=new Array(
[1,1,1,1,1,0],
[1,1,0,0,0,1],
[1,1,0,0,0,1],
[1,1,1,1,1,0],
[1,1,0,0,0,0],
[1,1,0,0,0,0]);
letterO=new Array(
[0,1,1,1,1,0],
[1,1,0,0,0,1],
[1,1,0,0,0,1],
[1,1,0,0,0,1],
[1,1,0,0,0,1],
[0,1,1,1,1,0]);
letterM=new Array(
[1,1,0,0,0,1],
[1,1,1,0,1,1],
[1,1,0,1,0,1],
[1,1,0,0,0,1],
[1,1,0,0,0,1],
[1,1,0,0,0,1]);

function containerRollOVer(){
delete this.onRollOver;
for (var clip in this) this[clip].explode();
}

function displayCell(letter){
var num=1,i,j,mc;
clip=this.createEmptyMovieClip("container"+numLetter,numLetter++);
clip._x=30+numLetter*letterSpacing;
clip._y=20;
clip.createEmptyMovieClip("cell",0)._visible = 0;
clip.cell.lineStyle(cellSize,0xcccccc,100);
clip.cell.lineTo(.15,.45);
for (j=0;j<letter.length;j++){
for (i=0;i<letter[0].length;i++){
if (letter[j][i]==1){
mc=clip.cell.duplicateMovieClip("cell"+num,num);
mc.i=i;
mc.j=j;
mc._x=i*(cellSize+shift);
mc._y=j*(cellSize+shift);
num++;
}
}
}
clip.cell.removeMovieClip();
this.clip.onRollOver=containerRollOver;
}

MovieClip.prototype.explode=function(){
this.vx=(Math.random()-.5)*2*radius;
this.vy=(Math.random()-.5)*2*radius;
this.onEnterFrame=function(){
this.resizeCell();
this._x+=this.vx;
this._y+=this.vy;
this.vx*=damp;
this.vy*=damp;
if (Math.abs(this.vx)+Math.abs(this.vy) < .08)
this.onEnterFrame=spinningAround;
}
}

function spinningAround(){
var diffx=this._x-this.i*(cellSize+shift);
var diffy=this._y-this.j*(cellSize+shift);
this.resizeCell();
this.vx-=diffx/7;
this.vy-=diffy/7;
this.vx*=dampR;
this.vy*=dampR;
this._x+=this.vx;
this._y+=this.vy;
if (Math.abs(this.vx)+Math.abs(this.vy) < .01){
this._x=this.i*(cellSize+shift);
this._y=this.j*(cellSize+shift);
delete this.onEnterFrame;
this._parent.onRollOver=containerRollOver;
}
}

MovieClip.prototype.resizeCell=function(){
var diffx=this._x-this.i*cellSize;
var diffy=this._y-this.j*cellSize;
var dist=diffx*diffx+diffy*diffy;
this._xscale=this._yscale=this._alpha=(10000-dist)/100;
// you can try that instead:
// this._xscale=this._yscale=this._alpha=(1000-dist)/10;
}

displayCell(letterP);
displayCell(letterO);
displayCell(letterM);


and here is the .fla using the repel effect using pre-made mc:

Jubba
June 16th, 2003, 10:34 AM
MovieClip.prototype.explode

is purely for the explosion...

no bone movie
June 16th, 2003, 10:49 AM
it works but when i run the mouse over the letters, the whole letters move rather than become divided as in the junioronline fla. any ideas how i can free up the small square sections in each letter?

thanks.

Jubba
June 16th, 2003, 11:04 AM
whats the code in your movie?

no bone movie
June 16th, 2003, 11:20 AM
I haven't got any real code yet! just thought i'd add this if i could get it to work the way i want it to. just tried replacing the explode script with the repel script. the repel script affect any mc on the stage, but it's treating the small squares as the whole letter the create rather than individual squares. hope this makes sense.
here's what i've been messing with:


cellSize=2;
radius=10;
damp=.8;
dampR=.8;
numLetter=0;
letterSpacing=30;
shift = .5;

letterL=new Array(
[1,1,0,0,0,0,0,0],
[1,1,0,0,0,0,0,0],
[1,1,0,0,0,0,0,0],
[1,1,0,0,0,0,0,0],
[1,1,0,0,0,0,0,0],
[1,1,0,0,0,0,0,0],
[1,1,0,0,0,0,0,0],
[1,1,1,1,1,1,1,1]);
letterO=new Array(
[0,1,1,1,1,1,1,0],
[1,1,0,0,0,0,1,1],
[1,1,0,0,0,0,1,1],
[1,1,0,0,0,0,1,1],
[1,1,0,0,0,0,1,1],
[1,1,0,0,0,0,1,1],
[1,1,0,0,0,0,1,1],
[0,1,1,1,1,1,1,0]);
letterA=new Array(
[0,1,1,1,1,1,1,0],
[1,1,0,0,0,0,1,1],
[1,1,0,0,0,0,1,1],
[1,1,0,0,0,0,1,1],
[1,1,0,0,0,0,1,1],
[1,1,1,1,1,1,1,1],
[1,1,0,0,0,0,1,1],
[1,1,0,0,0,0,1,1]);
letterD=new Array(
[1,1,1,1,1,1,0,0],
[1,1,0,0,0,0,1,1],
[1,1,0,0,0,0,1,1],
[1,1,0,0,0,0,1,1],
[1,1,0,0,0,0,1,1],
[1,1,0,0,0,0,1,1],
[1,1,0,0,0,0,1,1],
[1,1,1,1,1,1,0,0]);
letterI=new Array(
[0,0,1,1,1,1,0,0],
[0,0,0,1,1,0,0,0],
[0,0,0,1,1,0,0,0],
[0,0,0,1,1,0,0,0],
[0,0,0,1,1,0,0,0],
[0,0,0,1,1,0,0,0],
[0,0,0,1,1,0,0,0],
[0,0,1,1,1,1,0,0]);
letterN=new Array(
[1,1,0,0,0,0,1,1],
[1,1,1,0,0,0,1,1],
[1,1,1,1,0,0,1,1],
[1,1,0,1,1,0,1,1],
[1,1,0,0,1,1,1,1],
[1,1,0,0,0,1,1,1],
[1,1,0,0,0,0,1,1],
[1,1,0,0,0,0,1,1]);
letterG=new Array(
[0,1,1,1,1,1,1,0],
[1,1,0,0,0,0,1,1],
[1,1,0,0,0,0,1,1],
[1,1,0,0,0,0,0,0],
[1,1,0,0,1,1,1,1],
[1,1,0,0,0,0,1,1],
[1,1,0,0,0,0,1,1],
[0,1,1,1,1,1,1,0]);
function containerRollOVer(){
delete this.onRollOver;
for (var clip in this) this[clip].explode();
}

function displayCell(letter){
var num=1,i,j,mc;
clip=this.createEmptyMovieClip("container"+numLetter,numLetter++);
clip._x=30+numLetter*letterSpacing;
clip._y=20;
clip.createEmptyMovieClip("cell",0)._visible = 0;
clip.cell.lineStyle(cellSize,0xcccccc,100);
clip.cell.lineTo(.15,.45);
for (j=0;j<letter.length;j++){
for (i=0;i<letter[0].length;i++){
if (letter[j][i]==1){
mc=clip.cell.duplicateMovieClip("cell"+num,num);
mc.i=i;
mc.j=j;
mc._x=i*(cellSize+shift);
mc._y=j*(cellSize+shift);
num++;
}
}
}
clip.cell.removeMovieClip();
this.clip.onRollOver=containerRollOver;
}

MovieClip.prototype.onEnterFrame = function()
{
if (this._name != "")
{
if (!this.defaultX) this.defaultX = this._x;
if (!this.defaultY) this.defaultY = this._y;
magnet = 500;

this.X0 = this._x;
this.y0 = this._y;
this.X1 = _root._xmouse;
this.Y1 = _root._ymouse;

this.distanceX = this.X1-this.X0
this.distanceY = this.Y1-this.Y0
this.distance = Math.sqrt((this.distanceX * this.distanceX) + (this.distanceY * this.distanceY))

this.powerX = this._x - (this.distanceX / this.distance) * magnet / this.distance;
this.powerY = this._y - (this.distanceY / this.distance) * magnet / this.distance;
this.forceX = (this.forceX + (this.defaultX - this.X0) / 2) / 1.66
this.forceY = (this.forceY + (this.defaultY - this.Y0) / 2) / 1.66

this._x = this.powerX + this.forceX;
this._y = this.powerY + this.forceY;
}
}

function spinningAround(){
var diffx=this._x-this.i*(cellSize+shift);
var diffy=this._y-this.j*(cellSize+shift);
this.resizeCell();
this.vx-=diffx/7;
this.vy-=diffy/7;
this.vx*=dampR;
this.vy*=dampR;
this._x+=this.vx;
this._y+=this.vy;
if (Math.abs(this.vx)+Math.abs(this.vy) < .01){
this._x=this.i*(cellSize+shift);
this._y=this.j*(cellSize+shift);
delete this.onEnterFrame;
this._parent.onRollOver=containerRollOver;
}
}

MovieClip.prototype.resizeCell=function(){
var diffx=this._x-this.i*cellSize;
var diffy=this._y-this.j*cellSize;
var dist=diffx*diffx+diffy*diffy;
this._xscale=this._yscale=this._alpha=(10000-dist)/100;
// you can try that instead:
// this._xscale=this._yscale=this._alpha=(1000-dist)/10;
}

displayCell(letterL);
displayCell(letterO);
displayCell(letterA);
displayCell(letterD);
displayCell(letterI);
displayCell(letterN);
displayCell(letterG);

pom
June 16th, 2003, 11:54 AM
It's going to kill your CPU, I'm afraid... And what do you mean by this?
Originally posted by no bone movie
any ideas how i can free up the small square sections in each letter?

no bone movie
June 16th, 2003, 12:16 PM
Originally posted by Ilyas
It's going to kill your CPU, I'm afraid... And what do you mean by this?

i had a feeling it was getting a bit much :sigh:

i meant allow the small squares (which make up the letters) to move freely rather than be rigid, the way they do in the junioronline fla.

thanks anyway :)