Created
May 2, 2022 16:20
-
-
Save japhib/8874b9224b72fe88dc434c28e6d8d760 to your computer and use it in GitHub Desktop.
Aseprite script to generate a 2d light sprite for Godot
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- 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 |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Result:
