Posted 12 December 2015 - 08:47 PM
I'm creating a 3D Cube API, by that I mean it puts a texture into an easily rendered table, then it crops part of that table out to show a square at an "angle" then what it does is put a filter over the screen, where if the rotation is big, then the screen gets exponentially stretched, to add 3D effect. How would I go about the effect? The code is:
os.loadAPI("colorapi")
rotation = 0
length = 3
cube = {
{
"7777",
"7777",
"7777",
"7777"
},
{
"aaaa",
"aaaa",
"aaaa",
"aaaa"
},
{
"3333",
"3333",
"3333",
"3333"
},
{
"bbbb",
"bbbb",
"bbbb",
"bbbb"
}
}
function Pixel(str)
for i=1,#str do
term.setBackgroundColor(colorapi.codeToNum(str:sub(i,i)))
write(" ")
end
write("\n")
end
function drawObject(sides,rotation,length)
int = #sides
draw = ""
lines = {}
for create=1,#sides[1] do
lines[#lines + 1] = ""
end
--Pan effect... ??
for a=1,int do
side = sides[a]
for b=1,#side do
lines[b] = lines[b]..sides[a][b]
end
end
for i=1,#lines do
term.setTextColor(colorapi.codeToNum(lines[i]:sub(i,i))) --ColorAPI aids with translating color codes, nothing special.
Pixel(lines[i]:sub(rotation,rotation + length)) --Custom print function, just turns paint color codes into a colored pixel, pixel by pixel.
end
return lines
end
while true do
local event, key = os.pullEvent("key")
if(key == keys.right and rotation < 13) then
rotation = rotation + 1
term.setBackgroundColor(colors.black)
term.clear()
term.setCursorPos(1,1)
drawObject(cube,rotation,length)
elseif(key == keys.left and rotation > 1) then
rotation = rotation - 1
term.setBackgroundColor(colors.black)
term.clear()
term.setCursorPos(1,1)
drawObject(cube,rotation,length)
end
end