Skip to content

Commit 967c080

Browse files
committed
update testing page to use public animation api
1 parent 5b4ceec commit 967c080

File tree

2 files changed

+67
-1
lines changed

2 files changed

+67
-1
lines changed

internal/animate/testing/index.html

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,19 @@
1313
body * {
1414
border: 1px solid #eee;
1515
}
16+
17+
.buttons {
18+
display: flex;
19+
flex-direction: column;
20+
}
1621
</style>
1722
</head>
1823

1924
<body>
20-
<button id="toggle">TOGGLE<br />DEBUG</button>
25+
<div class="buttons">
26+
<button id="toggle">TOGGLE<br />DEBUG</button>
27+
<button id="interact">INTERACT</button>
28+
</div>
2129
<script src="./script.ts"></script>
2230
</body>
2331
</html>

internal/animate/testing/script.ts

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {clear, drawInfo, drawClosed} from "../../render/canvas";
66
import {genBlob} from "../../gen";
77
import {rand} from "../../rand";
88
import * as blobs2 from "../../../public/blobs";
9+
import * as blobs2Animate from "../../../public/animate";
910

1011
let animationSpeed = 2;
1112
let animationStart = 0.3;
@@ -24,6 +25,9 @@ const toggle = document.getElementById("toggle");
2425
if (toggle === null) throw new Error("no toggle");
2526
toggle.onclick = () => (debug = !debug);
2627

28+
const interact = document.getElementById("interact") as any;
29+
if (toggle === null) throw new Error("no interact");
30+
2731
const point = (x: number, y: number, ia: number, il: number, oa: number, ol: number): Point => {
2832
return {
2933
x: x * size,
@@ -255,6 +259,58 @@ const loopBetween = (percentage: number, a: Point[], b: Point[]): Point[] => {
255259
}
256260
};
257261

262+
const animation = blobs2Animate.canvasPath();
263+
264+
const loopAnimation = () => {
265+
console.log("LOOP");
266+
267+
animation.transition(
268+
{
269+
duration: 2000,
270+
blobOptions: {
271+
extraPoints: 3,
272+
randomness: 3,
273+
seed: "blob1",
274+
size: 200,
275+
},
276+
},
277+
{
278+
duration: 2000,
279+
callback: loopAnimation,
280+
blobOptions: {
281+
extraPoints: 3,
282+
randomness: 3,
283+
seed: "blob2",
284+
size: 200,
285+
},
286+
},
287+
);
288+
};
289+
290+
animation.transition({
291+
duration: 100,
292+
callback: loopAnimation,
293+
blobOptions: {
294+
extraPoints: 3,
295+
randomness: 3,
296+
seed: "start",
297+
size: 200,
298+
},
299+
});
300+
301+
interact.onclick = () => {
302+
animation.transition({
303+
duration: 1000,
304+
callback: loopAnimation,
305+
blobOptions: {
306+
extraPoints: 3,
307+
randomness: 7,
308+
seed: "onClick",
309+
size: 200,
310+
},
311+
});
312+
};
313+
258314
(() => {
259315
let percentage = animationStart;
260316

@@ -276,6 +332,8 @@ const loopBetween = (percentage: number, a: Point[], b: Point[]): Point[] => {
276332
percentage += animationSpeed / 1000;
277333
percentage = mod(percentage, 1);
278334
if (animationSpeed > 0) requestAnimationFrame(renderFrame);
335+
336+
ctx.fill(animation.renderFrame());
279337
};
280338
renderFrame();
281339
})();

0 commit comments

Comments
 (0)