1. NodeBox 1
    1. Homepage
    2. NodeBox 3Node-based app for generative design and data visualization
    3. NodeBox OpenGLHardware-accelerated cross-platform graphics library
    4. NodeBox 1Generate 2D visuals using Python code (Mac OS X only)
  2. Gallery
  3. Documentation
  4. Forum
  5. Blog

svg

Posted by Boss hog on Jan 30, 2008

Hi, I'm having difficulty getting the following script to work.
Any insight would be much appreciated:-

##code>
size(500, 500)

svg = ximport("svg")

data = open("path.svg").read()
flower = svg.parse(data)
flower = flower[0]

scale(1) # size
translate(10, 10) # position
#

f = files("insects/*.svg")
paths = svg.parse(data)

spacing = 8
for x, y in grid(WIDTH/spacing , HEIGHT/spacing, spacing, spacing):
if flower.contains(x, y):
fill(2, random()/4, random(), 1) # color
push()
translate(x, y)
scale((0.2)) #
drawpath(choice(paths))
pop()

#All instances are on top of each otheer????


##


 
Posted by FabioF on Feb 03, 2008

paths = svg.parse(data)
refers to the first svg you had already loaded and not to the 'insects' list you would to use.
Maybe you should write something like:
f = files("insects/*.svg") #better to put this line out of the loop
random_file = choice(f)
random_svg = open(random_file).read()
svg_data = svg.parse(random_svg) 
drawpath(svg_data[0])
hope this help
Fabio



Posted by Tom De Smedt on Feb 04, 2008

Taking a quick look at your code, the drawpath command may also be a problem. If you want to draw a single path multiple times, each individually rotated and scaled, you need to use copies of it:

drawpath(choice(paths).copy())



Posted by James on Feb 04, 2008

another problem I encountered is when refering to multiple svg paths in the same file. I guessed it would be something like:

paths = svg.parse(data) [0],[1],[2]

or

paths = svg.parse(data) [0, 1, 2]

but could get it to work.
;-?



Posted by James on Feb 04, 2008

sorry. That should have read >could not get it to work



Posted by James on Feb 04, 2008

One more problem. How do I preserve an rgb color gradient that is in the original .svg file?



Posted by Tom De Smedt on Feb 25, 2008

Right now you can't, the SVG library will parse fill and stroke colors fom the source file, but not the gradients.