Difference between revisions of "User:Hajo/test1"

From Minetest Wiki
Jump to navigation Jump to search
(→‎Lua: Prog2)
(→‎Lua: Prog3)
Line 36: Line 36:
 
   end
 
   end
 
  end
 
  end
 
====Wiki-Table====
 
{| class="wikitable"
 
|-
 
! Y \ X          !! x=-100 !! x=-50 !! x=0 !! X=50 !! x=100
 
|-
 
| '''y=-150''' : || -100,-150 || -50,-150 || 0,-150 || 50,-150 || 100,-150
 
|-
 
| '''y=  0''' : || -100, 0  || -50, 0  || 0, 0 || +50, 0 || 100, 0
 
|-
 
| '''y= 150''' : || -100, 150 || -50, 150 || 0, 150 || +50, 150 || +100, 150
 
|}
 
  
 
====Prog2====
 
====Prog2====
Line 64: Line 52:
 
  print("--")
 
  print("--")
  
====Output====
+
=====Output=====
 
  ===Table===
 
  ===Table===
 
  y=-150 : -150,-150 -100,-150  -50,-150    0,-150  50,-150  100,-150  150,-150  
 
  y=-150 : -150,-150 -100,-150  -50,-150    0,-150  50,-150  100,-150  150,-150  
Line 76: Line 64:
  
 
====Prog3====
 
====Prog3====
 +
Task:
 +
====Wiki-Table====
 +
{| class="wikitable"
 +
|-
 +
! Y \ X          !! x=-100 !! x=-50 !! x=0 !! X=50 !! x=100
 +
|-
 +
| '''y=-150''' : || -100,-150 || -50,-150 || 0,-150 || 50,-150 || 100,-150
 +
|-
 +
| '''y=  0''' : || -100, 0  || -50, 0  || 0, 0 || +50, 0 || 100, 0
 +
|-
 +
| '''y= 150''' : || -100, 150 || -50, 150 || 0, 150 || +50, 150 || +100, 150
 +
|}
 +
 +
====Code====
 +
n1,n2,step=-200, 200, 50
 +
n1,n2,step=-150, 150, 50
 +
print("{| class="wikitable")
 +
 +
print("###")
 +
 +
for y = n1,n2,step do
 +
  --print(y..": ")
 +
  s=string.format("| y=%4d : ",y)
 +
  for x = n1,n2,step do
 +
  s = s..string.format("|| %4d,%4d ", x,y)
 +
  --print(x,y)
 +
  end
 +
  print(s); s=""
 +
end
 +
print("|}")
 +
 +
=====Output=====
 
...
 
...

Revision as of 10:48, 14 February 2017

Table-test

10x10

__ AA BB CC DD EE FF GG HH II JJ
:: a1 b1 c1 d1 e1 f1 g1 h1 i1 j1
:: a2 b2 c2 d2 e2 f2 g2 h2 i2 j2
:: a3 b3 c3 d3 e3 f3 g3 h3 i3 j3
:: d4 d1 d1 d1 d1 d1 d1 d1 d1 d4
:: e5 e1 e1 e1 e1 e1 e1 e1 e1 e5
:: f6 f1 f1 f1 f1 f1 f1 f1 f1 f6
:: g7 g1 g1 g1 g1 g1 g1 g1 g1 g7
:: h8 h1 h1 h1 h1 h1 h1 h1 h1 h8
:: i9 i1 i1 i1 i1 i1 i1 i1 i1 i9
:: j0 j1 j1 j1 j1 j1 j1 j1 j1 j0

Lua

https://www.lua.org/cgi-bin/demo

Prog1

for y = -200, 200, 20 do
 for x = -200, 200, 20 do
   print(x,y)
 end
end

Prog2

n1,n2,step=-200, 200, 50
n1,n2,step=-150, 150, 50
print("===Table===")
for y = n1,n2,step do
 --print(y..": ")
 s=string.format("y=%4d : ",y)
 for x = n1,n2,step do
  s = s..string.format("%4d,%4d ", x,y)
  --print(x,y)
 end
 print(s); s=""
end
print("--")
Output
===Table===
y=-150 : -150,-150 -100,-150  -50,-150    0,-150   50,-150  100,-150  150,-150 
y=-100 : -150,-100 -100,-100  -50,-100    0,-100   50,-100  100,-100  150,-100 
y= -50 : -150, -50 -100, -50  -50, -50    0, -50   50, -50  100, -50  150, -50 
y=   0 : -150,   0 -100,   0  -50,   0    0,   0   50,   0  100,   0  150,   0 
y=  50 : -150,  50 -100,  50  -50,  50    0,  50   50,  50  100,  50  150,  50 
y= 100 : -150, 100 -100, 100  -50, 100    0, 100   50, 100  100, 100  150, 100 
y= 150 : -150, 150 -100, 150  -50, 150    0, 150   50, 150  100, 150  150, 150 
--

Prog3

Task:

Wiki-Table

Y \ X x=-100 x=-50 x=0 X=50 x=100
y=-150 : -100,-150 -50,-150 0,-150 50,-150 100,-150
y= 0 : -100, 0 -50, 0 0, 0 +50, 0 100, 0
y= 150 : -100, 150 -50, 150 0, 150 +50, 150 +100, 150

Code

n1,n2,step=-200, 200, 50
n1,n2,step=-150, 150, 50
print("{| class="wikitable")

print("###")

for y = n1,n2,step do
 --print(y..": ")
 s=string.format("| y=%4d : ",y)
 for x = n1,n2,step do
  s = s..string.format("|| %4d,%4d ", x,y)
  --print(x,y)
 end
 print(s); s=""
end
print("|}")
Output

...