'diagout.bas Russian Circle Diagram b+ mod overhaul Danilin's 2021-11-15
N = 12 ' Number of pie slices or data items
Dim d
(N
) ' Store our random items, d(i) first stores totals that are converted to RadianAngles for arcs. Screen 12 ' Allows graphics like Circle (x, y), radius, color, startRadianForArc, stopRadianForArc For i
= 1 To N
' For each data item r
= Int(Rnd * 90 + 9) ' Pick random number 9 to 89, +9 guarantees at least 9, INT(rnd*90) = 0 to 89, so 9 to 98 max d(i) = d(i - 1) + r ' Add last total to this with new item
Color i
' Color code by i = index number Print r
' Show each item and it's color Color 15 ' White, not used by any other item Print "SUM= "; d
(N
) ' Sum is last total with all data items d
(i
) = d
(i
) / d
(N
) * _Pi(2) ' convert d(i) to a fraction of a circle and multiply by 2*Pi to convert to angle in radians If d
(i
) >= _Pi(2) Then d
(i
) = _Pi(2) - .0001 ' wow circle is really frick'n picky!!! ' Circle wont do stop Angle < start angle, that happens with imprecise math and 1 converted to something > 2*Pi
' This was big headache until I isolated which number was not working in Circle.
For j
= 0 To 200 Step .25 ' .25 to avoid holes between arcs For i
= 1 To N
' drawing arcs from d(i-1) to d(i) at j radii 'ref: Circle (x,y),radius, color, startRadianForArc, stopRadianForArc
If (i
Mod 2) = 1 Then Circle (320, 240), 200 - j
, i
, d
(i
- 1), d
(i
) ' outside in _Delay .016 ' to show the build either outside in or inside out