-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
867 lines (807 loc) · 46.1 KB
/
Copy pathindex.html
File metadata and controls
867 lines (807 loc) · 46.1 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
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, viewport-fit=cover">
<title>Nate's Portfolio</title>
<link rel="icon" type="image/svg+xml"
href="data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 100 100%22><text y=%22.9em%22 font-size=%2290%22 font-family=%22Optima, Iowan Old Style, Seravek, sans-serif%22 fill=%22%23d94a76%22>N</text></svg>">
<link rel="stylesheet" href="./style.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css">
</head>
<body>
<div class="page-wrapper">
<header class="hero">
<h1>Nathan Lodder</h1>
<p>Robotics, physical and mathematical modelling, and human-computer interfacing</p>
</header>
<main class="landing-container">
<nav class="centered-menu">
<ul class="menu-list">
<li><a href="https://www.linkedin.com/in/nathan-lodder/" target="_blank" class="social-link">
<i class="fa-brands fa-linkedin-in"></i>
<span>linkedin</span>
</a>
</li>
<li><a href="https://github.com/nlodder" target="_blank" class="social-link">
<i class="fa-brands fa-github"></i>
<span>github</span>
</a>
</li>
</ul>
</nav>
<!-- PET RESCUE ROBOT PROJECT -->
<section class="project-block">
<div class="project-media">
<div class="media-scroller">
<figure class="media-item">
<video autoplay muted loop playsinline poster="/assets/images/robotSum/PetRescDump.jpeg">
<source src="/assets/videos/robotSum/PetRescRobotTwoPet.mp4" type="video/mp4">
Your browser does not support the video tag.
</video>
<figcaption>1. Robot collecting pets</figcaption>
</figure>
<figure class="media-item">
<img src="/assets/images/robotSum/PetRescSide.jpeg" alt="Perspective view of robot" loading="lazy">
<figcaption>2. Perspective View</figcaption>
</figure>
<figure class="media-item">
<img src="/assets/images/robotSum/servoPower.jpg" alt="Servo power diagram" loading="lazy">
<figcaption>3. Servo Power Diagram</figcaption>
</figure>
<figure class="media-item">
<img src="/assets/images/robotSum/magnetometer.png" alt="Magnetometer diagram" loading="lazy">
<figcaption>4. Magnetometer Functional Overview</figcaption>
</figure>
<figure class="media-item">
<img src="/assets/images/robotSum/PetRescDump.jpeg" alt="Robot collecting pet" loading="lazy">
<figcaption>5. Robot Collecting Pet</figcaption>
</figure>
<figure class="media-item">
<img src="/assets/images/robotSum/PetRescSide2.jpeg" alt="Side view of robot" loading="lazy">
<figcaption>6. Side View</figcaption>
</figure>
</div>
<div class="scroller-dots">
<span class="dot active"></span>
<span class="dot"></span>
<span class="dot"></span>
<span class="dot"></span>
<span class="dot"></span>
<span class="dot"></span>
</div>
</div>
<div class="project-info">
<h2 class="project-header">Pet Rescue Robot</h2>
<ul class="project-tools">
<li class="project-tool-header">Tools</li>
<li>C++</li>
<li>ESP32</li>
<li>LiDar Sensors</li>
<li>Magnetometer Sensors</li>
<li>Servo Motors</li>
<li>OnShape</li>
</ul>
<ul class="project-skills">
<li class="project-skill-header">Skills</li>
<li>Object Oriented Programming</li>
<li>3D CAD</li>
<li>Circuit Design</li>
<li>Sensor Characterization</li>
<li>Prototyping</li>
<li>I2C Protocol</li>
<li>UART Protocol</li>
</ul>
<p class="project-description">
As part of a team of four, I designed, built, and competed with an autonomous robot capable
of seeking out and rescuing small stuffed animals (“pets”) from an obstacle-filled environment.
Our robot placed 2nd out of 15 teams in the final course competition.<br><br>
We integrated a range of hardware and control systems:<br>
- LiDAR for initial target detection and navigation support<br>
- Infrared reflectance sensor array in a PID feedback loop for line-following navigation<br>
- Dual triple-axis magnetometers to guide the robotic claw toward magnetic
targets<br>
- ESP32 microcontrollers, servos, DC motors, and other fundamental drive and control
components<br>
- I2C and UART Protocols for sensor and inter-microcontroller communication respectively<br><br>
The robot was powered by three lithium-polymer batteries, and its chassis, storage bay, and
arm were built from laser-cut hardboard and 3D-printed PLA components designed in OnShape.
</p>
</div>
</section>
<!-- BASS GUITAR COMPANION -->
<section class="project-block">
<div class="project-media">
<div class="media-scroller">
<figure class="media-item">
<img src="/assets/images/bassGuitar/fullSys.png" alt="Full system schematic" loading="lazy">
<figcaption>1. Full System Schematic</figcaption>
</figure>
<figure class="media-item">
<img src="/assets/images/bassGuitar/charging.png" alt="USB-C-LiPo charging schematic" loading="lazy">
<figcaption>2. USB-C-LiPo Charging Schematic</figcaption>
</figure>
<figure class="media-item">
<img src="/assets/images/bassGuitar/loadSharing.png" alt="Load sharing & power path management schematic" loading="lazy">
<figcaption>3. Load Sharing & Power Path Management Schematic</figcaption>
</figure>
<figure class="media-item">
<img src="/assets/images/bassGuitar/system.png" alt="Control system schematic" loading="lazy">
<figcaption>4. Control System Schematic</figcaption>
</figure>
</div>
<div class="scroller-dots">
<span class="dot active"></span>
<span class="dot"></span>
<span class="dot"></span>
<span class="dot"></span>
</div>
</div>
<div class="project-info">
<h2 class="project-header">Bass Guitar Companion</h2>
<ul class="project-tools">
<li class="project-tool-header">Tools</li>
<li>EasyEDA</li>
<li>ESP32</li>
</ul>
<ul class="project-skills">
<li class="project-skill-header">Skills</li>
<li>Power Systems Design</li>
<li>Circuit Design</li>
<li>Prototyping</li>
<li>I2C Protocol</li>
</ul>
<p class="project-description">
I am designing a companion system to my bass guitar that will allow me to control basic DAW functions remotely, and to track playing metrics.
The primary goal of this project is to learn safe power systems design for consumer-safe electronics.<br><br>
Initial inspiration for load sharing system from <a href="https://ww1.microchip.com/downloads/en/AppNotes/01149a.pdf">this document</a>
by Brian Chu at Microchip Technology Inc. I elected to replace the function of the Schottky diode (D1) with the LM66200 ORing Controller
to reduce power loss and provide a stable voltage rail to the ESP32 microcontroller. I also replaced the P-MOSFET (Q1) used to isolate the
battery in Brian Chu's design with an N-MOSFET used to enable the boost converter tasked with boosting the battery voltage to a stable 5V.
With this boost converter disabled, which occurs during charging when the usb-c cable is connected, the battery is isolated from the load
with redundant back-current protection from the LM66200 ORing controller and the TPS61022 boost converter.<br><br>
I am currently in the schematic design phase, working on control inputs and auxilliary system functions. PCB design, enclosure design, and
assembly will follow once the schematic is complete and tested through simulation!
</p>
</div>
</section>
<!-- ROBOTICS SIMULATOIN -->
<section class="project-block">
<div class="project-media">
<div class="media-scroller">
<figure class="media-item">
<img src="/assets/images/enph353/debugWindow.png" alt="Navigation debugging view" loading="lazy">
<figcaption>1. Navigation debugging view</figcaption>
</figure>
<figure class="media-item">
<img src="/assets/images/enph353/rpyControl.png" alt="Roll and pitch control flow" loading="lazy">
<figcaption>2. Roll and pitch control flow</figcaption>
</figure>
<figure class="media-item">
<img src="/assets/images/enph353/flyingDrone.png" alt="Drone in simulation" loading="lazy">
<figcaption>3. Drone in simulation</figcaption>
</figure>
<figure class="media-item">
<img src="/assets/images/enph353/blueMask.png" alt="Image processing-blue mask" loading="lazy">
<figcaption>4. Image processing-blue mask</figcaption>
</figure>
<figure class="media-item">
<img src="/assets/images/enph353/morphology.png" alt="Image processing-morphological closing" loading="lazy">
<figcaption>5. Image processing-morphological closing</figcaption>
</figure>
<figure class="media-item">
<img src="/assets/images/enph353/signHull.png" alt="Image processing-contours & convex hull" loading="lazy">
<figcaption>6. Image processing-contours & convex hull</figcaption>
</figure>
</div>
<div class="scroller-dots">
<span class="dot active"></span>
<span class="dot"></span>
<span class="dot"></span>
<span class="dot"></span>
<span class="dot"></span>
<span class="dot"></span>
</div>
</div>
<div class="project-info">
<h2 class="project-header">Simulated Drone Control</h2>
<ul class="project-tools">
<li class="project-tool-header">Tools</li>
<li>Python</li>
<li>OpenCV</li>
<li>ROSa</li>
<li>Gazebo</li>
<li>OnShape</li>
<li>GitHub</li>
</ul>
<ul class="project-skills">
<li class="project-skill-header">Skills</li>
<li>Networking</li>
<li>Bash Scripting</li>
<li>Drone Control</li>
<li>Version Control</li>
</ul>
<a href="https://github.com/nlodder/enph353-drone-controllers" target="_blank" class="social-link">
<i class="fa-brands fa-github"></i>
<span>drone controllers</span>
</a>
<a href="https://github.com/nlodder/enph353-drone-bringup" target="_blank" class="social-link">
<i class="fa-brands fa-github"></i>
<span>drone launcher</span>
</a>
<a href="https://github.com/nlodder/enph353-drone-desc" target="_blank" class="social-link">
<i class="fa-brands fa-github"></i>
<span>drone definition</span>
</a>
<a href="https://github.com/nlodder/enph353-drone-msgs" target="_blank" class="social-link">
<i class="fa-brands fa-github"></i>
<span>drone message</span>
</a>
<p class="project-description">
Created two-drone team to navigate simulated environment to collect data from signs in ROS/Gazebo.
<br><br>
Controller nodes were implemented in Python and communicated via rostopics. For high-frequency inter-drone communication
I created a custom lightweight message type (see drone message repository). Controllers and stabilizers would
send movement demands to a command bridge node which would apply all requested forces to the drone. This was to
isolate ownership of force application to a single node and reduce the number of service calls to Gazebo's
costly ApplyBodyWrench service.
<br><br>
Roll and pitch stabilization was handled by a node that took inputs from an IMU link on the drone body and published
required correction velocities (to be read by the command bridge) after passing the roll, pitch and angular velocity
values through a PID function.
<br><br>
I processed the front camera feed with OpenCV for navigation. I used the difference of the horizontal centroid of
blue signs from the centre of the frame as the error for left/right strafing and yaw PID controllers. For forward/backward movement
I used the relative height of the sign in the frame, pushing the drone back if the sign was too large in frame, and forward if the sign
was too small in frame, also through a PID function.
<br><br>
The base drone design was performed in OnShape and converted to a URDF file through the
<a href="https://onshape-to-robot.readthedocs.io/en/latest/">onshape-to-robot plugin</a>. I wrote a python script to convert
this .urdf file to a .xacro file for cleanliness and better handling of repeat parts. This file was then modified per developed
needs in controller development (adding sensors, modifying drone colors etc.).
</p>
</div>
</section>
<!-- DESIGN TEAM PROJECT -->
<section class="project-block">
<div class="project-media">
<div class="media-scroller">
<figure class="media-item">
<video autoplay muted loop playsinline poster="/assets/images/enable/bannerOverall.jpeg">
<source src="/assets/videos/enable/overallSetupLite.mov" type="video/mp4">
Your browser does not support the video tag.
</video>
<figcaption>1. Sensor overlay on camera feed prototype setup</figcaption>
</figure>
<figure class="media-item">
<video autoplay muted loop playsinline poster="/assets/images/enable/bannerUltra.jpeg">
<source src="/assets/videos/enable/ultra.mov" type="video/mp4">
Your browser does not support the video tag.
</video>
<figcaption>2. Sensor overlay on camera feed prototype setup</figcaption>
</figure>
<figure class="media-item">
<img src="/assets/images/enable/setup.jpeg" alt="Raspberry Pi setup" loading="lazy">
<figcaption>3. Raspberry Pi and ultrasonic sensors prototyping</figcaption>
</figure>
<figure class="media-item">
<img src="/assets/images/enable/guiOverlay.jpeg" alt="GUI overlay" loading="lazy">
<figcaption>4. Distance data overlay on camera feed</figcaption>
</figure>
</div>
<div class="scroller-dots">
<span class="dot active"></span>
<span class="dot"></span>
<span class="dot"></span>
<span class="dot"></span>
</div>
</div>
<div class="project-info">
<h2 class="project-header">Wheelchair Backup Assist Proximity Overlay</h2>
<ul class="project-tools">
<li class="project-tool-header">Tools</li>
<li>Python</li>
<li>Raspberry Pi</li>
<li>Raspberry Pi OS Linux</li>
<li>Ultrasonic Sensors</li>
<li>Data Processing</li>
</ul>
<ul class="project-skills">
<li class="project-skill-header">Skills</li>
<li>Software Construction</li>
<li>Command Line Interfacing</li>
<li>Sensor Characterization</li>
<li>Prototyping</li>
</ul>
<p class="project-description">
As part of the Electrical Sub-team at UBC BEST-Enable I programmed Raspberry Pi
to stream video from a Picam to a small monitor with a proximity-indicator
overlay to provide client in electric wheelchair with visibility and proximity
feedback when reversing in tight environments.<br><br>
This was my first introduction to working on a linux system and debugging
in the command line where our primary struggle was interfacing with the
external display to create a clean and effective stream for our client. We
overcame this by looking through the openCV documentation to find potential
solutions, landing on the Python OpenCV <a href="https://docs.opencv.org/4.x/d7/dfc/group__highgui.html#ga5afdf8410934fd099df85c75b2e0888b">namedWindow()</a> method.
</p>
</div>
</section>
<!-- VEXBOT PROJECT-->
<section class="project-block">
<div class="project-media">
<div class="media-scroller">
<figure class="media-item">
<img src="/assets/images/vexbot/BallCollRob4Balls.jpeg" alt="Vexbot holding four balls"
loading="lazy">
<figcaption>1. Balls Collected</figcaption>
</figure>
<figure class="media-item">
<img src="/assets/images/vexbot/BallCollRobFront.jpeg" alt="Front of Vexbot" loading="lazy">
<figcaption>2. Front View</figcaption>
</figure>
<figure class="media-item">
<img src="/assets/images/vexbot/BallCollRob-P1.jpeg" alt="Perspective view of Vexbot"
loading="lazy">
<figcaption>3. Perspective View</figcaption>
</figure>
<figure class="media-item">
<img src="/assets/images/vexbot/BallCollRob-P2.jpeg" alt="Perspective view of Vexbot"
loading="lazy">
<figcaption>4. Perspective View</figcaption>
</figure>
</div>
<div class="scroller-dots">
<span class="dot active"></span>
<span class="dot"></span>
<span class="dot"></span>
<span class="dot"></span>
</div>
</div>
<div class="project-info">
<h2 class="project-header">Vexbot</h2>
<ul class="project-tools">
<li class="project-tool-header">Tools</li>
<li>C++</li>
<li>Vex Vision Sensors</li>
<li>Vex Motors</li>
<li>Vex Distance Sensors</li>
</ul>
<ul class="project-skills">
<li class="project-skill-header">Skills</li>
<li>Object-Oriented Programming</li>
<li>Sensor Characterization</li>
<li>Prototyping</li>
</ul>
<p class="project-description">
I designed and built a Vexbot that uses vision sensors' color recognition cability to identify
and
collect coloured balls. The robot would then use the same sensor to scan for and
identify a delivery location, and would use a distance sensor to detect when
it was close enough to drop off the balls.
</p>
</div>
</section>
<!-- OBSIDIAN PLUGIN -->
<section class="project-block">
<div class="project-media">
<div class="media-scroller">
<figure class="media-item">
<video autoplay muted loop playsinline poster="/assets/images/obsidian/code.png">
<source src="/assets/videos/obsidian/vid.mp4" type="video/mp4">
Your browser does not support the video tag.
</video>
<figcaption>1. Demo of plugin</figcaption>
</figure>
<figure class="media-item">
<img src="/assets/images/obsidian/plot.png" alt="dark mode embedded plot in Obsidian"
loading="lazy">
<figcaption>2. Dark mode interactive plot</figcaption>
</figure>
<figure class="media-item">
<img src="/assets/images/obsidian/plot-light.png"
alt="light mode embedded plot in Obsidian" loading="lazy">
<figcaption>3. Light mode interactive plot</figcaption>
</figure>
<figure class="media-item">
<img src="/assets/images/obsidian/code.png" alt="code block for plot in Obsidian"
loading="lazy">
<figcaption>4. Code block for plot in Obsidian</figcaption>
</figure>
</div>
<div class="scroller-dots">
<span class="dot active"></span>
<span class="dot"></span>
<span class="dot"></span>
<span class="dot"></span>
</div>
</div>
<div class="project-info">
<h2 class="project-header">Obsidian Interactive Plot Plugin</h2>
<ul class="project-tools">
<li class="project-tool-header">Tools</li>
<li>CSS</li>
<li>JavaScript</li>
<li>Python</li>
</ul>
<ul class="project-skills">
<li class="project-skill-header">Skills</li>
<li>Object-Oriented Programming</li>
<li>Event-Driven Architecture</li>
<li>Inter-Process Communication</li>
<li>Resource Management</li>
</ul>
<a href="https://github.com/nlodder/local-python-obsidian" target="_blank" class="social-link">
<i class="fa-brands fa-github"></i>
<span>github repository</span>
</a>
<p class="project-description">
I developed a custom Obsidian plugin that integrates a live Python
execution environment directly into Markdown notes. Designed to replace
static hand-drawn plots with interactive data visualizations, the plugin
uses Node.js child processes to bridge Obsidian with the
Python/Plotly ecosystem. It features a custom CSS-to-Python theme engine
that dynamically injects Obsidian's UI variables into the rendering pipeline,
ensuring that plots automatically adapt their color palettes
during theme shifts (see photos) for a native user experience.<br><br>
I wrote this plugin to improve my knowledge management environment and engineering
and learning workflows. I plan to create more quality of life features such
as quick-plot shortcuts and other UI shortcuts (slider, variable manipulators etc.)
as time permits.<br><br>
NOTE: There is currently an issue where the plugin does not render regular python code
blocks properly, only rendering when the tage is 'python local-py'. I am actively working
on resolving this issue.<br><br>
NOTE: Development is on hold while I determine how to protect against recent and anticipated
supply chain vulnerabilities in python dependencies.
</p>
</div>
</section>
</main>
<footer>
<p>2026 | Nathan Lodder</p>
</footer>
</div>
<!-- MEDIA VIEWER -- glass panel for expanded media -->
<div class="media-viewer" id="media-viewer" role="dialog" aria-modal="true" aria-label="Media viewer"
aria-hidden="true">
<div class="viewer-scrim"></div>
<div class="viewer-panel">
<div class="viewer-bar">
<span class="viewer-title"></span>
<div class="viewer-actions">
<span class="viewer-counter"></span>
<button type="button" class="viewer-btn viewer-close" aria-label="Close media viewer">
<i class="fa-solid fa-xmark"></i>
</button>
</div>
</div>
<div class="viewer-stage">
<button type="button" class="viewer-btn viewer-nav prev" aria-label="Previous media">
<i class="fa-solid fa-chevron-left"></i>
</button>
<div class="viewer-canvas"></div>
<button type="button" class="viewer-btn viewer-nav next" aria-label="Next media">
<i class="fa-solid fa-chevron-right"></i>
</button>
</div>
<div class="viewer-foot">
<p class="viewer-caption"></p>
<div class="viewer-dots"></div>
<p class="viewer-hint">Scroll or pinch to zoom · drag to pan · double-click to reset</p>
</div>
</div>
</div>
<script>
// 2. Media Scroller Logic
document.querySelectorAll('.media-scroller').forEach((scroller) => {
let isScrolling = false;
let queuedDirection = 0; // Remembers intent that arrives mid-animation instead of dropping it
const container = scroller.closest('.project-media');
const dotsContainer = container?.querySelector('.scroller-dots');
const items = scroller.querySelectorAll('.media-item');
// Helper to get exact scroll distance between items
const getScrollStep = () => {
if (items.length <= 1) return scroller.clientWidth;
return items[1].offsetLeft - items[0].offsetLeft;
};
// A. Click on dots to jump to image
if (dotsContainer) {
const dots = dotsContainer.querySelectorAll('.dot');
dots.forEach((dot, i) => {
dot.addEventListener('click', () => {
scroller.scrollTo({
left: i * getScrollStep(),
behavior: 'smooth'
});
});
});
}
// B. Wheel Scroll Logic (Desktop)
// Steps one item per animation, queuing the latest direction that
// arrives mid-scroll instead of dropping it -- lets a fast, continuous
// scroll gesture cascade through items instead of stalling after the first.
const stepScroll = (direction) => {
isScrolling = true;
scroller.scrollBy({
left: getScrollStep() * direction,
behavior: 'smooth'
});
setTimeout(() => {
isScrolling = false;
if (queuedDirection !== 0) {
const next = queuedDirection;
queuedDirection = 0;
stepScroll(next);
}
}, 350);
};
scroller.addEventListener('wheel', (evt) => {
if (window.innerWidth > 768) {
// Only prevent default if we are scrolling horizontally
if (Math.abs(evt.deltaY) > Math.abs(evt.deltaX)) {
evt.preventDefault();
const threshold = 5;
if (Math.abs(evt.deltaY) <= threshold) return;
const direction = evt.deltaY > 0 ? 1 : -1;
if (isScrolling) {
queuedDirection = direction;
return;
}
stepScroll(direction);
}
}
}, { passive: false });
// C. Update Dots on Scroll
scroller.addEventListener('scroll', () => {
if (!dotsContainer || items.length <= 1) return;
const dots = dotsContainer.querySelectorAll('.dot');
const index = Math.round(scroller.scrollLeft / getScrollStep());
dots.forEach((dot, i) => dot.classList.toggle('active', i === index));
});
});
// 3. Media Viewer Logic -- opens a scroller in the glass panel with zoom + pan
(() => {
const viewer = document.getElementById('media-viewer');
if (!viewer) return;
const stage = viewer.querySelector('.viewer-stage');
const canvas = viewer.querySelector('.viewer-canvas');
const titleEl = viewer.querySelector('.viewer-title');
const captionEl = viewer.querySelector('.viewer-caption');
const counterEl = viewer.querySelector('.viewer-counter');
const dotsEl = viewer.querySelector('.viewer-dots');
const prevBtn = viewer.querySelector('.viewer-nav.prev');
const nextBtn = viewer.querySelector('.viewer-nav.next');
const closeBtn = viewer.querySelector('.viewer-close');
const MIN_SCALE = 1;
const MAX_SCALE = 6;
let gallery = [];
let index = 0;
let lastFocus = null;
let scale = 1, tx = 0, ty = 0;
// A. Transform helpers
const apply = () => {
canvas.style.transform = `translate(${tx}px, ${ty}px) scale(${scale})`;
stage.classList.toggle('is-zoomed', scale > 1.01);
};
// Keeps the media from being dragged off the stage
const clampPan = () => {
const media = canvas.firstElementChild;
if (!media) return;
const bounds = stage.getBoundingClientRect();
const maxX = Math.max(0, (media.clientWidth * scale - bounds.width) / 2);
const maxY = Math.max(0, (media.clientHeight * scale - bounds.height) / 2);
tx = Math.min(maxX, Math.max(-maxX, tx));
ty = Math.min(maxY, Math.max(-maxY, ty));
};
const resetView = () => {
scale = 1;
tx = 0;
ty = 0;
apply();
};
// Pointer position relative to the centre of the stage
const stagePoint = (clientX, clientY) => {
const bounds = stage.getBoundingClientRect();
return [clientX - bounds.left - bounds.width / 2, clientY - bounds.top - bounds.height / 2];
};
// Zooms toward a point so it stays put under the cursor
const zoomTo = (target, px, py) => {
const next = Math.min(MAX_SCALE, Math.max(MIN_SCALE, target));
if (next === scale) return;
tx = px - (px - tx) * (next / scale);
ty = py - (py - ty) * (next / scale);
scale = next;
if (scale === MIN_SCALE) { tx = 0; ty = 0; }
clampPan();
apply();
};
// B. Rendering
const render = () => {
const item = gallery[index];
canvas.innerHTML = '';
let media;
if (item.type === 'video') {
media = document.createElement('video');
media.controls = true;
media.autoplay = true;
media.loop = true;
media.muted = true;
media.playsInline = true;
if (item.poster) media.poster = item.poster;
item.sources.forEach((entry) => {
const source = document.createElement('source');
source.src = entry.src;
source.type = entry.type;
media.appendChild(source);
});
} else {
media = document.createElement('img');
media.src = item.src;
media.alt = item.alt;
}
canvas.appendChild(media);
captionEl.textContent = item.caption;
counterEl.textContent = `${index + 1} / ${gallery.length}`;
dotsEl.querySelectorAll('.dot').forEach((dot, i) => dot.classList.toggle('active', i === index));
resetView();
};
const go = (delta) => {
if (gallery.length < 2) return;
index = (index + delta + gallery.length) % gallery.length;
render();
};
const buildDots = () => {
dotsEl.innerHTML = '';
if (gallery.length < 2) return;
gallery.forEach((_, i) => {
const dot = document.createElement('span');
dot.className = 'dot';
dot.addEventListener('click', () => { index = i; render(); });
dotsEl.appendChild(dot);
});
};
// C. Open / close
const openViewer = (items, start, title, trigger) => {
gallery = items;
index = start;
lastFocus = trigger;
titleEl.textContent = title;
prevBtn.disabled = nextBtn.disabled = items.length < 2;
buildDots();
render();
viewer.classList.add('is-open');
viewer.setAttribute('aria-hidden', 'false');
document.body.classList.add('viewer-open');
closeBtn.focus();
};
const closeViewer = () => {
viewer.classList.remove('is-open');
viewer.setAttribute('aria-hidden', 'true');
document.body.classList.remove('viewer-open');
canvas.innerHTML = ''; // Stops any playing video
if (lastFocus) lastFocus.focus();
};
const isOpen = () => viewer.classList.contains('is-open');
closeBtn.addEventListener('click', closeViewer);
viewer.querySelector('.viewer-scrim').addEventListener('click', closeViewer);
prevBtn.addEventListener('click', () => go(-1));
nextBtn.addEventListener('click', () => go(1));
document.addEventListener('keydown', (evt) => {
if (!isOpen()) return;
if (evt.key === 'Escape') closeViewer();
else if (evt.key === 'ArrowRight') go(1);
else if (evt.key === 'ArrowLeft') go(-1);
else if (evt.key === '0') resetView();
});
// D. Zoom -- wheel and trackpad pinch both arrive here
stage.addEventListener('wheel', (evt) => {
evt.preventDefault();
const [px, py] = stagePoint(evt.clientX, evt.clientY);
zoomTo(scale * Math.exp(-evt.deltaY * 0.0022), px, py);
}, { passive: false });
stage.addEventListener('dblclick', (evt) => {
const [px, py] = stagePoint(evt.clientX, evt.clientY);
if (scale > 1.01) resetView();
else zoomTo(2.5, px, py);
});
// E. Drag to pan, two-finger pinch, swipe to navigate
const pointers = new Map();
let panStart = null;
let pinchStart = null;
stage.addEventListener('pointerdown', (evt) => {
if (evt.target.closest('.viewer-nav')) return;
// Leave native video controls alone until the media is zoomed
if (evt.target.tagName === 'VIDEO' && scale <= 1.01) return;
stage.setPointerCapture(evt.pointerId);
pointers.set(evt.pointerId, evt);
if (pointers.size === 1) {
panStart = { x: evt.clientX, y: evt.clientY, tx, ty };
stage.classList.add('is-panning');
} else if (pointers.size === 2) {
const [a, b] = [...pointers.values()];
pinchStart = { dist: Math.hypot(a.clientX - b.clientX, a.clientY - b.clientY), scale };
}
});
stage.addEventListener('pointermove', (evt) => {
if (!pointers.has(evt.pointerId)) return;
pointers.set(evt.pointerId, evt);
if (pointers.size === 2 && pinchStart) {
const [a, b] = [...pointers.values()];
const dist = Math.hypot(a.clientX - b.clientX, a.clientY - b.clientY);
const [px, py] = stagePoint((a.clientX + b.clientX) / 2, (a.clientY + b.clientY) / 2);
zoomTo(pinchStart.scale * (dist / pinchStart.dist), px, py);
return;
}
if (panStart && scale > 1.01) {
tx = panStart.tx + (evt.clientX - panStart.x);
ty = panStart.ty + (evt.clientY - panStart.y);
clampPan();
apply();
}
});
const endPointer = (evt) => {
if (!pointers.has(evt.pointerId)) return;
// A horizontal flick moves through the gallery when not zoomed
if (pointers.size === 1 && panStart && scale <= 1.01) {
const dx = evt.clientX - panStart.x;
if (Math.abs(dx) > 60) go(dx < 0 ? 1 : -1);
}
pointers.delete(evt.pointerId);
if (pointers.size < 2) pinchStart = null;
if (pointers.size === 0) {
panStart = null;
stage.classList.remove('is-panning');
}
};
stage.addEventListener('pointerup', endPointer);
stage.addEventListener('pointercancel', endPointer);
// F. Wire each project's scroller to the viewer
document.querySelectorAll('.project-block').forEach((block) => {
const scroller = block.querySelector('.media-scroller');
if (!scroller) return;
const title = block.querySelector('.project-header')?.textContent.trim() ?? '';
const figures = [...scroller.querySelectorAll('.media-item')];
const items = figures.map((figure) => {
const video = figure.querySelector('video');
const image = figure.querySelector('img');
const caption = figure.querySelector('figcaption')?.textContent.trim() ?? '';
if (video) {
return {
type: 'video',
poster: video.getAttribute('poster'),
sources: [...video.querySelectorAll('source')].map((s) => ({ src: s.src, type: s.type })),
caption
};
}
return { type: 'image', src: image?.src, alt: image?.alt ?? '', caption };
});
figures.forEach((figure, i) => {
// Expand affordance is added here so the markup stays clean
const badge = document.createElement('span');
badge.className = 'media-expand';
badge.innerHTML = '<i class="fa-solid fa-up-right-and-down-left-from-center"></i>';
figure.appendChild(badge);
figure.setAttribute('role', 'button');
figure.setAttribute('tabindex', '0');
figure.setAttribute('aria-label', 'Open media viewer');
// Only counts as a click if the scroller was not being dragged
let downX = 0, downY = 0;
figure.addEventListener('pointerdown', (evt) => {
downX = evt.clientX;
downY = evt.clientY;
});
figure.addEventListener('click', (evt) => {
if (Math.hypot(evt.clientX - downX, evt.clientY - downY) > 6) return;
openViewer(items, i, title, figure);
});
figure.addEventListener('keydown', (evt) => {
if (evt.key === 'Enter' || evt.key === ' ') {
evt.preventDefault();
openViewer(items, i, title, figure);
}
});
});
});
})();
</script>
</body>
</html>