Re: [NTG-context] plot data from file: cld
On Jan 5, 2015, at 5:51 AM, Hans Hagen
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
Thank you Hans. A few tools new to me in there! I am wondering (and will try to find) if multiple paths could be contained in the external file— a marker and test structure? Thanks again, John
participants (1)
-
John Kitzmiller