folk-canvas/website/canvas/morph/projector.html

99 lines
2.7 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Projector</title>
<style>
html {
height: 100%;
}
body {
min-height: 100%;
position: relative;
margin: 0;
overscroll-behavior: none;
}
folk-shape {
box-sizing: border-box;
background-color: rgb(187, 178, 178);
border-radius: 2px;
border: 2px solid rgba(0, 0, 0, 0.5);
}
folk-projector {
position: absolute;
inset: 0;
width: 100%;
height: 100%;
}
::view-transition-group(*) {
overflow: clip;
}
::view-transition-old(*),
::view-transition-new(*) {
height: 100%;
width: auto;
object-fit: cover;
}
</style>
</head>
<body>
<folk-projector>
<folk-shape x="100" y="100" width="50" height="50"></folk-shape>
<folk-shape x="100" y="200" width="50" height="50"></folk-shape>
<folk-shape x="100" y="300" width="50" height="50" rotation="45"></folk-shape>
<folk-shape x="300" y="150" width="80" height="40" rotation="45"></folk-shape>
<folk-shape x="400" y="250" width="60" height="90" rotation="45"></folk-shape>
</folk-projector>
<folk-shape x="500" y="290" width="80" height="40" rotation="45"></folk-shape>
<folk-shape x="300" y="350" width="60" height="90" rotation="45"></folk-shape>
<script type="module">
import '@labs/standalone/folk-shape.ts';
import '@labs/standalone/folk-projector.ts';
const projector = document.querySelector('folk-projector');
function XYCell(shape) {
const editor = document.createElement('div');
const xInput = document.createElement('input');
const yInput = document.createElement('input');
xInput.type = 'number';
yInput.type = 'number';
xInput.value = shape.x;
yInput.value = shape.y;
xInput.addEventListener('input', (e) => (shape.x = Number(e.target.value)));
yInput.addEventListener('input', (e) => (shape.y = Number(e.target.value)));
editor.appendChild(xInput);
editor.appendChild(yInput);
return editor;
}
const shapes = document.querySelectorAll('folk-shape');
shapes.forEach((shape) => {
projector.mapping(shape, XYCell);
});
document.addEventListener('keydown', (event) => {
if (event.key === 'v') {
projector.project();
}
});
document.addEventListener('click', (event) => {
if (event.target === document.body || event.target === projector) {
projector.project();
}
});
</script>
</body>
</html>