From 6bda4df11156e564b3f3965b6bbf760e0f6045e5 Mon Sep 17 00:00:00 2001 From: didier amyot Date: Sun, 21 Jan 2024 09:47:39 -0500 Subject: [PATCH] Improved frontend. --- dodgeballtracker/__init__.py | 2 +- dodgeballtracker/logic.py | 3 +++ frontend/index.html | 20 +++++++++++++------- frontend/main.js | 8 ++++++-- frontend/style.css | 11 +++++++++++ 5 files changed, 34 insertions(+), 10 deletions(-) create mode 100644 frontend/style.css diff --git a/dodgeballtracker/__init__.py b/dodgeballtracker/__init__.py index f7474a0..dc03919 100644 --- a/dodgeballtracker/__init__.py +++ b/dodgeballtracker/__init__.py @@ -6,7 +6,7 @@ import numpy as np here = Path(__file__).parent input_dir = here / '..' / 'data' -output_dir = here / '..' / 'data' +output_dir = here / '..' / 'outputs' if __name__ == "__main__": detected_box_objects = [ diff --git a/dodgeballtracker/logic.py b/dodgeballtracker/logic.py index 1b9362c..0457ac8 100644 --- a/dodgeballtracker/logic.py +++ b/dodgeballtracker/logic.py @@ -10,6 +10,7 @@ import numpy as np Color = tuple[int, int, int] + class DetectedObjectBox: def __init__(self, min_threshold: float, color: Color): self.min_threshold = min_threshold @@ -90,3 +91,5 @@ def main(input_filename: Path, output_filename: Path, detected_box_objects): writer.release() cv2.destroyAllWindows() + + diff --git a/frontend/index.html b/frontend/index.html index beb99a8..56e4f3f 100644 --- a/frontend/index.html +++ b/frontend/index.html @@ -1,16 +1,22 @@ - - Animation - - - - + + Animation + + + + + +

Hello, world!

- + + + + + diff --git a/frontend/main.js b/frontend/main.js index a33786e..b01587f 100644 --- a/frontend/main.js +++ b/frontend/main.js @@ -2,6 +2,9 @@ import anime from "https://esm.sh/animejs@3.2.2"; const second = 1000; +const canvasWidth = Number.parseFloat(document.querySelector("svg").getAttribute("width")); +const canvasHeight = Number.parseFloat(document.querySelector("svg").getAttribute("height")); + function gaussianRandom(mean=0, stdev=1) { const u = 1 - Math.random(); // Converting [0,1) to (0,1] const v = Math.random(); @@ -33,8 +36,9 @@ function* pseudoBrownian(n, limit){ } function* keyFrames(duration, framePerSeconds){ - const deltaX = 1000 / (duration * framePerSeconds); - for(const deltaY of pseudoBrownian(duration * framePerSeconds, 100)){ + const deltaX = canvasWidth / (duration * framePerSeconds); + const limit = 0.75 * (canvasHeight / 2); + for(const deltaY of pseudoBrownian(duration * framePerSeconds, limit)){ yield {translateX: `+=${deltaX}`, translateY: deltaY}; } } diff --git a/frontend/style.css b/frontend/style.css new file mode 100644 index 0000000..f7912f7 --- /dev/null +++ b/frontend/style.css @@ -0,0 +1,11 @@ +.court-border { + stroke: red; + stroke-width: 4px; + fill-opacity: 0; +} + +.return-line { + stroke: yellow; + stroke-width: 2px; + fill-opacity: 0; +} \ No newline at end of file