Skip to content

Instantly share code, notes, and snippets.

@Hypercubed
Created April 28, 2023 23:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Hypercubed/56494ad7dada033af61cc1c9c3d87776 to your computer and use it in GitHub Desktop.
Save Hypercubed/56494ad7dada033af61cc1c9c3d87776 to your computer and use it in GitHub Desktop.
// Name: Refresh Screen
import "@johnlindquist/kit"
await widget(`
<style>
body, html {
padding: 0 !important;
margin: 0 !important;
overflow: hidden;
}
</style>
<script>
console.log('refreshing screen');
// Create a canvas element that fills the entire window
const canvas = document.createElement('canvas');
const root = document.getElementById("__widget-container");
let width = canvas.width = window.innerWidth;
let height = canvas.height = window.innerHeight;
document.getElementById("__widget-container").appendChild(canvas);
// Get the canvas context and set the pixel size
const ctx = canvas.getContext('2d');
const pixelSize = 10;
// Draw random colored pixels
function drawPixels() {
if (width !== window.innerWidth || height !== window.innerHeight) {
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
}
// Loop through each pixel and fill it with a random color
const p = pixelSize;
for (let x = 0; x < canvas.width; x += p) {
for (let y = 0; y < canvas.height; y += p) {
let r = Math.floor(Math.random() * 256);
let g = Math.floor(Math.random() * 256);
let b = Math.floor(Math.random() * 256);
ctx.fillStyle = 'rgb(' + r + ',' + g + ',' + b + ')';
ctx.fillRect(x, y, p, p);
}
}
window.requestAnimationFrame(drawPixels);
}
drawPixels();
</script>
`, {
center: true,
resizable: true,
movable: true,
fullscreenable: true,
fullscreen: false,
draggable: true,
alwaysOnTop: true
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment