Created
April 18, 2021 15:24
-
-
Save lparkermg/896763b020c40537081416e1b5edbc8c to your computer and use it in GitHub Desktop.
Aseprite Dithering on currently selected layer.
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
-- Dithering (In Aseprite) | |
-- Dithers the selected layer using a basic algo. | |
-- By Luke Parker (https://twitter.com/MrLParker) | |
if app.apiVersion < 1 then | |
return app.alert("This script requires Aseprite v1.2.10+") | |
end | |
local cel = app.activeCel | |
if not cel then | |
return app.alert("There is no active image") | |
end | |
-- Currently we don't need to select a layer as the script runs on the selected layer | |
-- though that may change in future versions of aseprite. | |
-- Grab the image function. | |
local img = cel.image | |
-- Reference the rgba functions from app.pixelColor | |
local rgba = app.pixelColor.rgba | |
local rgbaR = app.pixelColor.rgbaR | |
local rgbaG = app.pixelColor.rgbaG | |
local rgbaB = app.pixelColor.rgbaB | |
-- Loop through all pixels keeping the colour, but applying 0 to alpha. | |
for it in img:pixels() do | |
if it.x % 1 == 0 and it.y % 2 == 0 then | |
it(rgba( | |
rgbaR(it()), | |
rgbaG(it()), | |
rgbaB(it()), | |
0)) | |
end | |
if it.x % 2 == 0 and it.y % 1 == 0 then | |
it(rgba( | |
rgbaR(it()), | |
rgbaG(it()), | |
rgbaB(it()), | |
0)) | |
end | |
end | |
-- Put updated image back. | |
cel.image = img | |
-- Don't need to refresh the image but it's better to be safe. | |
app.refresh() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment