Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,22 @@
function Allocate_Bitmap( width, height )
local bitmap = {}
for i = 1, width do
bitmap[i] = {}
for j = 1, height do
bitmap[i][j] = {}
end
end
return bitmap
end
function Fill_Bitmap( bitmap, color )
for i = 1, #bitmap do
for j = 1, #bitmap[1] do
bitmap[i][j] = color
end
end
end
function Get_Pixel( bitmap, x, y )
return bitmap[x][y]
end

View file

@ -0,0 +1,4 @@
bitmap = Allocate_Bitmap( 100, 50 )
Fill_Bitmap( bitmap, { 15, 200, 80 } )
pixel = Get_Pixel( bitmap, 20, 25 )
print( pixel[1], pixel[2], pixel[3] )

View file

@ -0,0 +1,39 @@
local Bitmap = {
new = function(self, width, height)
local instance = setmetatable({ width=width, height=height }, self)
instance:alloc()
return instance
end,
alloc = function(self)
self.pixels = {}
for y = 1, self.height do
self.pixels[y] = {}
for x = 1, self.width do
self.pixels[y][x] = 0x00000000
end
end
end,
clear = function(self, c)
for y = 1, self.height do
for x = 1, self.width do
self.pixels[y][x] = c or 0x00000000
end
end
end,
get = function(self, x, y)
x, y = math.floor(x+1), math.floor(y+1) -- given 0-based indices, use 1-based indices
if ((x>=1) and (x<=self.width) and (y>=1) and (y<=self.height)) then
return self.pixels[y][x]
else
return nil
end
end,
set = function(self, x, y, c)
x, y = math.floor(x+1), math.floor(y+1) -- given 0-based indices, use 1-based indices
if ((x>=1) and (x<=self.width) and (y>=1) and (y<=self.height)) then
self.pixels[y][x] = c or 0x00000000
end
end,
}
Bitmap.__index = Bitmap
setmetatable(Bitmap, { __call = function (t, ...) return t:new(...) end })

View file

@ -0,0 +1,28 @@
local bitmap = Bitmap(32,32)
-- default pixel representation is 32-bit packed ARGB on [0,255]
bitmap:clear(0xFFFF0000) -- fill with red
bitmap:set(1, 1, 0xFF00FF00) -- one green pixel
bitmap:set(2, 2, 0xFF0000FF) -- one blue pixel
print(string.format("pixel at 0,0 = %x", bitmap:get(0,0)))
print(string.format("pixel at 1,1 = %x", bitmap:get(1,1)))
print(string.format("pixel at 2,2 = %x", bitmap:get(2,2)))
-- but note that pixel representation is agnostic..
-- (it's just a wrapper around a 2d-array of any valid type)
-- want to switch to RGB-tuple on [0,1]??
bitmap:clear({1,0,0}) -- fill with red
bitmap:set(1, 1, {0,1,0}) -- one green pixel
bitmap:set(2, 2, {0,0,1}) -- one blue pixel
print(string.format("pixel at 0,0 = %s", table.concat(bitmap:get(0,0),", ")))
print(string.format("pixel at 1,1 = %s", table.concat(bitmap:get(1,1),", ")))
print(string.format("pixel at 2,2 = %s", table.concat(bitmap:get(2,2),", ")))
-- or strings??
bitmap:clear("red") -- fill with red
bitmap:set(1, 1, "green") -- one green pixel
bitmap:set(2, 2, "blue") -- one blue pixel
print(string.format("pixel at 0,0 = %s", bitmap:get(0,0)))
print(string.format("pixel at 1,1 = %s", bitmap:get(1,1)))
print(string.format("pixel at 2,2 = %s", bitmap:get(2,2)))