author | kyberneticist@gmail.com |
Fri, 19 Oct 2012 21:00:58 +0000 | |
changeset 255 | 18e1a94e1591 |
parent 254 | a21261c77793 |
child 256 | 0b93b3ec3ebf |
permissions | -rw-r--r-- |
254
a21261c77793
Created wiki page through web user interface.
kyberneticist@gmail.com
parents:
diff
changeset
|
1 |
#summary Drawing maps with Lua. |
a21261c77793
Created wiki page through web user interface.
kyberneticist@gmail.com
parents:
diff
changeset
|
2 |
|
a21261c77793
Created wiki page through web user interface.
kyberneticist@gmail.com
parents:
diff
changeset
|
3 |
= Drawing Maps With Lua = |
a21261c77793
Created wiki page through web user interface.
kyberneticist@gmail.com
parents:
diff
changeset
|
4 |
|
a21261c77793
Created wiki page through web user interface.
kyberneticist@gmail.com
parents:
diff
changeset
|
5 |
Starting in 0.9.18 it is possible to reliably use drawn map mode to draw maps with scripts. |
255
18e1a94e1591
Edited wiki page LuaDrawing through web user interface.
kyberneticist@gmail.com
parents:
254
diff
changeset
|
6 |
A simple example is given below. Note that Drawn maps use an area of 4096x2048 |
254
a21261c77793
Created wiki page through web user interface.
kyberneticist@gmail.com
parents:
diff
changeset
|
7 |
|
a21261c77793
Created wiki page through web user interface.
kyberneticist@gmail.com
parents:
diff
changeset
|
8 |
= Details = |
a21261c77793
Created wiki page through web user interface.
kyberneticist@gmail.com
parents:
diff
changeset
|
9 |
|
a21261c77793
Created wiki page through web user interface.
kyberneticist@gmail.com
parents:
diff
changeset
|
10 |
First, a couple of convenience functions for drawing to the map. |
a21261c77793
Created wiki page through web user interface.
kyberneticist@gmail.com
parents:
diff
changeset
|
11 |
<code lang="lua"> |
a21261c77793
Created wiki page through web user interface.
kyberneticist@gmail.com
parents:
diff
changeset
|
12 |
PointsBuffer = '' -- A string to accumulate points in |
a21261c77793
Created wiki page through web user interface.
kyberneticist@gmail.com
parents:
diff
changeset
|
13 |
function AddPoint(x, y, new, size, erase) |
a21261c77793
Created wiki page through web user interface.
kyberneticist@gmail.com
parents:
diff
changeset
|
14 |
PointsBuffer = PointsBuffer .. string.char(band(x,0xff00) / 256 , band(x,0xff) , band(y,0xff00) / 256 , band(y,0xff)) |
a21261c77793
Created wiki page through web user interface.
kyberneticist@gmail.com
parents:
diff
changeset
|
15 |
if new then |
255
18e1a94e1591
Edited wiki page LuaDrawing through web user interface.
kyberneticist@gmail.com
parents:
254
diff
changeset
|
16 |
size = bor(size,0x80) |
254
a21261c77793
Created wiki page through web user interface.
kyberneticist@gmail.com
parents:
diff
changeset
|
17 |
if erase then |
255
18e1a94e1591
Edited wiki page LuaDrawing through web user interface.
kyberneticist@gmail.com
parents:
254
diff
changeset
|
18 |
size = bor(size,0x40) |
18e1a94e1591
Edited wiki page LuaDrawing through web user interface.
kyberneticist@gmail.com
parents:
254
diff
changeset
|
19 |
end |
18e1a94e1591
Edited wiki page LuaDrawing through web user interface.
kyberneticist@gmail.com
parents:
254
diff
changeset
|
20 |
PointsBuffer = PointsBuffer .. string.char(size) |
18e1a94e1591
Edited wiki page LuaDrawing through web user interface.
kyberneticist@gmail.com
parents:
254
diff
changeset
|
21 |
else |
18e1a94e1591
Edited wiki page LuaDrawing through web user interface.
kyberneticist@gmail.com
parents:
254
diff
changeset
|
22 |
PointsBuffer = PointsBuffer .. string.char(0) |
254
a21261c77793
Created wiki page through web user interface.
kyberneticist@gmail.com
parents:
diff
changeset
|
23 |
end |
a21261c77793
Created wiki page through web user interface.
kyberneticist@gmail.com
parents:
diff
changeset
|
24 |
if #PointsBuffer > 245 then |
255
18e1a94e1591
Edited wiki page LuaDrawing through web user interface.
kyberneticist@gmail.com
parents:
254
diff
changeset
|
25 |
ParseCommand('draw '..PointsBuffer) |
254
a21261c77793
Created wiki page through web user interface.
kyberneticist@gmail.com
parents:
diff
changeset
|
26 |
PointsBuffer = '' |
255
18e1a94e1591
Edited wiki page LuaDrawing through web user interface.
kyberneticist@gmail.com
parents:
254
diff
changeset
|
27 |
end |
254
a21261c77793
Created wiki page through web user interface.
kyberneticist@gmail.com
parents:
diff
changeset
|
28 |
end |
a21261c77793
Created wiki page through web user interface.
kyberneticist@gmail.com
parents:
diff
changeset
|
29 |
function FlushPoints() |
a21261c77793
Created wiki page through web user interface.
kyberneticist@gmail.com
parents:
diff
changeset
|
30 |
if #PointsBuffer > 0 then |
255
18e1a94e1591
Edited wiki page LuaDrawing through web user interface.
kyberneticist@gmail.com
parents:
254
diff
changeset
|
31 |
ParseCommand('draw '..PointsBuffer) |
254
a21261c77793
Created wiki page through web user interface.
kyberneticist@gmail.com
parents:
diff
changeset
|
32 |
PointsBuffer = '' |
a21261c77793
Created wiki page through web user interface.
kyberneticist@gmail.com
parents:
diff
changeset
|
33 |
end |
a21261c77793
Created wiki page through web user interface.
kyberneticist@gmail.com
parents:
diff
changeset
|
34 |
end |
a21261c77793
Created wiki page through web user interface.
kyberneticist@gmail.com
parents:
diff
changeset
|
35 |
</code> |
a21261c77793
Created wiki page through web user interface.
kyberneticist@gmail.com
parents:
diff
changeset
|
36 |
AddPoint takes an x and y location for the point, 2 booleans: new (start of a line or not), erase (whether the line is erasing from the map) and size (size of the line - a value from 1 to 63) |
a21261c77793
Created wiki page through web user interface.
kyberneticist@gmail.com
parents:
diff
changeset
|
37 |
FlushPoints writes out any values from PointsBuffer that had not already been sent to the engine. It would be called at the end of a drawing session. |
a21261c77793
Created wiki page through web user interface.
kyberneticist@gmail.com
parents:
diff
changeset
|
38 |
|
a21261c77793
Created wiki page through web user interface.
kyberneticist@gmail.com
parents:
diff
changeset
|
39 |
A simple example below. |
a21261c77793
Created wiki page through web user interface.
kyberneticist@gmail.com
parents:
diff
changeset
|
40 |
|
a21261c77793
Created wiki page through web user interface.
kyberneticist@gmail.com
parents:
diff
changeset
|
41 |
<code lang="lua"> |
a21261c77793
Created wiki page through web user interface.
kyberneticist@gmail.com
parents:
diff
changeset
|
42 |
function onGameInit() |
255
18e1a94e1591
Edited wiki page LuaDrawing through web user interface.
kyberneticist@gmail.com
parents:
254
diff
changeset
|
43 |
MapGen = 2 |
18e1a94e1591
Edited wiki page LuaDrawing through web user interface.
kyberneticist@gmail.com
parents:
254
diff
changeset
|
44 |
TemplateFilter = 0 |
254
a21261c77793
Created wiki page through web user interface.
kyberneticist@gmail.com
parents:
diff
changeset
|
45 |
|
255
18e1a94e1591
Edited wiki page LuaDrawing through web user interface.
kyberneticist@gmail.com
parents:
254
diff
changeset
|
46 |
AddPoint(100,100,true,10) |
18e1a94e1591
Edited wiki page LuaDrawing through web user interface.
kyberneticist@gmail.com
parents:
254
diff
changeset
|
47 |
AddPoint(2000,2000) |
18e1a94e1591
Edited wiki page LuaDrawing through web user interface.
kyberneticist@gmail.com
parents:
254
diff
changeset
|
48 |
AddPoint(2000,100,true,10) |
18e1a94e1591
Edited wiki page LuaDrawing through web user interface.
kyberneticist@gmail.com
parents:
254
diff
changeset
|
49 |
AddPoint(100,2000) |
18e1a94e1591
Edited wiki page LuaDrawing through web user interface.
kyberneticist@gmail.com
parents:
254
diff
changeset
|
50 |
AddPoint(1000,1000,true,63,true) |
254
a21261c77793
Created wiki page through web user interface.
kyberneticist@gmail.com
parents:
diff
changeset
|
51 |
|
a21261c77793
Created wiki page through web user interface.
kyberneticist@gmail.com
parents:
diff
changeset
|
52 |
for i = 63,2,-4 do |
255
18e1a94e1591
Edited wiki page LuaDrawing through web user interface.
kyberneticist@gmail.com
parents:
254
diff
changeset
|
53 |
AddPoint(2000,1000,true,i) |
18e1a94e1591
Edited wiki page LuaDrawing through web user interface.
kyberneticist@gmail.com
parents:
254
diff
changeset
|
54 |
AddPoint(2000,1000,true,i-2,true) |
254
a21261c77793
Created wiki page through web user interface.
kyberneticist@gmail.com
parents:
diff
changeset
|
55 |
end |
a21261c77793
Created wiki page through web user interface.
kyberneticist@gmail.com
parents:
diff
changeset
|
56 |
|
a21261c77793
Created wiki page through web user interface.
kyberneticist@gmail.com
parents:
diff
changeset
|
57 |
for i = 1,2000,50 do |
255
18e1a94e1591
Edited wiki page LuaDrawing through web user interface.
kyberneticist@gmail.com
parents:
254
diff
changeset
|
58 |
AddPoint(i+2000,2000,true,1) |
18e1a94e1591
Edited wiki page LuaDrawing through web user interface.
kyberneticist@gmail.com
parents:
254
diff
changeset
|
59 |
AddPoint(4000,2000-i) |
254
a21261c77793
Created wiki page through web user interface.
kyberneticist@gmail.com
parents:
diff
changeset
|
60 |
end |
a21261c77793
Created wiki page through web user interface.
kyberneticist@gmail.com
parents:
diff
changeset
|
61 |
|
a21261c77793
Created wiki page through web user interface.
kyberneticist@gmail.com
parents:
diff
changeset
|
62 |
AddPoint(2000,2000,true,1) |
255
18e1a94e1591
Edited wiki page LuaDrawing through web user interface.
kyberneticist@gmail.com
parents:
254
diff
changeset
|
63 |
AddPoint(4000,2000) |
254
a21261c77793
Created wiki page through web user interface.
kyberneticist@gmail.com
parents:
diff
changeset
|
64 |
AddPoint(4000,0,true,1) |
255
18e1a94e1591
Edited wiki page LuaDrawing through web user interface.
kyberneticist@gmail.com
parents:
254
diff
changeset
|
65 |
AddPoint(4000,2000) |
254
a21261c77793
Created wiki page through web user interface.
kyberneticist@gmail.com
parents:
diff
changeset
|
66 |
|
255
18e1a94e1591
Edited wiki page LuaDrawing through web user interface.
kyberneticist@gmail.com
parents:
254
diff
changeset
|
67 |
FlushPoints() |
254
a21261c77793
Created wiki page through web user interface.
kyberneticist@gmail.com
parents:
diff
changeset
|
68 |
end |
a21261c77793
Created wiki page through web user interface.
kyberneticist@gmail.com
parents:
diff
changeset
|
69 |
</code> |
a21261c77793
Created wiki page through web user interface.
kyberneticist@gmail.com
parents:
diff
changeset
|
70 |
The first set of AddPoints draws a large X and erases the centre. |
a21261c77793
Created wiki page through web user interface.
kyberneticist@gmail.com
parents:
diff
changeset
|
71 |
The following loop draws a set of nested points, alternating erasure and fill, which results in a set of concentric circles. |
a21261c77793
Created wiki page through web user interface.
kyberneticist@gmail.com
parents:
diff
changeset
|
72 |
The 2nd loop draws a web of lines and frames it using some final AddPoints. |