Skip to content

Commit 35b0aca

Browse files
tune (#113)
1 parent 420785f commit 35b0aca

File tree

1 file changed

+20
-26
lines changed

1 file changed

+20
-26
lines changed

src/Pages/IkedaPattern.elm

Lines changed: 20 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module Pages.IkedaPattern exposing (Model, Msg, page, primes, quadraticResidueSe
33
import Array2D exposing (Array2D)
44
import Basics
55
import Browser.Dom
6-
import Browser.Events as Events
6+
import Browser.Events as BrowserEvents
77
import Dict
88
import Effect exposing (Effect)
99
import Element as E exposing (..)
@@ -108,7 +108,7 @@ type ViewportStatus
108108
type Msg
109109
= Got_Viewport Browser.Dom.Viewport
110110
| Got_ResizeEvent Int Int
111-
| Tick Time.Posix
111+
| Tick Float
112112

113113

114114
update_ : Msg -> Model -> ( Model, Effect Msg )
@@ -128,13 +128,13 @@ update_ msg model =
128128
update msg ( model, viewport )
129129

130130

131-
tickPage1 : Model -> ( Model, Effect Msg )
132-
tickPage1 model =
131+
tickPage1 : Model -> Float -> ( Model, Effect Msg )
132+
tickPage1 model dt =
133133
let
134134
rotDeg : Float
135135
rotDeg =
136136
-- continue rotation, mod 360 to avoid extraneous rotations (540 degrees is same as 180, for example)
137-
toFloat <| modBy 360 (round <| model.rotDeg + dTheta)
137+
toFloat <| modBy 360 (round <| model.rotDeg + dTheta dt)
138138

139139
a : Float
140140
a =
@@ -164,13 +164,13 @@ tickPage1 model =
164164
)
165165

166166

167-
tickPage3 : Model -> ( Model, Effect Msg )
168-
tickPage3 model =
167+
tickPage3 : Model -> Float -> ( Model, Effect Msg )
168+
tickPage3 model dt =
169169
let
170170
rotDeg : Float
171171
rotDeg =
172172
-- continue rotation, mod 360 to avoid extraneous rotations (540 degrees is same as 180, for example)
173-
toFloat <| modBy 360 (round <| model.rotDeg + dTheta)
173+
toFloat <| modBy 360 (round <| model.rotDeg + dTheta dt)
174174
in
175175
( { model
176176
| rotDeg = rotDeg
@@ -179,13 +179,13 @@ tickPage3 model =
179179
)
180180

181181

182-
tickPage2 : Model -> ( Model, Effect Msg )
183-
tickPage2 model =
182+
tickPage2 : Model -> Float -> ( Model, Effect Msg )
183+
tickPage2 model dt =
184184
let
185185
rotDeg : Float
186186
rotDeg =
187187
-- continue rotation, mod 360 to avoid extraneous rotations (540 degrees is same as 180, for example)
188-
toFloat <| modBy 360 (round <| model.rotDeg + dTheta)
188+
toFloat <| modBy 360 (round <| model.rotDeg + dTheta dt)
189189
in
190190
( { model
191191
| rotDeg = rotDeg
@@ -205,16 +205,16 @@ update msg ( model, viewport ) =
205205
, Effect.fromCmd <| Task.perform Got_Viewport Browser.Dom.getViewport
206206
)
207207

208-
Tick _ ->
208+
Tick dt ->
209209
case model.pageNo of
210210
1 ->
211-
tickPage1 model
211+
tickPage1 model dt
212212

213213
2 ->
214-
tickPage2 model
214+
tickPage2 model dt
215215

216216
3 ->
217-
tickPage3 model
217+
tickPage3 model dt
218218

219219
_ ->
220220
( model, Effect.none )
@@ -237,16 +237,10 @@ dx =
237237
10
238238

239239

240-
dTheta : Float
241-
dTheta =
240+
dTheta : Float -> Float
241+
dTheta dt =
242242
-- The rotation, in degrees, to apply each frame
243-
1.0
244-
245-
246-
dtMs : number
247-
dtMs =
248-
-- The target number of milliseconds between frames
249-
60
243+
dt / 30.0
250244

251245

252246

@@ -256,8 +250,8 @@ dtMs =
256250
subscriptions : Model -> Sub Msg
257251
subscriptions model =
258252
Sub.batch
259-
[ Events.onResize Got_ResizeEvent
260-
, Time.every dtMs Tick
253+
[ BrowserEvents.onResize Got_ResizeEvent
254+
, BrowserEvents.onAnimationFrameDelta Tick
261255
]
262256

263257

0 commit comments

Comments
 (0)