Skip to content

Instantly share code, notes, and snippets.

@thacuber2a03
Created March 22, 2024 03:15
Show Gist options
  • Save thacuber2a03/8f1e60882b0ed4bb9e0eb16e82c96771 to your computer and use it in GitHub Desktop.
Save thacuber2a03/8f1e60882b0ed4bb9e0eb16e82c96771 to your computer and use it in GitHub Desktop.
--- striped animated interactive wallpaper
--- @thacuber2a03
local bg, fg -- set in _update
local spacing = 9 -- should hardcode?
local width, height = 480, 270
local position = 0
local velocity = 3
local maxVelocity = 0.2
local acceleration = -0.02
local _, lastMouseY = mouse()
function _update()
bg, fg = theme "desktop0", theme "desktop1"
position += velocity
if abs(velocity) > maxVelocity then
velocity += acceleration * sgn(velocity)
else
velocity = maxVelocity * sgn(velocity)
end
local _, mouseY = mouse()
local delta = mouseY - lastMouseY
if abs(delta) > 5 then velocity += delta / 100 end
lastMouseY = mouseY
end
function _draw()
cls(bg)
local i = 1
for x=0, width+spacing, spacing do
local invert = i % 4 < 2
rectfill(x-spacing/2+1, 0, x+spacing/2+1, height, invert and fg or bg)
for y=0, height+spacing, spacing do
local drawY = y+x*(spacing/2)+position
if not invert then drawY = height - drawY end
local percent = y/height
circfill(x, drawY%height, 1+sin(percent), invert and bg or fg)
end
i += 1
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment