Post by Psycho on Jul 12, 2010 19:58:23 GMT -5
In my quest to create some pie charts in RB, I discovered how much I miss the pie and piefilled commands from LB. To begin this process on my own (which I have not yet done) I had to first know how to create the arcs at the outside of the pie shape. Looking back through the Liberty Basic Newsletters, I found issue #109 had several different examples on how to do this. I modified code from that newsletter, originally written by Tom Nally, to work in Run Basic. The following code will work in IE8 and FF 3.6 but stacks the graphic area in IE6. I think the entire screen would have to be cleared and redrawn in IE6.
The original article can be found here: babek.info/libertybasicfiles/lbnews/nl109/arcs.htm
Anyway, maybe this will help someone else along the way.
The center mark can be removed and outside lines added to this example program to create a single pie piece.
Now, filling in this and other pieces.....certainly a challenge (at least for me).
John "Psycho" Siejkowski
The original article can be found here: babek.info/libertybasicfiles/lbnews/nl109/arcs.htm
Anyway, maybe this will help someone else along the way.
The center mark can be removed and outside lines added to this example program to create a single pie piece.
Now, filling in this and other pieces.....certainly a challenge (at least for me).
'Demo program to show how to draw arcs in Run Basic
'Original program written in Liberty Basic by Tom Nally for LB newsletter
'http://babek.info/libertybasicfiles/lbnews/nl109/arcs.htm
'Converted for use in Run Basic by John "Psycho" Siejkowski 2010
'Released as Open Source
'Requires the following 6 arguments passed to the GenArc drawing sub:
'startAngle
'endAngle
'segments
'centerX
'centerY
'radius
'define graphic area handle as global to allow drawing both inside and outside of subs
global #main
'create user input area to test changes and view graphic results
html "<pre>"
print " X Center: ";:textbox #XCenter, "150", 10
print " Y Center: ";:textbox #YCenter, "150", 10
print " Radius: ";:textbox #Radius, "100", 10
print "Start Angle (degrees): ";:textbox #StartAngle, "15", 10
print " End Angle (degrees): ";:textbox #EndAngle, "85", 10
dim LineSegments(50)
for x = 1 to 50
LineSegments(x)=x
next x
print " No. Line Segments: ";:listbox #LineSegments, LineSegments(),0
#LineSegments select(20)
html "</pre>"
button #clear, "Clear Graphic Box", [clear]
print space$(5);
button #drawArc, "Draw Arc", [draw]
print space$(5);
button #quit, "Quit", [quit]
'display graphic box
html "<div style='position: relative; left: 5px; top: 5px; height:0px; width:0px;'>"
graphic #main, 300, 300
#main fill(255,255,100)
render #main
html "</div>"
wait
[clear]
html "<div style='position: relative; left: 5px; top: 5px; height:0px; width:0px;'>"
#main cls(255,255,100)
render #main
html "</div>"
wait
[quit]
cls
html "<b>Goodbye</b>"
end
[draw]
html "<div style='position: relative; left: 5px; top: 5px; height:0px; width:0px;'>"
'create same graphic area with yellow background
graphic #main, 300, 300
#main cls(255,255,100)
#main color("black")
#main size(1)
'get variable values from textboxes
XCenter = #XCenter value()
YCenter = #YCenter value()
Radius = #Radius value()
StartAngleDegs = #StartAngle value()
EndAngleDegs = #EndAngle value()
NLSegs = #LineSegments selection()
'call the sub which converts degrees to radians and generates arc
call GenArc XCenter, YCenter, Radius, StartAngleDegs, EndAngleDegs, NLSegs
render #main
html "</div>"
wait
Sub GenArc Xc, Yc, R, StartD, EndD, NLS
pi = 4*atn(1)
StartR = (StartD/360)*(2*pi)
EndR = (EndD/360)*(2*pi)
ArcElement = (EndR - StartR) / NLS
dim xplot(NLS)
dim yplot(NLS)
xplot(0) = Xc + R * cos(StartR)
yplot(0) = Yc - R * sin(StartR)
For i = 1 to NLS
xplot(i) = Xc + R * cos(StartR + i*ArcElement)
yplot(i) = Yc - R * sin(StartR + i*ArcElement)
Next i
'Draw a small cross at the arc center
#main line(Xc - 5, Yc, Xc + 5, Yc)
#main line(Xc, Yc + 5, Xc, Yc - 5)
'Plot the Arc
For i = 1 to NLS
#main line(xplot(i-1), yplot(i-1), xplot(i), yplot(i))
next i
End Sub
John "Psycho" Siejkowski