104 lines
3.5 KiB
HTML
104 lines
3.5 KiB
HTML
<!doctype html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8" />
|
|
<title>Folk Space Demo</title>
|
|
<style>
|
|
html,
|
|
body {
|
|
margin: 0;
|
|
height: 100%;
|
|
}
|
|
|
|
folk-space {
|
|
width: 100%;
|
|
height: 100%;
|
|
}
|
|
|
|
folk-shape {
|
|
background: rgb(134, 37, 37);
|
|
border: 1px solid rgba(0, 0, 0, 0.5);
|
|
}
|
|
|
|
[slot='front'] folk-shape {
|
|
background: rgb(187, 178, 178);
|
|
}
|
|
|
|
folk-rope {
|
|
position: absolute;
|
|
inset: 0;
|
|
pointer-events: none;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<folk-rope id="rope"></folk-rope>
|
|
<folk-space id="space">
|
|
<div slot="front">
|
|
<folk-shape id="source" 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-shape x="600" y="600" width="200" height="200" rotation="450"></folk-shape>
|
|
<folk-shape x="700" y="700" width="250" height="250" rotation="540"></folk-shape>
|
|
</div>
|
|
<div slot="back">
|
|
<folk-shape id="target" x="550" y="150" width="50" height="50" rotation="45"></folk-shape>
|
|
<folk-shape x="300" y="400" width="150" height="50" rotation="45"></folk-shape>
|
|
<folk-shape x="250" y="350" width="100" height="100" rotation="135"></folk-shape>
|
|
<folk-shape x="400" y="200" width="75" height="75" rotation="225"></folk-shape>
|
|
<folk-shape x="200" y="450" width="50" height="50" rotation="315"></folk-shape>
|
|
<folk-shape x="600" y="600" width="200" height="200" rotation="405"></folk-shape>
|
|
<folk-shape x="700" y="700" width="250" height="250" rotation="495"></folk-shape>
|
|
</div>
|
|
</folk-space>
|
|
|
|
<script type="module">
|
|
import '@labs/standalone/folk-shape.ts';
|
|
import '@labs/standalone/folk-space.ts';
|
|
import '@labs/standalone/folk-rope.ts';
|
|
|
|
const space = document.getElementById('space');
|
|
|
|
// Create multiple ropes
|
|
const ropes = Array.from({ length: 1 }, () => {
|
|
const rope = document.createElement('folk-rope');
|
|
document.body.appendChild(rope);
|
|
return rope;
|
|
});
|
|
|
|
// Get all shapes from both front and back
|
|
const frontShapes = Array.from(document.querySelectorAll('[slot="front"] folk-shape'));
|
|
const backShapes = Array.from(document.querySelectorAll('[slot="back"] folk-shape'));
|
|
|
|
function updateRopePoints() {
|
|
// Connect shapes in various patterns
|
|
ropes.forEach((rope, index) => {
|
|
const sourceShape = frontShapes[index % frontShapes.length];
|
|
const targetShape = backShapes[index % backShapes.length];
|
|
|
|
if (sourceShape && targetShape) {
|
|
const sourceRect = space.getElementScreenRect(sourceShape);
|
|
const targetRect = space.getElementScreenRect(targetShape);
|
|
|
|
if (sourceRect && targetRect) {
|
|
rope.sourceRect = sourceRect;
|
|
rope.targetRect = targetRect;
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
function animate() {
|
|
updateRopePoints();
|
|
requestAnimationFrame(animate);
|
|
}
|
|
animate();
|
|
|
|
// Handle transition
|
|
document.addEventListener('click', () => space.transition());
|
|
</script>
|
|
</body>
|
|
</html>
|