|
旋转的长方体
代码: a = 50*Math.cos(n*Math.PI/180);
b = 100*Math.sin(n*Math.PI/180);
c1 = 300;
c2 = 200;
_root.createEmptyMovieClip("triangle", 1);
with (_root.triangle) {
lineStyle(1, 0x000000, 50);
moveTo(a+c1, b+c2);
lineTo(50*math.cos((n+90)*math.pi/180)+
c1,100*math.sin((n+90)*math.pi/180)+c2);
lineTo(50*math.cos((n+180)*math.pi/180)+
c1,100*math.sin((n+180)*math.pi/180)+c2);
lineTo(50*math.cos((n+270)*math.pi/180)+
c1,100*math.sin((n+270)*math.pi/180)+c2);
lineTo(50*math.cos((n+360)*math.pi/180)+
c1,100*math.sin((n+360)*math.pi/180)+200);
lineStyle(1, 0x000000, 50);
moveTo(a+200, b+100);
lineTo(50*math.cos((n+90)*math.pi/180)+
200,100*math.sin((n+90)*math.pi/180)+100);
lineTo(50*math.cos((n+180)*math.pi/180)+
200,100*math.sin((n+180)*math.pi/180)+100);
lineTo(50*math.cos((n+270)*math.pi/180)+
200,100*math.sin((n+270)*math.pi/180)+100);
lineTo(50*math.cos((n+360)*math.pi/180)+
200,100*math.sin((n+360)*math.pi/180)+100);
lineStyle(1, 0x000000, 30);
moveTo(a+200, b+100);
lineTo(a+c1, b+c2);
moveTo(50*math.cos((n+90)*math.pi/180)
+c1,100*math.sin((n+90)*math.pi/180)+c2);
lineTo(50*math.cos((n+90)*math.pi/180)
+200,100*math.sin((n+90)*math.pi/180)+100);
moveTo(50*math.cos((n+180)*math.pi/180)
+c1,100*math.sin((n+180)*math.pi/180)+c2);
lineTo(50*math.cos((n+180)*math.pi/180)
+200,100*math.sin((n+180)*math.pi/180)+100);
moveTo(50*math.cos((n+270)*math.pi/180)
+c1,100*math.sin((n+270)*math.pi/180)+c2);
lineTo(50*math.cos((n+270)*math.pi/180)
+200,100*math.sin((n+270)*math.pi/180)+100);
}
用as做烛光,相当逼真。
代码: offsetX = 275;
offsetY = 100;
left = 0;
right = 0;
top = 0;
leftGoal = 0;
rightGoal = 0;
topGoal = 0;
rate = .2;
decay = .9;
for (var i = 0; i<shapes.length; i++) {
var name = "flame"+i;
createEmptyMovieClip(name, i);
_root[name]._x = offsetX;
_root[name]._y = offsetY;
_root[name].offset = parseInt(shapes[i].split("")[0]);
_root[name].fade = parseInt(shapes[i].split("")[1]);
}
createEmptyMovieClip("heat", i);
heat._x = offsetX;
heat._y = offsetY;
checkEdge = function (cur, side, dist) {
change = 0;if (cur>side) {
change -= Math.random()*dist;
} else if (cur<-side) {
change += Math.random()*dist;
}
return change;
};
onEnterFrame = function () {
leftGoal += Math.random()*6-3;
leftGoal += checkEdge(leftGoal,10, 3);
rightGoal += Math.random()*6-3;
rightGoal += checkEdge(rightGoal, 10,3);
topGoal += Math.random()*8-4;
topGoal += checkEdge(topGoal, 15, 4);
leftAccel = (leftGoal-left)*rate;
leftVeloc += leftAccel;
leftVeloc *= decay;
left += leftVeloc;
rightAccel = (rightGoal-right)*rate;
rightVeloc += rightAccel;
rightVeloc *= decay;right += rightVeloc;
topAccel = (topGoal-top)*rate;
topVeloc += topAccel;
topVeloc *= decay;top += topVeloc;
for (var i = 0; i<shapes.length; i++) {
with (_root["flame"+i]) {
clear();colors = [0xFCE39C, 0xF4AC35];
alphas = [_root["flame"+i].fade,
_root["flame"+i].fade-20];
ratios = [70, 255];
matrix = {matrixType:"box", x:-50,
y:50, w:100, h:200, r:0};
beginGradientFill("radial",colors,
alphas, ratios, matrix);
lineStyle(1, 0x000000, 0);
moveTo(0-left+right,0-top-_root
["flame"+i].offset*2);
curveTo(40+_root["flame"+i].
offset+right, 180,0, 200);
curveTo(-40-_root["flame"+i].
offset-left, 180, 0-left+right,
0-top-_root["flame"+i].offset*2);
endFill();
}
} with (_root.heat) {
clear();colors = [0x986932, 0x986932];
alphas = [70, 0];
ratios = [20, 255];
matrix = {matrixType:"box",
x:-20-left/2, y:120-top, w:40+right/2,h:120+top, r:0
};
beginGradientFill("radial",
colors, alphas, ratios, matrix);
lineStyle(1,0x000000, 0);
moveTo(-50, 0);
lineTo(50, 0);
lineTo(50, 200);
lineTo(-50, 200);
lineTo(-50,0);
endFill();
}
duplicateMovieClip(
_root["flame"+(shapes.length-1)],
"shapeMask",shapes.length+1);
heat.setMask(shapeMask);
};
上一篇:AS1.0的OOP 与 AS2.0的OOP对比
下一篇:FlashMX教程-Load Movie
|