// This program demonstrates the use of the
// CHANGESHAPE statement to display switches
// and indicators.  After the graph is drawn,
// click the "continue" button repeatedly to
// change the indicators and switch positions.
// (requires QuickCalc 2.5)

include standard_colors.txt
degrees
graph equalscales, landscape, bgcolor=gray_06
graph nogrid, noaxes
dim rs (5,2)

// Toggle Switch

shape center=(1,1)
shape radius=.1
shape fillcolor=gray_25
shape ellipse
shape radius=.075
shape ellipse

shape center=(1, 1.20)
shape rotatecenter=(1,1)
shape hradius=.07, vradius=.20
shape fillcolor=gray_25
shape ellipse
handle_id = lastshapeid

// Progress bar
w=2
shape left=.07, right=w+.13, top=.23, bottom=.07
shape fillcolor=gray_50, rectangle
shape left=.1, right=.1+w, top=.2, bottom=.1
shape fillcolor=yellow, rectangle
shape right=.1, fillcolor=green, rectangle
bar_id = lastshapeid
progress=0

// Indicator light (could be pushbutton with mouseclick)
shape center=(.3, 1.4)
shape hradius=.2, vradius=.1
shape fillcolor=green, rectangle
light_id = lastshapeid

// Text on the light
shape bottom=1.36, top=1.48, left=.3, right=.3
shape fillcolor=black
shape characters="ON", justify=center, text
text_id = lastshapeid

// Analog Meter

shape center=(1.8, 1.47)
shape vradius=.16, hradius=.28
shape fillcolor=yellow, rectangle

shape linestart=(1.8, 1.2), lineend=(2.22, 1.2)
shape rotatecenter=(1.8, 1.2), rotate=0, line
line_id = lastshapeid
gosub 600 // update needle

shape center=(1.8, 1.2)
shape startangle=45, endangle=135
shape radius=.4, arc
// You could put any scale you desired 
// on the meter with shape text statements.

// complex shape to make "window" in panel
shape beginpath
shape center=(1.8, 1.4)
shape hradius=.3, vradius=.25, rectangle
shape closefigure
shape direction=reverse, center=(1.8, 1.47)
shape vradius=.16, hradius=.28, rectangle
shape direction=normal
shape endpath
shape fillcolor=gray_25, strokefill

shape center=(1.8, 1.2)
shape radius=.02, fillcolor=gray_25, ellipse

// Digital indicator

shape center=(1.8, .8)
shape hradius=.2, vradius=.1
shape fillcolor=gold, rectangle
digital_id = lastshapeid

// Text on the indicator
shape bottom=.76, top=.90, left=1.8, right=1.8
shape fillcolor=black
shape characters="00", justify=center, text
digital_id = lastshapeid

// Rotary Switch
rs (0,0) = .35: rs (0,1) = .43
rs (1,0) = .45: rs (1,1) = .43
rs (2,0) = .47: rs (2,1) = .6
rs (3,0) = .40: rs (3,1) = .8
rs (4,0) = .33: rs (4,1) = .6
shape rotate=0, rotatecenter=(.4, .6)
shape polypoints=rs, polycount=5
shape fillcolor = sapphire, polygon
rotary_id = lastshapeid

shape center=(.4, .6)
shape radius=.25, filltype=none, ellipse
shape linestart=(.65, .6), lineend=(.7, .6)
shape rotatecenter=(.4, .6)
ang=0
while ang < 360
  shape rotate=ang, line
  ang = ang + 30
wend
rsp=0
gosub 800 // position rotary switch

100
stop
changeshape handle_id, rotate=180
changeshape light_id, fillcolor=red
changeshape text_id, characters="OFF"
gosub 500
gosub 600
gosub 700
gosub 800

stop
changeshape handle_id, rotate=0
changeshape light_id, fillcolor=green
changeshape text_id, characters="ON"
gosub 500
gosub 600
gosub 700
gosub 800

goto 100


500 // update progress bar
progress = progress + 4
if progress > 100 then progress = 0
changeshape bar_id, right=progress * w / 100 + .1
return

600 // Set analog meter position
// 0 = 135 degrees, 100 = 45 degrees
a = -(135 - 45) *  progress / 100 + 135
changeshape line_id, rotate=a
return

700 // Set digital display value
s$ = str$(progress, "###")
changeshape digital_id, characters=s$
return

800 // change rotary switch
a = -180 * rsp / 6 + 90
changeshape rotary_id, rotate=a
rsp = rsp + 1
if rsp > 11 then rsp = 0
return

