This commit is contained in:
2025-01-06 15:05:51 +01:00
parent cc608379fc
commit c51f5837aa
3 changed files with 200 additions and 35 deletions
+75 -13
View File
@@ -12,19 +12,81 @@
<meta property="og:description" content="Make bingo grids quickly" /> <meta property="og:description" content="Make bingo grids quickly" />
</head> </head>
<body> <body>
<main id="app" style="display: none"> <div id="app" style="display: none">
<main>
<h1>🏭 Bingo Factory</h1>
<table class="config">
<tr>
<td>Ratio</td>
<td>
<select v-model="config.ratio">
<option value="1">square (1:1)</option>
<option value="1.414">portrait (1:1.414)</option>
<option value="0.707">landscape (1.414:1)</option>
<option value="1.25">phone (4:5)</option>
</select>
</td>
</tr>
<tr>
<td>Margin</td>
<td>
<select v-model="config.margin">
<option value="0.05">5%</option>
<option value="0.1">10%</option>
<option value="0.15">15%</option>
<option value="0.2">20%</option>
</select>
</td>
</tr>
<tr>
<td>Grid</td>
<td>
<select v-model="config.grid">
<option value="3">3x3</option>
<option value="4">4x4</option>
<option value="5">5x5</option>
<option value="6">6x6</option>
</select>
</td>
</tr>
<tr>
<td>Seed</td>
<td>
<div class="withButton">
<input v-model="config.seed" />
<button @click="newSeed">new</button>
</div>
</td>
</tr>
<tr>
<td>Title</td>
<td>
<input v-model="config.title" />
</td>
</tr>
<tr>
<td>Color</td>
<td>
<div class="withButton">
<input v-model="config.color" />
<button @click="newColor">new</button>
</div>
</td>
</tr>
</table>
<br />
<small
><a href="https://github.com/clement-gouin" target="_blank"
>@clement-gouin</a
>
-
<a href="https://github.com/clement-gouin/bingo" target="_blank"
>Github Repository</a
>
- 2025</small
>
</main>
<canvas width="400" height="400" ref="canvas"></canvas> <canvas width="400" height="400" ref="canvas"></canvas>
<br /> </div>
<small
><a href="https://github.com/clement-gouin" target="_blank"
>@clement-gouin</a
>
-
<a href="https://github.com/clement-gouin/bingo" target="_blank"
>Github Repository</a
>
- 2025</small
>
</main>
</body> </body>
</html> </html>
+98 -10
View File
@@ -3,14 +3,15 @@
const utils = { const utils = {
strokeGrid(ctx, x, y, w, h, cols, rows) { strokeGrid(ctx, x, y, w, h, cols, rows) {
ctx.beginPath(); ctx.beginPath();
for (let c = 0; c < cols + 1; c++) { for (let c = 1; c < cols; c++) {
ctx.moveTo(Math.round(x + (w / cols) * c), y); ctx.moveTo(Math.round(x + (w / cols) * c), y);
ctx.lineTo(Math.round(x + (w / cols) * c), y + h); ctx.lineTo(Math.round(x + (w / cols) * c), y + h);
} }
for (let r = 0; r < rows + 1; r++) { for (let r = 1; r < rows; r++) {
ctx.moveTo(x, Math.round(y + (h / rows) * r)); ctx.moveTo(x, Math.round(y + (h / rows) * r));
ctx.lineTo(x + w, Math.round(y + (h / rows) * r)); ctx.lineTo(x + w, Math.round(y + (h / rows) * r));
} }
ctx.rect(x, y, w, h);
ctx.stroke(); ctx.stroke();
}, },
fitText(ctx, x, y, w, h, txt) { fitText(ctx, x, y, w, h, txt) {
@@ -79,37 +80,124 @@ const utils = {
); );
}); });
}, },
randomColor() {
return ("#" + Math.floor(Math.random() * 16777215).toString(16)).padEnd(
7,
"0"
);
},
}; };
let app = { let app = {
data() { data() {
return {}; return {
config: {
ratio: 1,
margin: 0.1,
grid: 4,
seed: (100000000 * Math.random()).toFixed(0),
title: "Bingo",
color: utils.randomColor(),
},
};
}, },
computed: {}, computed: {},
watch: {
config: {
handler() {
this.draw();
},
deep: true,
},
},
methods: { methods: {
showApp() { showApp() {
document.getElementById("app").setAttribute("style", ""); document.getElementById("app").setAttribute("style", "");
this.draw(); this.draw();
}, },
newSeed() {
this.config.seed = (100000000 * Math.random()).toFixed(0);
this.draw();
},
newColor() {
this.config.color = utils.randomColor();
this.draw();
},
draw() { draw() {
const ctx = this.$refs.canvas?.getContext("2d"); const ctx = this.$refs.canvas?.getContext("2d");
if (!ctx) { if (!ctx) {
return; return;
} }
utils.strokeGrid(ctx, 2, 2, 398, 398, 5, 5);
utils.fitText( const height = window.innerHeight;
const width = height / parseFloat(this.config.ratio);
this.$refs.canvas.height = height;
this.$refs.canvas.width = width;
ctx.clearRect(0, 0, width, height);
ctx.fillStyle = "white";
ctx.fillRect(0, 0, width, height);
ctx.fillStyle = this.config.color + "33";
ctx.fillRect(0, 0, width, height);
const margin = parseFloat(this.config.margin);
const gridSize = Math.min(
(1 - margin * 2) * width,
(1 - margin * 2) * height
);
ctx.lineJoin = "miter";
ctx.strokeStyle = this.config.color;
ctx.lineWidth = gridSize * 0.005;
utils.strokeGrid(
ctx, ctx,
3, (width - gridSize) / 2,
3, (height - gridSize) * (this.config.title ? 2 / 3 : 1 / 2),
79, gridSize,
79, gridSize,
"This is a very long text, I hope this fits well" parseInt(this.config.grid),
parseInt(this.config.grid)
);
ctx.lineWidth = gridSize * 0.01;
ctx.strokeRect(
(width - gridSize) / 2,
(height - gridSize) * (this.config.title ? 2 / 3 : 1 / 2),
gridSize,
gridSize
);
if (this.config.title) {
ctx.font = `bold ${gridSize * 0.1}px serif`;
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillStyle = this.config.color;
ctx.fillText(this.config.title, width / 2, (height - gridSize) / 3);
}
ctx.font = `bold ${gridSize * 0.02}px sans-serif`;
ctx.textAlign = "right";
ctx.textBaseline = "bottom";
ctx.fillStyle = this.config.color + "44";
ctx.fillText(
"clement-gouin.github.io/bingo",
width * 0.99,
height * 0.99
); );
}, },
}, },
mounted: function () { mounted: function () {
console.log("app mounted"); console.log("app mounted");
setTimeout(this.showApp); setTimeout(this.showApp);
addEventListener("resize", this.draw);
}, },
}; };
+27 -12
View File
@@ -85,7 +85,7 @@ CUSTOM STYLE
:root { :root {
/* https://materialui.co/colors/ */ /* https://materialui.co/colors/ */
--hue-primary: 65.52; --hue-primary: 24.42;
--sat-primary: 20%; --sat-primary: 20%;
--background: hsl(var(--hue-primary), var(--sat-primary), 96.08%); --background: hsl(var(--hue-primary), var(--sat-primary), 96.08%);
--background-primary: hsl(var(--hue-primary), var(--sat-primary), 93.33%); --background-primary: hsl(var(--hue-primary), var(--sat-primary), 93.33%);
@@ -113,13 +113,37 @@ body {
body { body {
background-color: var(--background); background-color: var(--background);
min-height: 100vh;
}
#app {
display: flex;
flex-direction: row;
min-height: 100vh;
} }
main { main {
padding: 1.5rem; padding: 1.5rem;
margin: auto;
background-color: var(--background-primary); background-color: var(--background-primary);
min-height: 100%; }
canvas {
border: 1px dashed;
width: min-content;
}
.config td:first-child {
text-align: right;
padding-right: 1em;
}
.config td select,
.config td input {
width: 100%;
}
.withButton {
display: flex;
} }
table { table {
@@ -160,12 +184,3 @@ textarea {
a { a {
color: inherit; color: inherit;
} }
@media only screen and (min-width: 768px) {
main {
max-width: 42rem;
}
table {
font-size: inherit;
}
}