-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFFT_Animation.elm
More file actions
609 lines (561 loc) · 19.5 KB
/
Copy pathFFT_Animation.elm
File metadata and controls
609 lines (561 loc) · 19.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
-- Author: Michael Balas
import GraphicSVG exposing (..)
import Array
import Time exposing (Time, second)
type Message = GameTick Float GetKeyState --The tick needs to have Float and GetKeyState which handles key presses.
| NextSlide
| LastSlide
main = gameApp GameTick {
model = init,
view = view,
update = update
}
-- MODEL
init = {
t = 0 ,
idx = 0 ,
p = False, -- Pause
r = 1 , -- Rewind
a = 1 -- Acceleration
}
-- VIEW
view model = let t = model.t
slide = Maybe.withDefault default (Array.get model.idx slides)
in collage 1000 500 (slide t ++ borders ++ navigators)
-- UPDATE
update message model =
case message of
GameTick tick (getKeyState,changeP1,changeP2) ->
if (getKeyState LeftArrow) == JustDown then
{ model |
t = 0 ,
idx = max (model.idx - 1) 0
}
else if (getKeyState RightArrow) == JustDown then
{ model |
t = 0 ,
idx = min (model.idx + 1) (Array.length slides - 1) -- Next Slide
}
else if (getKeyState Space) == JustDown then
{ model |
p = not model.p -- Pause Animation(s)
}
else if (getKeyState UpArrow) == JustDown then
{ model |
a = min (model.a * 2) 4 -- Accelerate Animation(s)
}
else if (getKeyState DownArrow) == JustDown then
{ model |
a = max (model.a / 2) 0.5 -- Deccelerate Animation(s)
}
else if (getKeyState (Key "R")) == JustDown then
{ model |
r = -model.r -- Reverse Animation(s)
}
else if (getKeyState Backspace) == JustDown then
{ model |
t = 0 -- Reset Slide/Animation(s)
}
else if model.p then
model
else
{ model |
t = max (model.t + 2.5 * model.a * model.r) 0
}
NextSlide -> { model |
t = 0 ,
idx = min (model.idx + 1) (Array.length slides - 1)
}
LastSlide -> { model |
t = 0 ,
idx = max (model.idx - 1) 0
}
--- MISCELLANEOUS
default t = []
borders = [rect 5000 5000
|> filled white
|> move (3000,0),
rect 5000 5000
|> filled white
|> move (-3000,0),
rect 5000 5000
|> filled white
|> move (0,2750),
rect 5000 5000
|> filled white
|> move (0,-2750)]
navigators = [ group [ circle 30
|> filled gray
,
triangle 20
|> filled purple
] |> move (450,-200)
|> makeTransparent 0.5
|> notifyTap NextSlide
,
group [ circle 30
|> filled gray
,
triangle 20
|> filled purple
] |> rotate (degrees 180)
|> move (-450,-200)
|> makeTransparent 0.5
|> notifyTap LastSlide
]
-- FUNCTIONS
disappear x n = if x > n then makeTransparent 0 else makeTransparent 1
loop t n = let y = toFloat (floor (t / n))
in t - y * n
appear x n = if x > n then makeTransparent 1 else makeTransparent 0
fadeIn t n = makeTransparent (tranSin (t-n) 1)
fadeOut t n = makeTransparent (1 - (tranSin (t-n) 1))
trans t y = if t < 0 -- Used for all permanent transitions (fading out, color change, etc.) LINEAR.
then 0
else Basics.min t y
tranSin t y = if t < 0 -- Used for all permanent transitions (fading out, color change, etc.) Uses sin.
then 0
else if t/100 > pi/2 then y
else sin(t/100) * y
drawLine t (x1,y1) (x2,y2) = line (x1,y1) (x1 + tranSin (t) (x2 - x1), y1 + tranSin (t) (y2 - y1))
-- Total of 6 Slides
slides = Array.fromList [slide1,slide2,slide3,slide4, slide5, slide6]
--<< SLIDE 1>>-
slide1 t = [
rect 1000 1000
|> filled lightBlue
,
text "The Fast Fourier Transform (FFT)"
|> size 50
|> customFont "Roboto"
|> bold
|> centered
|> filled white
|> move (-100,-40),
text "Left & Right Arrow keys for previous and next slide, respectively."
|> size 10
|> customFont "Roboto"
|> bold
|> centered
|> filled black
|> move (0,-160)
|> fadeIn t 1000
,
text "Up & Down Array keys for speeding up and down, respectively. Space for pause."
|> size 10
|> customFont "Roboto"
|> bold
|> centered
|> filled black
|> move (0,-180)
|> fadeIn t 1000
,
text "Adapted From: Fast Fourier Transform: Algorithms and Applications"
|> size 25
|> customFont "Roboto"
|> centered
|> filled white
|> move (-95,-100)
|> fadeIn t 700
,
ellipses (loop t 330) -- Flashing ellipses indicating it's time to move to the next slide
|> fadeIn t 600 ,
rect 1000 500
|> filled black
|> move (-500 - (tranSin (t-550) 500),0),
text "HIS FI"
|> size 40
|> customFont "Helvetica"
|> bold
|> filled white
|> move (-115 - (tranSin (t-550) 500),30)
|> appear t 100
,
text "PRESEN"
|> size 40
|> customFont "roboto"
|> bold
|> filled white
|> move (-150 - (tranSin (t-550) 500),-20)
|> appear t 100
,
rect 1000 500
|> filled white
|> move (500 + (tranSin (t-550) 500),0),
text "RST ELM"
|> size 40
|> customFont "roboto"
|> bold
|> filled black
|> move (0 + (tranSin (t-550) 500),30)
|> appear t 100
,
text "TATION"
|> size 40
|> customFont "roboto"
|> bold
|> filled black
|> move (0 + (tranSin (t-550) 500),-20)
|> appear t 100
,
rect 1000 500
|> filled white
|> move (0,200 + tranSin(t-300) 300)
,
rect 1000 500
|> filled black
|> move (0,-250 - tranSin(t-300) 300),
text "MICHAEL"
|> size 40
|> customFont "roboto"
|> bold
|> filled black
|> move (-480,45 + tranSin(t-300) 300)
|> appear t 100
,
text "PRESENTS"
|> size 40
|> customFont "roboto"
|> bold
|> filled white
|> move (-480,-60 - tranSin(t-300) 300)
|> appear t 200
]
ellipses t = group [ -- Each circle fades in and out right after the previous
circle 10
|> filled white
|> move (300,-25)
|> fadeIn t 50
|> fadeOut t 100
,
circle 10
|> filled white
|> move(360, -25)
|> fadeIn t 100
|> fadeOut t 150
,
circle 10
|> filled white
|> move (420, -25)
|> fadeIn t 150
|> fadeOut t 200
]
--<< SLIDE 2 >>--
slide2 t = [
rect 1000 500
|> filled lightBlue
|> move (0,350),
text "What Is It?"
|> size 40
|> customFont "Roboto"
|> bold
|> centered
|> filled white
|> move (-230,130)
|> fadeIn t 100
,
group( makeGreyBullets (t-130)
["Efficient implementation of the Discrete Fourier Transform (DFT) or its inverse",
"Many types: Split radix, prime factor, Winograd Fourier transform, vector radix",
"Focus will be on the Radix-2 Decimation in time FFT Algorithm"] 0)
|> move (-120,0)
]
--<< SLIDE 3 >>--
slide3 t = [
rect 1000 500
|> filled lightBlue
|> move (500,0),
text "What's the Big Deal?"
|> size 40
|> customFont "Roboto"
|> centered
|> filled black
|> move (-250,0)
|> fadeIn t 100
,
text "Included in the Top 10 Algorithms of"
|> size 20
|> customFont "Roboto"
|> centered
|> filled darkGrey
|> move (-250,-60)
|> fadeIn t 140
,
text "the 20th Century by the IEEE journal:"
|> size 20
|> customFont "Roboto"
|> centered
|> filled darkGrey
|> move (-250,-90)
|> fadeIn t 140
,
text "Computing in Science & Engineering"
|> size 20
|> customFont "Roboto"
|> centered
|> filled darkGrey
|> move (-250,-120)
|> fadeIn t 140
,
group( makeWhiteBullets (t-100)
["EKG and EEG signal processing",
"Forensic Science",
"Magnetic Resonance Imaging (MRI)",
"Video/image compression",
"Pattern Recognition",
"Noise filtering",
"Image quality measures",
"Optical signal processing"] 0)
|> move (240,220)
]
--<< SLIDE 4 >>--
slide4 t = [
rect 1000 500
|> filled lightBlue
|> move (0,350),
text "Time Comparison"
|> size 40
|> customFont "Roboto"
|> bold
|> centered
|> filled white
|> move (-230,130)
|> fadeIn t 100
,
table t -- "Table" showing time differences between DFT and FFT
,
text "Assuming 1 nanosecond per operation"
|> size 25
|> customFont "Roboto"
|> centered
|> filled darkGrey
|> move (-80,-200)
|> fadeIn t 840
,
blackellipses (loop t 330) -- Black ellipses indicating that it's time for the next slide
|> fadeIn t 900
]
table t = group [
text "Sample Size (N):"
|> size 20
|> customFont "Roboto"
|> centered
|> filled darkGrey
|> move (-220,0)
|> fadeIn t 140
,
text "1000"
|> size 20
|> customFont "Roboto"
|> centered
|> filled darkGrey
|> move (-30,0)
|> fadeIn t 160
,
text "10^6"
|> size 20
|> customFont "Roboto"
|> centered
|> filled darkGrey
|> move (100,0)
|> fadeIn t 220
,
text "10^9"
|> size 20
|> customFont "Roboto"
|> centered
|> filled darkGrey
|> move (230,0)
|> fadeIn t 280
,
text "Discrete Fourier Transform (N^2):"
|> size 20
|> customFont "Roboto"
|> centered
|> filled darkGrey
|> move (-290,-50)
|> fadeIn t 340
,
text "10^6"
|> size 20
|> customFont "Roboto"
|> centered
|> filled darkGrey
|> move (-30,-50)
|> fadeIn t 400
,
text "10^12"
|> size 20
|> customFont "Roboto"
|> centered
|> filled darkGrey
|> move (100,-50)
|> fadeIn t 460
,
text "10^18"
|> size 20
|> customFont "Roboto"
|> centered
|> filled darkGrey
|> move (230,-50)
|> fadeIn t 520
,
text "Fast Fourier Transform (Nlog2N):"
|> size 20
|> customFont "Roboto"
|> centered
|> filled darkGrey
|> move (-290,-100)
|> fadeIn t 580
,
text "10^4"
|> size 20
|> customFont "Roboto"
|> centered
|> filled darkGrey
|> move (-30,-100)
|> fadeIn t 640
,
text "20 x 10^6"
|> size 20
|> customFont "Roboto"
|> centered
|> filled darkGrey
|> move (100,-100)
|> fadeIn t 700
,
text "30 x 10^9"
|> size 20
|> customFont "Roboto"
|> centered
|> filled darkGrey
|> move (230,-100)
|> fadeIn t 760
]
blackellipses t = group [
circle 10
|> filled black
|> move (160,-190)
|> fadeIn t 50
|> fadeOut t 100
,
circle 10
|> filled black
|> move(220, -190)
|> fadeIn t 100
|> fadeOut t 150
,
circle 10
|> filled black
|> move (280, -190)
|> fadeIn t 150
|> fadeOut t 200
]
--<< SLIDE 5 >>--
slide5 t = [
text "DFT: 31.2 years!"
|> size 30
|> customFont "Roboto"
|> bold
|> centered
|> filled black
|> move (-275,150)
|> fadeIn t 100
,
text "FFT: 30 seconds!"
|> size 30
|> customFont "Roboto"
|> bold
|> centered
|> filled black
|> move (275,150)
|> fadeIn t 100
,
circle 100 -- DFT clock (shows that the DFT is slow)
|> filled red
|> move (-275, 0)
|> fadeIn t 150
,
drawLine (t-150) (0,0) (100 * cos(t/3600),-100 * sin(t/3600)) -- Hour hand on DFT clock
|> outlined (solid 2) black
|> move(-275, 0)
,
drawLine (t-150) (0,0) (100 * cos(t/60),-100 * sin(t/60)) -- Minute hand on DFT clock
|> outlined (solid 1) black
|> move(-275, 0)
,
circle 100 -- FFT clock (shows that the FFT is fast)
|> filled lightBlue
|> move (275, 0)
|> fadeIn t 150
,
drawLine (t-150) (0,0) (100 * cos(t/300),-100 * sin(t/300)) -- Hour hand on FFT clock
|> outlined (solid 2) black
|> move(275, 0)
,
drawLine (t-150) (0,0) (100 * cos(t/5),-100 * sin(t/5)) -- Minute Hand on FFT clock
|> outlined (solid 1) black
|> move(275, 0)
]
slide6 t = [
rect 1000 1000
|> filled lightBlue
,
text "The Fast and the Fourier" -- Clever pun inserted here
|> size 50
|> customFont "Roboto"
|> bold
|> centered
|> filled white
|> move (-100,-40)
,
text "The End"
|> size 35
|> customFont "Roboto"
|> centered
|> filled white
|> move (-295, -120)
,
circle 25 -- White circle that moves around in a circle
|> filled white
|> move (50 * cos(t/30) + 320, -50 * sin(t/30))
,
circle 25 -- Black circle that moves around in a circle
|> filled black
|> move (-50 * cos(t/30) + 320, 50 * sin(t/30))
]
-- Widely spaced out dark grey and white bullet points
makeWhiteBullets t l start = case l of
x::xs -> group [
text x
|> size 22
|> customFont "Roboto"
|> filled white
|> move (-200,start)
|> fadeIn t 100
,
circle 5
|> filled white
|> move (-220,start+5)
|> fadeIn t 100
] :: makeWhiteBullets (t-100) xs (start - 65)
_ -> []
makeGreyBullets t l start = case l of
x::xs -> group [
text x
|> size 22
|> customFont "Roboto"
|> filled darkGrey
|> move (-200,start)
|> fadeIn t 100
,
circle 5
|> filled darkGrey
|> move (-220,start+5)
|> fadeIn t 100
] :: makeGreyBullets (t-100) xs (start - 65)
_ -> []
darkGrey = rgb 115 115 115
lightBlue = rgb 66 133 244
--< Hope You Enjoyed >--
-- Michael Balas