Elasticité d’un maillage – Action Script


Élasticité d’un maillage, Action Script [2008]

Essai de reproduction de code d’une bannière publicitaire trouvée sur le net.


L’original : Bannière Viacom, non créditée [nom : viacom_intro2k7.swf]

[swf:http://www.profusif.eu/wp-content/uploads/2017/05/viacom_intro2k7.swf 700]


La copie :

[swf:http://www.profusif.eu/wp-content/uploads/2017/05/00_Cubes.swf 550 400]


Le code de la copie :

var shapeFlag:Boolean = true;
var constante:Number = 17;
var constScreen:Number = 815;
var tab:Array = new Array();
var tabY:Array = new Array();
_global.matrice = new Array();
_global.sphere = new Array();
_global.whoIndex;
c1._alpha = 0;

function duplicate (movclip){
for (j=0; j<=constScreen; j++){
movclip.duplicateMovieClip(“a_”+(j), j);
var k:Number = adjust (j);
var l:Number = (adjust (j)*2);
setProperty (“a_”+(j), _y, k);
setProperty (“a_”+(j), _x, (j-l)*constante);
var clip = this[“a_”+(j)];
var hit_X = this[“a_”+(j)]._x;
var hit_Y = this[“a_”+(j)]._y;
var indexTab = j;
tab[j] = new Object( { obj1:clip, obj2:hit_X, obj3:hit_Y, obj4:test, obj5:indexTab} );
this[“a_”+(j)]._alpha = 63;
this[“a_”+(j)].onRollOver = function ()
{
circle_mc._x = _xmouse – ((constante * 11)/2);
circle_mc._y = _ymouse – ((constante * 11)/2);
matrice = zone(this);
}
}
}
function adjust (j){
var i = n = 0;
var m:Number = j;
for (n=0;n<24;n++){ if (m- constante * 2>=0) {m -= constante * 2;}
else if (m- constante * 2<0){break;}
}
i= constante * n;
return (i);
}
function zone(clip){
tabY.length = 0;
matrice.length = 0;
var k =0;
var whoBool = false;
for(j=-5; j<6; j++){
var str:String = clip._name;
StrIndex = str.slice(2);
StrIndex = int(StrIndex);
NumIndex = StrIndex;
var Yclip = tab[NumIndex + j].obj1;
var YindexTab = tab[NumIndex + j].obj5;
if (j==0) {whoBool = true;}
else if (j!=0) {whoBool = false;}
if (tab[NumIndex + j].obj3 == tab[NumIndex].obj3){
tabY[k] = new Object( { obj1:Yclip, obj2:YindexTab, obj3:whoBool } );
k++;
}
else if (tab[NumIndex + j].obj3 != tab[NumIndex].obj3){
if (tabY.length == 0){}
if (tabY.length != 0){tabY.length = k; break;}
}
}
k = -5;
for(j=0; j<11; j++){
indexOrigine = tabY[0].obj2 + (k * (2*constante));
if (indexOrigine<0){k++;} else if (indexOrigine>0){break;}
}
i = 0;
var seuil = 0;
for (j=0;k<6;j++,k++){
for(i=0;i<tabY.length;i++){
var temp = (indexOrigine + i) + ((2*constante)*j);
if(temp<=(tab.length-1)){ Mclip = tab[temp].obj1; Mhit_X = tab[temp].obj2; Mhit_Y = tab[temp].obj3; var temp2 = (j * tabY.length) + i; var posY = k; var posX = i; matrice[temp2] = new Object({ obj1:Mclip, obj2:Mhit_X, obj3:Mhit_Y, obj4:Mtest}); if ((tabY[i].obj3 == true)&&(k==0)){ whoIndex = temp2; } } else if(temp>tab.length){seuil = 1; break;}
}
if (seuil ==1){break;}
}
return (matrice);
}
duplicate (c1);

trace(getTimer());

//____________________________________________________________________________________

var raideur = 0.2;
var frottement = 0.95;
vx = vy = v2x = v2y = 0;
var ATANSCALE = 2/Math.PI;
var first_x = first_y = 0;
var widthX = heightY = 187;

onEnterFrame = function() {
for (i=0;i<tab.length;i++){
tab[i].obj4 = circle_mc.hitTest(tab[i].obj2, tab[i].obj3, shapeFlag);
if (!tab[i].obj4){
ax = raideur * ((tab[i].obj2 – tab[i].obj1._x)/3);
ay = raideur * ((tab[i].obj3 – tab[i].obj1._y)/3);
vx += ax;
vy += ay;
vx *= (frottement * 1);
vy *= (frottement * 1);
tab[i].obj1._x += vx;
tab[i].obj1._y += vy;
}
}
for (i=0;i<matrice.length;i++){
matrice[i].obj4 = circle_mc.hitTest(matrice[i].obj2, matrice[i].obj3, shapeFlag);
if (matrice[i].obj4){
var total = matrice.length-1;
var y_mc = matrice[i].obj3 – matrice[0].obj3;
var x_mc = matrice[i].obj2 – matrice[0].obj2;
if ((matrice[whoIndex].obj2 < (constante*5))||(matrice[whoIndex].obj3 < (constante*5))){
if (matrice[whoIndex].obj2 < (constante*5)){
x_mc = matrice[i].obj2 – matrice[0].obj2 + ((constante*5) – matrice[whoIndex].obj2);
}
if (matrice[whoIndex].obj3 < (constante*5)){
y_mc = matrice[i].obj3 – matrice[0].obj3 + ((constante*5) – matrice[whoIndex].obj3);
}
var xk=(x_mc / widthX)*2-1;
var yk=(y_mc / heightY)*2-1;
var zk = Math.sqrt(1.3-(xk * xk + yk*yk));
var xs = Math.atan( xk / zk ) * ATANSCALE;
var ys = Math.atan( yk / zk ) * ATANSCALE;
if (matrice[whoIndex].obj2 < (constante*5)){ var xtex = (matrice[0].obj2 – ((constante*5) – matrice[whoIndex].obj2))+(widthX * (xs+1)/2); } else if(matrice[whoIndex].obj2 >= (constante*5)){
var xtex = matrice[0].obj2 + (widthX * (xs+1)/2);
}
if (matrice[whoIndex].obj3 < (constante*5)){ var ytex = (matrice[0].obj3 – ((constante*5) – matrice[whoIndex].obj3))+(heightY * (ys+1)/2); } else if(matrice[whoIndex].obj3 >= (constante*5)){
var ytex = matrice[0].obj3 + (heightY * (ys+1)/2);
}
}
else if ((matrice[whoIndex].obj2 >= (constante*5)) && (matrice3[whoIndex].obj3 >= (constante*5))){
var xk=(x_mc / widthX)*2-1;
var yk=(y_mc / heightY)*2-1;
var zk = Math.sqrt(1.3-(xk * xk + yk*yk));
var xs = Math.atan( xk / zk ) * ATANSCALE;
var ys = Math.atan( yk / zk ) * ATANSCALE;
var xtex = matrice[0].obj2+(widthX * (xs+1)/2);
var ytex = matrice[0].obj3+(heightY * (ys+1)/2);
}
var tempX = ((xtex – matrice[i].obj2)) + matrice[i].obj2;
var tempY = ((ytex – matrice[i].obj3)) + matrice[i].obj3;
var difX = matrice[i].obj2 – tempX;
var difY = matrice[i].obj3 – tempY;
var clipS = matrice[i].obj1;
var oldSX = matrice[i].obj2;
var oldSY = matrice[i].obj3;
var newSX = matrice[i].obj2 + difX;
var newSY = matrice[i].obj3 + difY;
sphere[i] = new Object( {obj1:clipS, obj2:oldSX, obj3:oldSY, obj4:newSX, obj5:newSY, obj6:a2x, obj7:a2y, obj8:v2x, obj9:v2y} );
sphere[i].obj6 = raideur * (sphere[i].obj4 – sphere[i].obj1._x);
sphere[i].obj7 = raideur * (sphere[i].obj5 – sphere[i].obj1._y);
sphere[i].obj8 += sphere[i].obj6;
sphere[i].obj9 += sphere[i].obj7;
sphere[i].obj8 *= frottement;
sphere[i].obj9 *= frottement;
sphere[i].obj1._x += sphere[i].obj8;
sphere[i].obj1._y += sphere[i].obj9;
}
}
trace(getTimer());
}

//____________________________________________________________________________________

gotoAndPlay(5);