guglprovider.blogg.se

Nodebox recursion
Nodebox recursion






nodebox recursion

You can just feed in a word lookup from any CSV file. The third approach, using shape widths as described above, will work for any arbitrarily long list of words. First I feed that list into a set of five meiosis subnetworks to turn them back into a single line of text. To demonstrate the other two methods I break that sentence into a list of individual words this is your situation. If you feed that directly into a text path node and set the width to, say, 280 you will get a nice paragraph in a single bound. I first create a string of the first sentence of the Gettysburg address. I have attached an example network that shows all three methods. The result is a somewhat ragged paragraph, but it may be good enough for your purposes. I say "crude" because you have to do all the lines at once the second line cannot adjust based on exactly where the first line broke (that would, again, require recursion). You can find the width of each shape, compute a running total of these word shape widths, calculate a crude estimate of the break points, slice up the word shapes into subsets, and stack each set together to form lines. Oddly, you can't just do this n times in NodeBox because NodeBox is stateless and has no ability to do recursion.Ī more complicated method is to work with the words after each one has already been turned into a separate text path. The catch with this approach is that you have to wire together the meiosis nodes by hand with enough nodes to match a specific number of words. String enough of these together (n where 2^n > than number of words in original list) and you would then have a single string which you could feed into the textpath node for an instant paragraph. Each time you apply this "meiosis" the size of the list would be cut in half. So that's one workaround.Ī stranger workaround is a to create a subnetwork that does a kind of cell division: combines each string into a pair of strings separated by a space. It would be fairly easy to write a custom node to do that in Python. There is no "concatenate this list" node. There is a concatenate node, but it can only concatenate up to seven specific strings at a time. You can easily turn one string into a list of words (just use the make_string node and use a space as the separator), but strangely there is no way to do the reverse. When you feed that string into a textpath node all you have to do is set the width value (to anything other than the default of 0) and NodeBox will do the word breaks for you. If you could concatenate all your words into a single string (or one string per paragraph) this would be effortless. What you want to do is straightforward and should be extremely easy - but it's not. Sometimes my pesky day job gets in the way. #scale(.Sorry for the delay in responding. Rotate (leftTurnAngle ) return elif rule = "[": Rotate (rightTurnAngle ) return elif rule = '-': Rules = 'FF' # Be careful with large numbers of iterations, # the complexity grows exponentiallyīeginpath ( 0, 0 ) lineto ( 0, -segmentLength ) endpath ( ) transform (mode=CORNER ) translate ( 0, -segmentLength ) def iterate (n, rule ): # + and - = turn right and left respectively (based on angles given above) # Other symbolds are recursively substituted # and then processed as a draw forward instruction Rules= # The symbold for the formal language are: # = restore state (i.e. 35 ) nofill ( ) translate ( 300, 800 ) #starting point size ( 600, 800 ) strokewidth ( 1 ) stroke (. Illustrates how a minor change has major effects - same rules but one angle changed by.

nodebox recursion nodebox recursion

This one uses a scale factor with each iteration of. The letters represent other rules so in the above rule we need to make sure there is also a rule defined for F or we get a key error. For a rule like: X -> FFX just add a entry to the rules dictionary like rules = 'FFX'. The rule system is a simple dictionary - it should be pretty self explanatory. Here are the rules used to create the output. You may also want to check out some of Mark's beautiful photography on his website.

NODEBOX RECURSION CODE

a branch of a tree is a small tree in itself, etc.) Mark has shared his code with us so now we can all experiment with L-systems! L-systems are based on recursion - a programming principle in which parts of the whole involve invoking the whole again (e.g. An L-system or Lindenmayer system is a set of rules and symbols used to model the growth processes of plant development - you may remember it from Dryad. Mark Meyer has created an L-system algorithm in NodeBox.








Nodebox recursion