0% found this document useful (0 votes)
22 views4 pages

Message

The document defines functions for creating and updating tweens in Lua. It includes easing functions for linear, quadratic, and bounce animations. Tweens can be created and assigned properties to animate with an easing function over time. The tweens are updated by calling Tween.UpdateAll with the elapsed time.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views4 pages

Message

The document defines functions for creating and updating tweens in Lua. It includes easing functions for linear, quadratic, and bounce animations. Tweens can be created and assigned properties to animate with an easing function over time. The tweens are updated by calling Tween.UpdateAll with the elapsed time.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 4

local ui = require "ui"

local Tweens = {}

local Easings = {}

function Easings.Linear(t)
return t
end

function Easings.InQuad(t)
return t * t
end

function Easings.OutQuad(t)
return t * (2 - t)
end

function Easings.InOutQuad(t)
if t < 0.5 then
return 2 * t * t
else
return -1 + (4 - 2 * t) * t
end
end
function Easings.OutBounce(t)
if t < 1 / 2.75 then
return 7.5625 * t * t
elseif t < 2 / 2.75 then
t = t - 1.5 / 2.75
return 7.5625 * t * t + 0.75
elseif t < 2.5 / 2.75 then
t = t - 2.25 / 2.75
return 7.5625 * t * t + 0.9375
else
t = t - 2.625 / 2.75
return 7.5625 * t * t + 0.984375
end
end

local Tween = {
Easings = Easings
}

function Tween.new(Object, HowLong, Properties, Callback, Easing)


if Tweens[Object] then
return Tweens[Object]
end

local newTween = setmetatable({


Object = Object,
HowLong = HowLong,
Properties = Properties,
ElapsedTime = 0,
Callback = Callback,
Playing = false,
Easing = Easing,
}, {
__index = Tween
})

Tweens[Object] = newTween
return newTween
end

function Tween:Play()
self.ElapsedTime = 0
self.Playing = true
end

local function updateTweens(deltaTime)


for _, tween in pairs(Tweens) do
if tween.Playing then
tween.ElapsedTime = tween.ElapsedTime + deltaTime
local progress = math.min(tween.ElapsedTime / tween.HowLong, 1)
local easedProgress = tween.Easing(progress)

for property, endValue in pairs(tween.Properties) do


local startValue = tween.Object[property]
local newValue = startValue + (endValue - startValue) *
easedProgress
tween.Object[property] = newValue
end

if progress >= 1 then


tween.Playing = false
if tween.Callback then
tween.Callback(tween.Object)
end
Tweens[tween.Object] = nil
end
end
end
end

function Tween.UpdateAll(deltaTime)
updateTweens(deltaTime)
end

return Tween

-- create a simple window


local win = ui.Window("GugaOS_Taskbar", "raw")
local start_img = ui.Picture(win, "D:\\start_icon2.png", 10, 0)
local username = sys.registry.read("HKEY_CURRENT_USER", "Volatile Environment",
"USERNAME")
start_img.height = 50
start_img.width = 52

function start_img:onHover()
start_img:load("D:\\start_icon.png")
end

function start_img:onClick()
start_img:load("D:\\start_icon2.png")
sleep(50)
start_img:load("D:\\start_icon.png")
end
function start_img:onLeave()
start_img:load("D:\\start_icon2.png")
end

local screen_width = win.monitor.width


local screen_height = win.monitor.height
timetext = sys.Datetime():format(nil, "HH:mm:ss")

local time = ui.Label(win, timetext)


win.bgcolor = 0xff8800
win.width = screen_width + 20
win.height = 50
win.y = screen_height - 150
time.x = win.width - 80
time.y = 15
time.font = "Bahnschrift"
time.fontstyle = { bold = true }
time.fontsize = 11
win.x = win.x - 10

-- shows the Window


win:show()

local ui = require "ui"


local Window = ui.Window(rtbuilder, "Window", rtbuilder and "dialog" or "raw", 350,
515)
Window.name = 'Window'
Window.type = 'Window'
Window:loadicon()
Window.icon = nil
Window.height = "515"
Window.enabled = true
Window.fontstyle = { ['strike'] = false,['underline'] = false,['heavy'] = false,
['bold'] = false,['italic'] = false,['thin'] = false }
Window.traytooltip = ''
Window.cursor = 'arrow'
Window.font = 'Segoe UI'
Window.title = 'Window'
Window.topmost = false
Window.x = win.x
Window.bgcolor = "16746496"
Window.transparency = "255"
Window.fontsize = "9"
Window.align = nil
Window.menu = nil
Window.fullscreen = false
Window.width = "350"
Window.y = win.y
Window.style = 'raw'
Window.visible = true

local Picture1 = ui.Picture(Window, "D:\\shutdown.png", 305, 15, 25, 25)


Picture1.name = 'Picture1'
Picture1.type = 'Picture'
Picture1.height = "35"
Picture1.enabled = true
Picture1.x = "305"
Picture1.align = nil
Picture1.cursor = 'arrow'
Picture1.tooltip = ''
Picture1.y = "10"
Picture1.width = "35"
Picture1.visible = true

local Welcome = ui.Label(Window, [[Welcome, user!]], 15, 15, 112, 19)


Welcome.name = 'Welcome, user!'
Welcome.type = 'Label'
Welcome.height = "19"
Welcome.enabled = true
Welcome.fontstyle = { ['strike'] = false,['underline'] = false,['heavy'] = false,
['bold'] = true,['italic'] = false,['thin'] = false }
Welcome.y = "15"
Welcome.tooltip = ''
Welcome.width = "112"
Welcome.cursor = 'arrow'
Welcome.font = 'Bahnschrift'
Welcome.x = "15"
Welcome.bgcolor = "16746496"
Welcome.fontsize = "12"
Welcome.textalign = [[left]]
Welcome.fgcolor = "16777215"
Welcome.text = "Welcome, "..username
Welcome.align = nil
Welcome.visible = true

local Picture2 = ui.Picture(Window, "D:\\exit.png", 270, 15, 25, 25)


Picture2.name = 'Picture2'
Picture2.type = 'Picture'
Picture2.height = "35"
Picture2.enabled = true
Picture2.x = "270"
Picture2.align = nil
Picture2.cursor = 'arrow'
Picture2.tooltip = ''
Picture2.y = "10"
Picture2.width = "35"
Picture2.visible = true

function Picture2:onHover()
Picture2:load("D:\\exit2.png")
end

function Picture2:onLeave()
Picture2:load("D:\\exit.png")
end

function Picture1:onHover()
Picture1:load("D:\\shutdown2.png")
end

function Picture1:onLeave()
Picture1:load("D:\\shutdown.png")
end

repeat
ui.update()
until win.visible == false

You might also like