folk-canvas/website/[shaders]falling-sand.html

102 lines
2.9 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Falling Sand Demo</title>
<style>
html {
height: 100%;
}
body {
min-height: 100%;
position: relative;
margin: 0;
overscroll-behavior: none;
}
folk-shape {
background: transparent;
position: absolute;
background-color: rgba(119, 119, 119, 1);
border-radius: 2px;
}
key-helper {
position: fixed;
top: 20px;
right: 20px;
background: rgba(0, 0, 0, 0.7);
color: white;
padding: 10px;
border-radius: 5px;
font-family: monospace;
z-index: 1000;
display: flex;
flex-direction: column;
gap: 5px;
button {
all: unset;
&[active] key-number {
background: rgba(255, 255, 255, 0.6);
}
key-number {
display: inline-block;
background: rgba(255, 255, 255, 0.2);
padding: 2px 8px;
border-radius: 3px;
margin-right: 10px;
}
}
}
p {
box-sizing: border-box;
color: white;
position: absolute;
top: 150px;
left: 25px;
border: 1px solid white;
}
</style>
</head>
<body>
<key-helper>
<button><key-number>1</key-number> Smoke</button>
<button><key-number>2</key-number> Water</button>
<button><key-number>3</key-number> Lava</button>
<button active><key-number>4</key-number> Sand</button>
<button><key-number>5</key-number> Plant</button>
<button><key-number>6</key-number> Stone</button>
<button><key-number>7</key-number> Wall</button>
<button><key-number>8</key-number> Ice</button>
<button><key-number>9</key-number> Fire</button>
</key-helper>
<folk-sand>
<p>Sanding</p>
<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"></folk-shape>
<folk-shape x="300" y="150" width="80" height="40"></folk-shape>
<folk-shape x="400" y="250" width="60" height="90"></folk-shape>
<folk-shape x="200" y="400" width="100" height="100"></folk-shape>
<folk-shape x="500" y="100" width="30" height="70"></folk-shape>
</folk-sand>
<script type="module">
import '../lib/standalone/folk-shape.ts';
import '../lib/standalone/folk-sand.ts';
document.querySelector('folk-sand').onMaterialChange = (materialNumber) => {
document.querySelector('key-helper button[active]').removeAttribute('active');
document.querySelector(`key-helper button:nth-child(${materialNumber})`).setAttribute('active', '');
};
</script>
</body>
</html>