Re: [NTG-context] plot data from file: cld

2015-01-05 Thread John Kitzmiller
On Jan 5, 2015, at 5:51 AM, Hans Hagen pra...@wxs.nl mailto:pra...@wxs.nl 
wrote:

 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




___
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki : http://contextgarden.net
___

Re: [NTG-context] plot data from file: cld

2015-01-04 Thread 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




-
  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
-
___
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki : http://contextgarden.net
___

Re: [NTG-context] plot data from file: cld

2015-01-04 Thread John Kitzmiller
On Jan 4, 2015, at 6:00 AM, ntg-context-requ...@ntg.nl wrote:
 Dear John,
 
 How to make this a polygon?
 
 An example:

Many thanks to you Akira.

Reading the file into lua tables is good sense, and thank you for the string 
manipulations to pass to metafun().

From your teaching I changed this assignment:

 t1 = tostring(x[1])
 t2 = tostring(y[1])
 s = s..(..t1..cm,..t2..cm)
 s = s.. withpen pencircle scaled 1bp;

to: s = s..cycle withpen pencircle scaled 1bp;”

to close the polygon.

With respect,

John






 

___
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki : http://contextgarden.net
___

[NTG-context] plot data from file: cld

2015-01-03 Thread John Kitzmiller
I seek how to use context-lua to draw a path from ‘points’ in an external file. 

Below is one way to plot points from an external file, call the file DATA with 
contents:

1 3
-2 2
-3 -1
3 -2

\starttext
\startluacode
local metafun = context.metafun
metafun.start()

io.input(“DATA)
while true do
  local x, y = io.read(*n, *n)
  if not x then break end
  metafun(filldraw fullcircle scaled 2mm shifted(%dcm,%dcm);,x,y)
end

metafun.stop()
\stopluacode
\stoptext


How to make this a polygon?

I know other ways to read and manipulate DATA with Lua—it is the drawing part 
where I most look for help.

Thanks,
John


___
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki : http://contextgarden.net
___

[NTG-context] plot data from file: cld

2015-01-03 Thread Akira Kakuto

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

Best,
Akira

___
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki : http://contextgarden.net
___