Deborah R. Fowler
Wrangle Node Example -
Fizz Buzz
Posted on Jan 21 2018
A popular programming example is Fizz Buzz. Since I assign this in two of my courses, one using hscript and the other C++ I will not show those solutions, however I thought it would be fun to replicate it using a point wrangle node. The hscript version can be completed in 3 nodes, here I have a few other nodes.
This is for those of you who are learning vex snippets in wrangle nodes. Video version on Vimeo
For those who have not heard of Fizz Buzz, it is described on wiki as a children's game and by some as a drinking game. It is also a very popular interview test.
The solution I will describe is based on the following rules:
- print a table of 1 to 100 in columns of 20
- if multiples of 5 print Kermit
- if multiples of 13 print Frog
- if multiples of both print Kermit Frog
- if multiples of 7 or 8 color magenta
The network for the solution with a point wrangle node (which may look different from your hscript solution):
POINT WRANGLE: Focusing on the pointwrangle to provide the attributes required:
Detail (only once) rather than points means the code will be executed once instead of the default which iterates over all points
The icon that looks like a slider creates parameters on the node for user input. You can use the various types by specifying chi for integer, chf for float, chramp for ramp etc.
The pts[] is a list of the points and we will be associating attributes with each point and these can be seen in the geometry spreadsheet.
Next we iterate or "loop" through the points using a for loop and add the attributes associated with each point for position, phrase, and color:
click here for version from my vimeo video
COPY NODE:
Now on the copy node, we can easily keep these attributes by
- going to the Attribute tab in the copy node and
- checking the box Use Template Point Attributes
In the Stamp tab we will set the Attribute Stamps to "phrase" which contains our phrase needed in the font node
Check on Pack Geometry so that only one packed geo is copied to the points
FONT NODE:
In the Font node
Use the stamps function to return a string and backticks to convert to string type
`stamps("../copy1","phrase",0)`
DELETE NODE:
The delete node is required so that the points are not displayed
NULL NODE:
The Null node is added as a "good practice" in Houdini to delineate the bottom of your network for reference in other nodes
CAM NODE:
Here I reference the bbox values in the camera so that if other tables of numbers are created the camera will adjust automatically
There are similar expressions in the Transform x and y to center the table