Wallpapers rework is finished

This commit is contained in:
IgorTimofeev 2024-01-30 03:00:35 +03:00
parent 51b5ebb6c2
commit 96d2748ace
8 changed files with 519 additions and 521 deletions

View File

@ -17,9 +17,10 @@ local function configure()
end
-- Add new controls if needed
if system.wallpaper and system.wallpaper.configure then
local wallpaper = system.getWallpaper()
if wallpaper.configure then
configureFrom = #window.contentLayout.children + 1
system.wallpaper.configure(window.contentLayout)
wallpaper.configure(window.contentLayout)
configureTo = #window.contentLayout.children
end
end

View File

@ -35,9 +35,7 @@ local dockContainer
local desktopMenu
local desktopMenuLayout
local desktopIconField
local desktopBackground
local desktopBackgroundWallpaperX
local desktopBackgroundWallpaperY
local wallpaper
-- Caching commonly used icons
local iconCache = {
@ -485,7 +483,7 @@ function system.addSetAsWallpaperMenuItem(menu, path)
system.updateWallpaper()
end
system.wallpaper.setPicture(path)
wallpaper.setPicture(path)
workspace:draw()
system.saveUserSettings()
@ -2414,43 +2412,45 @@ function system.execute(path, ...)
return success, errorPath, line, traceback
end
local function desktopBackgroundAmbientDraw()
screen.drawRectangle(1, desktopBackground.y, desktopBackground.width, desktopBackground.height, 0x1E1E1E, 0, " ")
local function wallpaperDraw()
screen.drawRectangle(1, wallpaper.y, wallpaper.width, wallpaper.height, 0x1E1E1E, 0, " ")
end
function system.getWallpaper()
return wallpaper
end
function system.updateWallpaper()
desktopBackground.draw = desktopBackgroundAmbientDraw
local function reset()
wallpaper.draw = wallpaperDraw
wallpaper.eventHandler = nil
wallpaper.configure = nil
end
local function alert(...)
GUI.alert(...)
reset()
end
interfaceDrawInterval = 1
reset()
if not userSettings.interfaceWallpaperPath then
return
end
local executable, reason = loadfile(userSettings.interfaceWallpaperPath .. "Main.lua")
if not executable then
GUI.alert(reason)
local result, reason = loadfile(userSettings.interfaceWallpaperPath .. "Main.lua")
if not result then
alert(reason)
return
end
local success, wallpaperOrError = xpcall(executable, debug.traceback)
if not success then
GUI.alert(wallpaperOrError)
result, reason = xpcall(result, debug.traceback, workspace, wallpaper)
if not result then
alert()
return
end
if type(wallpaperOrError) ~= "table" then
GUI.alert("Wallpaper script didn't return table")
return
elseif type(wallpaperOrError.draw) ~= "function" then
GUI.alert("Wallpaper does not contain proper draw function")
return
end
desktopBackground.draw = wallpaperOrError.draw
desktopBackground.eventHandler = wallpaperOrError.eventHandler
system.wallpaper = wallpaperOrError
interfaceDrawInterval = 0.01
end
@ -2475,7 +2475,7 @@ function system.updateResolution()
desktopMenu.width = workspace.width
desktopMenuLayout.width = workspace.width
desktopBackground.localY, desktopBackground.width, desktopBackground.height = 2, workspace.width, workspace.height - 1
wallpaper.localY, wallpaper.width, wallpaper.height = 2, workspace.width, workspace.height - 1
desktopWindowsContainer.width, desktopWindowsContainer.height = workspace.width, workspace.height - 1
@ -2963,11 +2963,12 @@ function system.updateWorkspace()
workspace.ignoresCapturedObject = true
-- Creating desktop background object
desktopBackground = workspace:addChild(GUI.object(1, 1, workspace.width, workspace.height))
desktopBackground.ignoresCapturedObject = true
wallpaper = workspace:addChild(GUI.object(1, 1, workspace.width, workspace.height))
-- wallpaper.ignoresCapturedObject = true
wallpaper.blockScreenEvents = false
local oldDraw = desktopBackground and desktopBackground.draw
desktopBackground.draw = oldDraw or desktopBackgroundAmbientDraw
local oldDraw = wallpaper and wallpaper.draw
wallpaper.draw = oldDraw or wallpaperDraw
end
function system.createUser(name, language, password, wallpaper)
@ -3038,7 +3039,7 @@ function system.authorize()
local container = workspace:addChild(GUI.container(1, 1, workspace.width, workspace.height))
-- If we've loaded wallpaper(from user logout or above) then add a panel to make it darker
if desktopBackground.draw ~= desktopBackgroundAmbientDraw then
if wallpaper.draw ~= wallpaperDraw then
container:addChild(GUI.panel(1, 1, container.width, container.height, 0x0, 0.5))
end

View File

@ -5,6 +5,8 @@ local GUI = require("GUI")
--------------------------------------------------------------------------------
local workspace, wallpaper = select(1, ...), select(2, ...)
local configPath = filesystem.path(system.getCurrentScript()) .. "Config.cfg"
local config = {
@ -46,75 +48,71 @@ end
reset(object)
--------------------------------------------------------------------------------
wallpaper.draw = function(object)
screen.drawRectangle(object.x, object.y, object.width, object.height, config.backgroundColor, 0, " ")
return {
draw = function(object)
screen.drawRectangle(object.x, object.y, object.width, object.height, config.backgroundColor, 0, " ")
local point1, point2
local point1, point2
for i = 1, config.lineCount - 1 do
point1, point2 = points[i], points[i + 1]
for i = 1, config.lineCount - 1 do
point1, point2 = points[i], points[i + 1]
screen.drawSemiPixelLine(
math.floor(object.x + point1.x),
math.floor(object.y * 2 - 1 + point1.y),
screen.drawSemiPixelLine(
math.floor(object.x + point1.x),
math.floor(object.y * 2 - 1 + point1.y),
math.floor(object.x + point2.x),
math.floor(object.y * 2 - 1 + point2.y),
math.floor(object.x + point2.x),
math.floor(object.y * 2 - 1 + point2.y),
config.lineColor
)
end
local uptime = computer.uptime()
local deltaTime = uptime - lastUptime
lastUptime = uptime
for i = 1, config.lineCount do
point1 = points[i]
point1.x = point1.x + point1.vx * deltaTime
point1.y = point1.y + point1.vy * deltaTime
if point1.x < 0 or point1.x >= object.width then point1.vx = -point1.vx end
if point1.y < 0 or point1.y >= object.height * 2 then point1.vy = -point1.vy end
end
end,
configure = function(layout)
layout:addChild(GUI.colorSelector(1, 1, 36, 3, config.backgroundColor, "Background color")).onColorSelected = function(_, object)
config.backgroundColor = object.color
saveConfig()
end
layout:addChild(GUI.colorSelector(1, 1, 36, 3, config.lineColor, "Line color")).onColorSelected = function(_, object)
config.lineColor = object.color
saveConfig()
end
local slider = layout:addChild(
GUI.slider(
1, 1,
36,
0x66DB80,
0xE1E1E1,
0xFFFFFF,
0xA5A5A5,
1, 10,
config.lineCount,
false,
"Line count: "
)
config.lineColor
)
slider.roundValues = true
slider.onValueChanged = function(workspace, object)
config.lineCount = math.floor(object.value)
saveConfig()
reset()
end
end
}
local uptime = computer.uptime()
local deltaTime = uptime - lastUptime
lastUptime = uptime
for i = 1, config.lineCount do
point1 = points[i]
point1.x = point1.x + point1.vx * deltaTime
point1.y = point1.y + point1.vy * deltaTime
if point1.x < 0 or point1.x >= object.width then point1.vx = -point1.vx end
if point1.y < 0 or point1.y >= object.height * 2 then point1.vy = -point1.vy end
end
end
wallpaper.configure = function(layout)
layout:addChild(GUI.colorSelector(1, 1, 36, 3, config.backgroundColor, "Background color")).onColorSelected = function(_, object)
config.backgroundColor = object.color
saveConfig()
end
layout:addChild(GUI.colorSelector(1, 1, 36, 3, config.lineColor, "Line color")).onColorSelected = function(_, object)
config.lineColor = object.color
saveConfig()
end
local slider = layout:addChild(
GUI.slider(
1, 1,
36,
0x66DB80,
0xE1E1E1,
0xFFFFFF,
0xA5A5A5,
1, 10,
config.lineCount,
false,
"Line count: "
)
)
slider.roundValues = true
slider.onValueChanged = function(workspace, object)
config.lineCount = math.floor(object.value)
saveConfig()
reset()
end
end

View File

@ -6,6 +6,8 @@ local GUI = require("GUI")
--------------------------------------------------------------------------------
local workspace, wallpaper = select(1, ...), select(2, ...)
local configPath = filesystem.path(system.getCurrentScript()) .. "Config.cfg"
local config = {
@ -30,121 +32,119 @@ end
local drops = {}
local lastUpdateTime = computer.uptime()
return {
draw = function(wallpaper)
-- Spawning drops
local distance
wallpaper.draw = function(wallpaper)
-- Spawning drops
local distance
for i = 1, config.dropAmount - #drops do
distance = math.random()
for i = 1, config.dropAmount - #drops do
distance = math.random()
table.insert(drops, {
x = math.random(wallpaper.width) - 1,
y = 0,
speed = 50 - 40 * distance,
color = color.transition(config.dropColor, config.backgroundColor, 0.2 + 0.8 * distance)
})
end
table.insert(drops, {
x = math.random(wallpaper.width) - 1,
y = 0,
speed = 50 - 40 * distance,
color = color.transition(config.dropColor, config.backgroundColor, 0.2 + 0.8 * distance)
})
end
-- Clear the area
screen.drawRectangle(wallpaper.x, wallpaper.y, wallpaper.width, wallpaper.height, config.backgroundColor, 0, " ")
-- Clear the area
screen.drawRectangle(wallpaper.x, wallpaper.y, wallpaper.width, wallpaper.height, config.backgroundColor, 0, " ")
-- Rendering drops
local drop, x, y
-- Rendering drops
local drop, x, y
for i = 1, #drops do
drop = drops[i]
for i = 1, #drops do
drop = drops[i]
x, y = math.floor(drop.x), math.floor(drop.y)
x, y = math.floor(drop.x), math.floor(drop.y)
screen.set(
wallpaper.x + x,
wallpaper.y + y,
config.backgroundColor,
drop.color,
(x == wallpaper.width - 1 or y == wallpaper.height - 1) and '*' or '\\'
)
end
-- Updating drops
local updateTime = computer.uptime()
local deltaTime = updateTime - lastUpdateTime
local i = 1
while i <= #drops do
drop = drops[i]
drop.x = drop.x + drop.speed * config.speed * deltaTime
drop.y = drop.y + drop.speed * config.speed * deltaTime
if drop.x < 0 then
drop.x = wallpaper.width - drop.x
elseif drop.x >= wallpaper.width then
drop.x = wallpaper.width - drop.x
end
if drop.y >= wallpaper.height then
table.remove(drops, i)
else
i = i + 1
end
end
lastUpdateTime = updateTime
end,
configure = function(layout)
layout:addChild(GUI.colorSelector(1, 1, 36, 3, config.backgroundColor, "Background color")).onColorSelected = function(_, object)
config.backgroundColor = object.color
saveConfig()
end
layout:addChild(GUI.colorSelector(1, 1, 36, 3, config.dropColor, "Drop color")).onColorSelected = function(_, object)
config.dropColor = object.color
saveConfig()
end
local dropAmountSlider = layout:addChild(
GUI.slider(
1, 1,
36,
0x66DB80,
0xE1E1E1,
0xFFFFFF,
0xA5A5A5,
10, 500,
config.dropAmount,
false,
"Drop amount: "
)
screen.set(
wallpaper.x + x,
wallpaper.y + y,
config.backgroundColor,
drop.color,
(x == wallpaper.width - 1 or y == wallpaper.height - 1) and '*' or '\\'
)
end
dropAmountSlider.roundValues = true
dropAmountSlider.onValueChanged = function()
config.dropAmount = math.floor(dropAmountSlider.value)
saveConfig()
-- Updating drops
local updateTime = computer.uptime()
local deltaTime = updateTime - lastUpdateTime
local i = 1
while i <= #drops do
drop = drops[i]
drop.x = drop.x + drop.speed * config.speed * deltaTime
drop.y = drop.y + drop.speed * config.speed * deltaTime
if drop.x < 0 then
drop.x = wallpaper.width - drop.x
elseif drop.x >= wallpaper.width then
drop.x = wallpaper.width - drop.x
end
local speedSlider = layout:addChild(
GUI.slider(
1, 1,
36,
0x66DB80,
0xE1E1E1,
0xFFFFFF,
0xA5A5A5,
20, 200,
config.speed * 100,
false,
"Speed: ",
"%"
)
)
speedSlider.roundValues = true
speedSlider.onValueChanged = function()
config.speed = speedSlider.value / 100
saveConfig()
if drop.y >= wallpaper.height then
table.remove(drops, i)
else
i = i + 1
end
end
}
lastUpdateTime = updateTime
end
wallpaper.configure = function(layout)
layout:addChild(GUI.colorSelector(1, 1, 36, 3, config.backgroundColor, "Background color")).onColorSelected = function(_, object)
config.backgroundColor = object.color
saveConfig()
end
layout:addChild(GUI.colorSelector(1, 1, 36, 3, config.dropColor, "Drop color")).onColorSelected = function(_, object)
config.dropColor = object.color
saveConfig()
end
local dropAmountSlider = layout:addChild(
GUI.slider(
1, 1,
36,
0x66DB80,
0xE1E1E1,
0xFFFFFF,
0xA5A5A5,
10, 500,
config.dropAmount,
false,
"Drop amount: "
)
)
dropAmountSlider.roundValues = true
dropAmountSlider.onValueChanged = function()
config.dropAmount = math.floor(dropAmountSlider.value)
saveConfig()
end
local speedSlider = layout:addChild(
GUI.slider(
1, 1,
36,
0x66DB80,
0xE1E1E1,
0xFFFFFF,
0xA5A5A5,
20, 200,
config.speed * 100,
false,
"Speed: ",
"%"
)
)
speedSlider.roundValues = true
speedSlider.onValueChanged = function()
config.speed = speedSlider.value / 100
saveConfig()
end
end

View File

@ -6,6 +6,8 @@ local GUI = require("GUI")
--------------------------------------------------------------------------------
local workspace, wallpaper = select(1, ...), select(2, ...)
local configPath = filesystem.path(system.getCurrentScript()) .. "Config.cfg"
local config = {
@ -53,166 +55,164 @@ local wind = 0
local lastUpdateTime = computer.uptime()
return {
draw = function(wallpaper)
-- Spawning snowflakes
local distance
wallpaper.draw = function(wallpaper)
-- Spawning snowflakes
local distance
for i = 1, config.snowflakeAmount - #snowflakes do
distance = math.random()
for i = 1, config.snowflakeAmount - #snowflakes do
distance = math.random()
tableInsert(snowflakes, {
x = mathRandom(1, wallpaper.width) - 1,
y = 0,
color = colorTransition(config.snowflakeColor, config.backgroundColor, .2 + .8 * distance),
speed = 2 - 1.5 * distance,
vx = 0
})
end
tableInsert(snowflakes, {
x = mathRandom(1, wallpaper.width) - 1,
y = 0,
color = colorTransition(config.snowflakeColor, config.backgroundColor, .2 + .8 * distance),
speed = 2 - 1.5 * distance,
vx = 0
})
end
-- Clearing the area
screenDrawRectangle(wallpaper.x, wallpaper.y, wallpaper.width, wallpaper.height, config.backgroundColor, 0, " ")
-- Clearing the area
screenDrawRectangle(wallpaper.x, wallpaper.y, wallpaper.width, wallpaper.height, config.backgroundColor, 0, " ")
-- Rendering snowflakes
local snowflake
-- Rendering snowflakes
local snowflake
for i = 1, #snowflakes do
snowflake = snowflakes[i]
for i = 1, #snowflakes do
snowflake = snowflakes[i]
screenSemiPixelSet(
mathFloor(wallpaper.x + snowflake.x),
mathFloor(wallpaper.y + snowflake.y),
snowflake.color
)
end
-- Rendering stacks
local stackHeight
for x, stackHeight in pairs(stacks) do
screenDrawSemiPixelRectangle(wallpaper.x + x, wallpaper.y + wallpaper.height * 2 - stackHeight + 1, 1, stackHeight, config.snowflakeColor)
if stackHeight > config.maxStackHeight then
stacks[x] = stackHeight - 2
end
end
-- Updating snowflakes
local currentTime = computer.uptime()
local deltaTime = (currentTime - lastUpdateTime) * 20
wind = wind + .1 * (2 * mathRandom() - 1) * deltaTime
if wind > config.maxWind then wind = config.maxWind end
if wind < -config.maxWind then wind = -config.maxWind end
local doubleHeight = wallpaper.height * 2
local x, y
local i = 1
while i <= #snowflakes do
snowflake = snowflakes[i]
snowflake.y = snowflake.y + deltaTime * snowflake.speed
snowflake.x = snowflake.x + deltaTime * (wind * snowflake.speed + snowflake.vx)
snowflake.vx = snowflake.vx + (mathRandom() * 2 - 1) * 0.1 * deltaTime
if snowflake.vx > 1 then
snowflake.vx = 1
elseif snowflake.vx < -1 then
snowflake.vx = -1
end
-- When snowflake moves out of wallpaper bounds - teleporting
-- it to the opposite side
if snowflake.x < 0 then
snowflake.x = wallpaper.width - snowflake.x
elseif snowflake.x >= wallpaper.width then
snowflake.x = snowflake.x - wallpaper.width
end
x, y = mathFloor(snowflake.x), mathFloor(snowflake.y)
stackHeight = stacks[x] or 0
if y >= doubleHeight - stackHeight then
stacks[x] = stackHeight + 1
if x > 0 then
local leftStackHeight = stacks[x-1] or 0
if stacks[x] - leftStackHeight > 2 then
stacks[x-1] = leftStackHeight + 1
stacks[x] = stackHeight
end
end
if x < wallpaper.width-1 then
local rightStackHeight = stacks[x+1] or 0
if stacks[x] - rightStackHeight > 2 then
stacks[x+1] = rightStackHeight + 1
stacks[x] = stackHeight
end
end
tableRemove(snowflakes, i)
else
i = i + 1
end
end
lastUpdateTime = currentTime
end,
configure = function(layout)
layout:addChild(GUI.colorSelector(1, 1, 36, 3, config.backgroundColor, "Background color")).onColorSelected = function(_, object)
config.backgroundColor = object.color
saveConfig()
end
layout:addChild(GUI.colorSelector(1, 1, 36, 3, config.snowflakeColor, "Snowflake color")).onColorSelected = function(_, object)
config.snowflakeColor = object.color
saveConfig()
end
local snowflakeAmountSlider = layout:addChild(
GUI.slider(
1, 1,
36,
0x66DB80,
0xE1E1E1,
0xFFFFFF,
0xA5A5A5,
5, 50,
config.snowflakeAmount,
false,
"Snowflake amount: "
)
screenSemiPixelSet(
mathFloor(wallpaper.x + snowflake.x),
mathFloor(wallpaper.y + snowflake.y),
snowflake.color
)
end
snowflakeAmountSlider.roundValues = true
snowflakeAmountSlider.onValueChanged = function()
config.snowflakeAmount = math.floor(snowflakeAmountSlider.value)
saveConfig()
end
-- Rendering stacks
local stackHeight
local maxStackHeightSlider = layout:addChild(
GUI.slider(
1, 1,
36,
0x66DB80,
0xE1E1E1,
0xFFFFFF,
0xA5A5A5,
0, 50,
config.maxStackHeight,
false,
"Stack height limit: "
)
)
for x, stackHeight in pairs(stacks) do
screenDrawSemiPixelRectangle(wallpaper.x + x, wallpaper.y + wallpaper.height * 2 - stackHeight + 1, 1, stackHeight, config.snowflakeColor)
maxStackHeightSlider.roundValues = true
maxStackHeightSlider.onValueChanged = function()
config.maxStackHeight = math.floor(maxStackHeightSlider.value)
saveConfig()
if stackHeight > config.maxStackHeight then
stacks[x] = stackHeight - 2
end
end
}
-- Updating snowflakes
local currentTime = computer.uptime()
local deltaTime = (currentTime - lastUpdateTime) * 20
wind = wind + .1 * (2 * mathRandom() - 1) * deltaTime
if wind > config.maxWind then wind = config.maxWind end
if wind < -config.maxWind then wind = -config.maxWind end
local doubleHeight = wallpaper.height * 2
local x, y
local i = 1
while i <= #snowflakes do
snowflake = snowflakes[i]
snowflake.y = snowflake.y + deltaTime * snowflake.speed
snowflake.x = snowflake.x + deltaTime * (wind * snowflake.speed + snowflake.vx)
snowflake.vx = snowflake.vx + (mathRandom() * 2 - 1) * 0.1 * deltaTime
if snowflake.vx > 1 then
snowflake.vx = 1
elseif snowflake.vx < -1 then
snowflake.vx = -1
end
-- When snowflake moves out of wallpaper bounds - teleporting
-- it to the opposite side
if snowflake.x < 0 then
snowflake.x = wallpaper.width - snowflake.x
elseif snowflake.x >= wallpaper.width then
snowflake.x = snowflake.x - wallpaper.width
end
x, y = mathFloor(snowflake.x), mathFloor(snowflake.y)
stackHeight = stacks[x] or 0
if y >= doubleHeight - stackHeight then
stacks[x] = stackHeight + 1
if x > 0 then
local leftStackHeight = stacks[x-1] or 0
if stacks[x] - leftStackHeight > 2 then
stacks[x-1] = leftStackHeight + 1
stacks[x] = stackHeight
end
end
if x < wallpaper.width-1 then
local rightStackHeight = stacks[x+1] or 0
if stacks[x] - rightStackHeight > 2 then
stacks[x+1] = rightStackHeight + 1
stacks[x] = stackHeight
end
end
tableRemove(snowflakes, i)
else
i = i + 1
end
end
lastUpdateTime = currentTime
end
wallpaper.configure = function(layout)
layout:addChild(GUI.colorSelector(1, 1, 36, 3, config.backgroundColor, "Background color")).onColorSelected = function(_, object)
config.backgroundColor = object.color
saveConfig()
end
layout:addChild(GUI.colorSelector(1, 1, 36, 3, config.snowflakeColor, "Snowflake color")).onColorSelected = function(_, object)
config.snowflakeColor = object.color
saveConfig()
end
local snowflakeAmountSlider = layout:addChild(
GUI.slider(
1, 1,
36,
0x66DB80,
0xE1E1E1,
0xFFFFFF,
0xA5A5A5,
5, 50,
config.snowflakeAmount,
false,
"Snowflake amount: "
)
)
snowflakeAmountSlider.roundValues = true
snowflakeAmountSlider.onValueChanged = function()
config.snowflakeAmount = math.floor(snowflakeAmountSlider.value)
saveConfig()
end
local maxStackHeightSlider = layout:addChild(
GUI.slider(
1, 1,
36,
0x66DB80,
0xE1E1E1,
0xFFFFFF,
0xA5A5A5,
0, 50,
config.maxStackHeight,
false,
"Stack height limit: "
)
)
maxStackHeightSlider.roundValues = true
maxStackHeightSlider.onValueChanged = function()
config.maxStackHeight = math.floor(maxStackHeightSlider.value)
saveConfig()
end
end

View File

@ -5,6 +5,8 @@ local GUI = require("GUI")
--------------------------------------------------------------------------------
local workspace, wallpaper = select(1, ...), select(2, ...)
local configPath = filesystem.path(system.getCurrentScript()) .. "Config.cfg"
local config = {
@ -23,15 +25,13 @@ end
--------------------------------------------------------------------------------
return {
draw = function(object)
screen.drawRectangle(object.x, object.y, object.width, object.height, config.color, 0, ' ')
end,
wallpaper.draw = function(object)
screen.drawRectangle(object.x, object.y, object.width, object.height, config.color, 0, ' ')
end
configure = function(layout)
layout:addChild(GUI.colorSelector(1, 1, 36, 3, config.color, "Color")).onColorSelected = function(_, object)
config.color = object.color
saveConfig()
end
wallpaper.configure = function(layout)
layout:addChild(GUI.colorSelector(1, 1, 36, 3, config.color, "Color")).onColorSelected = function(_, object)
config.color = object.color
saveConfig()
end
}
end

View File

@ -6,6 +6,8 @@ local color = require("Color")
--------------------------------------------------------------------------------
local workspace, wallpaper = select(1, ...), select(2, ...)
local configPath = filesystem.path(system.getCurrentScript()) .. "Config.cfg"
local config = {
@ -72,170 +74,166 @@ end
resetColors()
--------------------------------------------------------------------------------
wallpaper.draw = function(wallpaper)
local hitsDeadline = computerUptime() >= deadline
return {
draw = function(wallpaper)
local hitsDeadline = computerUptime() >= deadline
-- Drawing background
screen.drawRectangle(wallpaper.x, wallpaper.y, wallpaper.width, wallpaper.height, config.backgroundColor, 0, " ")
-- Drawing background
screen.drawRectangle(wallpaper.x, wallpaper.y, wallpaper.width, wallpaper.height, config.backgroundColor, 0, " ")
-- Spawning missing stars
local rotationAngle, targetX, targetY
-- Spawning missing stars
local rotationAngle, targetX, targetY
while #stars < config.starAmount do
rotationAngle = mathRandom(6265) / 1000
targetX = mathCos(rotationAngle) * wallpaper.width * 0.75 + wallpaper.width / 2
targetY = mathSin(rotationAngle) * wallpaper.width * 0.375 + wallpaper.height / 2
while #stars < config.starAmount do
rotationAngle = mathRandom(6265) / 1000
targetX = mathCos(rotationAngle) * wallpaper.width * 0.75 + wallpaper.width / 2
targetY = mathSin(rotationAngle) * wallpaper.width * 0.375 + wallpaper.height / 2
table.insert(stars, {
targetX = targetX,
targetY = targetY,
startX = (targetX - wallpaper.width / 2) * config.starOffset + wallpaper.width / 2,
startY = (targetY - wallpaper.height / 2) * config.starOffset + wallpaper.height / 2,
speed = mathRandom(25, 75) / 1000 + 1,
table.insert(stars, {
targetX = targetX,
targetY = targetY,
startX = (targetX - wallpaper.width / 2) * config.starOffset + wallpaper.width / 2,
startY = (targetY - wallpaper.height / 2) * config.starOffset + wallpaper.height / 2,
speed = mathRandom(25, 75) / 1000 + 1,
-- Defines the star lifetime in range (0.0; 1.0]
-- Shouldn't be zero, because it will be mutiplied to
-- simulate "speed up" effect on sides of screen
age = 0.01
})
end
-- Defines the star lifetime in range (0.0; 1.0]
-- Shouldn't be zero, because it will be mutiplied to
-- simulate "speed up" effect on sides of screen
age = 0.01
})
end
-- Drawing stars
local star, x, y, xmod, ymod, color
-- Drawing stars
local star, x, y, xmod, ymod, color
local i = 1
while i <= #stars do
star = stars[i]
local i = 1
while i <= #stars do
star = stars[i]
x = star.startX + (star.targetX - star.startX) * star.age
y = star.startY + (star.targetY - star.startY) * star.age
x = star.startX + (star.targetX - star.startX) * star.age
y = star.startY + (star.targetY - star.startY) * star.age
if x > wallpaper.width + 1 or x < 1 or y > wallpaper.height + 1 or y < 1 then
tableRemove(stars, i)
else
xmod = x * 2;
xmod = (xmod - xmod % 1) % 2
if x > wallpaper.width + 1 or x < 1 or y > wallpaper.height + 1 or y < 1 then
tableRemove(stars, i)
else
xmod = x * 2;
xmod = (xmod - xmod % 1) % 2
ymod = y * 4; ymod = (ymod - ymod % 1) % 4
ymod = y * 4; ymod = (ymod - ymod % 1) % 4
color = star.age * #colors * config.starBrightness
color = colors[color - color % 1 + 1] or colors[#colors]
color = star.age * #colors * config.starBrightness
color = colors[color - color % 1 + 1] or colors[#colors]
-- Small stars
if star.age < 0.3 then
if xmod == 0 then
if ymod == 0 then char = braille1
elseif ymod == 1 then char = braille3
elseif ymod == 2 then char = braille5
else char = braille7
end
else
if ymod == 0 then char = braille2
elseif ymod == 1 then char = braille4
elseif ymod == 2 then char = braille6
else char = braille8
end
-- Small stars
if star.age < 0.3 then
if xmod == 0 then
if ymod == 0 then char = braille1
elseif ymod == 1 then char = braille3
elseif ymod == 2 then char = braille5
else char = braille7
end
-- Big stars
else
if ymod < 2 then
char = braille9
else
char = braille10
if ymod == 0 then char = braille2
elseif ymod == 1 then char = braille4
elseif ymod == 2 then char = braille6
else char = braille8
end
end
screen.set(x - x % 1, y - y % 1, config.backgroundColor, color, char)
i = i + 1
if hitsDeadline then
star.age = star.age * star.speed
-- Big stars
else
if ymod < 2 then
char = braille9
else
char = braille10
end
end
screen.set(x - x % 1, y - y % 1, config.backgroundColor, color, char)
i = i + 1
if hitsDeadline then
star.age = star.age * star.speed
end
end
end
if hitsDeadline then
deadline = computerUptime() + 0.05
end
end,
if hitsDeadline then
deadline = computerUptime() + 0.05
end
end
configure = function(layout)
layout:addChild(GUI.colorSelector(1, 1, 36, 3, config.backgroundColor, "Background color")).onColorSelected = function(_, object)
config.backgroundColor = object.color
resetColors()
saveConfig()
end
wallpaper.configure = function(layout)
layout:addChild(GUI.colorSelector(1, 1, 36, 3, config.backgroundColor, "Background color")).onColorSelected = function(_, object)
config.backgroundColor = object.color
resetColors()
saveConfig()
end
layout:addChild(GUI.colorSelector(1, 1, 36, 3, config.starColor, "Star color")).onColorSelected = function(_, object)
config.starColor = object.color
resetColors()
saveConfig()
end
layout:addChild(GUI.colorSelector(1, 1, 36, 3, config.starColor, "Star color")).onColorSelected = function(_, object)
config.starColor = object.color
resetColors()
saveConfig()
end
local starAmountSlider = layout:addChild(
GUI.slider(
1, 1,
36,
0x66DB80,
0xE1E1E1,
0xFFFFFF,
0xA5A5A5,
10, 500,
config.starAmount,
false,
"Star amount: "
)
)
starAmountSlider.roundValues = true
starAmountSlider.onValueChanged = function()
config.starAmount = math.floor(starAmountSlider.value)
saveConfig()
end
local starBrightnessSlider = layout:addChild(
GUI.slider(
1, 1,
36,
0x66DB80,
0xE1E1E1,
0xFFFFFF,
0xA5A5A5,
50, 300,
config.starBrightness * 100,
false,
"Star brightness: ",
"%"
)
)
starBrightnessSlider.roundValues = true
starBrightnessSlider.onValueChanged = function()
config.starBrightness = starBrightnessSlider.value / 100
saveConfig()
end
local offsetSlider = layout:addChild(GUI.slider(
local starAmountSlider = layout:addChild(
GUI.slider(
1, 1,
36,
0x66DB80,
0xE1E1E1,
0xFFFFFF,
0xA5A5A5,
0, 100,
config.starOffset * 100,
10, 500,
config.starAmount,
false,
"Offset: ",
"%"
))
"Star amount: "
)
)
offsetSlider.roundValues = true
offsetSlider.onValueChanged = function()
config.starOffset = offsetSlider.value / 100
saveConfig()
end
starAmountSlider.roundValues = true
starAmountSlider.onValueChanged = function()
config.starAmount = math.floor(starAmountSlider.value)
saveConfig()
end
}
local starBrightnessSlider = layout:addChild(
GUI.slider(
1, 1,
36,
0x66DB80,
0xE1E1E1,
0xFFFFFF,
0xA5A5A5,
50, 300,
config.starBrightness * 100,
false,
"Star brightness: ",
"%"
)
)
starBrightnessSlider.roundValues = true
starBrightnessSlider.onValueChanged = function()
config.starBrightness = starBrightnessSlider.value / 100
saveConfig()
end
local offsetSlider = layout:addChild(GUI.slider(
1, 1,
36,
0x66DB80,
0xE1E1E1,
0xFFFFFF,
0xA5A5A5,
0, 100,
config.starOffset * 100,
false,
"Offset: ",
"%"
))
offsetSlider.roundValues = true
offsetSlider.onValueChanged = function()
config.starOffset = offsetSlider.value / 100
saveConfig()
end
end

View File

@ -6,6 +6,8 @@ local image = require("Image")
--------------------------------------------------------------------------------
local workspace, wallpaper = select(1, ...), select(2, ...)
local configPath = filesystem.path(system.getCurrentScript()) .. "Config.cfg"
local config = {
@ -40,24 +42,22 @@ loadPicture()
--------------------------------------------------------------------------------
return {
draw = function(object)
if picture then
screen.drawImage(object.x, object.y, picture)
else
screen.drawRectangle(object.x, object.y, object.width, object.height, 0x161616, 0x000000, " ")
wallpaper.draw = function(object)
if picture then
screen.drawImage(object.x, object.y, picture)
else
screen.drawRectangle(object.x, object.y, object.width, object.height, 0x161616, 0x000000, " ")
local text = reason or "Unknown reason"
screen.drawText(math.floor(object.x + object.width / 2 - unicode.len(text) / 2), math.floor(object.y + object.height / 2), 0x646464, text)
end
end,
local text = reason or "Unknown reason"
screen.drawText(math.floor(object.x + object.width / 2 - unicode.len(text) / 2), math.floor(object.y + object.height / 2), 0x646464, text)
end
end
configure = function(layout)
local chooser = layout:addChild(GUI.filesystemChooser(1, 1, 36, 3, 0xE1E1E1, 0x696969, 0xD2D2D2, 0xA5A5A5, config.path, "Open", "Cancel", "Wallpaper path", "/"))
chooser:setMode(GUI.IO_MODE_OPEN, GUI.IO_MODE_FILE)
chooser:addExtensionFilter(".pic")
chooser.onSubmit = setPicture
end,
wallpaper.configure = function(layout)
local chooser = layout:addChild(GUI.filesystemChooser(1, 1, 36, 3, 0xE1E1E1, 0x696969, 0xD2D2D2, 0xA5A5A5, config.path, "Open", "Cancel", "Wallpaper path", "/"))
chooser:setMode(GUI.IO_MODE_OPEN, GUI.IO_MODE_FILE)
chooser:addExtensionFilter(".pic")
chooser.onSubmit = setPicture
end
setPicture = setPicture
}
wallpaper.setPicture = setPicture