Skip to content

Commit 5be07f2

Browse files
Add light-colored theme
1 parent 6c768ac commit 5be07f2

5 files changed

Lines changed: 457 additions & 70 deletions

File tree

public/app.mjs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,27 @@ function resizeCanvas(config) {
475475
canvas.height = config.hauteur * cell;
476476
}
477477

478+
function canvasBackgroundFor(configuration) {
479+
const cssBackground = getComputedStyle(document.documentElement).getPropertyValue("--bg").trim();
480+
const theme = document.documentElement.dataset.theme || "dark";
481+
const configuredBackground = configuration.rendu.fond;
482+
if (!configuredBackground) return cssBackground || "#05070d";
483+
if (theme === "light") {
484+
const darkPresetBackgrounds = new Set([
485+
"#020b12",
486+
"#04080a",
487+
"#05070d",
488+
"#06050a",
489+
"#07110a",
490+
"#07111a",
491+
]);
492+
if (darkPresetBackgrounds.has(String(configuredBackground).toLowerCase())) {
493+
return cssBackground || "#ffffff";
494+
}
495+
}
496+
return configuredBackground;
497+
}
498+
478499
function render() {
479500
if (!state.universe) return;
480501
const { configuration, lignes, sorties } = state.universe;
@@ -483,7 +504,7 @@ function render() {
483504
featureModules.perturb.onConfigApplied(configuration);
484505
}
485506
const cell = Number(configuration.rendu.taille_cellule || 5);
486-
ctx.fillStyle = configuration.rendu.fond || "#05070d";
507+
ctx.fillStyle = canvasBackgroundFor(configuration);
487508
ctx.fillRect(0, 0, canvas.width, canvas.height);
488509
const gridHeight = lignes.length;
489510
const gridWidth = lignes.length > 0 ? lignes[0].length : 1;

public/apropos.html

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@
77
<title>À propos — Automaginarium</title>
88
<meta name="description"
99
content="Découvrez Automaginarium, un laboratoire configurable d'automates cellulaires en Multilingual français." />
10+
<script>
11+
(() => {
12+
const storedTheme = localStorage.getItem("automaginarium-theme");
13+
const theme = storedTheme || (matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light");
14+
document.documentElement.dataset.theme = theme;
15+
document.documentElement.style.colorScheme = theme;
16+
})();
17+
</script>
1018
<link rel="stylesheet" href="style.css" />
1119
<style>
1220
body {
@@ -86,7 +94,7 @@
8694

8795
.tech-card {
8896
padding: 20px;
89-
background: rgba(var(--panel), 0.5);
97+
background: rgb(var(--panel-rgb) / 0.5);
9098
border: 1px solid var(--line);
9199
border-radius: 8px;
92100
-webkit-backdrop-filter: blur(10px);
@@ -145,7 +153,7 @@
145153
.attribution {
146154
margin-top: 48px;
147155
padding: 24px;
148-
background: rgba(var(--panel), 0.3);
156+
background: rgb(var(--panel-rgb) / 0.3);
149157
border-left: 3px solid var(--accent);
150158
border-radius: 4px;
151159
font-size: 0.9rem;
@@ -161,6 +169,7 @@
161169
<h1 id="app-title">Automaginarium</h1>
162170
</div>
163171
<nav class="header-links">
172+
<button type="button" class="ghost-btn theme-toggle" data-theme-toggle>Mode sombre</button>
164173
<a href="index.html" title="Retour à l'application">Application</a>
165174
<a href="https://github.com/multilingualprogramming/Automaginarium" title="GitHub" target="_blank"
166175
rel="noopener noreferrer">GitHub</a>
@@ -296,6 +305,8 @@ <h2>Documentation</h2>
296305
<a href="index.html">Retour à l'Application</a>
297306
</div>
298307
</main>
308+
<script src="theme.js"></script>
299309
</body>
300310

301-
</html>
311+
</html>
312+

public/index.html

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@
88
name="description"
99
content="Laboratoire configurable d'automates cellulaires en Multilingual fran&ccedil;ais."
1010
/>
11+
<script>
12+
(() => {
13+
const storedTheme = localStorage.getItem("automaginarium-theme");
14+
const theme = storedTheme || (matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light");
15+
document.documentElement.dataset.theme = theme;
16+
document.documentElement.style.colorScheme = theme;
17+
})();
18+
</script>
1119
<link rel="stylesheet" href="style.css" />
1220
</head>
1321
<body>
@@ -21,6 +29,7 @@ <h1 id="app-title">Automaginarium</h1>
2129
<span id="hero-status-text">Synchronisation live</span>
2230
</div>
2331
<nav class="header-links">
32+
<button type="button" class="ghost-btn theme-toggle" data-theme-toggle>Mode sombre</button>
2433
<a href="apropos.html" title="À propos">À propos</a>
2534
<a href="https://github.com/multilingualprogramming/Automaginarium" title="GitHub" target="_blank" rel="noopener noreferrer">GitHub</a>
2635
</nav>
@@ -434,6 +443,7 @@ <h2 id="gallery-title">Univers remarquables</h2>
434443
</section>
435444
</main>
436445

446+
<script src="theme.js"></script>
437447
<script src="automate-core.js"></script>
438448
<script type="module" src="app.mjs"></script>
439449
</body>

0 commit comments

Comments
 (0)