Forgot your password?
typodupeerror
Graphics Math Science

Using Prime Numbers to Generate Backgrounds 180

Posted by Unknown Lamer
from the insects-are-surprisingly-good-at-design dept.
bpeh123 pointed out an article about generating organically tiled backgrounds inspired by the life cycle of cicadas. The trick is to overlay multiple background tiles with prime widths thus generating a series that does not repeat for a sufficiently long period. This introduces a seeming irregularity and makes the background appear much more natural.
This discussion has been archived. No new comments can be posted.

Using Prime Numbers to Generate Backgrounds

Comments Filter:
  • Fuck you slashdot (Score:2, Informative)

    by Anonymous Coward on Thursday April 07, 2011 @02:35PM (#35748652)

    Why can I only check Post Anonymously when I post a new comment but not a reply? Also, it would be kinda cool if I could click on fucking links again without having to triple right click and then open in a new window.

  • by Anonymous Coward on Thursday April 07, 2011 @02:38PM (#35748700)

    From TFA:

    They’re all prime numbers—numbers that can only be divided by themselves and 1 (that is,1, 2, 3, 5, 7, 11, 13, 17, 19, 23, and so on).

    FAIL. 1 is not prime.

  • by Gordonjcp (186804) on Thursday April 07, 2011 @02:50PM (#35748858) Homepage

    Yes, some characters do. The Slashdot Janitors have decreed that only 7-bit ASCII can be used on the site and everything else should be presented in as broken a way as possible.

    Because obviously, we're geeks so we're all using 30-year-old ADM3A terminals.

  • 1 is a prime. (Score:2, Informative)

    by Cyberax (705495) on Thursday April 07, 2011 @03:08PM (#35749134)

    There are two schools of thought, one considers 1 to be a prime (since its divisors are "1" and itself) the other school of thought doesn't. Some proofs work nicer if 1 is considered to be a prime, some proofs don't.

    So it's just a matter of opinion.

  • by maxwell demon (590494) on Thursday April 07, 2011 @04:05PM (#35749804) Journal

    Primes have, by definition, exactly two factors. 1 has only one: 1.

    Of course, you could define them differently, and a hundred years ago, 1 indeed was considered a prime. But the definition excluding 1 has turned out to be much more useful (because almost everywhere you use primes you'd have to add "except 1" otherwise), therefore 1 is no longer considered prime.

  • by _0xd0ad (1974778) on Thursday April 07, 2011 @04:14PM (#35749892) Journal

    The point isn't randomness, the point is unwanted harmonics in pseudo-random patterns. These unwanted harmonics cause regular repetitions in the pattern that make it seem predictable and non-random. Prime numbers are the basis by which a simple PRNG (pseudo-random number generator) generates seemingly-random data that doesn't repeat in any predictable manner. By overlapping two or more sequences with prime lengths, the length of the harmonic is maximized. That means the sequence goes longer before repeating itself. Sequences with non-prime lengths short-circuit the cycle.

    For instance, overlapping three sequences of length 7, 11, and 13 forms the following pattern:
    http://tinyurl.com/3wserj7 [tinyurl.com]

    At a glance, the pattern looks fairly random and non-repeating; however if you look more closely you see that the vertical bands of color are repeating very regularly within the pattern. But, since their periodicity is prime, the pattern as a whole doesn't appear to repeat itself. Using alpha and larger 2-dimensional tiles you can create even more complex and random-seeming patterns.

    The life cycle of cicadas is similar in that the overlapping cycles tend to cause a seemingly-random pattern of years with lots of cicadas and few cicadas, such that the life cycle of their predators is less likely to hit a bunch of good cicada years in a row and seriously harm the population of them.

  • Re:1 is a prime. (Score:3, Informative)

    by Anonymous Coward on Thursday April 07, 2011 @04:37PM (#35750094)

    A lot of proofs in recursion / computability theory actually depend on the fact that one is not a prime number. More specifically, they depend on the property of numbers that is called unique factorisation into primes, a very important theorem in mathematics that is a corner stone for many proofs in a variety of mathematical disciplines. If you count 1 as a prime number, this theorem does not hold, with all the consequences that you might suspect it entails.

    Just sayin'. 1 is not a prime number.

  • Re:1 is a prime. (Score:5, Informative)

    by ObsessiveMathsFreak (773371) <obsessivemathsfreakNO@SPAMeircom.net> on Thursday April 07, 2011 @04:49PM (#35750204) Homepage Journal

    This is in fact true.

    The best reason for leaving one out of the prime number set is because it enables you to state the prime number theorem more succinctly:

    Every integer n>1 has a unique factorisation as a product of primes (Prime factorisation)

    If one was prime, then the factorisation would not be unique. For example 6=2.3, but if 1 was an allowed prime then 6=1.2.3=1.1.2.3=1.1.1.2.3= .... 1^n .2.3. So it's preferred to leave one out.

    There are other reasons, but the prime number theorem is perhaps the best one.

  • by _0xd0ad (1974778) on Thursday April 07, 2011 @04:56PM (#35750282) Journal

    This is very much not like Perlin noise, because Perlin noise uses octaves (doubles in frequency). Octaves are harmonic with each other by definition. This uses primes, specifically to cause the harmonics to occur as far apart as possible. Using octaves in this way would cause very repetitive-seeming patterns because the maximum size of your pattern would be defined as the size of your largest sequence, and all of the shorter sequences would tile into it in a neat checkerboard.

    Perlin noise requires infinite sequences of pseudo-random numbers and would be extremely ill-suited to using short repeating sequences. This is specifically designed to minimize the length of the sequences you use without causing obvious repetitions in the pattern by using sequences of prime length (since your "sequence" is a PNG, if it's too large it takes a long time to load).

"Just Say No." - Nancy Reagan "No." - Ronald Reagan

Working...