Prime numbers

florisdejonge's Avatar


05 Nov, 2022 10:30 AM

Hi fellow Nodeboxers,

Lately I've tried to use prime numbers. I got interested since it creates another possibility to create non-random patterns, other than a perlin noise or wave-function. Attached is an example of the application of prime numbers in a sacks spiral. I was wondering 1. if there is a more elegang way to generate prime numbers and 2. is there a better way to segment the archimedean spiral that is used as a grid.


  1. Support Staff 1 Posted by john on 06 Nov, 2022 01:40 AM

    john's Avatar


    Interesting challenge.

    Attached find my attempt. It uses a "primes" node that returns all prime numbers up to a limit using a variant of the Sieve of Eratosthenes. It's quite inefficient, yet can return all primes up to 10,000 instantly and all primes up to 100,000 in about a second. If you need more primes than that it will eventually bog down, but that should be sufficient for most purposes.

    I show two demos. The network on the left recreates your Sacks Spiral but only takes a second or two to run. The network on the right (see screenshot) tries a different way to segment the Archimedes spiral. I set the output of my spiral node to points instead of path; this returns inflection points that gradually become more sparse as the spiral expands outward. The number of apparent spiral arms depends on the Angle parameter (set to 600 in the screenshot). You can get some interesting effects by playing with that angle setting but beware: the performance degrades as the angle decreases - I would keep it above about 200 to avoid slowing things to a halt.

    Do you think the primes node is worth adding to my library?


  2. 2 Posted by florisdejonge on 06 Nov, 2022 05:32 PM

    florisdejonge's Avatar


    Thanks for the reply. It's great that you were able to come up with a solution for generating prime numbers that quick. The limit for performance is more than sufficient in most cases. I think it would be cool to add to the library.

    In regard to the spiral, I really liked the animation you posted. As I read about the Sacks spiral I was given to understand that the right (east) axis ought to be horizontal. But I wasn't able to do that with the spiral node. Were you able to get that as a result without the spiral getting irregular? It's hard to see in the animation.


  3. Support Staff 3 Posted by john on 08 Nov, 2022 09:11 AM

    john's Avatar


    If you could freeze my animation and look at it more closely you would see that it was just as wobbly as yours - for the same reason: my spiral node is a bit of a kludge. The underlying fit_curve node inside it is slow and imprecise; the spiral node makes a series of compromises to produce serviceable spirals at a better-than-glacial pace.

    I didn't know anything about Sacks Spirals before seeing your post, so looked it up and made a precise Sacks node with perfectly horizontal arms (demo attached). The Sacks node just draws the sequential points of the curve, not the curve itself. Feed it a range of 0 to 1000 and it will draw the points corresponding to those values; feed it just the prime numbers up to 1000 (using my primes node) and it will only draw those.

    The screenshot shows the display with 20,000 dots - which it draws in just a few seconds.

    To draw the actual spiral you could connect those dots and feed that into a fit_curve node, but it will start to bog down after only a thousand points or so. I left a connected curve based on the first 500 points disconnected in the demo - reconnect and gradually increase the slice to see the quality and speed of the curve. I also left your network to one side as a comparison.

    By the way - I was rather impressed by how close you came to a precise Sacks Spiral just by resampling and setting the spiral node parameters just right. It must have taken you some experimentation.

    A fun project. Thanks for introducing it to me.


  4. 4 Posted by florisdejonge on 08 Nov, 2022 07:35 PM

    florisdejonge's Avatar

    Hi John,

    Thanks for providing this perfect result. Getting the outcome I had with setting the parameters as accurate as I could was quite unsatisfactory.

    The maximum of 20.000 dots is a lot considering the level of detail when plotted. In regard to the fit_curve node breaking down: I can work around that. The plotter actually resamples curves in tiny segments automatically, which makes it slow. I usually resample curves with larger segments to increase speed. This doesn't decrease the visual result when plotted (attached is a screenshot). So I can just use the result of the connect node, and only render the first 500 or so points with the fit_curve node (because in the centre the lack of curves would become visible). So, I'll try to plot another one :D


  5. Support Staff 5 Posted by john on 08 Nov, 2022 10:44 PM

    john's Avatar

    I would love to see this plotted! Also curious how long the plot takes.

    The Sacks Spiral is beautiful, isn't it? I may play around with it some more.


Reply to this discussion

Internal reply

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

Attaching KB article:


Already uploaded files

  • 18.6 KB
  • Schermafbeelding_2022-11-05_om_11.25.40.png 601 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


? 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

22 Nov, 2022 03:21 PM
22 Nov, 2022 10:40 AM
22 Nov, 2022 09:55 AM
20 Nov, 2022 12:06 PM
08 Nov, 2022 10:44 PM


05 Nov, 2022 08:40 AM
03 Nov, 2022 09:38 PM
24 Oct, 2022 11:32 AM
06 Oct, 2022 09:07 AM
05 Oct, 2022 02:22 AM
30 Sep, 2022 11:36 PM