Compose.jl
Compose.jl copied to clipboard
Composing with an array of forms
It seems that the following was intended to work:
u = 16
lines = [line([(0.5,0.6),((1+(i-1)/sqrt(u))*0.5w,0.7w)]) for i=1:sqrt(u)]
compose(context(),lines,linewidth(0.1mm),stroke("black"))
It fails with:
`compose` has no method matching compose(::Form{LinePrimitive}, ::Form{LinePrimitive}, ::Form{LinePrimitive}, ::Form{LinePrimitive})
while loading In[43], in expression starting on line 1
in compose at /Users/kfischer/.julia/Compose/src/container.jl:253
The following works though:
compose(context(),lines...,linewidth(0.1mm),stroke("black"))
This is pretty much by design. Since compose
will interpret its arguments as a sort of S-expression, here it will try to make the first object in the array an internal and the rest it's children, but forms like Lines are always leaves in the tree.
I should have a more descriptive error than "no matching method" though.
I am baffled here... What does ...
mean here and how should it be used correctly?
I am having similar problems. I can create circles with vector arguments as the examples, but not lines, and that is quite unconfortable.
The ...
is regular Julia syntax. For example f(xs...)
is equivalent to f(xs[1], xs[2], xs[3])
if xs
has three elements. See http://julia.readthedocs.org/en/latest/manual/functions/#varargs-functions.
There are two ways to draw multiple lines. As multiple line
forms...
compose(context(), line([(0,0), (1,1)]), line([(0,1), (1,0)]), stroke("black"))
...or as a single vectorized line form
compose(context(), line([[(0,0), (1,1)], [(0,1), (1,0)]]), stroke("black"))