Difference between revisions of "User:Hajo/test2"
Jump to navigation
Jump to search
(x,y,z) |
(http://ideone.com/nbSPkn) |
||
(2 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
==Table-test2== | ==Table-test2== | ||
− | + | x,y,z | |
===Lua - Online-IDEs=== | ===Lua - Online-IDEs=== | ||
Line 10: | Line 10: | ||
====Prog1==== | ====Prog1==== | ||
+ | http://ideone.com/1fhw6j | ||
+ | |||
<source lang="lua"> | <source lang="lua"> | ||
+ | -- table x,y,z | ||
n=1 | n=1 | ||
y=0 | y=0 | ||
for x = -n, n do | for x = -n, n do | ||
for z = -n, n do | for z = -n, n do | ||
− | print(x,y,z) | + | --print(x,y,z) |
+ | print( string.format("%3d %2d %2d", x,y,z) ) | ||
end | end | ||
end | end | ||
Line 21: | Line 25: | ||
=====Output===== | =====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==== | ||
+ | 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