Texturizer Node

Rory's Avatar

Rory

01 Apr, 2015 07:23 AM

Sometimes I am color constrained when making graphs if for example the figure will appear in an academic setting (black and white, or basic colors only). So perhaps you might want to create some old school textured shapes.

Here is a sub-network called 'Texturize" that takes a shape and fills it with whatever symbol the user provides from the keyboard - for example . or + or * and so on. The network also accepts a density argument to control how man of the symbols will appear inside the shape.

It works pretty well on what I have tested so far, but certain polygons don't work too well near the edges as effectively the network creates a squared grid inside the polygon to be textured.

If anyone has any other ideas how this could be achieved then please let me know! Thanks

  1. 1 Posted by Rory on 01 Apr, 2015 07:40 AM

    Rory's Avatar

    One thing I was wondering:

    Before I found the Delete node, I was thinking to try to implement this algorithm for seeing if a point on the background grid fell within the bounds of the polygon:

    http://en.wikipedia.org/wiki/Point_in_polygon

    However I could not think how to do it in Nodebox. It would be simple enough to take a point on the grid, get its y value, and then draw and line from x = -500 to y = 500, maintaining that same value of y, but how to find out where that line intersects the polygon? Anyone have any leads on that?

  2. Support Staff 2 Posted by john on 02 Apr, 2015 11:24 AM

    john's Avatar

    You can recover a list of all the inflection points in a polygon by attaching a lookup node, setting the key to "points", and changing the output range of the lookup node from "value" to "list" (via "settings" in the metadata dialog).

    Once you have this you can take each pair of adjacent points in turn and reconstruct each line segment of the polygon (remembering that the last point is adjacent to the first). One way of determining whether each segment intersects with your ray from outside is to calculate the slope of the ray r and the line s extending through the segment, put the equation for each line in slope intercept form, and use basic algebra to solve for intersection, that is, solve for r(x) = s(x). (You can make that even easier by choosing a horizontal line for the ray so that r(x)=0.) Unless the two lines are parallel they will intersect somewhere. Once you have that point it's a simple matter to see whether the intersection occurs within the bounds of the original segment, and before the endpoint of the ray. (There is probably an easier way but this is the first thing that came to mind.)

    The final outcome will be 0 if false (no intersection within segment bounds) or 1 if true.
    Now just repeat for each segment and take the sum of the outcomes. If this number is odd, the point is inside, if even outside.

    That's one approach. Perhaps someone else can suggest a simpler method.

    John

  3. Support Staff 3 Posted by john on 02 Apr, 2015 11:46 AM

    john's Avatar

    Incidentally, you can get a cleaner texture fill using the compound node. Create a grid of dots bigger than the shape and adjust dot size and density to your taste. Then hook the shape and the grid of dots to the compound node (set to intersection).

    This will give you the interior. To create a nice edge, attach a colorize node to the shape, set its fill to white and its edge width > 0, and feed the colorize node and the compound node (in that order) into a combine node.

    NodeBox file and screenshot attached.

    For other textures you could make a grid of white touching rectangles to form a cross-hatch pattern, rotate that 45 degrees for another variation, and so on.

    This is a fun idea. Now I want to make some old-school textures for my shapes!

    John

  4. 4 Posted by Rory on 02 Apr, 2015 12:03 PM

    Rory's Avatar

    John, thats very cool!

    That was exactly the approach I tried to take first, but I neglected to connect the polygon both to the compound and separately to the combine node. So much simpler. Thanks.....

    I think a NodeBox challenge would be a super useful way to learn (for me!). This week texture, next week ???

  5. 5 Posted by Rory on 02 Apr, 2015 12:36 PM

    Rory's Avatar

    Thanks!

  6. Support Staff 6 Posted by john on 02 Apr, 2015 11:51 PM

    john's Avatar

    :)

Reply to this discussion

Internal reply

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

Attaching KB article:

»

Already uploaded files

  • texturizer.ndbx 6.25 KB
  • texture.png 107 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

26 Mar, 2023 12:11 PM
26 Mar, 2023 12:02 PM
24 Mar, 2023 09:51 PM
23 Mar, 2023 09:43 PM
23 Mar, 2023 08:23 AM

 

21 Mar, 2023 11:00 AM
21 Mar, 2023 09:32 AM
21 Mar, 2023 04:46 AM
12 Mar, 2023 03:02 AM
11 Mar, 2023 02:11 AM
10 Mar, 2023 06:47 AM