十天学会aw之第三天:程序
三、程序语句代码范例
了解上面的一些程序语句编写基本知识和技巧后,我们来加深一下认识,尝试编写一段程序代码,在Authorware窗口中绘制一个饼状模拟分布图。
启动Authorware 6.5并新建一个a6p文件,在流程线上拖入一个计算图标,并输入以下程序代码:
--//相关变量初始化
orgx := 200
orgy := 200
radius := 150
pensize:=2
multiplier:=10
percentages:="30,15,20,35"
num_angles:=LineCount(percentages,",")
--//绘制饼状分布模拟图
repeat with i := 1 to num_angles
percentage := GetLine(percentages,i,i,",")
if i = 1 then
SetFrame(TRUE , RGB(255,0,0))
else if i=2 then
SetFrame(TRUE , RGB(0,255,0))
else if i=3 then
SetFrame(TRUE , RGB(0,0,255))
else if i=4 then
SetFrame(TRUE , RGB(255,255,0))
end if
start:=finish
finish:=finish+percentage
repeat with j:=start*multiplier to finish*multiplier
angle := (((50 - (j*(1/multiplier))) * Pi / 50))
x := SIN(angle) * radius
y := COS(angle) * radius
Line(pensize, orgx,orgy,orgx+x,orgy+y)
end repeat
total := total + percentage
end repeat
输入完毕后按快捷键Ctrl+R调试执行,您将看到窗口屏幕上自动绘制出一个饼状模拟分布图,如图3所示。

图 3
这里魔岩并不要求大家对上述的代码完全读懂(因此本文也不做详细分析),我们的重点是给大家一个感性认识,使大家了解并掌握Authorware 6.5程序语句与结构的编写特点和相关基础知识即可。

