發新話題

Flash製作實例 - 《網頁製作技巧》三角函數

Flash製作實例 - 《網頁製作技巧》三角函數

●預覽成品:在Flash 4中,算術計算函數十分有限,很多函數計算都必須手寫很多代碼得以進行,這對一些不太懂編程的朋友來說是一件很痛苦的事情。此實例我們提供了一些常用的三角函數:正弦,餘弦。

訪客無法瀏覽此圖片或連結,請先 註冊登入會員


●逐步說明:
  1)選擇工具欄中的文字工具,在工作區中的適當位置點擊並輸入文字「在此輸入角度:」。按下文字參數欄中的按鈕,並在文字右邊拉出一文本框為如圖所示。

設置其變量為名為「angle」。

  2)同理,在工作區中的下方輸入文字並拉出文本框為如圖所示。設置文本框的變量名為「output」。

  3)選擇菜單Insert->New Symbol,

彈出圖符屬性對話框,輸入圖符名稱為「trig」,並選擇Movie Clip項,

設置完畢,點擊OK按鈕,進入圖符編輯模式。
  4)建立程序為如圖所示。

stop層中只有一個空的關鍵幀,設置的Actions為:
stop。
  表示執行到該幀時停止。
  set values層中也只有一個空的關鍵幀,其Actions為:

Set Variable: "sin0" = 0
Set Variable: "sin1" = .0175
    ……
Set Variable: "sin90" = 1
Set Variable: "count" = 91
Loop While (count <=180)
 Set Variable: "sin" & count = eval ("sin" & (180 - count))
 Set Variable: "count" = count + 1
End Loop
Set Variable: "count" = 181
Loop While (count <=270)
 Set Variable: "sin" & count = eval ("sin" & (count - 180)) * -1
 Set Variable: "count" = count + 1
End Loop
Set Variable: "count" = 271
Loop While (count <=360)
 Set Variable: "sin" & count = eval ("sin" & (360 - count)) * -1
 Set Variable: "count" = count + 1
End Loop
Set Variable: "count" = 0
Loop While (count <= 90)
 Set Variable: "cos" & count = eval ("sin" & (90 - count))
 Set Variable: "count" = count + 1
End Loop
Set Variable: "count" = 91
Loop While (count <=180)
 Set Variable: "cos" & count = eval ("cos" & (180 - count)) * -1
 Set Variable: "count" = count + 1
End Loop
Set Variable: "count" = 181
Loop While (count <=270)
 Set Variable: "cos" & count = eval ("cos" & (count - 180)) * -1
 Set Variable: "count" = count + 1
End Loop
Set Variable: "count" = 271
Loop While (count <=360)
 Set Variable: "cos" & count = eval ("cos" & (360 - count))
 Set Variable: "count" = count + 1
End Loop
  該程序表示:設置不同範圍內「整數角度」的正弦、餘弦值。請注意這裡是「整數角度」。
  5)layer 1層中有四個空的關鍵幀,第1個關鍵幀表示獲得正弦的值並在輸出框「output」中輸出。設置該幀的標籤為「Sin」,以便調用。

其Actions為:
Call ("adjustAngle")
Set Variable: "output" = eval ("sin" & intDegree)

  第1條語句表示調用標籤為「adjustAngle」,即第3幀的程序。第2條語句表示從輸出框中 輸出正弦的值。 下面我們來看第3幀,第3幀的標籤為:adjustAngle,Actions為:

Call ("adjustAngle2")
If (intDegree > 360)
 Set Variable: "intDegree" = intDegree - (int (intDegree / 360) * 360) End If
If (intDegree < 0)
 If (intDegree < -360)
  Set Variable: "intDegree" = intDegree - (int (intDegree / 360) * 360)
 End If
 Set Variable: "intDegree" = intDegree + 360
End If
  第1條語句表示:調用標籤為「adjustAngle2」,即第4幀的程序。第1條以下的語句表示:輸入角度大於360或小於0兩種情況下的角度取值。 最後我們來看標籤為「adjustAngle2」,即第4幀的Actions:

If (arg > 0)
 If (int (arg + .5) > int (arg))
  Set Variable: "intDegree" = int (arg + .5)
 Else
  Set Variable: "intDegree" = int (arg)
 End If
Else If (int (arg - .5) < int (arg))
 Set Variable: "intDegree" = int (arg - .5)
Else
  Set Variable: "intDegree" = int (arg)
End If
End If
  以上程序表示:當輸入的角度為小數時,把角度值化為整數。
  6)第2個關鍵幀表示獲得餘弦的值並在輸出框「output」中輸出。其Actions為:

Call ("adjustAngle")
Set Variable: "output" = eval ("cos" & intDegree)
  原理與第1幀一樣。
  7)點擊等時線窗口左上角的Scene 1按鈕,切換到場景1。
  8)製作一按鈕「btn」,

打開圖符資料庫,

把按鈕拉入到工作區中的適當位置,並複製它。分別在按鈕的左邊輸入文字「正弦--sin」及「 餘弦--cos」。
  9)從圖符資料庫中拉入「trig」,

並定義其實體名字為:trig。
  10)雙擊「正弦--sin」旁邊的按鈕並切換到Actions選項卡,輸入語句:

On (Release)
 Set Variable: "/trig:arg" = angle Call ("/trig:Sin")
 Set Variable: "output" = /trigutput
End On
  表示當執行該按鈕時,設置在圖符「trig」中的變量「arg」為輸入框輸入的值。調用圖符「trig」中的標籤名為「Sin」的幀,即取得輸入角度的正弦值。最後從輸出框中輸出正弦值。
  11)雙擊「餘弦--cos」旁邊的按鈕並切換到Actions選項卡,輸入語句:

On (Release)
 Set Variable: "/trig:arg" = angle Call ("/trig:Cos")
 Set Variable: "output" = /trigutput
End On
  原理與正弦一樣。
  12)選擇菜單Control->Test Movie,即可測試。

TOP

回個帖先 ...

感謝無私分享 ...

努力吸收中 ...

TOP

發新話題

本站所有圖文均屬網友發表,僅代表作者的觀點與本站無關,如有侵權請通知版主會盡快刪除。