File: pie_chart.kbs

package info (click to toggle)
basic256 2.0.99.10-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 6,888 kB
  • sloc: cpp: 17,185; yacc: 4,025; lex: 1,466; java: 1,091; sh: 39; xml: 33; makefile: 20
file content (47 lines) | stat: -rw-r--r-- 1,166 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# pie_chart.kbs
# 2012-12-29 j.m.reneau - example of pie statement added on 0.9.9.25
# 2016-09-08 j.m.reneau - added bounding circle example 1.99.99.65
#
# 

dim data(5)
data = {1,3,5,7,10}
dim colors(5)
colors = {red,blue,green,yellow,cyan}
total = 0
for n = 0 to data[?]-1
   total += data[n]
next n

print "with rectange bounding area"
clg
font "Arial", 20,100
startangle = 0
for n = 0 to data[?]-1
   # calculate the with of the pie slice in radians
   slicesize = 2*pi*data[n]/total
   color colors[n]
   pie 50,50,200,200,startangle,slicesize
   # draw the value's number  outside the pie
   text 140+sin(startangle+slicesize*.5)*120, 140-cos(startangle+slicesize*.5)*120, data[n]
   startangle += slicesize
next n

input "press enter", crap

print "with circle bounding area"
clg
font "Arial", 20,100
startangle = 0
for n = 0 to data[?]-1
   # calculate the with of the pie slice in radians
   slicesize = 2*pi*data[n]/total
   color colors[n]
   pie 150,150,100,startangle,slicesize
   # draw the value's number  outside the pie
   text 140+sin(startangle+slicesize*.5)*120, 140-cos(startangle+slicesize*.5)*120, data[n]
   startangle += slicesize
next n