-
Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy pathclock.red
More file actions
122 lines (106 loc) · 3.48 KB
/
clock.red
File metadata and controls
122 lines (106 loc) · 3.48 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
Red [
Title: "Analog Clock demo"
Author: "Nenad Rakocevic"
File: %clock.red
Needs: 'View
Date: "22/06/2016"
License: "MIT"
Notes: {
This demo simulates the vintage AmigaOS analog clock.
If launched from the console, the clock will run in the background, so
you can continue using the console.
The source code required is currently pretty big and complex as
many features are still missing in Red runtime library, like
auto-resizing system, and facilities to apply matrix transformations
to Draw shapes. Once all these features will be implemented, the
resulting code should be shorter and much more elegant.
Anyway, this is a good test for current Red capabilities.
Feel free to hack it!
}
]
context [
clock: big-handle: small-handle: sec-handle: none
line: [line _ _]
thin: [line-width 1 pen 240.128.0 line _ _]
poly: [line-width 2 fill-pen black polygon _ _ _ _ fill-pen off]
draw-handle: function [
coords [block!] center [pair! point2D!] r-mid [number!] r-max [number!] angle [integer! float!] offset
/square r-min [integer! float!]
][
coords/1: either square [center + as-point2D (r-min * cosine angle) (r-min * sine angle)][center]
coords/3: center + as-point2D (r-max * cosine angle) (r-max * sine angle)
coords/2: center + as-point2D (r-mid * cosine (angle - offset)) (r-mid * sine (angle - offset))
coords/4: center + as-point2D (r-mid * cosine (angle + offset)) (r-mid * sine (angle + offset))
]
draw-clock: function [
face [object!]
/resize
/extern big-handle small-handle sec-handle
][
time: now/time
center: face/size / 2
radius-in: center/x - (10% * center/x)
radius-out: center/x - (5% * center/x)
radius-mid: (radius-out - radius-in) / 2 + radius-in
big: radius-in * 95%
big-mid: radius-in * 80%
sml: radius-in * 65%
sml-mid: radius-in * 45%
either all [not resize block? face/draw][
canvas: face/draw
][
face/draw: clear any [face/draw make block! 1000]
canvas: face/draw
prolog: [
anti-alias on pen black
fill-pen white circle -center- -radius- fill-pen off
line-width 2 line-join bevel
]
prolog/8: center
prolog/9: center/x
append canvas prolog
angle: 0
until [
either zero? angle // 30 [
append canvas poly
draw-handle/square skip tail canvas -6 center radius-mid radius-out angle 1.5 radius-in
][
line/2: center + as-point2D (radius-in * cosine angle) (radius-in * sine angle)
line/3: center + as-point2D (radius-out * cosine angle) (radius-out * sine angle)
append canvas line
]
360 = angle: angle + 6
]
append canvas poly
big-handle: skip tail canvas -6
append canvas poly
small-handle: skip tail canvas -6
sec-handle: tail canvas
append canvas thin
]
angle: time/hour + (time/minute / 60.0) * 30 - 90
draw-handle small-handle center sml-mid sml angle 7
angle: time/minute * 6 - 90
draw-handle big-handle center big-mid big angle 4
angle: time/second * 6 - 90
sec-handle/6: center
sec-handle/7: center + as-point2D (big * cosine angle) (big * sine angle)
show clock
]
size-handler: insert-event-func 'resize-clock [
if all [event/window = win event/type = 'resizing clock/state][
clock/size: face/size
draw-clock/resize clock
]
none
]
amiga-blue: 0.82.176
win: layout/tight [
title "Amiga Clock"
on-close [remove-event-func :size-handler]
clock: base 400x400 amiga-blue
on-created [draw-clock clock]
rate 0:0:1 on-time [draw-clock clock]
]
view/flags win [resize]
]