diff --git a/Applications/Picture Edit.app/Extensions/.pic/Context menu.lua b/Applications/Picture Edit.app/Extensions/.pic/Context menu.lua index db27260a..72a65708 100755 --- a/Applications/Picture Edit.app/Extensions/.pic/Context menu.lua +++ b/Applications/Picture Edit.app/Extensions/.pic/Context menu.lua @@ -1,25 +1,6 @@ - -local filesystem = require("Filesystem") -local GUI = require("GUI") -local paths = require("Paths") local system = require("System") -local workspace, icon, menu = select(1, ...), select(2, ...), select(3, ...) -local localization = system.getSystemLocalization() - -menu:addItem("💻", localization.setAsWallpaper).onTouch = function() - local userSettings = system.getUserSettings() - - local staticPictureWallpaperPath = paths.system.wallpapers .. "Static picture.wlp" - if userSettings.interfaceWallpaperPath ~= staticPictureWallpaperPath then - userSettings.interfaceWallpaperPath = staticPictureWallpaperPath - system.updateWallpaper() - end - - system.wallpaper.setPicture(icon.path) - - workspace:draw() - system.saveUserSettings() -end +local workspace, icon, menu = table.unpack({...}) +system.addSetAsWallpaperMenuItem(menu, icon.path) system.addUploadToPastebinMenuItem(menu, icon.path) \ No newline at end of file diff --git a/Applications/Picture View.app/Extensions/.pic/Context menu.lua b/Applications/Picture View.app/Extensions/.pic/Context menu.lua index db27260a..72a65708 100644 --- a/Applications/Picture View.app/Extensions/.pic/Context menu.lua +++ b/Applications/Picture View.app/Extensions/.pic/Context menu.lua @@ -1,25 +1,6 @@ - -local filesystem = require("Filesystem") -local GUI = require("GUI") -local paths = require("Paths") local system = require("System") -local workspace, icon, menu = select(1, ...), select(2, ...), select(3, ...) -local localization = system.getSystemLocalization() - -menu:addItem("💻", localization.setAsWallpaper).onTouch = function() - local userSettings = system.getUserSettings() - - local staticPictureWallpaperPath = paths.system.wallpapers .. "Static picture.wlp" - if userSettings.interfaceWallpaperPath ~= staticPictureWallpaperPath then - userSettings.interfaceWallpaperPath = staticPictureWallpaperPath - system.updateWallpaper() - end - - system.wallpaper.setPicture(icon.path) - - workspace:draw() - system.saveUserSettings() -end +local workspace, icon, menu = table.unpack({...}) +system.addSetAsWallpaperMenuItem(menu, icon.path) system.addUploadToPastebinMenuItem(menu, icon.path) \ No newline at end of file diff --git a/Applications/Settings.app/Modules/1_Wallpaper/Main.lua b/Applications/Settings.app/Modules/1_Wallpaper/Main.lua index c24fa78a..8c32e7fc 100644 --- a/Applications/Settings.app/Modules/1_Wallpaper/Main.lua +++ b/Applications/Settings.app/Modules/1_Wallpaper/Main.lua @@ -1,65 +1,62 @@ local GUI = require("GUI") local system = require("System") -local fs = require("Filesystem") +local filesystem = require("Filesystem") local paths = require("Paths") -local module = {} - -local workspace, window, localization = table.unpack({...}) -local userSettings = system.getUserSettings() - -------------------------------------------------------------------------------- -local wallpaperConfigurationControlsBegin, wallpaperConfigurationControlsEnd = nil, nil +local workspace, window, localization = table.unpack({...}) +local userSettings = system.getUserSettings() +local configureFrom, configureTo -local function updateWallpaperConfigurationControls(layout) +local function configure() -- Remove previously added controls from layout - if wallpaperConfigurationControlsBegin ~= nil then - layout:removeChildren(wallpaperConfigurationControlsBegin, wallpaperConfigurationControlsEnd) - wallpaperConfigurationControlsBegin, wallpaperConfigurationControlsEnd = nil, nil + if configureFrom then + window.contentLayout:removeChildren(configureFrom, configureTo) + configureFrom, configureTo = nil, nil end -- Add new controls if needed if system.wallpaper and system.wallpaper.configure then - wallpaperConfigurationControlsBegin = #layout.children + 1 - system.wallpaper.configure(layout) - wallpaperCOnfigurationControlsEnd = #layout.children + configureFrom = #window.contentLayout.children + 1 + system.wallpaper.configure(window.contentLayout) + configureTo = #window.contentLayout.children end end -------------------------------------------------------------------------------- -module.name = localization.wallpaper -module.margin = 0 +return { + name = localization.wallpaper, + margin = 0, + onTouch = function() + window.contentLayout:addChild(GUI.text(1, 1, 0x2D2D2D, localization.wallpaperWallpaper)) -module.onTouch = function() - window.contentLayout:addChild(GUI.text(1, 1, 0x2D2D2D, localization.wallpaperWallpaper)) + local comboBox = window.contentLayout:addChild(GUI.comboBox(1, 1, 36, 3, 0xE1E1E1, 0x696969, 0xD2D2D2, 0xA5A5A5)) + local files = filesystem.list(paths.system.wallpapers) - local comboBox = window.contentLayout:addChild(GUI.comboBox(1, 1, 36, 3, 0xE1E1E1, 0x696969, 0xD2D2D2, 0xA5A5A5)) - for _, filename in pairs(fs.list(paths.system.wallpapers)) do - local path = paths.system.wallpapers .. filename - - if fs.isDirectory(path) and fs.extension(path) == ".wlp" then - local item = comboBox:addItem(fs.hideExtension(filename)) + for i = 1, #files do + local file = files[i] + local path = paths.system.wallpapers .. file + + if filesystem.isDirectory(path) and filesystem.extension(path) == ".wlp" then + comboBox:addItem(filesystem.hideExtension(file)) - item.onTouch = function() - userSettings.interfaceWallpaperPath = path - system.updateWallpaper() - workspace:draw() - - system.saveUserSettings() - updateWallpaperConfigurationControls(window.contentLayout) - end - - if userSettings.interfaceWallpaperPath == path then - comboBox.selectedItem = comboBox:count() + if userSettings.interfaceWallpaperPath == path then + comboBox.selectedItem = i + end end end + + comboBox.onItemSelected = function(index) + userSettings.interfaceWallpaperPath = paths.system.wallpapers .. files[index] + system.updateWallpaper() + configure(window.contentLayout) + + workspace:draw() + system.saveUserSettings() + end + + configure() end - - updateWallpaperConfigurationControls(window.contentLayout) -end - --------------------------------------------------------------------------------- - -return module \ No newline at end of file +} \ No newline at end of file diff --git a/Libraries/System.lua b/Libraries/System.lua index 846e15b5..36c15d28 100755 --- a/Libraries/System.lua +++ b/Libraries/System.lua @@ -98,8 +98,6 @@ function system.getDefaultUserSettings() interfaceBlurRadius = 3, interfaceBlurTransparency = 0.6, - interfaceColorDesktopBackground = 0x1E1E1E, - filesShowExtension = false, filesShowHidden = false, filesShowApplicationIcon = true, @@ -477,6 +475,23 @@ function system.addUploadToPastebinMenuItem(menu, path) end end +function system.addSetAsWallpaperMenuItem(menu, path) + menu:addItem("💻", localization.setAsWallpaper).onTouch = function() + local userSettings = system.getUserSettings() + local wallpaperPath = paths.system.wallpapers .. "Static picture.wlp/" + + if userSettings.interfaceWallpaperPath ~= wallpaperPath then + userSettings.interfaceWallpaperPath = wallpaperPath + system.updateWallpaper() + end + + system.wallpaper.setPicture(path) + + workspace:draw() + system.saveUserSettings() + end +end + function system.launchWithArguments(path) local container = addBackgroundContainerWithInput("", localization.launchWithArguments) @@ -2375,40 +2390,40 @@ function system.execute(path, ...) end local function desktopBackgroundAmbientDraw() - screen.drawRectangle(1, desktopBackground.y, desktopBackground.width, desktopBackground.height, userSettings.interfaceColorDesktopBackground or 0x1E1E1E, 0, " ") + screen.drawRectangle(1, desktopBackground.y, desktopBackground.width, desktopBackground.height, 0x1E1E1E, 0, " ") end function system.updateWallpaper() desktopBackground.draw = desktopBackgroundAmbientDraw interfaceDrawInterval = 1 - if userSettings.interfaceWallpaperPath then - local executable, reason = loadfile(userSettings.interfaceWallpaperPath .. "Main.lua") - if not executable then - GUI.alert(reason) - return - end - - local success, wallpaperOrError = xpcall(executable, debug.traceback) - if not success then - GUI.alert(wallpaperOrError) - return - end - - if type(wallpaperOrError) ~= "table" then - GUI.alert("Wallpaper script didn't return table") - return - end - - if type(wallpaperOrError.draw) ~= "function" then - GUI.alert("Wallpaper does not contain proper draw function") - return - end - - system.wallpaper = wallpaperOrError - desktopBackground.draw = system.wallpaper.draw - interfaceDrawInterval = 0.01 + if not userSettings.interfaceWallpaperPath then + return end + + local executable, reason = loadfile(userSettings.interfaceWallpaperPath .. "Main.lua") + if not executable then + GUI.alert(reason) + return + end + + local success, wallpaperOrError = xpcall(executable, debug.traceback) + if not success then + GUI.alert(wallpaperOrError) + 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 + + system.wallpaper = wallpaperOrError + desktopBackground.draw = system.wallpaper.draw + interfaceDrawInterval = 0.01 end function system.updateScreen() @@ -2830,7 +2845,7 @@ function system.updateDesktop() end function system.updateColorScheme() - GUI.BACKGROUND_CONTAINER_PANEL_COLOR = userSettings.interfaceTransparencyEnabled and 0x0 or userSettings.interfaceColorDesktopBackground + GUI.BACKGROUND_CONTAINER_PANEL_COLOR = userSettings.interfaceTransparencyEnabled and 0x0 or 0x1E1E1E GUI.BACKGROUND_CONTAINER_PANEL_TRANSPARENCY = userSettings.interfaceTransparencyEnabled and 0.3 end diff --git a/Wallpapers/Lines.wlp/Main.lua b/Wallpapers/Lines.wlp/Main.lua index 7637c615..1a152042 100644 --- a/Wallpapers/Lines.wlp/Main.lua +++ b/Wallpapers/Lines.wlp/Main.lua @@ -1,109 +1,134 @@ local screen = require("Screen") -local fs = require("Filesystem") +local filesystem = require("Filesystem") local system = require("System") local GUI = require("GUI") -local wallpaper = {} - -------------------------------------------------------------------------------- -local configPath = fs.path(system.getCurrentScript()) .. "Config.cfg" +local configPath = filesystem.path(system.getCurrentScript()) .. "Config.cfg" + +local config = { + backgroundColor = 0x161616, + lineCount = 10, + lineColor = 0xFFFFFF +} + +if filesystem.exists(configPath) then + for key, value in pairs(filesystem.readTable(configPath)) do + config[key] = value + end +end local function saveConfig() - fs.writeTable(configPath, wallpaper.config) -end - -if fs.exists(configPath) then - wallpaper.config = fs.readTable(configPath) -else - wallpaper.config = { - backgroundColor = 0x161616, - lineCount = 10, - lineColor = 0xFFFFFF - } + filesystem.writeTable(configPath, config) end -------------------------------------------------------------------------------- +local points = {} +local lastUptime = computer.uptime() + local function reset() - wallpaper.points = {} + points = {} local resX, resY = screen.getResolution() - for i = 1, wallpaper.config.lineCount do - table.insert(wallpaper.points, { - x = math.random(0, resX-1), - y = math.random(0, resY-1), + for i = 1, config.lineCount do + table.insert(points, { + x = math.random(0, resX - 1), + y = math.random(0, (resY - 1) * 2), vx = (2 * math.random() - 1) * 25, vy = (2 * math.random() - 1) * 25 }) end - wallpaper.lastUpdateTime = computer.uptime() + lastUptime = computer.uptime() end reset(object) -function wallpaper.draw(object) - screen.drawRectangle(object.x, object.y, object.width, object.height, wallpaper.config.backgroundColor, 0, " ") - - for i = 1, wallpaper.config.lineCount - 1 do - screen.drawSemiPixelLine( - math.floor(wallpaper.points[i ].x), math.floor(wallpaper.points[i ].y), - math.floor(wallpaper.points[i+1].x), math.floor(wallpaper.points[i+1].y), - wallpaper.config.lineColor - ) - end - - local currentTime = computer.uptime() - local dt = currentTime - wallpaper.lastUpdateTime - wallpaper.lastUpdateTime = currentTime - - for i = 1, wallpaper.config.lineCount do - local point = wallpaper.points[i] - - point.x = point.x + point.vx * dt - point.y = point.y + point.vy * dt - - if point.x < 0 or point.x >= object.width then point.vx = -point.vx end - if point.y < 0 or point.y >= object.height then point.vy = -point.vy end - end -end - -function wallpaper.configure(layout) - layout:addChild(GUI.colorSelector(1, 1, 36, 3, wallpaper.config.backgroundColor, "Background color")).onColorSelected = function(_, object) - wallpaper.config.backgroundColor = object.color - saveConfig() - end - - layout:addChild(GUI.colorSelector(1, 1, 36, 3, wallpaper.config.lineColor, "Line color")).onColorSelected = function(_, object) - wallpaper.config.lineColor = object.color - saveConfig() - end - - local slider = layout:addChild( - GUI.slider( - 1, 1, - 36, - 0x66DB80, - 0xE1E1E1, - 0xFFFFFF, - 0xA5A5A5, - 1, 10, - wallpaper.config.lineCount, - false, - "Line count: " - ) - ) - - slider.roundValues = true - - slider.onValueChanged = function(workspace, object) - wallpaper.config.lineCount = math.floor(object.value) - saveConfig() - reset() - end -end - -------------------------------------------------------------------------------- -return wallpaper \ No newline at end of file +return { + draw = function(object) + screen.drawRectangle(object.x, object.y, object.width, object.height, config.backgroundColor, 0, " ") + + local point1, point2 + + 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), + + math.floor(object.x + point2.x), + math.floor(object.y * 2 - 1 + point2.y), + + config.lineColor + ) + + screen.semiPixelSet( + math.floor(object.x + point1.x), + math.floor(object.y * 2 - 1 + point1.y), + + 0x880000 + ) + + screen.semiPixelSet( + math.floor(object.x + point2.x), + math.floor(object.y * 2 - 1 + point2.y), + + 0x008800 + ) + 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: " + ) + ) + + slider.roundValues = true + + slider.onValueChanged = function(workspace, object) + config.lineCount = math.floor(object.value) + saveConfig() + reset() + end + end +} \ No newline at end of file diff --git a/Wallpapers/Solid color.wlp/Main.lua b/Wallpapers/Solid color.wlp/Main.lua index 81896e61..79d0fb3d 100644 --- a/Wallpapers/Solid color.wlp/Main.lua +++ b/Wallpapers/Solid color.wlp/Main.lua @@ -1,41 +1,37 @@ --- The simplest solid color wallpaper - local system = require("System") -local fs = require("Filesystem") +local filesystem = require("Filesystem") local screen = require("Screen") local GUI = require("GUI") -local wallpaper = {} - -------------------------------------------------------------------------------- -local configPath = fs.path(system.getCurrentScript()) .. "/" .. "Config.cfg" +local configPath = filesystem.path(system.getCurrentScript()) .. "Config.cfg" -local function saveConfig() - fs.writeTable(configPath, wallpaper.config) -end +local config = { + color = 0x161616 +} -if fs.exists(configPath) then - wallpaper.config = fs.readTable(configPath) -else - wallpaper.config = { - color = 0x161616 - } -end - --------------------------------------------------------------------------------- - -wallpaper.draw = function(object) - screen.drawRectangle(object.x, object.y, object.width, object.height, wallpaper.config.color, 0, ' ') -end - -wallpaper.configure = function(layout) - layout:addChild(GUI.colorSelector(1, 1, 36, 3, wallpaper.config.color, "Color")).onColorSelected = function(_, object) - wallpaper.config.color = object.color - saveConfig() +if filesystem.exists(configPath) then + for key, value in pairs(filesystem.readTable(configPath)) do + config[key] = value end end +local function saveConfig() + filesystem.writeTable(configPath, config) +end + -------------------------------------------------------------------------------- -return wallpaper \ No newline at end of file +return { + 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 + end +} \ No newline at end of file diff --git a/Wallpapers/Stars.wlp/Main.lua b/Wallpapers/Stars.wlp/Main.lua index 1bf2cda4..819273a3 100644 --- a/Wallpapers/Stars.wlp/Main.lua +++ b/Wallpapers/Stars.wlp/Main.lua @@ -1,48 +1,69 @@ local screen = require("Screen") -local fs = require("Filesystem") +local filesystem = require("Filesystem") local GUI = require("GUI") local system = require("System") local color = require("Color") -------------------------------------------------------------------------------- -local braille1, braille2, braille3, braille4, braille5, braille6, braille7, braille8, braille9, braille10 = "⠁", "⠈", "⠂", "⠐", "⠄", "⠠", "⡀", "⢀", "⠛", "⣤" +local configPath = filesystem.path(system.getCurrentScript()) .. "Config.cfg" + +local config = { + starAmount = 100, + backgroundColor = 0x0F0F0F, + starColor = 0xF0F0F0, + delay = 0.05, + offset = 0.01, + speed = 100 +} + +if filesystem.exists(configPath) then + for key, value in pairs(filesystem.readTable(configPath)) do + config[key] = value + end +end + +local function saveConfig() + filesystem.writeTable(configPath, config) +end + +-------------------------------------------------------------------------------- -- Faster access without tables indexing local computerUptime, tableRemove, mathSin, mathCos, mathRandom, screenUpdate = computer.uptime, table.remove, math.sin, math.cos, math.random --------------------------------------------------------------------------------- - -local wallpaper = {} - -local configPath = fs.path(system.getCurrentScript()) .. "Config.cfg" -local function saveConfig() - fs.writeTable(configPath, wallpaper.config) -end - -if fs.exists(configPath) then - wallpaper.config = fs.readTable(configPath) -else - wallpaper.config = { - starAmount = 100, - backgroundColor = 0x0F0F0F, - starColor = 0xFFFFFF, - delay = 0.05, - initialWay = 0.01, - speed = 100 - } -end - --------------------------------------------------------------------------------- - +local braille1, braille2, braille3, braille4, braille5, braille6, braille7, braille8, braille9, braille10 = "⠁", "⠈", "⠂", "⠐", "⠄", "⠠", "⡀", "⢀", "⠛", "⣤" local stars, deadline, colors local function resetColors() - colors = {} - - local colorCount = 16 - for i = 1, colorCount do - table.insert(colors, color.transition(wallpaper.config.backgroundColor, wallpaper.config.starColor, (i - 1) / (colorCount - 1))) + -- This case uses default OC palette, which is based & redpilled + if config.starColor >= 0xF0F0F0 then + colors = { + 0x0F0F0F, + 0x1E1E1E, + 0x2D2D2D, + 0x3C3C3C, + 0x4B4B4B, + 0x5A5A5A, + 0x696969, + 0x787878, + 0x878787, + 0x969696, + 0xA5A5A5, + 0xB4B4B4, + 0xC3C3C3, + 0xD2D2D2, + 0xE1E1E1, + 0xF0F0F0 + } + -- Otherwise palette will be auto-generated + else + colors = {} + + local colorCount = 16 + for i = 1, colorCount do + colors[i] = color.transition(config.backgroundColor, config.starColor, (i - 1) / (colorCount - 1)) + end end end @@ -54,142 +75,161 @@ end resetColors() resetStars() -function wallpaper.draw(object) - local hitsDeadline = computerUptime() >= deadline - - -- Spawning stars - while #stars < wallpaper.config.starAmount do - local rotationAngle = mathRandom(6265) / 1000 - - local targetX = mathCos(rotationAngle) * object.width * 0.75 + object.width / 2 - local targetY = mathSin(rotationAngle) * object.width * 0.375 + object.height / 2 - - local startWay = mathRandom() - table.insert(stars, { - targetX = targetX, - targetY = targetY, - startX = (targetX - object.width / 2) * startWay + object.width / 2, - startY = (targetY - object.height / 2) * startWay + object.height / 2, - way = wallpaper.config.initialWay, - speed = (mathRandom(25, 75) / 1000 + 1) * (wallpaper.config.speed / 100) - }) - end - - -- Clear background - screen.drawRectangle(object.x, object.y, object.width, object.height, wallpaper.config.backgroundColor, 0, " ") - - -- Drawing stars - local i = 1 - while i <= #stars do - local star = stars[i] - - local x = star.startX + (star.targetX - star.startX) * star.way - local y = star.startY + (star.targetY - star.startY) * star.way - - if x > object.width + 1 or x < 1 or y > object.height + 1 or y < 1 then - tableRemove(stars, i) - else - local xmod = x * 2; - xmod = (xmod - xmod % 1) % 2 - - local ymod = y * 4; ymod = (ymod - ymod % 1) % 4 - - local color = star.way * 4.0156862745098 * #colors - color = colors[color - color % 1 + 1] or colors[#colors] - - if star.way < 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 - end - else - if ymod < 2 then - char = braille9 - else - char = braille10 - end - end - - screen.set(x - x % 1, y - y % 1, wallpaper.config.backgroundColor, color, char) - i = i + 1 - - if hitsDeadline then - star.way = star.way * star.speed - end - end - end - - if hitsDeadline then - deadline = computerUptime() + wallpaper.config.delay - end -end - -function wallpaper.configure(layout) - layout:addChild(GUI.colorSelector(1, 1, 36, 3, wallpaper.config.backgroundColor, "Background color")).onColorSelected = function(_, object) - wallpaper.config.backgroundColor = object.color - saveConfig() - resetColors() - end - - layout:addChild(GUI.colorSelector(1, 1, 36, 3, wallpaper.config.starColor, "Star color")).onColorSelected = function(_, object) - wallpaper.config.starColor = object.color - saveConfig() - resetColors() - end - - local starAmountSlider = layout:addChild( - GUI.slider( - 1, 1, - 36, - 0x66DB80, - 0xE1E1E1, - 0xFFFFFF, - 0xA5A5A5, - 10, 200, - wallpaper.config.starAmount, - false, - "Star amount: " - ) - ) - - starAmountSlider.roundValues = true - starAmountSlider.onValueChanged = function(workspace, object) - wallpaper.config.starAmount = math.floor(object.value) - saveConfig() - -- resetStars() - end - - local starSpeedSlider = layout:addChild(GUI.slider( - 1, 1, - 36, - 0x66DB80, - 0xE1E1E1, - 0xFFFFFF, - 0xA5A5A5, - 100, 200, - wallpaper.config.speed, - false, - "Speed: ", - "%" - )) - - starSpeedSlider.roundValues = true - starSpeedSlider.onValueChanged = function(_, object) - wallpaper.config.speed = object.value - saveConfig() - resetStars() - end -end - -------------------------------------------------------------------------------- -return wallpaper \ No newline at end of file +return { + draw = function(object) + local hitsDeadline = computerUptime() >= deadline + + -- Spawning stars + while #stars < config.starAmount do + local rotationAngle = mathRandom(6265) / 1000 + + local targetX = mathCos(rotationAngle) * object.width * 0.75 + object.width / 2 + local targetY = mathSin(rotationAngle) * object.width * 0.375 + object.height / 2 + + table.insert(stars, { + targetX = targetX, + targetY = targetY, + startX = (targetX - object.width / 2) * config.offset + object.width / 2, + startY = (targetY - object.height / 2) * config.offset + object.height / 2, + way = 0.01, + speed = (mathRandom(25, 75) / 1000 + 1) * (config.speed / 100) + }) + end + + -- Clear background + screen.drawRectangle(object.x, object.y, object.width, object.height, config.backgroundColor, 0, " ") + + -- Drawing stars + local i = 1 + while i <= #stars do + local star = stars[i] + + local x = star.startX + (star.targetX - star.startX) * star.way + local y = star.startY + (star.targetY - star.startY) * star.way + + if x > object.width + 1 or x < 1 or y > object.height + 1 or y < 1 then + tableRemove(stars, i) + else + local xmod = x * 2; + xmod = (xmod - xmod % 1) % 2 + + local ymod = y * 4; ymod = (ymod - ymod % 1) % 4 + + local color = star.way * 4.0156862745098 * #colors + color = colors[color - color % 1 + 1] or colors[#colors] + + if star.way < 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 + end + 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.way = star.way * star.speed + end + end + end + + if hitsDeadline then + deadline = computerUptime() + config.delay + 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 + + layout:addChild(GUI.colorSelector(1, 1, 36, 3, config.starColor, "Star color")).onColorSelected = function(_, object) + config.starColor = object.color + resetColors() + saveConfig() + end + + local amountSlider = layout:addChild( + GUI.slider( + 1, 1, + 36, + 0x66DB80, + 0xE1E1E1, + 0xFFFFFF, + 0xA5A5A5, + 10, 200, + config.starAmount, + false, + "Star amount: " + ) + ) + + amountSlider.roundValues = true + amountSlider.onValueChanged = function() + config.starAmount = math.floor(amountSlider.value) + saveConfig() + end + + local speedSlider = layout:addChild(GUI.slider( + 1, 1, + 36, + 0x66DB80, + 0xE1E1E1, + 0xFFFFFF, + 0xA5A5A5, + 100, 200, + config.speed, + false, + "Speed: ", + "%" + )) + + speedSlider.roundValues = true + speedSlider.onValueChanged = function() + config.speed = speedSlider.value + resetStars() + saveConfig() + end + + local offsetSlider = layout:addChild(GUI.slider( + 1, 1, + 36, + 0x66DB80, + 0xE1E1E1, + 0xFFFFFF, + 0xA5A5A5, + 0, 100, + config.offset * 100, + false, + "Offset: ", + "%" + )) + + offsetSlider.roundValues = true + offsetSlider.onValueChanged = function() + config.offset = offsetSlider.value / 100 + resetStars() + saveConfig() + end + end +} \ No newline at end of file diff --git a/Wallpapers/Static picture.wlp/Main.lua b/Wallpapers/Static picture.wlp/Main.lua index 0a7e85da..5fa23891 100644 --- a/Wallpapers/Static picture.wlp/Main.lua +++ b/Wallpapers/Static picture.wlp/Main.lua @@ -1,30 +1,38 @@ local system = require("System") -local fs = require("Filesystem") +local filesystem = require("Filesystem") local screen = require("Screen") local GUI = require("GUI") local image = require("Image") -local wallpaper = {} - -------------------------------------------------------------------------------- -local configPath = fs.path(system.getCurrentScript()) .. "/" .. "Config.cfg" +local configPath = filesystem.path(system.getCurrentScript()) .. "Config.cfg" -local function loadPicture() - wallpaper.image, wallpaper.reason = image.load(wallpaper.config.path) +local config = { + path = filesystem.path(system.getCurrentScript()) .. "Pictures/Girl.pic" +} + +if filesystem.exists(configPath) then + for key, value in pairs(filesystem.readTable(configPath)) do + config[key] = value + end end local function saveConfig() - fs.writeTable(configPath, wallpaper.config) + filesystem.writeTable(configPath, config) end -if fs.exists(configPath) then - wallpaper.config = fs.readTable(configPath) -else - wallpaper.config = { - path = fs.path(system.getCurrentScript()) .. "Pictures/Girl.pic" - } +-------------------------------------------------------------------------------- +local picture, reason + +local function loadPicture() + picture, reason = image.load(config.path) +end + +local function setPicture(path) + config.path = path + loadPicture() saveConfig() end @@ -32,34 +40,24 @@ loadPicture() -------------------------------------------------------------------------------- -wallpaper.draw = function(object) - if wallpaper.image then - screen.drawImage(object.x, object.y, wallpaper.image) - else - screen.drawRectangle(object.x, object.y, object.width, object.height, 0x161616, 0x000000, " ") +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, " ") - local text = wallpaper.reason - screen.drawText(math.floor(object.x + object.width / 2 - #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, -wallpaper.configure = function(layout) - local wallpaperChooser = layout:addChild(GUI.filesystemChooser(1, 1, 36, 3, 0xE1E1E1, 0x696969, 0xD2D2D2, 0xA5A5A5, wallpaper.config.path, "Open", "Cancel", "Wallpaper path", "/")) - wallpaperChooser:setMode(GUI.IO_MODE_OPEN, GUI.IO_MODE_FILE) - wallpaperChooser:addExtensionFilter(".pic") - wallpaperChooser.onSubmit = function(path) - wallpaper.config.path = path - loadPicture() - saveConfig() - 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.setPicture = function(path) - wallpaper.config.path = path - saveConfig() - loadPicture() -end - --------------------------------------------------------------------------------- - -return wallpaper \ No newline at end of file + setPicture = setPicture +} \ No newline at end of file