Contents
Articles
Behaviors
Books
Director News
Director Web Sites
FAQ
Games
Mailing Lists
News Groups
Project Examples
Reviews
Software
Tools
Useful Web Sites
Utilities
Xtras

Don't miss these
Wait for DigitalVideo Cuepoint
CD-ROM Drive Letter Finder-Using a File
Power Point Viewer
Compound Interest
FAQ Page
Dryclean
Push Dial-Alphamania
Import Linked Bitmaps
Font Dialog Behavior
A Star Lingo Pathfinding Algorithm
 

 

 

Behavior Pie Chart - Vector Shapes

Added on 7/16/2000

 

Compatibilities:
behavior D8 Mac PC Shockwave

This item has not yet been rated

Author: MediaMacros (website)

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.

Download PC Source    Download Mac Source
--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

property radius, pieCenterH, pieCenterV, pieGroup, pieValue, spriteNum, pieColor

on getPropertyDescriptionList me
  p_list = [:]
  p_list.addProp(#radius, [#format : #integer, #comment : "Pie Radius", #default : 100])
  c = sprite(the currentSpriteNum).loc
  p_list.addProp(#pieCenterH, [#format : #integer, #comment : "Pie Center H", #default : c.locH])
  p_list.addProp(#pieCenterV, [#format : #integer, #comment : "Pie Center V", #default : c.locV])
  p_list.addProp(#pieGroup, [#format : #integer, #comment : "Group Number (For multiple Charts)", #default : 1])
  p_list.addProp(#pieValue, [#format : #float, #comment : "Slice Value", #default : 5])
  p_list.addProp(#pieColor, [#format : #color, #comment : "Piece Color", #default : "#000000"])
  return p_list
end

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

Send e-mail