Skip to content

Instantly share code, notes, and snippets.

-- Evaluate a string from a parametric input box and return a number.
-- Expressions are sandboxed with access to standard Lua math functions.
local parametricEval do
local envTemplate = {
abs = math.abs,
acos = math.acos,
asin = math.asin,
atan = math.atan,
atan2 = math.atan2,
ceil = math.ceil,
@Fraktality
Fraktality / guiPointToWorld.lua
Created September 27, 2018 01:02
SurfaceGui space -> world space
-- Vector3 guiPointToWorld(SurfaceGui gui, Vector2 point)
-- SurfaceGui space -> world space
local function guiPointToWorld(gui, point)
local adornee = assert(gui.Adornee)
local normalizedPoint = point/gui.AbsoluteSize
local dir = Vector3.FromNormalId(gui.Face)
local projY = math.abs(dir.z + dir.x)
local projZ = dir.x + math.abs(dir.y)
@Fraktality
Fraktality / Dumpster.lua
Last active April 9, 2024 00:22
Some people just want to watch the world burn
local Dumpster = {} do
Dumpster.__index = Dumpster
local finalizers = setmetatable(
{
["function"] = function(item)
return item()
end,
["Instance"] = game.Destroy,
["RBXScriptConnection"] = Instance.new("BindableEvent").Event:Connect(function() end).Disconnect,
local Spring = {} do
Spring.__index = Spring
local pi = math.pi
local exp = math.exp
local sin = math.sin
local cos = math.cos
local sqrt = math.sqrt
function Spring.new(dampingRatio, frequency, position)
local camera, cameraChanged
local viewport, viewportChanged
-- Challenge:
-- 1. Make `camera' always point to the the current or last known camera.
-- a. Problem: CurrentCamera can be nil.
-- b. Guarantee that `camera' is never nil.
-- 2. Make `viewport' always be the current actual size of the viewport.
-- a. Problem: ViewportSize can falsely report (1,1) before it gets fixed up by RenderPrepare.
-- b. Guarantee that `viewport' is never (1,1).
local function hostos()
local msvc
local posix
for _ = 1, 8 do
local k = math.random()
msvc = 0 == k*0x7FFF%1
posix = 0 == k*0x7FFFFFFF%1
if msvc ~= posix then
break
end
local ln = math.log
local abs = math.abs
local sin = math.sin
local cos = math.cos
local exp = math.exp
local acos = math.acos
local sqrt = math.sqrt
local function MulLn(w0, x0, y0, z0, w1, x1, y1, z1)
local w, x, y, z =
@Fraktality
Fraktality / LerpCIELUV.lua
Last active February 14, 2024 02:09
Perceptually uniform color interpolation
local LerpCIELUV do
-- Combines two colors in CIELUV space.
-- function<function<Color3 result>(float t)>(Color3 fromColor, Color3 toColor)
-- https://www.w3.org/Graphics/Color/srgb
local clamp = math.clamp
local C3 = Color3.new
local black = C3(0, 0, 0)
local fuzzy = {
NOT = function(x)
return 1 - x
end;
AND = function(x, y)
return x*y
end;
OR = function(x, y)
return x + y - x*y
end;