Last active
July 11, 2025 13:49
-
-
Save increpare/ea0c175b87dc362b136b70f336413dbb to your computer and use it in GitHub Desktop.
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
-- Aseprite script for permuting the palette | |
-- permute_palette_colours.lua | |
-- by increpare - public domain | |
-- This script randomly permutes the color palette in the active indexed sprite. | |
-- Ensure there is an active sprite | |
local sprite = app.activeSprite | |
if not sprite then | |
app.alert("There is no active sprite.") | |
return | |
end | |
-- Only work in Indexed mode | |
if sprite.colorMode ~= ColorMode.INDEXED then | |
app.alert("The sprite must be in Indexed mode to permute its palette.") | |
return | |
end | |
local palette = sprite.palettes[1] | |
-- Read all palette colors into a table | |
local colors = {} | |
for i = 0, #palette - 1 do | |
table.insert(colors, palette:getColor(i)) | |
end | |
-- Seed random number generator | |
math.randomseed(os.time()) | |
-- Perform a Fisher-Yates shuffle on the colors table | |
for i = #colors, 2, -1 do | |
local j = math.random(i) | |
colors[i], colors[j] = colors[j], colors[i] | |
end | |
-- Apply the new shuffled palette colors in a transaction | |
app.transaction(function() | |
for i = 0, #palette - 1 do | |
palette:setColor(i, colors[i+1]) | |
end | |
app.refresh() | |
end) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment