wip
This commit is contained in:
+18
-19
@@ -1,31 +1,30 @@
|
|||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8" />
|
||||||
<title><!-- TODO -->Change this you moron</title>
|
<title>Bingo Factory</title>
|
||||||
<link rel="stylesheet" href="style.css">
|
<link rel="stylesheet" href="style.css" />
|
||||||
<script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
|
<script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
|
||||||
<script type="text/javascript" src="main.js"></script>
|
<script type="text/javascript" src="main.js"></script>
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||||
<!-- card related -->
|
<!-- card related -->
|
||||||
<!--
|
<meta property="og:title" content="Bingo Factory" />
|
||||||
<meta name="twitter:card" content="summary_large_image">
|
<meta property="og:description" content="Make bingo grids quickly" />
|
||||||
<meta property="og:title" content="">
|
|
||||||
<meta property="twitter:title" content="">
|
|
||||||
<meta property="og:description" content="">
|
|
||||||
<meta property="twitter:description" content="">
|
|
||||||
<meta property="og:image" content="https://.../preview_640x320.jpg">
|
|
||||||
<meta property="twitter:image" content="">
|
|
||||||
<meta property="org:url" content="https://...">
|
|
||||||
-->
|
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<main id="app" style="display: none">
|
<main id="app" style="display: none">
|
||||||
<h1>{{title}}</h1>
|
<canvas width="400" height="400" ref="canvas"></canvas>
|
||||||
<br>
|
<br />
|
||||||
<p v-html="content"></p>
|
<small
|
||||||
<br>
|
><a href="https://github.com/clement-gouin" target="_blank"
|
||||||
<small><a href="https://twitter.com/_klemek" target="_blank">@Klemek</a> - <a href="" target="_blank">Github Repository</a> - {{currentYear}}</small>
|
>@clement-gouin</a
|
||||||
|
>
|
||||||
|
-
|
||||||
|
<a href="https://github.com/clement-gouin/bingo" target="_blank"
|
||||||
|
>Github Repository</a
|
||||||
|
>
|
||||||
|
- 2025</small
|
||||||
|
>
|
||||||
</main>
|
</main>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
@@ -1,20 +1,110 @@
|
|||||||
/* exported app */
|
/* exported app */
|
||||||
|
|
||||||
|
const utils = {
|
||||||
|
strokeGrid(ctx, x, y, w, h, cols, rows) {
|
||||||
|
ctx.beginPath();
|
||||||
|
for (let c = 0; c < cols + 1; c++) {
|
||||||
|
ctx.moveTo(Math.round(x + (w / cols) * c), y);
|
||||||
|
ctx.lineTo(Math.round(x + (w / cols) * c), y + h);
|
||||||
|
}
|
||||||
|
for (let r = 0; r < rows + 1; r++) {
|
||||||
|
ctx.moveTo(x, Math.round(y + (h / rows) * r));
|
||||||
|
ctx.lineTo(x + w, Math.round(y + (h / rows) * r));
|
||||||
|
}
|
||||||
|
ctx.stroke();
|
||||||
|
},
|
||||||
|
fitText(ctx, x, y, w, h, txt) {
|
||||||
|
ctx.textAlign = "center";
|
||||||
|
ctx.textBaseline = "top";
|
||||||
|
ctx.font = "bold 100px serif";
|
||||||
|
|
||||||
|
let totalSize = 0;
|
||||||
|
const spaceSize = ctx.measureText(" ").width;
|
||||||
|
|
||||||
|
const words = txt.split(" ").map((word) => {
|
||||||
|
const size = ctx.measureText(word).width;
|
||||||
|
if (totalSize > 0) {
|
||||||
|
totalSize += spaceSize;
|
||||||
|
}
|
||||||
|
totalSize += size;
|
||||||
|
return {
|
||||||
|
text: word,
|
||||||
|
size: size,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
const lines = words.map((word, i) => {
|
||||||
|
const targetLineCount = i + 1;
|
||||||
|
const targetSize = totalSize / targetLineCount;
|
||||||
|
let text = [];
|
||||||
|
let lineSize = 0;
|
||||||
|
let maxSize = 0;
|
||||||
|
let lineCount = 0;
|
||||||
|
words.forEach((word, j) => {
|
||||||
|
if (lineSize == 0 || lineSize + spaceSize + word.size > targetSize) {
|
||||||
|
lineCount += 1;
|
||||||
|
text.push(word.text);
|
||||||
|
lineSize = word.size;
|
||||||
|
} else {
|
||||||
|
text[text.length - 1] += " " + word.text;
|
||||||
|
lineSize += spaceSize + word.size;
|
||||||
|
}
|
||||||
|
maxSize = Math.max(maxSize, lineSize);
|
||||||
|
});
|
||||||
|
return {
|
||||||
|
lineCount: lineCount,
|
||||||
|
text: text,
|
||||||
|
width: maxSize,
|
||||||
|
height: 110 * text.length,
|
||||||
|
scale: 1 / Math.max(maxSize / w, (110 * text.length) / h),
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
lines.sort((w1, w2) => w2.scale - w1.scale);
|
||||||
|
|
||||||
|
const targetSplit = lines[0];
|
||||||
|
const targetFontSize = 100 * targetSplit.scale;
|
||||||
|
const targetLineHeight = targetFontSize * 1.1;
|
||||||
|
|
||||||
|
ctx.font = `bold ${targetFontSize}px serif`;
|
||||||
|
|
||||||
|
targetSplit.text.forEach((line, i) => {
|
||||||
|
ctx.fillText(
|
||||||
|
line,
|
||||||
|
x + w / 2,
|
||||||
|
y +
|
||||||
|
(h - targetSplit.height * targetSplit.scale) / 2 +
|
||||||
|
targetLineHeight * i +
|
||||||
|
(targetLineHeight - targetFontSize) / 2
|
||||||
|
);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
let app = {
|
let app = {
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {};
|
||||||
title: "Vue-Boilerplate",
|
|
||||||
content:
|
|
||||||
"Fill this page with <i>whatever</i> you're going to develop.<br><b>Then enjoy!</b>",
|
|
||||||
};
|
|
||||||
},
|
|
||||||
computed: {
|
|
||||||
currentYear() {
|
|
||||||
return new Date().getFullYear();
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
|
computed: {},
|
||||||
methods: {
|
methods: {
|
||||||
showApp() {
|
showApp() {
|
||||||
document.getElementById("app").setAttribute("style", "");
|
document.getElementById("app").setAttribute("style", "");
|
||||||
|
this.draw();
|
||||||
|
},
|
||||||
|
draw() {
|
||||||
|
const ctx = this.$refs.canvas?.getContext("2d");
|
||||||
|
if (!ctx) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
utils.strokeGrid(ctx, 2, 2, 398, 398, 5, 5);
|
||||||
|
utils.fitText(
|
||||||
|
ctx,
|
||||||
|
3,
|
||||||
|
3,
|
||||||
|
79,
|
||||||
|
79,
|
||||||
|
"This is a very long text, I hope this fits well"
|
||||||
|
);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
mounted: function () {
|
mounted: function () {
|
||||||
|
|||||||
Reference in New Issue
Block a user