On 1/4/2015 6:04 AM, Akira Kakuto wrote:
Dear John,
How to make this a polygon?
An example:
\starttext \startluacode local metafun = context.metafun metafun.start() io.input("DATA") local i, j local x, y, s, t1, t2 i = 1 x={} y={} s="draw " while true do x[i], y[i] = io.read("*n", "*n") if not x[i] then break end metafun("filldraw fullcircle scaled 2mm shifted(%dcm,%dcm);",x[i],y[i]) i = i + 1 end i = i - 1 for j = 1, i do t1 = tostring(x[j]) t2 = tostring(y[j]) s = s.."("..t1.."cm,"..t2.."cm)--" end t1 = tostring(x[1]) t2 = tostring(y[1]) s = s.."("..t1.."cm,"..t2.."cm)" s = s.." withpen pencircle scaled 1bp;" metafun(s) metafun.stop() \stopluacode \stoptext
Here is a bit more compact version. A path can normally nicely be concat using "--" or ".." and we have a metafun helper drawpoints. \starttext \startluacode context.metafun.start() local split = utilities.parsers.csvsplitter { separator = " " } local data = split(io.loaddata("data.txt")) for i=1,#data do data[i] = string.formatters["(%s,%s)"](unpack(data[i])) end context.metafun("path p ; p := (%s -- cycle) scaled cm ;",table.concat(data,"--")) context.metafun("draw p withpen pencircle scaled 0.25mm ;") context.metafun("drawpoints p withpen pencircle scaled 2.00mm ;") context.metafun.stop() \stopluacode \stoptext ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | voip: 087 875 68 74 | www.pragma-ade.com | www.pragma-pod.nl -----------------------------------------------------------------