File tree Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change
1
+ ---- ------------------------------------------------------------------
2
+ -- Randomize colors in the palette.
3
+ ---- ------------------------------------------------------------------
4
+
5
+ local spr = app .activeSprite
6
+ if not spr then
7
+ return app .alert (" There is no active sprite" )
8
+ end
9
+
10
+ -- Each Palette:setColor() call will be grouped in one undoable
11
+ -- transaction. In this way the Edit > Undo History will contain only
12
+ -- one item that can be undone.
13
+ app .transaction (
14
+ function ()
15
+ math.randomseed (os.time ())
16
+ local pal = spr .palettes [1 ]
17
+ for i = 0 ,# pal - 1 do
18
+ -- Here we change each color of the palette with random RGB
19
+ -- values from 0-255 for each Red, Green, Blue component.
20
+ pal :setColor (i , Color { r = math.random (256 )- 1 ,
21
+ g = math.random (256 )- 1 ,
22
+ b = math.random (256 )- 1 })
23
+ end
24
+ end )
25
+
26
+ -- Here we redraw the screen to show the new palette, in a future this
27
+ -- shouldn't be necessary, but just in case...
28
+ app .refresh ()
You can’t perform that action at this time.
0 commit comments