folk-canvas/website/canvas/space-transform.html

67 lines
1.9 KiB
HTML

<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Simple Space Demo</title>
<style>
html,
body {
margin: 0;
height: 100%;
}
folk-shape {
background: rgb(134, 37, 37);
border: 1px solid rgba(0, 0, 0, 0.5);
}
</style>
</head>
<body>
<folk-gizmos></folk-gizmos>
<folk-transformed-space>
<folk-gizmos layer="transformed"></folk-gizmos>
<folk-shape x="250" y="100" width="50" height="50"></folk-shape>
<folk-shape x="200" y="200" width="75" height="75" rotation="90"></folk-shape>
<folk-shape x="50" y="250" width="25" height="25" rotation="180"></folk-shape>
<folk-shape x="350" y="50" width="100" height="100" rotation="270"></folk-shape>
<folk-shape x="500" y="500" width="150" height="150" rotation="360"></folk-shape>
</folk-transformed-space>
<script type="module">
import '@labs/standalone/folk-shape.ts';
import '@labs/standalone/folk-transformed-space.ts';
import { FolkTransformedSpace } from '@labs/folk-transformed-space';
const space = document.querySelector('folk-transformed-space');
let isPointerDown = false;
document.addEventListener('pointerdown', (event) => {
isPointerDown = true;
});
document.addEventListener('pointermove', (event) => {
if (!isPointerDown) return;
const point = {
x: event.clientX,
y: event.clientY,
};
const transformedPoint = FolkTransformedSpace.projectPoint(point, space);
});
document.addEventListener('pointerup', () => {
isPointerDown = false;
});
document.addEventListener('click', (event) => {
if (event.target !== space) return;
const min = -50;
const max = 50;
const randomRotation = Math.random() * (max - min) + min;
space.rotate(randomRotation);
});
</script>
</body>
</html>