1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
| import flash.filters.*;
import mx.transitions.Tween;
import mx.transitions.easing.*;
Stage.scaleMode = "noScale";
// Valeurs de départ des coefficients de la mtrice
var rwgt:Number = .3086;
var gwgt:Number = .6094;
var bwgt:Number = .0820;
// La matrice
var colorMatrix:Array = [rwgt, gwgt, bwgt, 0, 0, rwgt, gwgt, bwgt, 0, 0, rwgt, gwgt, bwgt, 0, 0, 0, 0, 0, 1, 0];
// Le filtre
var luminanceTransform:ColorMatrixFilter = new ColorMatrixFilter(colorMatrix);
// On l'applique au clip
mc.filters = [luminanceTransform];
// Dans une seconde, on démarre la Tween, qui va de 0 à 1 en 3 secondes
var foo:Tween;
function startTween():Void {
foo = new Tween(null, null, Regular.easeInOut, 0, 1, 30, false);
foo.onMotionChanged = refreshFilter;
}
// A chaque changement de la Tween, on redéfinit les coef de la matrice,
// et on applique le filtre au clip
function refreshFilter(argTween:Tween, argValue:Number):Void {
/*
Les coefs marqués de "####" vont de leur valeur de départ (rwgt, gwgt ou bwgt) à 1.
Alors que les autres vont de leur valeur de départ à 0.
*/
// rouge
// #### coef rouge (il va de la valeur de départ "rwgt" à 1)
colorMatrix[0] = rwgt+(1-rwgt)*argValue;
// coef vert (il va de la valeur de départ "gwgt" à 0)
colorMatrix[1] = gwgt*(1-argValue);
// coef bleu (il va de la valeur de départ "bwgt" à 0)
colorMatrix[2] = bwgt*(1-argValue);
// vert
// coef rouge
colorMatrix[5] = rwgt*(1-argValue);
// #### coef vert
colorMatrix[6] = gwgt+(1-gwgt)*argValue;
// coef bleu
colorMatrix[7] = bwgt*(1-argValue);
//bleu
// coef rouge
colorMatrix[10] = rwgt*(1-argValue);
// coef vert
colorMatrix[11] = gwgt*(1-argValue);
// #### coef bleu
colorMatrix[12] = bwgt+(1-bwgt)*argValue;
// On donne la nouvelle matrice au filtre
luminanceTransform.matrix = colorMatrix;
// On applique le filtre au clip
mc.filters = [luminanceTransform];
}
startTween(); |
Partager