Drop on a vector shape to create a pie chart. Make sure each piece has the same center point in the dialog. Using the property inspector you can choose colors from a paletter.
--Copyright 2000 Chuck Neal / 2000 Bob Ippolito
--chuck@mediamacros.com
--If you find this code helpful, send me an e-mail and let me know. :-)
--Pie Chart routines based on the work of Bob Ippolito
--bob@vir2l.com
on beginSprite me
pieList = [:]
sprite(spriteNum).foreColor = pieColor.paletteindex
sendAllSprites(#updatePie)
end
on getPieList me, whatGroup, pieList
if whatGroup = pieGroup then
pieList.addProp(symbol(string(spriteNum)), pieValue)
end if
end
on buildTotal pieList
total=0
repeat with n=1 to pieList.count
total=total+pieList[n]
end repeat
-- You shouldn"t have a zero total. But this will prevent an error anyways
if total=0 then total=1
return total
end
on updatePie me
pieList = [:]
sendAllSprites(#getPieList, pieGroup, pieList)
total = buildTotal(pieList)
current = pieList.findPos(symbol(string(spriteNum)))
mOffset = 0
if current > 1 then
repeat with x = 1 to current - 1
mOffset = mOffset+2*PI*pieList[x]/total
end repeat
end if
mOffsetB = mOffset+2*PI*pieList[current]/total
sprite(spriteNum).member.vertexList=nArc(radius,mOffset,mOffsetB)
sprite(spriteNum).member.regPointVertex=1
end
on nArc radius,theta0,theta1
retVec=[[#vertex:point(0,0)],[#vertex:anglePt(radius,theta0), #handle1: point(0,0), #handle2: point(0,0)]]
scale=0
n=2
repeat while (theta1-theta0)>0
t1=theta1
if (theta1-theta0)>=PI/2 then
t1=theta0+PI/2
scale=0.5350
else
scale=0.5350 * 2 * (theta1-theta0) / PI
end if
retVec[n].handle1 = scale*angleDeriv(radius,theta0)
retVec.add([#vertex:anglePt(radius,t1), #handle1: point(0,0), #handle2:-scale*angleDeriv(radius,t1)])
theta0=t1
n=n+1
end repeat
return retVec
end
on anglePt radius,theta
return point(radius*cos(theta),radius*sin(theta))
end
on angleDeriv radius,theta
return point(-radius*sin(theta),radius*cos(theta))
end
on getBehaviorDescription me
d = "This behavior can be dropped on a vector shape to create a pie chart piece. To edit, change the pieValue property and call a sendAllSprites(#updatePie, groupNumber)"
d = d & return & "Group Number allows for multiple pies to be on screen at once."
return d
end
Contact
MMI
36 South Court Sq
Suite 300
Newnan, GA 30263
USA