Stack Tight Node

john's Avatar

john

23 Mar, 2021 06:16 AM

Attached is a demo of my latest node: Stack_tight. Stack_tight works just like the Stack node, except that it can tuck shapes tightly together.

The stack node bases its adjustments on the boundary around each shape (the maximum width and height). This makes it unsuitable for general purpose kerning or for pressing convex shapes snugly into concave shapes.

Fitting shapes together like jigsaw puzzle pieces is one of those things that is effortless for people but hard for computers. In order to do it I had to find key points along the north, east, south, or west sides of a shape and measure the distances to similar points on each adjoining shape. I finally found a way of doing this that is reasonably fast even for large shapes or long sequences.

The fit is not always perfect. My method requires resampling each shape. The finer the resolution the more accurate the fit, but the longer the computation time. For most case you can keep resolution at 1 pixel (the finest setting), but if you have very large or numerous shapes you can speed the computations by making the resolution more coarse.

Stack_tight works best with a consecutive list of shapes all roughly in a line (like characters in a sentence). if you use it to stack widely scattered shapes there may be some unexpected results. If a shape is not adjacent at any point to its nearest neighbor it has no way of determining how far to slide, so will just stay put (but will still move with the rest of the list).

The attached demo includes several demonstrations (see screenshot):

  • At the top you can see output from the edge_points node, a node inside stack_tight that may be useful in other situations as well. It finds regularly spaced points on the north, east, south, or west sides of a shape (shown as red dots).
  • At mid left I show a simple demo of the string "sTack*" first using a normal stack node and then, below it, using stack_tight. You can see that with stack_tight the T is kerned tightly between the s and a, and the asterisk at the end snuggles into the k.
  • At the bottom I show "sTackTight" stacked tightly with three rows of stars, at various rotations, falling into the crevices of the text. The stars are first tucked together horizontally and then stacked vertically one at a time.
  • The bottom example can be animated (MP4 attached). A wave node feeding into stack_tight's margin port causes the text to expand and contract; as it does so some of the stars fall further down or bounce back up as they catch edges of the text characters. Set to loop for a groovy viewing experience.
  • As an added bonus I also include a pentagram node, handy for making perfect five-point stars (using the golden ratio).

I've wanted to make a node like this for years. It has many possible uses. Feedback appreciated.

Enjoy!

John

  1. 1 Posted by D on 28 Mar, 2021 12:53 PM

    D's Avatar

    The star packing is beautiful, John!
    Combined with your image node—this image below might be interesting. Packing stars of various sizes inside an object :-)
    Thank you for sharing

  2. Support Staff 2 Posted by john on 13 Apr, 2021 09:20 AM

    john's Avatar

    Hi D,

    Sorry for the delay in responding. My plan was to actually follow your excellent suggestion of combining my stack_tight node with my image_node before writing back, but I got distracted and will probably stay distracted for awhile longer. But if and when I do come up with something interesting I will reply here and share it.

    By the way, true packing is something I've wanted to do in NodeBox for a long time. stack_tight is a step in that direction, but only a small step. Real packing will require lots of math and some recursion which will in turn require writing a custom node in Python. A Voronoi node would get us much closer.

    Someday...

    John

Reply to this discussion

Internal reply

Formatting help / Preview (switch to plain text) No formatting (switch to Markdown)

Attaching KB article:

»

Already uploaded files

  • stack_tight_screenshot.png 496 KB
  • stack_tight_demo.zip 20.2 KB
  • stack_tight_animation.mp4 95.5 KB

Attached Files

You can attach files up to 10MB

If you don't have an account yet, we need to confirm you're human and not a machine trying to post spam.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac

Recent Discussions

04 Nov, 2024 10:52 AM
02 Nov, 2024 11:22 AM
01 Nov, 2024 12:41 AM
01 Oct, 2024 07:59 AM
30 Sep, 2024 11:37 PM

 

30 Sep, 2024 11:11 AM
30 Sep, 2024 02:37 AM
28 Sep, 2024 10:33 AM
26 Sep, 2024 06:41 AM
24 Sep, 2024 12:32 AM
24 Sep, 2024 12:27 AM