-
Notifications
You must be signed in to change notification settings - Fork 2
/
isoblock.lua
61 lines (60 loc) · 1.87 KB
/
isoblock.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
-- improved by LostAstronaut.com
function init()
setName("IsoBlock")
setDesc("Isometric Block Simulation")
setSize(100, 24+64+8+8+18+7+4+18)
addOutput(24+32)
addInput("z",24+8+8+8)
addInput("x",24+8+8+8+8)
addInput("y",24+8+8+8+8+8)
addInput("fi",24+8+8+8+8+8+8+8)
addParameter("Height", "Height of the block", 24+64+8+8, 0, 0, 100,true)
addParameter("Width", "Width of the block", 24+64+8+8+18, 100, 0, 100,true)
addParameter("Depth", "Depth of the block", 24+64+8+8+18+18, 100, 0, 100,true)
end
function apply()
tileSize = getTileSize()
Height = getValue(4,0,0,1)/100
sizeHeight = Height*(tileSize/2-1)
Width = getValue(5,0,0,1)/100
sizeWidth = Width*tileSize
Depth = getValue(6,0,0,1)/100
sizeDepth = Depth*tileSize
-- Fill background
for i=0, tileSize*tileSize-1 do
x = i%tileSize
y = math.floor(i/tileSize)
r,g,b=getValue(3,x,y,1)
setPixel(0,x,y, r,g,b);
end
-- Top side of cube (Width x Depth)
for i=0, tileSize*tileSize-1 do
x = i%tileSize
y = math.floor(i/tileSize)
if (x >= tileSize-sizeWidth and y > tileSize-sizeDepth) then
r,g,b = getValue(0,x,y,1)
s = tileSize/2 - 0.5
setPixel(0, s+((x-y)/2), s+math.ceil((x+y)/4)-sizeHeight, r, g, b )
end
end
-- Right side of cube (Depth x Height)
for i=0, tileSize*tileSize-1 do
x = i%tileSize
y = math.floor(i/tileSize)
if (x <= sizeDepth and y < sizeHeight*2-1) then
r,g,b = getValue(1,x,y,1)
s = tileSize/2 - 0.5
setPixel(0, s+(x/2), ((y/2)-math.ceil(x/4))-sizeHeight, r, g, b )
end
end
-- Left side of cube (Width x Height)
for i=0, tileSize*tileSize-1 do
x = i%tileSize
y = math.floor(i/tileSize)
if (x <= sizeWidth and y < sizeHeight*2-1) then
r,g,b = getValue(2,x,y,1)
s = tileSize/2 - 0.5
setPixel(0, s-(x/2), ((y/2)-math.ceil(x/4))-sizeHeight, r, g, b )
end
end
end