-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlib.lua
More file actions
72 lines (61 loc) · 2.85 KB
/
Copy pathlib.lua
File metadata and controls
72 lines (61 loc) · 2.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
--
-- dxCreateRoundedTexture
-- https://github.com/Pioruniasty/MTA_rounded_rectangle
-- https://forum.mtasa.com/viewtopic.php?f=108&t=96096
-- Author: Piorun
-- All credits of this function to him
--
function dxCreateRoundedTexture(text_width,text_height,radius)
assert(text_width,"Missing argument 'text_width' at dxCreateRoundedTexture")
assert(text_height,"Missing argument 'height' at dxCreateRoundedTexture")
assert(radius,"Missing argument 'radius' at dxCreateRoundedTexture")
if type(text_width) ~= "number" then outputDebugString("Bad argument @ 'dxCreateRoundedTexture' [Excepted number at argument 1, got " .. type(text_width) .. "]",2) return false end
if type(text_height) ~= "number" then outputDebugString("Bad argument @ 'dxCreateRoundedTexture' [Excepted number at argument 2, got " .. type(text_height) .. "]",2) return false end
if type(radius) ~= "number" then outputDebugString("Bad argument @ 'dxCreateRoundedTexture' [Excepted number at argument 3, got " .. type(radius) .. "]",2) return false end
if text_width < 0 then outputDebugString("text_width can't be less than 0",1) return false end
if text_height < 0 then outputDebugString("text_height can't be less than 0",1) return false end
if radius < 0 or radius > 100 then outputDebugString("Parameter 'radius' can't be between 0 and 100",1) return false end
local texture = DxTexture(text_width,text_height)
local pix = texture:getPixels()
radius = (radius * (text_height / 2)) / 100
for x=0,text_width do
for y=0,text_height do
if x >= radius and x <= text_width - radius then
dxSetPixelColor(pix,x,y,255,255,255,255)
end
if y >= radius and y <= text_height - radius then
dxSetPixelColor(pix,x,y,255,255,255,255)
end
if math.sqrt((x - radius)^2 + (y - radius)^2) < radius then
dxSetPixelColor(pix,x,y,255,255,255,255) -- lewy gorny rog
end
if math.sqrt((x - (text_width - radius))^2 + (y - radius)^2) < radius then
dxSetPixelColor(pix,x,y,255,255,255,255) -- prawy gorny rog
end
if math.sqrt((x - radius)^2 + (y - (text_height - radius))^2) < radius then
dxSetPixelColor(pix,x,y,255,255,255,255) -- lewy dolny rog
end
if math.sqrt((x - (text_width - radius))^2 + (y - (text_height - radius))^2) < radius then
dxSetPixelColor(pix,x,y,255,255,255,255) -- prawy dolny rog
end
end
end
texture:setPixels(pix)
return texture
end
-- outElastic | Got from https://github.com/EmmanuelOga/easing/blob/master/lib/easing.lua
local pi = math.pi
function outElastic(t, b, c, d, a, p)
if t == 0 then return b end
t = t / d
if t == 1 then return b + c end
if not p then p = d * 0.3 end
local s
if not a or a < math.abs(c) then
a = c
s = p / 4
else
s = p / (2 * pi) * math.asin(c/a)
end
return a * math.pow(2, -10 * t) * math.sin((t * d - s) * (2 * pi) / p) + c + b
end