Skip to content

Commit 48ceaba

Browse files
committed
Add input control
1 parent 467da59 commit 48ceaba

File tree

1 file changed

+28
-8
lines changed

1 file changed

+28
-8
lines changed

Patterns/hollowRhombus/index.html

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,27 +18,47 @@
1818
background-color: #ededed;
1919
}
2020

21-
pre {
21+
#controller {
22+
width: 100%
23+
}
24+
25+
#console {
2226
font-family: 'Courier New', Courier, monospace;
2327
color: #ececec;
2428
background-color: #30475e;
2529
border: 1px solid #222831;
2630
border-radius: 2px;
27-
padding: 17px 13px 10px
31+
padding: 19px 17px 10px
2832
}
2933
</style>
3034
<script src='hollowRhombus.js'></script>
35+
<script>
36+
const draw = (input, output) => {
37+
const shape = generateCanvas(
38+
{ width: input.value, height: input.value },
39+
{ hollow: ' ', solid: '*' }
40+
)
41+
output.innerHTML = shape
42+
}
43+
</script>
3144
</head>
3245

3346
<body>
34-
<pre id='main'></pre>
47+
<main>
48+
<form id='input'>
49+
<input type='range' name='controller' id='controller' value='9' min='1' max='19' step='2'>
50+
</form>
51+
<pre id='console'></pre>
52+
</main>
3553
</body>
3654
<script>
37-
const shape = generateCanvas(
38-
{ width: 9, height: 9 },
39-
{ hollow: ' ', solid: '*' }
40-
)
41-
document.querySelector('#main').innerHTML = shape
55+
const input = document.querySelector('#controller')
56+
const output = document.querySelector('#console')
57+
draw(input, output)
58+
input.addEventListener(
59+
'change',
60+
e => draw(e.target, output)
61+
)
4262
</script>
4363

4464
</html>

0 commit comments

Comments
 (0)