drawing individual triangles from a list of points?
I'm trying to draw irregular triangles along a freehand line by breaking the line into points and drawing a vertical line at every other point.
Now i would like to have triangles drawn, the end points of which are on the outside of the vertical line and on the line at the two neighboring points, but I can't convert the list of points into individual triangle objects. (tried to slice the list with a range as starting ponts, but that created just a copy of the points list.)
Since I want to color the triangles differently later (as shown in the litte illustration), i need individual objects. Is there a way to do this in Nodebox that I don't see? I can not use the ›shape on path‹ node, because the shapes do overlap or get space in between.
Thanks for any help with this.
|?||Show this help|
|ESC||Blurs the current field|
|r||Focus the comment reply box|
|^ + ↩||Submit the comment|
You can use
Command ⌘ instead of
Control ^ on Mac
Support Staff 1 Posted by john on 20 Sep, 2021 09:35 AM
The easiest way to do this is to make a subnetwork. See attached Nodebox file and screenshot.
I made a subnetwork that takes three inputs: the tick lines, the points before each tick line, and the points after each tick line. By feeding these into a subnetwork one at a time it makes it easy to pull out the top of the line, make a triangle out of that, and pull out the bottom of the line, and make a second triangle out of that. You can peer inside the triangle subnetwork to see how I did it.
To get one list of before points and one list of after points, I just took the list of black dot points and dropped the last point for the before list and dropped the first point for the after list.
This method assumes that there is always one point before the first tick line, and one point after the last tick line. Because of your shift node your network was actually drawing an extra tick mark at the front; I removed this using a drop_last node (from my node library).
When playing with this, I noticed that the Freehand node occasionally created an invalid point (with NaN points for Not a Number). So I added a few more nodes to test for this and remove any bogus points.
I assigned the colors from your example for the triangles, but of course you can modify that with whatever colors you want.
Give this a spin and let me know if it solves your problem, and if you have any more questions.
This looks like a fun project! Thanks for sharing it!
2 Posted by ppape on 22 Sep, 2021 09:06 AM
Thank you John, that's exactly what I tried to achieve. Now trying to understand how you did it I get stuck with the problem of – as you write – ›feeding these into a subnetwork ONE AT A TIME‹. Thats where I get stuck all the time. If I try to do something like that, all the points from a list get connected in one shape.
Support Staff 3 Posted by john on 22 Sep, 2021 10:19 AM
The main function of subnetworks is to let you control whether items are input one at a time or all at once. But the method of choosing one or the other is not obvious.
When you make a subnetwork and publish one or more ports, select that subnetwork and click Metadata (above the settings pane). This will summon the metadata dialog. Select a port on the left to see its settings on the right.
For the Range setting you have two choices: Value will force the port to accept items one at a time; List will force the port to accept items all at once (each time the subnetwork fires).
This is a subtle distinction that took me quite awhile to get used to. But once I understood it whole new worlds opened up.
By the way, you can also inspect the Range setting for ports on standard nodes. If you do this you will see that some are set to value and others to list. You can't change this behavior (changing the value will only cause errors), but you can wrap the node inside a subnetwork, publish the ports you need, and THEN change the port behaviors.
An example of this is the humble combine node. If you inspect it you will see that all seven ports are set to list. This means that if you feed two lists into a combine node it will give you all the elements of list A and then all the elements of list B.
But what if you want to interweave the lists to produce A1, B1, A2, B2, A3... etc.? Just select the custom node, say "Group into Network", open the subnetwork, and publish the first two ports (list1 and list2). Then close the subnetwork, open the Metadata dialog, and change the Range values of both list1 and list2 from List to Value. Voila! You now have an interweave subnetwork.
Try playing around with this the next time you run into this issue. If you still have questions send me another misbehaving network and I will try to straighten it out for you.
4 Posted by ppape on 22 Sep, 2021 02:21 PM
This really opened up my eyes and a whole new way of working with Nodebox. Thank you so much for your helpful answers!