CoolCat467 8878f095fb
Basically only imortant from #408
Leave blackSqare and step counters alone, but make it be able to handle textures where width and height are not the same so no more invalid color error.
For example, with original code, materials.newDebugTexture(8, 16, 40) has odd color because when it gets to pixel (1, 9), color value is (15, 9, -2) in RGB. After color.RGBToInteger inside color.HSBToInteger, integer value for color would be -2. The reason it's not apparent is likely from optimization of colors from palette, turning -2 into 65535 or (0, 255, 255), instead of an invalid color.
This has the effect of screwing up the colors for the image
If steps are swapped as this proposes, this issue is fixed and the colors wouldn't go crazy.
2022-01-08 09:12:03 -06:00

52 lines
1.1 KiB
Lua
Executable File

local color = require("Color")
local materials = {}
------------------------------------------------------------------------------------------------------------------------
materials.types = {
textured = 1,
solid = 2,
}
function materials.newDebugTexture(width, height, h)
local texture = {width = width, height = height}
local bStep = 1 / width
local sStep = 1 / height
local s, b = 0, 0
local blackSquare = false
for y = 1, height do
texture[y] = {}
for x = 1, width do
texture[y][x] = blackSquare == true and 0x0 or color.HSBToInteger(h, s, b)
blackSquare = not blackSquare
b = b + bStep
end
b = 0
s = s + sStep
blackSquare = not blackSquare
end
return texture
end
function materials.newSolidMaterial(color)
return {
type = materials.types.solid,
color = color
}
end
function materials.newTexturedMaterial(texture)
return {
type = materials.types.textured,
texture = texture
}
end
------------------------------------------------------------------------------------------------------------------------
return materials