-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Basic clock function
- Loading branch information
0 parents
commit 5eedb57
Showing
4 changed files
with
56 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/out/** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{:deps {org.clojure/clojurescript {:mvn/version "1.11.54"}}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="UTF-8"> | ||
</head> | ||
<body> | ||
<canvas id="draw" width="500" height="500"></canvas> | ||
<script src="out/main.js" type="text/javascript"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
(ns weird-clock.main) | ||
|
||
|
||
(def hours '(1 2 3 4 5 6 7 8 9 10 11 12)) | ||
|
||
(def draw-canvas (.getElementById js/document "draw")) | ||
|
||
(def draw-width (.-width draw-canvas)) | ||
(def draw-height (.-height draw-canvas)) | ||
(def draw-ctx (.getContext draw-canvas "2d")) | ||
|
||
(defn draw-line [ctx angle len] | ||
(.beginPath ctx) | ||
(.moveTo ctx (/ draw-width 2) (/ draw-height 2)) | ||
(.lineTo ctx | ||
(+ (/ draw-width 2) (* (/ draw-width 2) (Math/cos angle) len)) | ||
(+ (/ draw-height 2) (* (/ draw-height 2) (Math/sin angle) len))) | ||
(.stroke draw-ctx)) | ||
|
||
|
||
(defn draw-fn [] | ||
(set! (.-fillStyle draw-ctx) "rgb(0,255,255)") | ||
(.fillRect draw-ctx 0 0 draw-width draw-height) | ||
(set! (.-font draw-ctx) "18px sans-serif") | ||
(set! (.-fontStyle draw-ctx) "bold") | ||
(set! (.-fillStyle draw-ctx) "rgb(0,0,0)") | ||
(loop | ||
[index 11] | ||
(when (>= index 0) | ||
(.fillText draw-ctx | ||
(nth hours index) | ||
(+ (/ draw-width 2) (* (/ draw-width 2) (Math/cos (/ (* Math/PI index) 6)) 0.9)) | ||
(+ (/ draw-height 2) (* (/ draw-height 2) (Math/sin (/ (* Math/PI index) 6)) 0.9))) | ||
(recur (- index 1)))) | ||
(set! (.-fillStyle draw-ctx) "rgb(255,0,0)") | ||
(set! (.-lineWidth draw-ctx) 6) | ||
(let [ | ||
time (/ (.now js/Date) 1000 60) | ||
minute (mod time 60) | ||
hour (- (mod (/ time 60) 12) (/ (.getTimezoneOffset (js/Date.)) 60))] | ||
(draw-line draw-ctx (- (* Math/PI minute .0333333333) (/ Math/PI 2)) 0.9) | ||
(draw-line draw-ctx (- (* Math/PI hour (/ 1 6)) (/ Math/PI 2)) 0.6))) | ||
|
||
(js/setInterval draw-fn 1000) |