mirror of
https://github.com/IgorTimofeev/MineOS.git
synced 2025-12-24 04:52:48 +01:00
I was testing a copy of this in Python, and noticed that bStep and sStep appear to be swapped, as bStep changed b up by 1/height, but the loop is by width, leading b to exceed 1 if the height is smaller than width. This is only apparent if the width and height of the new debug texture is not the same. And then I also noticed that the whole "invert blackSquare in two places" part could be simplified to if x + y is an odd number for each pixel in the texture. I don't claim to know the specifics of how to make lua faster, and this may be slower, so whatever is better.
42 lines
878 B
Lua
Executable File
42 lines
878 B
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}
|
|
|
|
for y = 1, height do
|
|
texture[y] = {}
|
|
for x = 1, width do
|
|
texture[y][x] = not (x+y)%2 and 0x0 or color.HSBToInteger(h, y/height, x/width)
|
|
end
|
|
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
|
|
|