diff options
Diffstat (limited to 'docs/examples/spiral_snake.lua.html')
-rw-r--r-- | docs/examples/spiral_snake.lua.html | 152 |
1 files changed, 152 insertions, 0 deletions
diff --git a/docs/examples/spiral_snake.lua.html b/docs/examples/spiral_snake.lua.html new file mode 100644 index 0000000..7ebb838 --- /dev/null +++ b/docs/examples/spiral_snake.lua.html | |||
@@ -0,0 +1,152 @@ | |||
1 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" | ||
2 | "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> | ||
3 | <html> | ||
4 | <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> | ||
5 | <head> | ||
6 | <title>Lua-System docs</title> | ||
7 | <link rel="stylesheet" href="../ldoc.css" type="text/css" /> | ||
8 | </head> | ||
9 | <body> | ||
10 | |||
11 | <div id="container"> | ||
12 | |||
13 | <div id="product"> | ||
14 | <div id="product_logo"></div> | ||
15 | <div id="product_name"><big><b></b></big></div> | ||
16 | <div id="product_description"></div> | ||
17 | </div> <!-- id="product" --> | ||
18 | |||
19 | |||
20 | <div id="main"> | ||
21 | |||
22 | |||
23 | <!-- Menu --> | ||
24 | |||
25 | <div id="navigation"> | ||
26 | <br/> | ||
27 | <h1>Lua-System</h1> | ||
28 | |||
29 | |||
30 | <ul> | ||
31 | <li><a href="../index.html">Index</a></li> | ||
32 | </ul> | ||
33 | |||
34 | |||
35 | |||
36 | <h2>Examples</h2> | ||
37 | <ul class="nowrap"> | ||
38 | <li><a href="../examples/compat.lua.html">compat.lua</a></li> | ||
39 | <li><a href="../examples/flag_debugging.lua.html">flag_debugging.lua</a></li> | ||
40 | <li><a href="../examples/password_input.lua.html">password_input.lua</a></li> | ||
41 | <li><a href="../examples/read.lua.html">read.lua</a></li> | ||
42 | <li><a href="../examples/readline.lua.html">readline.lua</a></li> | ||
43 | <li><a href="../examples/spinner.lua.html">spinner.lua</a></li> | ||
44 | <li><strong>spiral_snake.lua</strong></li> | ||
45 | <li><a href="../examples/terminalsize.lua.html">terminalsize.lua</a></li> | ||
46 | </ul> | ||
47 | <h2>Modules</h2> | ||
48 | <ul class="nowrap"> | ||
49 | <li><a href="../modules/system.html">system</a></li> | ||
50 | </ul> | ||
51 | <h2>Classes</h2> | ||
52 | <ul class="nowrap"> | ||
53 | <li><a href="../classes/bitflags.html">bitflags</a></li> | ||
54 | </ul> | ||
55 | <h2>Topics</h2> | ||
56 | <ul class=""> | ||
57 | <li><a href="../topics/01-introduction.md.html">1. Introduction</a></li> | ||
58 | <li><a href="../topics/02-development.md.html">2. Development</a></li> | ||
59 | <li><a href="../topics/03-terminal.md.html">3. Terminal functionality</a></li> | ||
60 | <li><a href="../topics/CHANGELOG.md.html">CHANGELOG</a></li> | ||
61 | <li><a href="../topics/LICENSE.md.html">MIT License</a></li> | ||
62 | </ul> | ||
63 | |||
64 | </div> | ||
65 | |||
66 | <div id="content"> | ||
67 | |||
68 | <h2>spiral_snake.lua</h2> | ||
69 | <pre> | ||
70 | <span class="keyword">local</span> sys = <span class="global">require</span> <span class="string">"system"</span> | ||
71 | |||
72 | <span class="global">print</span> <span class="string">[[ | ||
73 | |||
74 | This example will draw a snake like spiral on the screen. Showing ANSI escape | ||
75 | codes for moving the cursor around. | ||
76 | |||
77 | ]]</span> | ||
78 | |||
79 | <span class="comment">-- backup term settings with auto-restore on exit | ||
80 | </span>sys.<span class="function-name">autotermrestore</span>() | ||
81 | |||
82 | <span class="comment">-- setup Windows console to handle ANSI processing | ||
83 | </span>sys.<span class="function-name">setconsoleflags</span>(<span class="global">io</span>.stdout, sys.<span class="function-name">getconsoleflags</span>(<span class="global">io</span>.stdout) + sys.COF_VIRTUAL_TERMINAL_PROCESSING) | ||
84 | |||
85 | <span class="comment">-- start drawing the spiral. | ||
86 | </span><span class="comment">-- start from current pos, then right, then up, then left, then down, and again. | ||
87 | </span><span class="keyword">local</span> x, y = <span class="number">1</span>, <span class="number">1</span> <span class="comment">-- current position | ||
88 | </span><span class="keyword">local</span> dx, dy = <span class="number">1</span>, <span class="number">0</span> <span class="comment">-- direction after each step | ||
89 | </span><span class="keyword">local</span> wx, wy = <span class="number">30</span>, <span class="number">30</span> <span class="comment">-- width and height of the room | ||
90 | </span><span class="keyword">local</span> mx, my = <span class="number">1</span>, <span class="number">1</span> <span class="comment">-- margin | ||
91 | </span> | ||
92 | <span class="comment">-- commands to move the cursor | ||
93 | </span><span class="keyword">local</span> move_left = <span class="string">"\27[1D"</span> | ||
94 | <span class="keyword">local</span> move_right = <span class="string">"\27[1C"</span> | ||
95 | <span class="keyword">local</span> move_up = <span class="string">"\27[1A"</span> | ||
96 | <span class="keyword">local</span> move_down = <span class="string">"\27[1B"</span> | ||
97 | |||
98 | <span class="comment">-- create room: 30 empty lines | ||
99 | </span><span class="global">print</span>((<span class="string">"\n"</span>):<span class="function-name">rep</span>(wy)) | ||
100 | <span class="keyword">local</span> move = move_right | ||
101 | |||
102 | <span class="keyword">while</span> wx > <span class="number">0</span> <span class="keyword">and</span> wy > <span class="number">0</span> <span class="keyword">do</span> | ||
103 | sys.<span class="function-name">sleep</span>(<span class="number">0.01</span>) <span class="comment">-- slow down the drawing a little | ||
104 | </span> <span class="global">io</span>.<span class="function-name">write</span>(<span class="string">"*"</span> .. move_left .. move ) | ||
105 | <span class="global">io</span>.<span class="function-name">flush</span>() | ||
106 | x = x + dx | ||
107 | y = y + dy | ||
108 | |||
109 | <span class="keyword">if</span> x > wx <span class="keyword">and</span> move == move_right <span class="keyword">then</span> | ||
110 | <span class="comment">-- end of move right | ||
111 | </span> dx = <span class="number">0</span> | ||
112 | dy = <span class="number">1</span> | ||
113 | move = move_up | ||
114 | wy = wy - <span class="number">1</span> | ||
115 | my = my + <span class="number">1</span> | ||
116 | <span class="keyword">elseif</span> y > wy <span class="keyword">and</span> move == move_up <span class="keyword">then</span> | ||
117 | <span class="comment">-- end of move up | ||
118 | </span> dx = -<span class="number">1</span> | ||
119 | dy = <span class="number">0</span> | ||
120 | move = move_left | ||
121 | wx = wx - <span class="number">1</span> | ||
122 | mx = mx + <span class="number">1</span> | ||
123 | <span class="keyword">elseif</span> x < mx <span class="keyword">and</span> move == move_left <span class="keyword">then</span> | ||
124 | <span class="comment">-- end of move left | ||
125 | </span> dx = <span class="number">0</span> | ||
126 | dy = -<span class="number">1</span> | ||
127 | move = move_down | ||
128 | wy = wy - <span class="number">1</span> | ||
129 | my = my + <span class="number">1</span> | ||
130 | <span class="keyword">elseif</span> y < my <span class="keyword">and</span> move == move_down <span class="keyword">then</span> | ||
131 | <span class="comment">-- end of move down | ||
132 | </span> dx = <span class="number">1</span> | ||
133 | dy = <span class="number">0</span> | ||
134 | move = move_right | ||
135 | wx = wx - <span class="number">1</span> | ||
136 | mx = mx + <span class="number">1</span> | ||
137 | <span class="keyword">end</span> | ||
138 | <span class="keyword">end</span> | ||
139 | |||
140 | <span class="global">io</span>.<span class="function-name">write</span>(move_down:<span class="function-name">rep</span>(<span class="number">15</span>)) | ||
141 | <span class="global">print</span>(<span class="string">"\nDone!"</span>)</pre> | ||
142 | |||
143 | |||
144 | </div> <!-- id="content" --> | ||
145 | </div> <!-- id="main" --> | ||
146 | <div id="about"> | ||
147 | <i>generated by <a href="http://github.com/lunarmodules/LDoc">LDoc 1.5.0</a></i> | ||
148 | <i style="float:right;">Last updated 2024-06-20 23:11:37 </i> | ||
149 | </div> <!-- id="about" --> | ||
150 | </div> <!-- id="container" --> | ||
151 | </body> | ||
152 | </html> | ||