It draws Pie Graphs (o rly?)
Enter the data as showing in lines 16-38, call Pie_GetPieImage, and there you go.
type PieData
Value as float
Name as string
AngleStart as float
AngleEnd as float
R as byte
G as byte
B as byte
X as integer
Y as integer
PtNo as integer
endtype
global DIM PieData(4) as PieData
PieData(1).Value=10.0
PieData(1).Name="Cake"
PieData(1).R=255
PieData(1).G=0
PieData(1).B=0
PieData(2).Value=12.0
PieData(2).Name="Pie"
PieData(2).R=0
PieData(2).G=0
PieData(2).B=255
PieData(3).Value=15.5
PieData(3).Name="Cookies"
PieData(3).R=150
PieData(3).G=150
PieData(3).B=150
PieData(4).Value=3.0
PieData(4).Name="Salad"
PieData(4).R=0
PieData(4).G=255
PieData(4).B=0
Pie_GetPieImage(1,500,255,255,255)
paste image 1,100,100
wait key
end
function Pie_GetPieImage(ImageNo,Diameter,TextR,TextG,TextB)
tempbmp=FreeBitmap()
create bitmap tempbmp,Diameter,Diameter
totaldata#=0.0
for c=1 to array count(PieData(0))
inc totaldata#,PieData(c).Value
next c
currentangle#=0
for c=1 to array count(PieData(0))
currentpor#=PieData(c).Value/totaldata#
PieData(c).AngleStart=currentangle#-180
inc currentangle#,currentpor#*360
PieData(c).AngleEnd=currentangle#-180
next c
lock pixels
for x=1 to Diameter
for y=1 to Diameter
if SQRT((X-Diameter/2)*(X-Diameter/2)+(Y-Diameter/2)*(Y-Diameter/2))<Diameter/2
tmpangle#=atanfull(x-Diameter/2,y-Diameter/2)
for c=1 to array count(PieData(0))
if tmpangle#>PieData(c).AngleStart and tmpangle#<=PieData(c).AngleEnd
dot X,Y,rgb(PieData(c).R,PieData(c).G,PieData(c).B)
inc PieData(c).PtNo,1
inc PieData(c).X,X
inc PieData(c).Y,Y
endif
next c
endif
next y
next x
unlock pixels
ink rgb(TextR,TextG,TextB),0
for c=1 to array count(PieData(0))
tmplocx=PieData(c).X/PieData(c).PtNo
tmplocy=PieData(c).Y/PieData(c).PtNo
center text tmplocx,tmplocy,PieData(c).Name
center text tmplocx,tmplocy+12,str$(int((PieData(c).Value/totaldata#)*100))+"%"
next c
get image ImageNo,0,0,Diameter,Diameter,1
delete bitmap tempbmp
endfunction
function FreeBitmap()
repeat
inc tempno
until bitmap exist(tempno)=0
endfunction tempno
One small problem that could use fixing: At the end of the Pie_GetPieImage function, the for c-next c loop prints the text onto the different parts of the graph. I'm pretty sure this can be done with SIN() and COS() but for the life of me I couldn't get them to line up with the graph. I resorted to finding the average X and Y positions of all the dots in that segment of the pie. I bet the function could be sped up a lot of someone could get that to work with SIN and COS.