mirror of
https://github.com/rough-stuff/rough.git
synced 2026-01-14 17:07:58 -05:00
69 lines
1.5 KiB
HTML
69 lines
1.5 KiB
HTML
<!doctype html>
|
|
<html lang="en">
|
|
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<meta name="viewport" content="width=device-width, minimum-scale=1, initial-scale=1, user-scalable=yes">
|
|
<title>RoughJS Curve</title>
|
|
</head>
|
|
|
|
<body>
|
|
<canvas width="1000" height="1000"></canvas>
|
|
<br>
|
|
<input type="range" style="width: 100%; display: block; box-sizing: border-box;" min="0" max="800">
|
|
|
|
<script type="module">
|
|
import rough from '../../bin/rough.js';
|
|
const canvas = document.querySelector('canvas');
|
|
const rc = rough.canvas(canvas);
|
|
const ctx = rc.ctx;
|
|
const input = document.querySelector('input');
|
|
|
|
const getRings = () => {
|
|
const xPos = +input.value;
|
|
return [
|
|
[
|
|
[100, 300],
|
|
[800, 300],
|
|
[800, 0],
|
|
[100, 0]
|
|
],
|
|
[
|
|
[200, 250],
|
|
[200, 50],
|
|
[600, 50],
|
|
[600, 250]
|
|
],
|
|
[
|
|
[400, 200],
|
|
[550, 200],
|
|
[550, 100],
|
|
[400, 100]
|
|
],
|
|
[
|
|
[xPos + 25, 175],
|
|
[xPos + 25, 125],
|
|
[xPos + 75, 125],
|
|
[xPos + 75, 175]
|
|
]
|
|
]
|
|
};
|
|
|
|
const draw = () => {
|
|
ctx.clearRect(0, 0, 1000, 1000);
|
|
const path = getRings().map((d) => `M${d.join("L")}Z`).join(' ') + ' M 650, 150 a 50,50 0 1,0 100,0 a 50,50 0 1,0 -100,0';
|
|
rc.path(path, {
|
|
seed: 2142156371,
|
|
fill: 'orange',
|
|
fillWeight: 2
|
|
});
|
|
}
|
|
|
|
draw();
|
|
input.addEventListener('input', () => draw());
|
|
|
|
|
|
</script>
|
|
</body>
|
|
|
|
</html> |