教你用FLASH制作漂亮的图形旋转动画效果
程序员文章站
2022-06-08 11:06:57
本教程是向大家介绍利用FLASH制作漂亮的图形旋转动画效果,采用代码实现特效,对于编程人员非常适合学习,转发过来,希望大家喜欢... 14-07-31...
本教程是向大家介绍利用flash制作漂亮的图形旋转动画效果,采用代码实现特效,对于编程人员非常适合学习,转发过来,希望大家喜欢!
效果:
代码如下:
复制代码
代码如下:var pmaxsize:number = 150;
var pcenterx:number = 275;
var pcentery:number = 200;
var pnumtraces:number = 20;
var pnumlayers:number = 30;
var pcurrentlayer:number = 0;
var plinecolour:number;
var ppointdegree:array = new array();
var ppointdegreechange:array = new array();
var ppointscale:array = new array();
var ppointscalechange:array = new array();
var ppointx:array = new array();
var ppointy:array = new array();
var pbasetimeline:movieclip;
var pintervalid:number;
function init(basetimeline:movieclip):void {
pbasetimeline = basetimeline;
pbasetimeline.createemptymovieclip("holder", 0);
for (var j:number = 0; j<pnumlayers; j++) {
pbasetimeline.createemptymovieclip("layer"+j, j+1);
pbasetimeline["layer"+j]._x = pcenterx;
pbasetimeline["layer"+j]._y = pcentery;
}
inittraces();
pbasetimeline.holder.onenterframe = function() {
movespheres();
};
pintervalid = setinterval(this, "updateseeds", 2000);
}
function inittraces() {
for (var i:number = 0; i<pnumtraces; i++) {
ppointx = 0;
ppointy = 0;
ppointdegree = (6.28318530718/pnumtraces)*i;
ppointscale = 50;
}
updateseeds();
for (i=0; i<pnumtraces; i++) {
plotline(i);
}
}
function movespheres() {
for (var i:number = 0; i<pnumtraces; i++) {
ppointdegree += ppointdegreechange;
ppointscale += ppointscalechange;
plotline(i, true);
}
pbasetimeline["layer"+pcurrentlayer]._alpha = 100;
pcurrentlayer = (pcurrentlayer+1)%pnumlayers;
for (var j:number = 0; j<pnumlayers; j++) {
pbasetimeline["layer"+((pcurrentlayer+j)%pnumlayers)]._alpha = (j/pnumlayers)*100;
}
pbasetimeline["layer"+pcurrentlayer].clear();
}
function plotline(i:number, drawline:boolean) {
pbasetimeline["layer"+pcurrentlayer].linestyle(1, plinecolour, 100);
pbasetimeline["layer"+pcurrentlayer].moveto(ppointx, ppointy);
ppointx = (math.cos(ppointdegree)*ppointscale);
ppointy = (math.sin(ppointdegree)*ppointscale);
if (drawline == true) {
pbasetimeline["layer"+pcurrentlayer].lineto(ppointx, ppointy);
}
}
function updateseeds() {
var deg:number;
var scale:number;
deg = randomrange(-100, 100)/2000;
if (ppointscale[0]>pmaxsize) {
scale = randomrange(-10, 0)/2;
} else if (ppointscale[0]<-pmaxsize) {
scale = randomrange(0, 10)/2;
} else {
scale = randomrange(-10, 10)/2;
}
for (var i:number = 0; i<pnumtraces; i++) {
ppointdegreechange = deg;
ppointscalechange = scale;
}
plinecolour = randomrange(0, 0xffffff);
}
function randomrange(min:number, max:number):number {
var randomnum:number = math.round(math.random()*(max-min))+min;
return randomnum;
}
init(this);
var pcenterx:number = 275;
var pcentery:number = 200;
var pnumtraces:number = 20;
var pnumlayers:number = 30;
var pcurrentlayer:number = 0;
var plinecolour:number;
var ppointdegree:array = new array();
var ppointdegreechange:array = new array();
var ppointscale:array = new array();
var ppointscalechange:array = new array();
var ppointx:array = new array();
var ppointy:array = new array();
var pbasetimeline:movieclip;
var pintervalid:number;
function init(basetimeline:movieclip):void {
pbasetimeline = basetimeline;
pbasetimeline.createemptymovieclip("holder", 0);
for (var j:number = 0; j<pnumlayers; j++) {
pbasetimeline.createemptymovieclip("layer"+j, j+1);
pbasetimeline["layer"+j]._x = pcenterx;
pbasetimeline["layer"+j]._y = pcentery;
}
inittraces();
pbasetimeline.holder.onenterframe = function() {
movespheres();
};
pintervalid = setinterval(this, "updateseeds", 2000);
}
function inittraces() {
for (var i:number = 0; i<pnumtraces; i++) {
ppointx = 0;
ppointy = 0;
ppointdegree = (6.28318530718/pnumtraces)*i;
ppointscale = 50;
}
updateseeds();
for (i=0; i<pnumtraces; i++) {
plotline(i);
}
}
function movespheres() {
for (var i:number = 0; i<pnumtraces; i++) {
ppointdegree += ppointdegreechange;
ppointscale += ppointscalechange;
plotline(i, true);
}
pbasetimeline["layer"+pcurrentlayer]._alpha = 100;
pcurrentlayer = (pcurrentlayer+1)%pnumlayers;
for (var j:number = 0; j<pnumlayers; j++) {
pbasetimeline["layer"+((pcurrentlayer+j)%pnumlayers)]._alpha = (j/pnumlayers)*100;
}
pbasetimeline["layer"+pcurrentlayer].clear();
}
function plotline(i:number, drawline:boolean) {
pbasetimeline["layer"+pcurrentlayer].linestyle(1, plinecolour, 100);
pbasetimeline["layer"+pcurrentlayer].moveto(ppointx, ppointy);
ppointx = (math.cos(ppointdegree)*ppointscale);
ppointy = (math.sin(ppointdegree)*ppointscale);
if (drawline == true) {
pbasetimeline["layer"+pcurrentlayer].lineto(ppointx, ppointy);
}
}
function updateseeds() {
var deg:number;
var scale:number;
deg = randomrange(-100, 100)/2000;
if (ppointscale[0]>pmaxsize) {
scale = randomrange(-10, 0)/2;
} else if (ppointscale[0]<-pmaxsize) {
scale = randomrange(0, 10)/2;
} else {
scale = randomrange(-10, 10)/2;
}
for (var i:number = 0; i<pnumtraces; i++) {
ppointdegreechange = deg;
ppointscalechange = scale;
}
plinecolour = randomrange(0, 0xffffff);
}
function randomrange(min:number, max:number):number {
var randomnum:number = math.round(math.random()*(max-min))+min;
return randomnum;
}
init(this);
教程结束,以上就是flash制作漂亮的图形旋转动画效果,希望大家喜欢本教程!