|
| 1 | +/* |
| 2 | +Hi, if you're reading this, this isn't my code. |
| 3 | +I personally use this as my Windows machine's wallpaper because it's so clean. |
| 4 | +Please check it out! https://benjamin.halko.ca/win11-circles/ (https://github.com/BenjaminHalko/win11-circles) |
| 5 | +All comments that they've left are not removed, incase you want to experiment with it :) |
| 6 | +If you wanna know what the lively wallpaper stuff in the code is about: |
| 7 | +This was designed by the creator for a live wallpaper software called Lively Wallpaper! |
| 8 | +
|
| 9 | +Just an FYI tho: |
| 10 | +Stuff I've changed are marked as [ME]. |
| 11 | +Most changes are to make the background more colorful and fit the entire page instead of the viewable area only. |
| 12 | +*/ |
| 13 | + |
| 14 | +// Variables |
| 15 | +var numCircles = 12; // [ME] Original value was 8 |
| 16 | + |
| 17 | +var minHue = 10; // [ME] Original value is 190 |
| 18 | +var maxHue = 40; // [ME] Original value is 285 |
| 19 | + |
| 20 | +var spd = 0.1; // [ME] Original value was 0.05 |
| 21 | + |
| 22 | +var startRadius = 100; // [ME] Original value was 200 |
| 23 | +var endRadius = 500; |
| 24 | + |
| 25 | +// Setup the canvas |
| 26 | +document.body.style.background = "black"; |
| 27 | +document.body.innerHTML = `<canvas id='canvas' style='position:absolute;left:0;top:0;z-index:-1'></canvas>` + document.body.innerHTML; // [ME] Changed position to absolute |
| 28 | +const canvas = document.getElementById("canvas"); |
| 29 | +const ctx = canvas.getContext("2d"); |
| 30 | + |
| 31 | +// Used for animation |
| 32 | +var lastTime = 0; |
| 33 | +var circles = []; |
| 34 | + |
| 35 | +// Functions |
| 36 | +function createCircles() { |
| 37 | + circles = []; |
| 38 | + for (var i = 0; i < numCircles; i++) { |
| 39 | + var colRand = Math.random(); |
| 40 | + circles.push({ |
| 41 | + x: Math.round(Math.random() * document.documentElement.scrollWidth), // [ME] Changed to document.documentElement.scrollWidth |
| 42 | + y: Math.round(Math.random() * document.documentElement.scrollHeight), // [ME] Changed to document.documentElement.scrollHeight |
| 43 | + r: i / numCircles, |
| 44 | + colorRand: colRand, |
| 45 | + color: minHue + Math.round(colRand * (maxHue - minHue)) |
| 46 | + }); |
| 47 | + } |
| 48 | +} |
| 49 | + |
| 50 | +function recolor() { |
| 51 | + const tempMaxHue = minHue > maxHue ? maxHue + 360 : maxHue; |
| 52 | + for (let i = 0; i < circles.length; i++) { |
| 53 | + circles[i].color = minHue + Math.round(circles[i].colorRand * (tempMaxHue - minHue)); |
| 54 | + } |
| 55 | +} |
| 56 | + |
| 57 | +function animate(timeStamp) { |
| 58 | + // Resize the canvas |
| 59 | + canvas.width = document.documentElement.scrollWidth; // [ME] Changed to document.documentElement.scrollWidth |
| 60 | + canvas.height = document.documentElement.scrollHeight; // [ME] Changed to document.documentElement.scrollHeight |
| 61 | + |
| 62 | + // Calculate the elapsed time since the last frame |
| 63 | + let elapsedTime = timeStamp - lastTime; |
| 64 | + lastTime = timeStamp; |
| 65 | + |
| 66 | + // If the elapsed time is too large, reset it |
| 67 | + if (elapsedTime > 500) elapsedTime = 1; |
| 68 | + |
| 69 | + // Clear the canvas |
| 70 | + ctx.clearRect(0, 0, canvas.width, canvas.height); // [ME] Changed to canvas.width and canvas.height |
| 71 | + |
| 72 | + for (let i = 0; i < circles.length; i++) { |
| 73 | + // Scale the animation value based on elapsed time |
| 74 | + circles[i].r += spd * (elapsedTime / 1000); |
| 75 | + |
| 76 | + if (circles[i].r >= 1) { |
| 77 | + circles[i].r = circles[i].r % 1; |
| 78 | + circles[i].x = Math.round(Math.random() * document.documentElement.scrollWidth); // [ME] Changed to document.documentElement.scrollWidth |
| 79 | + circles[i].y = Math.round(Math.random() * document.documentElement.scrollHeight); // [ME] Changed to document.documentElement.scrollHeight |
| 80 | + circles[i].colorRand = Math.random(); |
| 81 | + circles[i].color = minHue + Math.round(circles[i].colorRand * (maxHue - minHue)); |
| 82 | + } |
| 83 | + |
| 84 | + // Calculate the circle's radius |
| 85 | + const radius = startRadius + Math.sin(circles[i].r * Math.PI) * (endRadius - startRadius); |
| 86 | + |
| 87 | + // Set the fill style to a radial gradient |
| 88 | + ctx.fillStyle = ctx.createRadialGradient(circles[i].x, circles[i].y, 0, circles[i].x, circles[i].y, radius); |
| 89 | + ctx.fillStyle.addColorStop(0, `hsla(${circles[i].color}, 100%, 15%, ${Math.round(Math.min(100, (1 - Math.abs(1 - circles[i].r * 2)) * 140))}%)`); |
| 90 | + ctx.fillStyle.addColorStop(1, 'hsla(' + circles[i].color + ', 100%, 15%, 0)'); |
| 91 | + |
| 92 | + // Create the circle path and fill it |
| 93 | + ctx.beginPath(); |
| 94 | + ctx.arc(circles[i].x, circles[i].y, radius, 0, 2 * Math.PI); |
| 95 | + ctx.fill(); |
| 96 | + } |
| 97 | + |
| 98 | + requestAnimationFrame(animate); |
| 99 | +} |
| 100 | + |
| 101 | +// Main |
| 102 | +createCircles(); |
| 103 | +requestAnimationFrame(animate); |
| 104 | + |
| 105 | +// Lively Wallpaper |
| 106 | +function livelyPropertyListener(name, val) { |
| 107 | + switch(name) { |
| 108 | + case "numCircles": |
| 109 | + numCircles = val; |
| 110 | + createCircles(); |
| 111 | + break; |
| 112 | + case "minHue": |
| 113 | + minHue = val; |
| 114 | + recolor(); |
| 115 | + break; |
| 116 | + case "maxHue": |
| 117 | + maxHue = val; |
| 118 | + recolor(); |
| 119 | + break; |
| 120 | + case "spd": |
| 121 | + spd = val / 200; |
| 122 | + break; |
| 123 | + case "startRadius": |
| 124 | + startRadius = val; |
| 125 | + break; |
| 126 | + case "endRadius": |
| 127 | + endRadius = val; |
| 128 | + break; |
| 129 | + } |
| 130 | +} |
0 commit comments