请大家先看右边的动画演示。这个动画就是由 jimbob 制作的,您可以到这里来下载这个动画的原始文件。下面请看他的详细解释: If Frame Is Loaded ("end") |
initalise:
Comment:
Comment: 初始化全局变量
Set Variable: "pi" = 3 .1415
Set Variable: "worldRotX" = .496 //初始化旋转度
Set Variable: "worldRotY" = 5 .267
Set Variable: "centerx" = 160 //3D中心的X,Y位置
Set Variable: "centery" = 180
// 设置点的3D坐标值 用 ,分割XYZ R分割各个点
Set Variable: "ptsetstringA" = "40,40,-40R-40,40,-40R-40,-40,-40R40,-40,-40R40,40,40R-40,40,40R-40,-40,40R40,-40,40R"
Set Variable: "numberofpts" = 8 //点数
Start Drag ("/drag", lockcenter)
Comment:
Comment: 设置点位置
Set Variable: "inptsetstring" = ptsetstringA
Set Variable: "inshapename" = "cube"
Set Variable: "innumberofpts" = numberofpts
Call ("make matrix") //返回各个点的3D坐标如 cobe_01_x=50
// cobe_01_y=50
// cobe_01_z=-50
Comment:
Comment: 生成其余的光球
Set Variable: "counter" = 1
Loop While (counter <> numberofpts)
Set Variable: "counter" = counter + 1
Duplicate Movie Clip ("light1", "light" & counter, counter + 10)
End Loop
display stars:
Comment:
Comment: 获取当前鼠标位置
Set Variable: "Xm" = GetProperty ("/drag",_x)
Set Variable: "Ym" = GetProperty ("/drag",_y)
Comment: 获取当前跟踪位置
Set Variable: "Xf" = centerx
Set Variable: "Yf" = centery
Comment: 计算间隔并由加速度计算当前位置
Set Variable: "Sx" = Xm-Xf
Set Variable: "Sy" = Ym-Yf
Set Variable: "Xnew" = Xf+(Sx/50)
Set Variable: "Ynew" = Yf+(Sy/50)
Comment:
Comment: 设置旋转度
Comment:
Set Variable: "worldRotX" = worldRotX + (((Ym - Yf) /300)*0 .5)
// 根据鼠标位移来改变旋转度
If (worldRotX>(2*pi))
Set Variable: "worldRotX" = worldRotX-(2*pi)
End If
If (worldRotX<0)
Set Variable: "worldRotX" = worldRotX+(2*pi)
End If
Set Variable: "worldRotY" = worldRotY - (((Xm-Xf)/400)*0 .5)
// 根据鼠标位移来改变旋转度
If (worldRotY>(2*pi))
Set Variable: "worldRotY" = worldRotY-(2*pi)
End If
If (worldRotY<0)
Set Variable: "worldRotY" = worldRotY+(2*pi)
End If
Call ("spinXY") //获取转换后新点的3D坐标
// ? 如 cube_01_tx; cube_01_ty; cube_01_tz
Comment:
Comment: 画光球
Comment:
Set Variable: "counter" = 0
Loop While (counter <> numberofpts)
Set Variable: "counter" = counter + 1
Set Variable: "lightnum" = "0"&counter
Set Variable: "WhichLight" = "light" & counter
Call ("display light") //画出光球
End Loop
Set Variable: "centerx" = Xnew
Set Variable: "centery" = Ynew
loop back:
Go to and Play ("display stars")
spinXY:
If (worldRotX>0)
Set Variable: "tmpX" = worldRotX
Set Variable: "tmpX" = Substring(tmpX,1,1) & Substring(tmpX,3,2)
Set Variable: "sinX" = eval("/sin:sin"&tmpX)
Else
Set Variable: "tmpX" = worldRotX
Set Variable: "tmpX" = Substring(tmpX,2,1) & Substring(tmpX,4,2)
Set Variable: "sinX" = 0 - eval("/sin:sin"&tmpX)
End If
If (worldRotY>0)
Set Variable: "tmpY" = (worldRotY +10 .0001)
Set Variable: "tmpY" = Substring(tmpY,2,1) & Substring(tmpY,4,2)
Set Variable: "sinY" = eval("/sin:sin"&tmpY)
Else
Set Variable: "tmpY" = (worldRotY -10 .0001)
Set Variable: "tmpY" = Substring(tmpY,3,1) & Substring(tmpY,5,2)
Set Variable: "sinY" = 0 - eval("/sin:sin"&tmpY)
End If
Set Variable: "cosX" = eval("/cos:cos"&tmpX)
Set Variable: "cosY" = eval("/cos:cos"&tmpY)
Set Variable: "counter" = 0
Loop While (counter <> numberofpts)
Set Variable: "counter" = counter + 1
Set Variable: "in" = counter
If (length(in) = 1)
Set Variable: "in" = "0" & in
End If
// 根据旋转角度算出新的3D坐标
Set Variable: "tmp_zpos" = eval("cube_"&in&"_z") * cosY - eval("cube_"&in&"_x") * sinY
Set Variable: "cube_"&in&"_tx" = eval("cube_"&in&"_z") * sinY + eval("cube_"&in&"_x") * cosY
Set Variable: "cube_"&in&"_tz" = eval("cube_"&in&"_y") * sinX + tmp_zpos * cosX
Set Variable: "cube_"&in&"_ty" = eval("cube_"&in&"_y") * cosX - tmp_zpos * sinX
End Loop
display line:
Call ("make 2d pointset") //根据3D坐标算出2D的x,y位置
Set Variable: "tmpAlpha" = eval("cube_"&eval("lightnum")&"_fa") //获得点的透明度
If (tmpAlpha > 12)
Set Property (WhichLight, Alpha) = tmpAlpha
Set Property (WhichLight, X Scale) = tmpAlpha //光球的放大倍数=透明度
Set Property (WhichLight, Y Scale) = tmpAlpha
Set Property (WhichLight, X Position) = eval("cube_"&eval("lightnum")&"_fx")
Set Property (WhichLight, Y Position) = eval("cube_"&eval("lightnum")&"_fy")
Set Property (WhichLight, Visibility) = 1
Else
Set Property (WhichLight, Visibility) = 0
End If
make 2d pointset:
Set Variable: "scalar" = (1 / (eval( "cube_"&lightnum&"_tz" ) / 300+ 1))
// z坐标影响线的深度
Set Variable: "xp" = scalar * eval("cube_"&lightnum&"_tx")
Set Variable: "yp" = scalar * eval("cube_"&lightnum&"_ty")
Set Variable: "cube_"&lightnum&"_fx" = xp + Xnew
Set Variable: "cube_"&lightnum&"_fy" = yp + Ynew
Set Variable: "cube_"&lightnum&"_fa" = ((scalar - .7 ) * 133)+20
// 由深度取得透明度
make matrix:
Comment:
Comment: 设置点的3D坐标
Comment: 用 ,分割XYZ R分割各个点
Set Variable: "whichOne" = 1
Set Variable: "whichchar" = 0
Set Variable: "tmpstring" = ""
Loop While (whichOne <> (innumberofpts+1))
Set Variable: "letter" = whichOne
If (Length ( letter ) = 1)
Set Variable: "letter" = "0" & letter
End If
Set Variable: "whichXYZ" = "x"
Set Variable: "loopy" = "0"
Loop While (loopy <> 1)
Set Variable: "whichchar" = whichchar + 1
If (Ord(substring(inptsetstring,whichchar,1)) = 82)
Set Variable: "loopy" = 1
Set Variable: "whichOne" = whichOne + 1
Else If (Ord(substring(inptsetstring,whichchar,1)) = 44)
Set Variable: "tmpstring" = ""
If (whichXYZ eq "x")
Set Variable: "whichXYZ" = "y"
Else If (whichXYZ eq "y")
Set Variable: "whichXYZ" = "z"
End If
Else
Set Variable: "tmpstring" & whichXYZ = eval("tmpstring"&whichXYZ) & substring(inptsetstring,whichchar,1)
End If
End Loop
Set Variable: inshapename&"_"&letter&"_x" = tmpstringx
Set Variable: inshapename&"_"&letter&"_y" = tmpstringy
Set Variable: inshapename&"_"&letter&"_z" = tmpstringz
Set Variable: "tmpstringx" = ""
Set Variable: "tmpstringy" = ""
Set Variable: "tmpstringz" = ""
End Loop
MC sin: //从字符串中取出sin值
Set Variable: "thetext" = "0 .0000 .0100 ... (中间数据略) ....01-0 .00"
Set Variable: "counter" = -1
Loop While (counter < 629)
Set Variable: "counter" = counter + 1
If (length(counter)=1)
Set Variable: "tmpName" = "sin"&"00"&counter
Else If (length(counter)=2)
Set Variable: "tmpName" = "sin"&"0"&counter
Else If (length(counter)=3)
Set Variable: "tmpName" = "sin"&counter
End If
Set Variable: tmpName = substring(thetext,(counter*5)+1,5)
End Loop
MC cos: //从字符串中取出cos值
Set Variable: "thetext" = "1 .0001 .0000 ... (中间数据略) ... .9991 .000"
Set Variable: "counter" = -1
Loop While (counter < 629)
Set Variable: "counter" = counter + 1
If (length(counter)=1)
Set Variable: "tmpName" = "cos"&"00"&counter
Else If (length(counter)=2)
Set Variable: "tmpName" = "cos"&"0"&counter
Else If (length(counter)=3)
Set Variable: "tmpName" = "cos"&counter
End If
Set Variable: tmpName = substring(thetext,(counter*5)+1,5)
End Loop
有什么问题,请联系我们。
下载原始代码