aboutsummaryrefslogtreecommitdiff
path: root/src_frontend/Components/Editor/Simulation.svelte
diff options
context:
space:
mode:
authorJakob Stendahl <jakob.stendahl@outlook.com>2022-04-28 20:06:38 +0200
committerJakob Stendahl <jakob.stendahl@outlook.com>2022-04-28 20:08:55 +0200
commit916ab40d65c9c25f63256f2cd98be297c3da2208 (patch)
treedcf07544310fd34f79e72f34ef0e653f30a163f0 /src_frontend/Components/Editor/Simulation.svelte
parent4ee57ab935718a269fe7ab65b26ff27837d49003 (diff)
downloadLuxcena-Neo-916ab40d65c9c25f63256f2cd98be297c3da2208.tar.gz
Luxcena-Neo-916ab40d65c9c25f63256f2cd98be297c3da2208.zip
:bug: Small bugfixes
Diffstat (limited to 'src_frontend/Components/Editor/Simulation.svelte')
-rw-r--r--src_frontend/Components/Editor/Simulation.svelte27
1 files changed, 21 insertions, 6 deletions
diff --git a/src_frontend/Components/Editor/Simulation.svelte b/src_frontend/Components/Editor/Simulation.svelte
index abe202c..86cc66c 100644
--- a/src_frontend/Components/Editor/Simulation.svelte
+++ b/src_frontend/Components/Editor/Simulation.svelte
@@ -5,6 +5,7 @@
let svg;
let pixels = [];
+ let pixelBuffer = [];
function updateMatrix(matrix) {
if (matrix == null) { return; }
@@ -24,12 +25,26 @@
}
async function updateColors(colors) {
- for (let i = 0; i+2 < colors.length; i+=3) {
- try {
- document.querySelector("#sim-pixel-"+(i/3)).style.setProperty("fill", `rgb(${colors[i]}, ${colors[i+1]}, ${colors[i+2]})`);
- } catch(e) {}
- }
+ pixelBuffer = colors;
+ }
+
+ async function flushPixelBuffer() {
+ //console.log(pixelBuffer);
+ window.requestAnimationFrame((ts) => {
+ for (let i = 0; i+2 < pixelBuffer.length; i+=3) {
+ try {
+ document.querySelector("#sim-pixel-"+(i/3))
+ .style
+ .setProperty(
+ "fill",
+ `rgb(${pixelBuffer[i]}, ${pixelBuffer[i+1]}, ${pixelBuffer[i+2]})`);
+ } catch(e) {
+ console.log(e);
+ }
+ }
+ });
}
+ setInterval(flushPixelBuffer, 50);
onMount(() => {
authorizedSocket.on("matrix", updateMatrix);
@@ -58,4 +73,4 @@
<rect id="sim-pixel-{pixel.n}" x="{pixel.x*2+1}" y="{pixel.y*2+1}" width="1" height="1" style="fill:rgb(0,0,0);filter:blur(0.2px);" />
{/each}
</svg>
-</div> \ No newline at end of file
+</div>