-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
1,165 additions
and
941 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,111 +1,110 @@ | ||
module Clock exposing (..) | ||
|
||
import Animation as Anim | ||
import Calendar exposing (DateTime, Unit(..)) | ||
import Ease | ||
import Time | ||
|
||
import Calendar exposing ( DateTime, Unit(..) ) | ||
|
||
|
||
|
||
type alias Arm = | ||
{ radius : Float | ||
, armRadius : Float | ||
, ticks : Ticks | ||
, animatedAngle : Anim.Animation | ||
} | ||
{ radius : Float | ||
, armRadius : Float | ||
, ticks : Ticks | ||
, animatedAngle : Anim.Animation | ||
} | ||
|
||
|
||
type alias Ticks = | ||
{ unit : Unit | ||
, count : Int | ||
, labels : List String | ||
} | ||
{ unit : Unit | ||
, count : Int | ||
, labels : List String | ||
} | ||
|
||
|
||
createTicks : Unit -> DateTime -> Ticks | ||
createTicks unit datetime = | ||
let | ||
labels = Calendar.range unit datetime | ||
in | ||
{ unit = unit | ||
, count = List.length labels | ||
, labels = labels | ||
} | ||
let | ||
labels = | ||
Calendar.range unit datetime | ||
in | ||
{ unit = unit | ||
, count = List.length labels | ||
, labels = labels | ||
} | ||
|
||
|
||
updateTicks : Ticks -> DateTime -> Ticks | ||
updateTicks ticks datetime = | ||
let | ||
{ unit } = ticks | ||
in | ||
case unit of | ||
Days -> | ||
createTicks Days datetime | ||
|
||
_ -> | ||
ticks | ||
let | ||
{ unit } = | ||
ticks | ||
in | ||
case unit of | ||
Days -> | ||
createTicks Days datetime | ||
|
||
_ -> | ||
ticks | ||
|
||
|
||
init : Calendar.DateTime -> List Arm | ||
init datetime = | ||
let | ||
armRadius = 23 | ||
in | ||
[ { radius = 100 | ||
, armRadius = armRadius | ||
, ticks = createTicks Months datetime | ||
, animatedAngle = Anim.static 0 | ||
} | ||
, { radius = 155 | ||
, armRadius = armRadius | ||
, ticks = createTicks Weekdays datetime | ||
, animatedAngle = Anim.static 0 | ||
} | ||
, { radius = 210 | ||
, armRadius = armRadius | ||
, ticks = createTicks Days datetime | ||
, animatedAngle = Anim.static 0 | ||
} | ||
, { radius = 300 | ||
, armRadius = armRadius | ||
, ticks = createTicks Hours datetime | ||
, animatedAngle = Anim.static 0 | ||
} | ||
, { radius = 355 | ||
, armRadius = armRadius | ||
, ticks = createTicks Minutes datetime | ||
, animatedAngle = Anim.static 0 | ||
} | ||
, { radius = 410 | ||
, armRadius = armRadius | ||
, ticks = createTicks Seconds datetime | ||
, animatedAngle = Anim.static 0 | ||
} | ||
] | ||
|
||
let | ||
armRadius = | ||
23 | ||
in | ||
[ { radius = 100 | ||
, armRadius = armRadius | ||
, ticks = createTicks Months datetime | ||
, animatedAngle = Anim.static 0 | ||
} | ||
, { radius = 155 | ||
, armRadius = armRadius | ||
, ticks = createTicks Weekdays datetime | ||
, animatedAngle = Anim.static 0 | ||
} | ||
, { radius = 210 | ||
, armRadius = armRadius | ||
, ticks = createTicks Days datetime | ||
, animatedAngle = Anim.static 0 | ||
} | ||
, { radius = 300 | ||
, armRadius = armRadius | ||
, ticks = createTicks Hours datetime | ||
, animatedAngle = Anim.static 0 | ||
} | ||
, { radius = 355 | ||
, armRadius = armRadius | ||
, ticks = createTicks Minutes datetime | ||
, animatedAngle = Anim.static 0 | ||
} | ||
, { radius = 410 | ||
, armRadius = armRadius | ||
, ticks = createTicks Seconds datetime | ||
, animatedAngle = Anim.static 0 | ||
} | ||
] | ||
|
||
|
||
update : Calendar.DateTime -> Float -> List Arm -> List Arm | ||
update datetime delta arms = | ||
let | ||
updateEach arm = | ||
let | ||
{ ticks, animatedAngle } = arm | ||
|
||
newTicks = updateTicks ticks datetime | ||
|
||
newAngle = | ||
toFloat ( Calendar.toPart ticks.unit datetime ) / toFloat newTicks.count * 360 | ||
|
||
newAnimatedAngle = | ||
Anim.retarget delta newAngle animatedAngle | ||
|> Anim.duration 750 | ||
|> Anim.ease Ease.outQuart | ||
|
||
in | ||
{ arm | ticks = newTicks, animatedAngle = newAnimatedAngle } | ||
|
||
in | ||
List.map updateEach arms | ||
let | ||
updateEach arm = | ||
let | ||
{ ticks, animatedAngle } = | ||
arm | ||
|
||
newTicks = | ||
updateTicks ticks datetime | ||
|
||
newAngle = | ||
toFloat (Calendar.toPart ticks.unit datetime) / toFloat newTicks.count * 360 | ||
|
||
newAnimatedAngle = | ||
Anim.retarget delta newAngle animatedAngle | ||
|> Anim.duration 750 | ||
|> Anim.ease Ease.outQuart | ||
in | ||
{ arm | ticks = newTicks, animatedAngle = newAnimatedAngle } | ||
in | ||
List.map updateEach arms |
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
Oops, something went wrong.