feat: add grid gap & canvas outline
This commit is contained in:
parent
4931cdc097
commit
ed0cffb8b3
3 changed files with 25 additions and 9 deletions
|
@ -31,6 +31,11 @@
|
||||||
<input id="scale" type="number" min="1" value="40">
|
<input id="scale" type="number" min="1" value="40">
|
||||||
px per module
|
px per module
|
||||||
</label>
|
</label>
|
||||||
|
<label for="gap">
|
||||||
|
<span>Grid gap:</span>
|
||||||
|
<input id="gap" type="number" min="0" value="0">
|
||||||
|
px between modules
|
||||||
|
</label>
|
||||||
<button id="gen-btn">Generate</button>
|
<button id="gen-btn">Generate</button>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
|
|
11
script.js
11
script.js
|
@ -57,23 +57,26 @@ addEventListener('DOMContentLoaded', () => {
|
||||||
size: document.getElementById("width"),
|
size: document.getElementById("width"),
|
||||||
ver: document.getElementById("version"),
|
ver: document.getElementById("version"),
|
||||||
scale: document.getElementById("scale"),
|
scale: document.getElementById("scale"),
|
||||||
|
gap: document.getElementById("gap"),
|
||||||
}
|
}
|
||||||
|
|
||||||
document.getElementById("gen-btn").addEventListener("click", () => {
|
document.getElementById("gen-btn").addEventListener("click", () => {
|
||||||
const mask = options.mask.value
|
const mask = options.mask.value
|
||||||
const size = options.size.value
|
const size = Number(options.size.value)
|
||||||
const scale = options.scale.value
|
const scale = Number(options.scale.value)
|
||||||
|
const gap = Math.min(Number(options.gap.value), scale) // not more than 1 module scaled size
|
||||||
|
|
||||||
|
const wh = scale - gap * 2 // width&height for 1 module with grid gap
|
||||||
|
|
||||||
canvas.width = canvas.height = size * scale
|
canvas.width = canvas.height = size * scale
|
||||||
|
|
||||||
ctx.clearRect(0, 0, canvas.width, canvas.height)
|
ctx.clearRect(0, 0, canvas.width, canvas.height)
|
||||||
|
|
||||||
ctx.fillStyle = "black"
|
ctx.fillStyle = "black"
|
||||||
|
|
||||||
for (let row = 0; row < size; row++) {
|
for (let row = 0; row < size; row++) {
|
||||||
for (let col = 0; col < size; col++) {
|
for (let col = 0; col < size; col++) {
|
||||||
if (eval(mask) == 0) {
|
if (eval(mask) == 0) {
|
||||||
ctx.fillRect(col * scale, row * scale, scale, scale)
|
ctx.fillRect(col * scale + gap, row * scale + gap, wh, wh)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
18
style.css
18
style.css
|
@ -3,14 +3,17 @@ body {
|
||||||
padding: 0.5rem;
|
padding: 0.5rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
#options {
|
body > div {
|
||||||
|
width: fit-content;
|
||||||
|
margin: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
body > div#options {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
row-gap: 0.25rem;
|
row-gap: 0.25rem;
|
||||||
|
|
||||||
width: fit-content;
|
|
||||||
max-width: calc(100vw - 0.5rem * 2);
|
max-width: calc(100vw - 0.5rem * 2);
|
||||||
margin: auto;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
select, input, button {
|
select, input, button {
|
||||||
|
@ -20,7 +23,7 @@ select, input, button {
|
||||||
}
|
}
|
||||||
|
|
||||||
input[type=number] {
|
input[type=number] {
|
||||||
width: calc(1rem * 4 + 0.125rem * 2);
|
width: calc(4rem + 0.125rem * 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
label {
|
label {
|
||||||
|
@ -35,6 +38,11 @@ label#width-wrapper > button {
|
||||||
}
|
}
|
||||||
|
|
||||||
label > span:nth-child(1) {
|
label > span:nth-child(1) {
|
||||||
width: calc(3.5rem);
|
width: 5rem;
|
||||||
text-align: right;
|
text-align: right;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
canvas {
|
||||||
|
margin-top: 0.5rem;
|
||||||
|
border: 2px solid #555;
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue