Going somewhere.

This commit is contained in:
didier.amyot committed 2024-01-29 07:50:13 -05:00
1 parent 1da186a759
commit 3d1ef31b90
8 files changed
+158 -14533

No files matched your search

+72
View File
@@ -0,0 +1,72 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Animation</title>
<meta name="viewport" content="width=device-width,initial-scale=1" />
<meta name="description" content="" />
<link rel="icon" href="favicon.png">
<link rel="stylesheet" href="style.css">
<script src="animation.js" type="module"></script>
</head>
<body>
<h1>Hello, world!</h1>
<svg width="900" height="450" >
<rect x="0" y="0" width="900" height="450" class="court-border"></rect>
<line x1="450" y1="0" x2="450" y2="450" class="court-border"></line>
<line x1="300" y1="0" x2="300" y2="450" class="return-line"></line>
<line x1="600" y1="0" x2="600" y2="450" class="return-line"></line>
<rect x="0" y="157.5" width="15" height="15"
style="fill: red;" id="rect-1"></rect>
<rect x="0" y="157.5" width="15" height="15"
style="fill: blue;" id="rect-2"></rect>
<rect x="0" y="157.5" width="15" height="15"
style="fill: yellow;" id="rect-3"></rect>
<rect x="0" y="157.5" width="15" height="15"
style="fill: pink;" id="rect-4"></rect>
<rect x="0" y="157.5" width="15" height="15"
style="fill: purple;" id="rect-5"></rect>
<rect x="0" y="157.5" width="15" height="15"
style="fill: black;" id="rect-6"></rect>
<rect x="0" y="157.5" width="15" height="15"
style="stroke: red; fill-opacity: 0;" id="rect-7"></rect>
<rect x="0" y="157.5" width="15" height="15"
style="stroke: blue; fill-opacity: 0;" id="rect-8"></rect>
<rect x="0" y="157.5" width="15" height="15"
style="stroke: yellow; fill-opacity: 0;" id="rect-9"></rect>
<rect x="0" y="157.5" width="15" height="15"
style="stroke: pink; fill-opacity: 0;" id="rect-10"></rect>
<rect x="0" y="157.5" width="15" height="15"
style="stroke: purple; fill-opacity: 0;" id="rect-11"></rect>
<rect x="0" y="157.5" width="15" height="15"
style="stroke: black; fill-opacity: 0;" id="rect-12"></rect>
</svg>
<div>
<button id="play">play</button> <br>
<button id="pause">pause</button>
<br>
<input type="number" id="seek-value">
<button id="seek">seek</button>
</div>
</body>
</html>
+66
View File
@@ -0,0 +1,66 @@
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();
const z = Math.sqrt( -2.0 * Math.log( u ) ) * Math.cos( 2.0 * Math.PI * v );
// Transform to the desired mean and standard deviation:
return z * stdev + mean;
}
function* brownian(n){
let x = 0;
for(let i = 0; i < n; i ++){
x += gaussianRandom(0, 10);
console.log(x);
yield x;
}
}
function* pseudoBrownian(n, limit){
let x = 0;
for(let i = 0; i < n; i ++){
let delta = gaussianRandom(0, 10);
if(Math.abs(x + delta) > limit){
delta = -1 * delta
}
x += delta;
yield x;
}
}
function* keyFrames(duration, framePerSeconds){
const deltaX = canvasWidth / (duration * framePerSeconds);
const limit = 0.75 * (canvasHeight / 2);
for(const deltaY of pseudoBrownian(duration * framePerSeconds, limit)){
yield {translateX: `+=${deltaX}`, translateY: deltaY};
}
}
const duration = 60;
const timeline = anime.timeline({
duration: duration * second,
autoplay: false,
easing: 'linear'});
for(let i = 1; i <= 12; i++){
timeline.add({
targets: `#rect-${i}`,
keyframes: Array.from(keyFrames(duration, 30)),
}, 0)
}
document.querySelector('#play').onclick = timeline.play;
document.querySelector('#pause').onclick = timeline.pause;
document.querySelector('#seek').onclick = function(){
const seekVal = Number.parseFloat(second * document.querySelector('#seek-value').value);
timeline.pause();
timeline.seek(seekVal);
}
-57
View File
@@ -26,62 +26,5 @@
<svg width="900" height="450" id="first" style="background-color: lightgray">
</svg>
<br>
<svg width="900" height="450" >
<rect x="0" y="0" width="900" height="450" class="court-border"></rect>
<line x1="450" y1="0" x2="450" y2="450" class="court-border"></line>
<line x1="300" y1="0" x2="300" y2="450" class="return-line"></line>
<line x1="600" y1="0" x2="600" y2="450" class="return-line"></line>
<rect x="0" y="157.5" width="15" height="15"
style="fill: red;" id="rect-1"></rect>
<rect x="0" y="157.5" width="15" height="15"
style="fill: blue;" id="rect-2"></rect>
<rect x="0" y="157.5" width="15" height="15"
style="fill: yellow;" id="rect-3"></rect>
<rect x="0" y="157.5" width="15" height="15"
style="fill: pink;" id="rect-4"></rect>
<rect x="0" y="157.5" width="15" height="15"
style="fill: purple;" id="rect-5"></rect>
<rect x="0" y="157.5" width="15" height="15"
style="fill: black;" id="rect-6"></rect>
<rect x="0" y="157.5" width="15" height="15"
style="stroke: red; fill-opacity: 0;" id="rect-7"></rect>
<rect x="0" y="157.5" width="15" height="15"
style="stroke: blue; fill-opacity: 0;" id="rect-8"></rect>
<rect x="0" y="157.5" width="15" height="15"
style="stroke: yellow; fill-opacity: 0;" id="rect-9"></rect>
<rect x="0" y="157.5" width="15" height="15"
style="stroke: pink; fill-opacity: 0;" id="rect-10"></rect>
<rect x="0" y="157.5" width="15" height="15"
style="stroke: purple; fill-opacity: 0;" id="rect-11"></rect>
<rect x="0" y="157.5" width="15" height="15"
style="stroke: black; fill-opacity: 0;" id="rect-12"></rect>
</svg>
<div>
<button id="play">play</button> <br>
<button id="pause">pause</button>
<br>
<input type="number" id="seek-value">
<button id="seek">seek</button>
</div>
</body>
</html>
+2 -75
View File
@@ -1,72 +1,6 @@
import anime from "https://esm.sh/animejs@3.2.2";
import m from "https://esm.sh/mithril@2.2.2"
import colormap from "https://esm.sh/colormap@2.3.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();
const z = Math.sqrt( -2.0 * Math.log( u ) ) * Math.cos( 2.0 * Math.PI * v );
// Transform to the desired mean and standard deviation:
return z * stdev + mean;
}
function* brownian(n){
let x = 0;
for(let i = 0; i < n; i ++){
x += gaussianRandom(0, 10);
console.log(x);
yield x;
}
}
function* pseudoBrownian(n, limit){
let x = 0;
for(let i = 0; i < n; i ++){
let delta = gaussianRandom(0, 10);
if(Math.abs(x + delta) > limit){
delta = -1 * delta
}
x += delta;
yield x;
}
}
function* keyFrames(duration, framePerSeconds){
const deltaX = canvasWidth / (duration * framePerSeconds);
const limit = 0.75 * (canvasHeight / 2);
for(const deltaY of pseudoBrownian(duration * framePerSeconds, limit)){
yield {translateX: `+=${deltaX}`, translateY: deltaY};
}
}
const duration = 60;
const timeline = anime.timeline({
duration: duration * second,
autoplay: false,
easing: 'linear'});
for(let i = 1; i <= 12; i++){
timeline.add({
targets: `#rect-${i}`,
keyframes: Array.from(keyFrames(duration, 30)),
}, 0)
}
document.querySelector('#play').onclick = timeline.play;
document.querySelector('#pause').onclick = timeline.pause;
document.querySelector('#seek').onclick = function(){
const seekVal = Number.parseFloat(second * document.querySelector('#seek-value').value);
timeline.pause();
timeline.seek(seekVal);
}
import {range} from "./util.js";
function generatePoints(points, frames){
const lst = [];
@@ -96,14 +30,7 @@ const url = "/dodgeball-tracker/outputs/output-lmbn_n_cuhk03_d.json";
const resp = await fetch(url);
const points = await resp.json();
function range(min, max){
const ret = [];
while(min < max){
ret.push(min);
min ++;
}
return ret
}
m.render(document.getElementById("first"), generatePoints(points.points, range(-10, 400)));
m.render(document.getElementById("first-ts"), m("span", getTimeStamp(points.points, 80)));
-14400
View File
File diff suppressed because it is too large. Load diff
+12
View File
@@ -0,0 +1,12 @@
export function range(min, max=undefined){
if(max === undefined){
max = min;
min = 0;
}
const ret = [];
while(min < max){
ret.push(min);
min ++;
}
return ret
}