73 lines
1.9 KiB
Plaintext
73 lines
1.9 KiB
Plaintext
1) lambdatalk code
|
|
{watch} // displays the watch
|
|
|
|
{def watch
|
|
{watch.init}
|
|
{div {@ id="watch"}}
|
|
}
|
|
|
|
{def watch.draw
|
|
{lambda {:r :g :b}
|
|
{svg {@ style="width:300px; height:300px;"}
|
|
{let { {:r :r} {:g :g} {:b :b} {:t {date}} }
|
|
{watch.path 150 150 100 20 :r 1 :t}
|
|
{watch.path 150 150 120 20 :g 2 :t}
|
|
{watch.path 150 150 140 20 :b 3 :t}
|
|
{watch.digit :t} }}}}
|
|
|
|
{def watch.path
|
|
{lambda {:x :y :r :e :c :i :t}
|
|
{path {@ d="{watch.arc :x :y :r {watch.time :i :t}}"
|
|
fill="none" stroke=":c" stroke-width=":e"}} }}
|
|
|
|
{def watch.arc
|
|
{lambda {:x :y :r :t}
|
|
{let { {:x :x} {:y :y} {:r :r}
|
|
{:start {watch.pol2car :x :y :r :t}}
|
|
{:end {watch.pol2car :x :y :r 0}}
|
|
{:flag {if {<= :t 180} then 0 else 1}} }
|
|
M {car :start} {cdr :start}
|
|
A :r :r 0 :flag 0 {car :end} {cdr :end} }}}
|
|
|
|
{def watch.time
|
|
{lambda {:i :t}
|
|
{if {= :i 1}
|
|
then {/ {* 360 {% {S.get {+ :i 2} :t} 12}} 12}
|
|
else {/ {* 360 {S.get {+ :i 2} :t}} 60} }}}
|
|
|
|
{def watch.pol2car
|
|
{lambda {:cx :cy :r :t}
|
|
{let { {:cx :cx} {:cy :cy} {:r :r}
|
|
{:T {* {- :t 90} {/ {PI} 180}}} }
|
|
{cons {+ :cx {* :r {cos :T}}}
|
|
{+ :cy {* :r {sin :T}}}} }}}
|
|
|
|
{def watch.digit
|
|
{lambda {:t}
|
|
{text {@ x="50%" y="48%"
|
|
base-line="middle"
|
|
text-anchor="middle"
|
|
font-size="2.0em"
|
|
stroke="#ccc"}
|
|
{S.get 0 :t}/{S.get 1 :t}/{S.get 2 :t} }
|
|
{text {@ x="50%" y="58%"
|
|
base-line="middle"
|
|
text-anchor="middle"
|
|
font-size="2.0em"
|
|
stroke="#ccc"}
|
|
{S.get 3 :t} : {S.get 4 :t} : {S.get 5 :t} } }}
|
|
|
|
2) javascript code (for timing)
|
|
|
|
{script
|
|
var update = function () {
|
|
document.getElementById("watch").innerHTML =
|
|
LAMBDATALK.eval_forms( "{watch.draw #f00 #0f0 #00f}" )
|
|
};
|
|
LAMBDATALK.DICT['watch.init'] = function () {
|
|
setTimeout( update, 10);
|
|
setInterval( update, 1000);
|
|
return ''
|
|
};
|
|
}
|