Create blocks of tests in image.lua

This commit is contained in:
David Capello 2018-09-03 14:28:31 -03:00
parent e7a4cce508
commit 017a7499d2

View File

@ -3,25 +3,31 @@
-- This file is released under the terms of the MIT license.
-- Read LICENSE.txt for more information.
local pc = app.pixelColor
local a = Image(32, 64)
assert(a.width == 32)
assert(a.height == 64)
assert(a.colorMode == ColorMode.RGB) -- RGB by default
do
local b = Image(32, 64, ColorMode.INDEXED)
assert(b.width == 32)
assert(b.height == 64)
assert(b.colorMode == ColorMode.INDEXED)
end
-- Get/put RGBA pixels
local pc = app.pixelColor
do
for y=0,a.height-1 do
for x=0,a.width-1 do
a:putPixel(x, y, pc.rgba(x, y, x+y, x-y))
end
end
end
-- Clone
do
local c = a:clone()
assert(c.width == 32)
assert(c.height == 64)
@ -33,9 +39,10 @@ for y=0,c.height-1 do
assert(c:getPixel(x, y) == pc.rgba(x, y, x+y, x-y))
end
end
end
-- Patch
local pc = app.pixelColor
do
local spr = Sprite(256, 256)
local image = app.site.image
local copy = image:clone()
@ -51,3 +58,4 @@ assert(image:getPixel(255, 255) == pc.rgba(0, 0, 0, 255))
app.undo()
assert(image:getPixel(0, 0) == pc.rgba(0, 0, 0, 0))
assert(image:getPixel(255, 255) == pc.rgba(0, 0, 0, 0))
end