Skip to content

Instantly share code, notes, and snippets.

@japhib
Created May 2, 2022 16:20
Show Gist options
  • Select an option

  • Save japhib/8874b9224b72fe88dc434c28e6d8d760 to your computer and use it in GitHub Desktop.

Select an option

Save japhib/8874b9224b72fe88dc434c28e6d8d760 to your computer and use it in GitHub Desktop.
Aseprite script to generate a 2d light sprite for Godot
-- Generate a 2d light for Godot
local rgba = app.pixelColor.rgba
local cel = app.activeCel
if not cel then
return app.alert("There is no active image")
end
local bounds = cel.bounds
local width = bounds.width
local height = bounds.height
local img = cel.image
if img.colorMode ~= ColorMode.RGB then
return app.alert("Active image must be RGB color mode")
end
for it in img:pixels() do
local x = it.x
local y = it.y
local dx = math.abs(x - width/2)
local dy = math.abs(y - height/2)
local distanceFromCenter = math.sqrt(dx * dx + dy * dy)
local maxDistance = math.min(width/2, height/2)
local brightness = (1-distanceFromCenter/maxDistance)
if distanceFromCenter > maxDistance then
brightness = 0
end
brightness = math.sqrt(brightness)
brightness = brightness * 255
local color = rgba(255,255,255,brightness)
it(color)
end
@japhib
Copy link
Author

japhib commented May 2, 2022

Result:
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment