Neocities /
Hodgepodge /
Programming / R2 d'Arsonval Meters
(this is just a screenshot; code is below that)
Code block for making the D'arsonval style:
stylize/master[ ; D'Arsonval analog meters
d'Arsonval: box 102x62 ibevel black 1x1 none white effect reduce ['draw [
pen black circle 50x90 88
circle 0x17 2 line 50x1 50x4 circle 99x17 2
pen black text 25x25 ""
pen black line-width 2 line 50x90 50x0
]] with [
max: 100 min: 0
nlen: 90 ; needle length
jwl: 50x90 ; the fulcrum
needlecolor: func[c][effect/2/21: c]
scalecolor: func[c][effect/2/2: c]
textcolor: func[c][effect/2/16: c]
textpos: func[xy][effect/2/18: xy]
width: func[z][
effect/2/5: z * 0.862745098039216
effect/2/4: effect/2/25: jwl: as-pair((z - 3) / 2)(z * 0.882352941176471)
nlen: jwl/2
effect/2/7/2: effect/2/13/2: (z / 5.8)
effect/2/13/1: z - 3
effect/2/10/1: effect/2/11/1: z / 2
effect/2/18/1: (z / 2) - 30
]
go: func[n /local a][
a: ((n - min) * 69.4 / (max - min)) - 34.7
effect/2/26: as-pair (jwl/1 + (nlen * sine a))(jwl/2 - (nlen * cosine a))
show self
]
caption: func[s][effect/2/19: s]
]]
That can be put in an include file, or
simply pasted into a rebol program.
Below is an example for testing that style:
view/new gui: layout [across
m1: d'Arsonval with [caption " Direct" max: 359 min: 0 needlecolor blue]
m2: d'Arsonval 300x70 with [width 300 caption " Sine" max: 1 min: -1]
m3: d'Arsonval 70x50 yellow with [width 70 caption " Cosine" max: 1 min: -1]
]
j: 0
while [viewed? gui][
m1/go j
m2/go (sine j)
m3/go (cosine j)
j: j + 1
if j > 359 [j: 0]
wait 0.03
]
quit