aboutsummaryrefslogtreecommitdiff
path: root/src_frontend/Components/Editor/Simulation.svelte
diff options
context:
space:
mode:
authorJakob Stendahl <jakobste@uio.no>2021-10-21 19:28:20 +0200
committerJakob Stendahl <jakobste@uio.no>2021-10-21 19:28:20 +0200
commit6e53fd0dfd830d6d96206419c530c71fa4b3f4e6 (patch)
tree9034a4c9adf3a41c6eb492f2fe6ac06e434275dd /src_frontend/Components/Editor/Simulation.svelte
parentf243dc8d7527cde3d5b5a4f6e659cf7604f5ae2a (diff)
downloadLuxcena-Neo-6e53fd0dfd830d6d96206419c530c71fa4b3f4e6.tar.gz
Luxcena-Neo-6e53fd0dfd830d6d96206419c530c71fa4b3f4e6.zip
:sparkles: Add attempt at the "simulation"
Diffstat (limited to 'src_frontend/Components/Editor/Simulation.svelte')
-rw-r--r--src_frontend/Components/Editor/Simulation.svelte82
1 files changed, 82 insertions, 0 deletions
diff --git a/src_frontend/Components/Editor/Simulation.svelte b/src_frontend/Components/Editor/Simulation.svelte
new file mode 100644
index 0000000..aba5cdd
--- /dev/null
+++ b/src_frontend/Components/Editor/Simulation.svelte
@@ -0,0 +1,82 @@
+<script>
+ import { onMount } from "svelte";
+ import { authorizedSocket, authorizedSocketNeeded } from "../../stores/socketStore";
+ authorizedSocketNeeded.set(true);
+
+ let pixels = [];
+ let strip_buffer = [];
+
+ let gridTemplateColumns = "1fr";
+ let gridTemplateRows = "1fr";
+
+ function updateMatrix(matrix) {
+ if (matrix == null) { return; }
+ pixels = [];
+ let columnN = 0;
+ for (let y = 0; y < matrix.length; y++) {
+ if (matrix[y].length > columnN) {
+ columnN = matrix[y].length;
+ }
+ }
+
+ for (let y = 0; y < matrix.length; y++) {
+ for (let x = 0; x < matrix[y].length; x++) {
+ pixels.push(matrix[y][x]);
+ }
+ for (let x = 0; x < (columnN - matrix[y].length); x++) {
+ pixels.push(-1);
+ }
+ }
+ gridTemplateColumns = `repeat(${columnN}, 1fr)`;
+ gridTemplateRows = `repeat(${matrix.length}, 1fr)`;
+ pixels = pixels;
+ }
+
+ async function updateColors(colors) {
+ for (let i = 0; i+2 < colors.length; i+=3) {
+ try {
+ document.querySelector("#sim-pixel-"+(i/3)).style.setProperty("--color", `rgb(${colors[i]}, ${colors[i+1]}, ${colors[i+2]})`);
+ } catch(e) {}
+ }
+ }
+
+ authorizedSocket.on("matrix", updateMatrix);
+ authorizedSocket.on("strip_buffer", updateColors);
+
+ onMount(() => {
+ authorizedSocket.emit("matrix:get");
+ });
+
+</script>
+
+<style>
+ .matrix {
+ display: grid;
+ width: 100%;
+ gap: 10px 10px;
+ }
+ .pixel {
+ display: inline-block;
+ width: 100%;
+ height: 5px;
+ background-color: var(--color);
+ box-shadow: 0 0 10px var(--color);
+ }
+ p {
+ margin: 0;
+ margin-bottom: 5px;
+ font-size: 10px;
+ color: var(--grey-500);
+ }
+</style>
+
+<p>(still quite buggy, especially for very fast changing pixels, if nothing is happening, try to restart the script)</p>
+<div class="matrix" style="grid-template-columns: {gridTemplateColumns}; grid-template-rows: {gridTemplateRows};">
+ {#each pixels as pixel}
+ {#if pixel > -1}
+ <div id="sim-pixel-{pixel}" style="--color:rgb(255, 255, 255)" class="pixel"></div>
+ {:else}
+ <div style="--color:none" class="pixel"></div>
+ {/if}
+ {/each}
+</div> \ No newline at end of file