Skip to content

Commit

Permalink
chore: format with elm-format
Browse files Browse the repository at this point in the history
  • Loading branch information
sandydoo committed Aug 24, 2024
1 parent e6bd2be commit ee872b7
Show file tree
Hide file tree
Showing 12 changed files with 1,165 additions and 941 deletions.
415 changes: 268 additions & 147 deletions src/Calendar.elm

Large diffs are not rendered by default.

165 changes: 82 additions & 83 deletions src/Clock.elm
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
136 changes: 87 additions & 49 deletions src/Color/Cubehelix.elm
Original file line number Diff line number Diff line change
@@ -1,80 +1,118 @@
module Color.Cubehelix exposing (..)


import Color.Rgb exposing ( RGB )
import Color.Interpolate as Interpolate
import Color.Rgb exposing (RGB)



-- A “Cubehelix” colour space, based on the work of David Green, Mike Bostock,
-- and Jason Davies.
--
-- See https://sandydoo.github.io/CubehelixExplained/ for a full explanation.
-- Constants


a =
-0.14861

-- Constants

b =
1.78277

a = -0.14861
b = 1.78277
c = -0.29227
d = -0.90649
e = 1.97294

ed = e * d
eb = e * b
bcDa = b * c - d * a
c =
-0.29227


d =
-0.90649


e =
1.97294


ed =
e * d


eb =
e * b

type Cubehelix =
Cubehelix
{ h : Float
, s : Float
, l : Float
}

bcDa =
b * c - d * a


type Cubehelix
= Cubehelix
{ h : Float
, s : Float
, l : Float
}


fromRgb : RGB -> Cubehelix
fromRgb rgb =
let
red = rgb.r / 255
green = rgb.g / 255
blue = rgb.b / 255
let
red =
rgb.r / 255

l = ( bcDa * blue + ed * red - eb * green ) / ( bcDa + ed - eb )
green =
rgb.g / 255

x = blue - l
blue =
rgb.b / 255

y = ( e * ( green - l ) - c * ( blue - l ) ) / d
l =
(bcDa * blue + ed * red - eb * green) / (bcDa + ed - eb)

s = ( sqrt ( x ^ 2 + y ^ 2 ) ) / ( e * l * ( 1 - l ) )
x =
blue - l

h = atan2 y x * 180 / pi - 120
y =
(e * (green - l) - c * (blue - l)) / d

s =
sqrt (x ^ 2 + y ^ 2) / (e * l * (1 - l))

h =
atan2 y x * 180 / pi - 120
in
Cubehelix
{ h =
if h < 0 then
h + 360

else
h
, s = s
, l = l
}

in
Cubehelix
{ h = if h < 0 then h + 360 else h
, s = s
, l = l
}


-- https://web.archive.org/web/20190814105952/http://astron-soc.in/bulletin/11June/289392011.pdf


toRgb : Cubehelix -> RGB
toRgb ( Cubehelix { h, s, l } ) =
let
hue = ( h + 120 ) * pi / 180
alpha = s * l * ( 1 - l )
cosH = cos hue
sinH = sin hue

in
{ r = 255 * ( l + alpha * ( a * cosH + b * sinH ) )
, g = 255 * ( l + alpha * ( c * cosH + d * sinH ) )
, b = 255 * ( l + alpha * ( e * cosH ) )
toRgb (Cubehelix { h, s, l }) =
let
hue =
(h + 120) * pi / 180

alpha =
s * l * (1 - l)

cosH =
cos hue

sinH =
sin hue
in
{ r = 255 * (l + alpha * (a * cosH + b * sinH))
, g = 255 * (l + alpha * (c * cosH + d * sinH))
, b = 255 * (l + alpha * (e * cosH))
}


Expand All @@ -83,9 +121,9 @@ toRgb ( Cubehelix { h, s, l } ) =


interpolate : Cubehelix -> Cubehelix -> Float -> Cubehelix
interpolate ( Cubehelix col1 ) ( Cubehelix col2 ) time =
Cubehelix
{ h = Interpolate.hue col1.h col2.h time
, s = Interpolate.float col1.s col2.s time
, l = Interpolate.float col1.l col2.l time
}
interpolate (Cubehelix col1) (Cubehelix col2) time =
Cubehelix
{ h = Interpolate.hue col1.h col2.h time
, s = Interpolate.float col1.s col2.s time
, l = Interpolate.float col1.l col2.l time
}
Loading

0 comments on commit ee872b7

Please sign in to comment.