Difference between revisions of "User:Hajo/test2"
Jump to navigation
Jump to search
(http://ideone.com/nbSPkn) |
|||
Line 36: | Line 36: | ||
====Prog2==== | ====Prog2==== | ||
− | .. | + | http://ideone.com/nbSPkn |
+ | |||
+ | <source lang="lua"> | ||
+ | -- table x,y,z --> w | ||
+ | function w(x,y,z) | ||
+ | c="black" | ||
+ | if z<0 then c="red" end | ||
+ | return c | ||
+ | end | ||
+ | |||
+ | n=1 | ||
+ | y=0 | ||
+ | for x = -n, n do | ||
+ | for z = -n, n do | ||
+ | c=w(x,y,z) | ||
+ | --print(x,y,z, c) | ||
+ | print( string.format("%3d %2d %2d %s", x,y,z, c) ) | ||
+ | end | ||
+ | end | ||
+ | </source> | ||
+ | |||
+ | =====Output===== | ||
+ | -1 0 -1 red | ||
+ | -1 0 0 black | ||
+ | -1 0 1 black | ||
+ | 0 0 -1 red | ||
+ | 0 0 0 black | ||
+ | 0 0 1 black | ||
+ | 1 0 -1 red | ||
+ | 1 0 0 black | ||
+ | 1 0 1 black |
Latest revision as of 06:12, 11 March 2017
Table-test2
x,y,z
Lua - Online-IDEs
Example - Formatting a table:
Prog1
-- table x,y,z
n=1
y=0
for x = -n, n do
for z = -n, n do
--print(x,y,z)
print( string.format("%3d %2d %2d", x,y,z) )
end
end
Output
-1 0 -1 -1 0 0 -1 0 1 0 0 -1 0 0 0 0 0 1 1 0 -1 1 0 0 1 0 1
Prog2
-- table x,y,z --> w
function w(x,y,z)
c="black"
if z<0 then c="red" end
return c
end
n=1
y=0
for x = -n, n do
for z = -n, n do
c=w(x,y,z)
--print(x,y,z, c)
print( string.format("%3d %2d %2d %s", x,y,z, c) )
end
end
Output
-1 0 -1 red -1 0 0 black -1 0 1 black 0 0 -1 red 0 0 0 black 0 0 1 black 1 0 -1 red 1 0 0 black 1 0 1 black