From ec9a0927516b0a6457fca53fea5a901285556aa8 Mon Sep 17 00:00:00 2001 From: Henrik Date: Sat, 21 Jan 2023 12:10:22 +0100 Subject: [PATCH] - Removed unused code - Changed rendering of large preview image --- wled00/data/pixart/boxdraw.js | 37 +++++++---------------------------- 1 file changed, 7 insertions(+), 30 deletions(-) diff --git a/wled00/data/pixart/boxdraw.js b/wled00/data/pixart/boxdraw.js index 9257caee4..f8366bc74 100644 --- a/wled00/data/pixart/boxdraw.js +++ b/wled00/data/pixart/boxdraw.js @@ -17,6 +17,8 @@ function drawBoxes(inputPixelArray, widthPixels, heightPixels) { let pixelSize = Math.floor(canvas.width/widthPixels); + let xOffset = (window.innerWidth - (widthPixels * pixelSize))/2 + //Set the canvas height to fit the right number of pixelrows canvas.height = (pixelSize * heightPixels) + 10 @@ -57,35 +59,10 @@ function drawBoxes(inputPixelArray, widthPixels, heightPixels) { ctx.fillText((pos + 1), (x * pixelSize) + (pixelSize /2), (y * pixelSize) + (pixelSize /2)); } } + var imageData = ctx.getImageData(0, 0, canvas.width, canvas.height); + ctx.clearRect(0, 0, canvas.width, canvas.height); + canvas.width = window.innerWidth; + ctx.putImageData(imageData, xOffset, 0); + console.log(xOffset); } -function drawBackground() { - const grid = cE("div"); - grid.id = "grid"; - grid.classList.add("grid-class"); - grid.style.cssText = ""; - - const boxSize = 20; - const boxCount = Math.ceil(window.innerWidth / boxSize) * Math.ceil(window.innerHeight / boxSize);; - - for (let i = 0; i < boxCount; i++) { - const box = cE("div"); - box.classList.add("box"); - box.style.backgroundColor = getRandomColor(); - grid.appendChild(box); - } - grid.style.zIndex = -1; - d.body.appendChild(grid); -} - -function getRandomColor() { - const letters = "0123456789ABCDEF"; - let color = "rgba("; - for (let i = 0; i < 3; i++) { - color += Math.floor(Math.random() * 256) + ","; - } - color += "0.05)"; - return color; -} - -window.drawBackground = drawBackground;