From 4d882f7997102b9b3f34154367587a04faad1e11 Mon Sep 17 00:00:00 2001 From: AnErrupTion Date: Fri, 19 Jun 2026 20:18:45 +0200 Subject: [PATCH] Fix example.lua doc + add ly-community in README Signed-off-by: AnErrupTion --- readme.md | 4 +++ res/example.lua | 96 ++++++++++++++++++++++++------------------------- 2 files changed, 52 insertions(+), 48 deletions(-) diff --git a/readme.md b/readme.md index 620929e..d5ea1fc 100644 --- a/readme.md +++ b/readme.md @@ -56,6 +56,10 @@ Join us on Matrix over at [#ly-dm:matrix.org](https://matrix.to/#/#ly-dm:matrix. [![Packaging status](https://repology.org/badge/vertical-allrepos/ly-display-manager.svg?exclude_unsupported=1)](https://repology.org/project/ly-display-manager/versions) +## Custom animations & user scripts + +If you want to pimp your Ly installation even further than what the traditional configuration file allows you to, a [community repository](https://codeberg.org/fairyglade/ly-community) exists containing custom animations & scripts, so go check it out! + ## Support Every environment that works on other login managers also should work on Ly. diff --git a/res/example.lua b/res/example.lua index 7309da6..81f9bc9 100644 --- a/res/example.lua +++ b/res/example.lua @@ -6,13 +6,13 @@ -- { -- height: number -- The height of the terminal -- width: number -- The width of the terminal --- putCell(byte, fg, bg, x, y) -- Draw a cell. --- All arguments to this function are integers, and +-- putCell(byte, fg, bg, x, y) -- Draw a cell. +-- All arguments to this function are integers, and -- must be in the unsigned 32-bit integer range: 0 to 2^32-1. -- If an argument cannot be converted to this range, it will throw -- an error. -- --- For reference, the XY coordinates (0,0) draw a cell on the top-left +-- For reference, the XY coordinates (0,0) draw a cell on the top-left -- of the terminal, where the positive-X axis moves right and the -- positive-Y axis moves down. -- @@ -22,7 +22,7 @@ -- -- For the byte argument, you may use string.byte to fill this argument. -- --- putCell(byte, fg, bg, x, y, w, h) -- Draw a rectangle. +-- putRect(byte, fg, bg, x, y, w, h) -- Draw a rectangle. -- Arguments are the same as putCell except for w and h, which are also -- unsigned integers. The rectangle will be drawn from the top-left, with -- argument w extending it to the right and argument h extending downwards. @@ -45,14 +45,14 @@ -- table -- -- The std libraries io and debug are NOT included. --- +-- -- ]] -- You should probably copy FPS and FPS_COUNT into any future LuaJIT animations -- you create. local FPS_COUNT = 40 local function FPS() - return (1/FPS_COUNT)*1000000 + return (1 / FPS_COUNT) * 1000000 end @@ -64,56 +64,56 @@ local SQUARE_COUNT = 25 local squares = {} for i = 1, SQUARE_COUNT do - local vx = 1 - local vy = 1 - if math.random(1, 2) == 2 then vx = -vx end - if math.random(1, 2) == 2 then vy = -vy end - squares[#squares+1] = { - x = math.random(1, ly.width - SQUARE_WIDTH), - y = math.random(1, ly.height - SQUARE_HEIGHT), - vx = vx, - vy = vy, - color = math.random(0xFFFFFF) - } + local vx = 1 + local vy = 1 + if math.random(1, 2) == 2 then vx = -vx end + if math.random(1, 2) == 2 then vy = -vy end + squares[#squares + 1] = { + x = math.random(1, ly.width - SQUARE_WIDTH), + y = math.random(1, ly.height - SQUARE_HEIGHT), + vx = vx, + vy = vy, + color = math.random(0xFFFFFF) + } end local timer = ly.clock() local perf = ly.clock() function draw() - -- Rather than progressing the animation by frame, do it based on - -- seconds, via ly.clock(). In this timeframe, you can update the animation - -- state. - -- DO NOT DRAW CELLS IN THIS TIMEFRAME. You will get flickering. + -- Rather than progressing the animation by frame, do it based on + -- seconds, via ly.clock(). In this timeframe, you can update the animation + -- state. + -- DO NOT DRAW CELLS IN THIS TIMEFRAME. You will get flickering. - -- if this check passes, we can update the animation - if timer + FPS() < ly.clock() then - for i, v in ipairs(squares) do - v.x = v.x + v.vx - v.y = v.y + v.vy - if v.x == 0 then - v.vx = 1; v.color = math.random(0xFFFFFF) - end - if v.x + SQUARE_WIDTH >= ly.width-1 then - v.vx = -1; v.color = math.random(0xFFFFFF) - end - if v.y == 0 then - v.vy = 1; v.color = math.random(0xFFFFFF) - end - if v.y + SQUARE_HEIGHT >= ly.height-1 then - v.vy = -1; v.color = math.random(0xFFFFFF) - end - end - timer = ly.clock() - end + -- if this check passes, we can update the animation + if timer + FPS() < ly.clock() then + for i, v in ipairs(squares) do + v.x = v.x + v.vx + v.y = v.y + v.vy + if v.x == 0 then + v.vx = 1; v.color = math.random(0xFFFFFF) + end + if v.x + SQUARE_WIDTH >= ly.width - 1 then + v.vx = -1; v.color = math.random(0xFFFFFF) + end + if v.y == 0 then + v.vy = 1; v.color = math.random(0xFFFFFF) + end + if v.y + SQUARE_HEIGHT >= ly.height - 1 then + v.vy = -1; v.color = math.random(0xFFFFFF) + end + end + timer = ly.clock() + end - for i, v in ipairs(squares) do - ly.putRect(string.byte(' '), 0, v.color, v.x, v.y, SQUARE_WIDTH, SQUARE_HEIGHT) - end + for i, v in ipairs(squares) do + ly.putRect(string.byte(' '), 0, v.color, v.x, v.y, SQUARE_WIDTH, SQUARE_HEIGHT) + end - local new_perf = ly.clock() - local str = "FT: "..((new_perf - perf) / 1000).."ms" - ly.putLabel(str , 0x00FFFFFF, 0, (ly.width/2) - (string.len(str)/2), ly.height-1) - perf = new_perf + local new_perf = ly.clock() + local str = "FT: " .. ((new_perf - perf) / 1000) .. "ms" + ly.putLabel(str, 0x00FFFFFF, 0, (ly.width / 2) - (string.len(str) / 2), ly.height - 1) + perf = new_perf end