Slashdot Mirror


Using Prime Numbers to Generate Backgrounds

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.

33 of 180 comments (clear)

  1. Let me be the first to say... by multipartmixed · · Score: 2, Interesting

    ...NEEEEEEieieiirrrnngngne eEEEEEEEEEEee eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeernrng!

    --

    Do daemons dream of electric sleep()?
  2. Fuck you slashdot by Anonymous Coward · · Score: 2, Informative

    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.

    1. Re:Fuck you slashdot by spun · · Score: 2, Insightful

      He's not the only one, bucky. No need to be an ass. I don't have the problem with the post anonymously checkbox, but I have not been able to click on any off-site links for a week, using Firefox 3.6.16. Internet Exploder works, but I'm not using that POS.

      --
      - None can love freedom heartily, but good men; the rest love not freedom, but license. -- John Milton
    2. Re:Fuck you slashdot by gstoddart · · Score: 2

      Probably because you haven't yet learned the intricacies of the "web browser", the "mouse" and quite possibly "the computer". Orrrr... you're somehow being served up a different version of slashdot than the rest of us.

      Maybe you are oh-so-lucky as to have Slashdot behave consistently and predictably lately.

      Half of the time when I go to meta-moderate, the +/- buttons don't do anything at all -- they're inert, and clicking on them doesn't do anything. Sometimes, if I browse away and come back, it works. Sometimes it doesn't work for days. I mean, I would expect the behavior of a web page to be deterministic but apparently that's not the case.

      It's been making me go "WTF" for a couple of weeks now. I've even reverted to the oldest-school layout because some of the stuff was acting even weirder.

      It's hard not to conclude there are some things on Slashdot that are working intermittently, and not in ways you might always predict.

      Dial it back ... he's not the only one seeing Slashdot behave somewhat flaky of late.

      --
      Lost at C:>. Found at C.
    3. Re:Fuck you slashdot by MozeeToby · · Score: 3, Insightful

      The new UI has been getting more buggy every week rather than less buggy. Off site links not working, clicking 'score' to view how things are moderated collapsing the comment, scrolling issues, clicking anywhere on the comment navigating to the parent, weird highlighting when submitting a comment... and that's just off the top of my head and coming from someone who was initially supportive of the changes. All on FF4.0

    4. Re:Fuck you slashdot by X0563511 · · Score: 2

      I can't even right click now. $DEITY knows how I've been keeping my spelling in check without being able to use the spell.... check.

      --
      For large sets, this will be our guide even unto death, for the LORD will work for each type of data it is applied to...
    5. Re:Fuck you slashdot by manwargi · · Score: 2

      I have no mod points so yeah frigging THIS. Between right clicking only working half the time, offsite links never working anymore, needing to open up all the parent posts to view post scores, and so much more, the redesign has been quite the pain.

  3. 1 is not prime by PriNT2357 · · Score: 3, Insightful

    They can't even quote an article they link to properly
    Their article: "that is,1, 2, 3, 5, 7, 11, 13, 17, 19, 23, and so on"
    Wikipedia: "2, 3, 5, 7, 11, 13. . ."

    1. Re:1 is not prime by jank1887 · · Score: 2

      yes, but dividing by themselves gives 1 and dividing by 1 gives themselves, hence distinctness of divisors.

  4. Other applications. by Toze · · Score: 4, Interesting

    Cool. I've looking at automatically generating stuff for games recently. Obviously, this works for authentic-looking backgrounds, but my friends and I were working on a project that involved automating critter generation using classic predator-prey models. One big worry was the farming-to-death of critters that are part of an ecosystem. This idea might be useful for much more nicely randomized or randomized-seeming mob population/spawning.

    --
    No OS on the planet can protect itself from a user with the admin password. - Yvan256
    1. Re:Other applications. by jank1887 · · Score: 2

      great. now we get the gold farmers in on factoring large primes. all encryption is about to go out the window.

  5. Re:TL;DR by Anonymous Coward · · Score: 4, Insightful

    How about: Designer discovers new way to use special properties of primes to create more realistic tiled background images.

    C'mon, the results are actually pretty cool.

  6. Re:TL;DR by gstoddart · · Score: 3, Funny

    Designer discovers basic properties of the prime numbers (and confuses 1 for a prime).

    You missed the important thing ... designer creates huge frickin' lego army using a small number of images and some pretty smart use of CSS.

    An army, but make out of lego. Put lasers on them and see who takes over the world. :-P

    --
    Lost at C:>. Found at C.
  7. Re:OMG Sicadas are illuminati by Gordonjcp · · Score: 3, Informative

    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.

  8. Re:Ow. That made my brain hurt. by bigsexyjoe · · Score: 2

    It doesn't matter if cicadas are important to birds or any other predator. Predators are important to cicadas.

    In any case, he's talking about making things look random enough for casual observation. He's not talking about some sort of advanced encryption algorithm. We know we can appeal to advance math and chaos theory for truly random. But this is just web design. If someone actually cracks the pattern, it isn't the end of the world.

  9. Re:Ow. That made my brain hurt. by spun · · Score: 5, Insightful

    Just because you do not understand something does not make it wrong. Birds haven't "evolved" a boom/bust cycle, that's not how that works. It's the standard predator/prey boom/bust cycle. Birds don't spend vast periods of time underground, you know. Curtains are natural, "natural" here taking the meaning of "organic" rather than "patterned.

    Please, don't be one of those guys who tries to prove how smart they are by attempting to find fault with the article. It does not make you look as smart as you think. The fact that you hurt your brain trying to comprehend something the rest of us had no trouble understanding actually makes you look pretty dumb.

    --
    - None can love freedom heartily, but good men; the rest love not freedom, but license. -- John Milton
  10. Really learned a LOT from that one by erroneus · · Score: 3, Interesting

    Not only did I learn interesting information about the insects I hate the most (and believe me, if I could, I would destroy every last one of the annoying bugs!) but I also learned that you can have multiple images for backgrounds in CSS and have them lay atop one another. (None of the books or software ever seemed to suggest that it was even possible!)

    While the idea is pretty ingenious, if I had known you could specify more than one image for backgrounds, I would have figured this one out on my own -- I have been overlaying images and background images inside of DIVs for a while to get some really nice effects. But now, to be able to lay one atop the another in the same block? AWESOME.

    And yes, at the article says, inferior browsers cannot handle this -- I tried it on IE8 to see what would happen and... yeah... it hung.

    1. Re:Really learned a LOT from that one by Hooya · · Score: 5, Insightful

      > if I had known you could specify more than one image for backgrounds, I would have figured this one out on my own

      You may want to read this: http://en.wikipedia.org/wiki/Egg_of_Columbus

      I have been doing layered images for over 4-5 years (multiple divs with backgrounds layered over one another) to come up with cool effects. But I would have never come up with this. I had been thinking about tiles and the non-random-ness for quite a while too. This didn't occur to me. Now that someone put this together - sure it's simple. But that's the genius of it.

      My hats are off - simple, efficient, brilliant.

    2. Re:Really learned a LOT from that one by blincoln · · Score: 2

      It's not *that* revolutionary. A few months ago, I used the same general principle to make a more interesting rotating "please wait" symbol: I made multiple ring animations with transparent backgrounds, with each ring completing one revolution in a different number of frames. I used odd numbers, but not primes specifically. Anyway, the result was conceptually the same - it takes quite awhile before the rings ever line up in exactly the way they started, but only a handful of animation frames are used, because it's separate files overlaid on each other, and each one alone is a short animation. I was thinking of the "counter-rotating concentric rings" look that has been used everywhere from Tron to Dead Space. The designers on those may have even done exactly the same thing I did.

      I'm also curious to see just how useful this specific technique is for things other than website backgrounds. For example, you couldn't use it (at least without modification) for most 3D object textures, because it only introduces variation along one axis.

      --
      "...always new atoms but always doing the same dance, remembering what the dance was yesterday." -Richard Feynman
    3. Re:Really learned a LOT from that one by Sloppy · · Score: 3, Interesting

      It's not *that* revolutionary. A few months ago, I used the same general principle..

      Well, that's the thing. The general principle is ancient. Using parametrics where each output maps to its own relatively prime cycle to get a very long period .. shit, I was doing that 27 years ago on my Vic20 to make some pretty graphs. (Really.) x=cos(t/7); y=sin(t/13); Graph it, varying "t"; it's purty. And it's pretty damn unlikely that I was the first person to discover (not invent) it; anyone fucking around is eventually going to stumble onto this kind of stuff.

      But this is about background images (and not just background images, but background images on web pages), and I sure as hell wasn't doing that on my Vic20.

      This reminds me the basic difficulty with patents. The ideas themselves often really aren't new, so they're not only obvious in hindsight, but they're even obvious to everyone without hindsight if you ever find yourself working on a problem in a certain area, but if you never end up working on the problems, you're never going to use the idea, so a guy really can be first to do something so basic, in 2011. (Whether this guy actually is, I don't know.) Sure, if you were ever assigned the problem of generating an image with a long period, you might invent this. But did you? (Have you ever needed to generate a background image with a long period? If so, then very likely might have done this. If not, then you just wouldn't ever come up with it.)

      And then some poor schmuck of a patent examiner is supposed to make a judgement call that people in general think is fair. No chance; he's doomed to fail, no matter which way he goes.

      All that aside, it's a cool idea and props to the guy. Just don't fucking patent it, ok? ;-)

      I'm also curious to see just how useful this specific technique is for things other than website backgrounds. For example, you couldn't use it (at least without modification) for most 3D object textures, because it only introduces variation along one axis.

      Heh heh.. don't worry, you'll have the any-dimensional case figured out in a few minutes, if you haven't already. :-)

      --
      As copyright owner of this comment, I authorize everyone to defeat any technological measure which limits access to it.
  11. Why did you do this? You hate America?? by 140Mandak262Jamuna · · Score: 2

    Now, next time Iran fakes out a missile launch test and claims it has tested some 53 rockets and shows pictures, it is going to be impossible to detect the cut/paste jet plumes.

    --
    sed -e 's/Chuck Norris/Rajnikant/g' joke > fact
  12. Re:1 is the loneliest (non-prime) number by Hognoxious · · Score: 2

    One is itself, so it only has one factor. Really.

    --
    Confucius say, "Find worm in apple - bad. Find half a worm - worse."
  13. Re:TL;DR by sootman · · Score: 4, Interesting

    How about: Designer comes up with interesting, relevant use of math that all the Math geeks who have been running the WWW for 20 years didn't think of on their own.

    Subtitle: Bitter math nazis harp on his confusion about 1 being a prime.

    --
    Dear Slashdot: next time you want to mess with the site, add a rich-text editor for comments.
  14. Re:1 is the loneliest (non-prime) number by maxwell+demon · · Score: 3, Informative

    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.

    --
    The Tao of math: The numbers you can count are not the real numbers.
  15. Re:Ow. That made my brain hurt. by _0xd0ad · · Score: 5, Informative

    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

    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.

  16. Re:1 is a prime. by Anonymous Coward · · Score: 3, Informative

    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.

  17. Re:1 is a prime. by ObsessiveMathsFreak · · Score: 4, Informative

    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.

    --
    May the Maths Be with you!
  18. Re:Congratulations... by _0xd0ad · · Score: 5, Informative

    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).

  19. Whatever happened to fractals? by DrVomact · · Score: 2

    Cool, but aren't we all supposed to be using fractals to generate realistic-looking virtual worlds and such by now? I mean, that's what I thought when I read that Scientific American article back in the 80s, and wrote a C program that ran for two weeks on my Compaq to create a picture of a Mandelbrot set. What was really funny was that the Compaq screen was grey scale...

    --
    Great men are almost always bad men--Lord Acton's Corollary
  20. Re:Ow. That made my brain hurt. by JordanL · · Score: 3, Insightful

    You somehow simultaneously displayed a lack of understanding for the mechanisms of evolution (mutation and natural selection), and obliviousness to the point of the mathematics being discussed: using prime numbers to reduce periodicty of a given set of cycles.

    Also, your third and fourth paragraphs display utter ignorance of biology.

    Why are you even here? This article was very well articulated, and more important, useful, unlike your reply.

  21. Re:Ow. That made my brain hurt. by spun · · Score: 2

    No, you are simply wrong, as I quite clearly demonstrated, which is why you were modded down and I was modded up. So let me try to explain it in the very simple terms you need.

    Again, birds did not evolve a boom/bust cycle. They can not pick it through evolution, it is not up to them, it is up to their predators and food sources. As the article clearly explains, a prime number cycle for cicadas ensures that only ONE predator boom/bust cycle will match up with theirs, and natural predator/prey cycles are not ever that long. Here, all you demonstrate is a complete lack of understanding of evolution and ecology.

    You also have quite clearly either not read, or not understood the article. More importantly, you appear to not have even looked at the pictures. By overlapping patterns in prime cycles, a complex pattern is built up that does not appear repetitive to the eye. It was clearly demonstrated in the pictures, in case you are illiterate.

    Curtains ARE nature, everything is. Hanging curtains create a natural, complex pattern of folds. A standard repeating background does not have those same complex patterns.

    When you say "random things look random because they are random." you clearly demonstrate again that you have not read the article. Are curtains random? If you generated a 'random' curtain texture and tiled it, would it still appear random? No! It would not be seamless. But if you generated the tile using prime numbers, you could tile it and not see obvious seams.

    As I explained, they are not using prime numbers to mimic randomness, they are using them to create tiles that appear seamless. You total fucking idiot.

    When you claim "Fifth, nature does cyclical rather handily; not everything need be random to look natural." you AGAIN clearly demonstrate your total lack of comprehension about the article. They are not trying to create "random" you microencephalic retard, they trying to create background patterns that can be repeated across a page without appearing to be repeating tiles. You utter cretin.

    Now fuck off and let the smart people talk. I'm done with you, you're dismissed from class.

    --
    - None can love freedom heartily, but good men; the rest love not freedom, but license. -- John Milton
  22. Re:Why prime? Any irrational numbers should be fin by curril · · Score: 2

    Well, the images do have to be an integer number of pixels wide, but if the ratio between lengths approximated an irrational number you would expect long periods. Even relatively prime numbers would work. Tiles of length 7, 15, and 16 won't repeat for 1,680 pixels. Basically, if you want to create a nice, non-repetitive pattern of overlayed tiles, make certain that the smallest common multiple for all of the tile sizes is larger than your expected screen width.

  23. Re:TL;DR by DMUTPeregrine · · Score: 2

    Penrose tiles are cooler. They are aperiodic, the tiling never repeats, instead of just having a long period.

    --
    Not a sentence!