Fix wallpapers

This commit is contained in:
Smok1e 2024-06-23 06:28:23 +03:00
parent ec55f179f4
commit 318c96d948
3 changed files with 33 additions and 10 deletions

View File

@ -36,8 +36,8 @@ local function reset()
local resX, resY = screen.getResolution() local resX, resY = screen.getResolution()
for i = 1, config.lineCount do for i = 1, config.lineCount do
table.insert(points, { table.insert(points, {
x = math.random(0, resX - 1), x = math.random(0, wallpaper.width - 1),
y = math.random(0, (resY - 1) * 2), y = math.random(0, (wallpaper.height - 1) * 2),
vx = (2 * math.random() - 1) * 25, vx = (2 * math.random() - 1) * 25,
vy = (2 * math.random() - 1) * 25 vy = (2 * math.random() - 1) * 25
}) })

View File

@ -15,7 +15,8 @@ local config = {
snowflakeColor = 0xFFFFFF, snowflakeColor = 0xFFFFFF,
snowflakeAmount = 20, snowflakeAmount = 20,
maxStackHeight = 10, maxStackHeight = 10,
maxWind = 2 maxWind = 2,
speed = 1
} }
if filesystem.exists(configPath) then if filesystem.exists(configPath) then
@ -82,7 +83,7 @@ wallpaper.draw = function(wallpaper)
screenSemiPixelSet( screenSemiPixelSet(
mathFloor( wallpaper.x + snowflake.x), mathFloor( wallpaper.x + snowflake.x),
mathFloor(wallpaper.y + snowflake.y), mathFloor(2 * wallpaper.y + snowflake.y),
snowflake.color snowflake.color
) )
end end
@ -91,7 +92,7 @@ wallpaper.draw = function(wallpaper)
local stackHeight local stackHeight
for x, stackHeight in pairs(stacks) do for x, stackHeight in pairs(stacks) do
screenDrawSemiPixelRectangle(wallpaper.x + x, wallpaper.y + wallpaper.height * 2 - stackHeight + 1, 1, stackHeight, config.snowflakeColor) screenDrawSemiPixelRectangle(wallpaper.x + x, 2 * (wallpaper.y + wallpaper.height) - stackHeight - 1, 1, stackHeight, config.snowflakeColor)
if stackHeight > config.maxStackHeight then if stackHeight > config.maxStackHeight then
stacks[x] = stackHeight - 2 stacks[x] = stackHeight - 2
@ -102,7 +103,7 @@ wallpaper.draw = function(wallpaper)
local currentTime = computer.uptime() local currentTime = computer.uptime()
local deltaTime = (currentTime - lastUpdateTime) * 20 local deltaTime = (currentTime - lastUpdateTime) * 20
wind = wind + .1 * (2 * mathRandom() - 1) * deltaTime wind = wind + .1 * (2 * mathRandom() - 1) * deltaTime * config.speed
if wind > config.maxWind then wind = config.maxWind end if wind > config.maxWind then wind = config.maxWind end
if wind < -config.maxWind then wind = -config.maxWind end if wind < -config.maxWind then wind = -config.maxWind end
@ -113,8 +114,8 @@ wallpaper.draw = function(wallpaper)
while i <= #snowflakes do while i <= #snowflakes do
snowflake = snowflakes[i] snowflake = snowflakes[i]
snowflake.y = snowflake.y + deltaTime * snowflake.speed snowflake.y = snowflake.y + deltaTime * config.speed * snowflake.speed
snowflake.x = snowflake.x + deltaTime * (wind * snowflake.speed + snowflake.vx) snowflake.x = snowflake.x + deltaTime * config.speed * (wind * snowflake.speed + snowflake.vx)
snowflake.vx = snowflake.vx + (mathRandom() * 2 - 1) * 0.1 * deltaTime snowflake.vx = snowflake.vx + (mathRandom() * 2 - 1) * 0.1 * deltaTime
@ -215,4 +216,26 @@ wallpaper.configure = function(layout)
config.maxStackHeight = math.floor(maxStackHeightSlider.value) config.maxStackHeight = math.floor(maxStackHeightSlider.value)
saveConfig() saveConfig()
end end
local speedSlider = layout:addChild(
GUI.slider(
1, 1,
36,
0x66DB80,
0xE1E1E1,
0xFFFFFF,
0xA5A5A5,
20, 1000,
config.speed * 100,
false,
"Speed: ",
"%"
)
)
speedSlider.roundValues = true
speedSlider.onValueChanged = function()
config.speed = speedSlider.value / 100
saveConfig()
end
end end

View File

@ -121,7 +121,7 @@ wallpaper.draw = function(wallpaper)
local t = config.speed * (computer.uptime() - startTime) / 10 local t = config.speed * (computer.uptime() - startTime) / 10
local lightPos = {lightSpinRadius * math.cos(t), lightSpinRadius * 0.5 * math.cos(t), lightSpinRadius * math.sin(t)} local lightPos = {lightSpinRadius * math.cos(t), lightSpinRadius * 0.5 * math.cos(t), lightSpinRadius * math.sin(t)}
local cx, cy = math.floor(wallpaper.width / 2), wallpaper.height local cx, cy = wallpaper.x + math.floor(wallpaper.width / 2), 2 * wallpaper.y + wallpaper.height
screen.drawRectangle(wallpaper.x, wallpaper.y, wallpaper.width, wallpaper.height, config.backgroundColor, 0, " ") screen.drawRectangle(wallpaper.x, wallpaper.y, wallpaper.width, wallpaper.height, config.backgroundColor, 0, " ")