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:
  • ...NEEEEEEieieiirrrnngngne eEEEEEEEEEEee eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeernrng!

    • by mwvdlee (775178)

      It's a nice idea.
      Too bad it's not supported by the majority of browsers.
      Try again in a few years, when all IE6-using companies have finally upgraded to IE7.

      • by asdf7890 (1518587)
        It is hardly a new idea: I've seen similar things done before, though with the images as the backgrounds to divs rather than as multiple background values for the html or body tags.

        Heck, some old 8/16-bit games (scrollers mainly) used a similar technique to draw their backgrounds, and it can also be a cheap way to distribute items around a map (pick a few of pseudo-random primes, and use them in a 2D grid to decide where to put things: items go on or near points where the patterns produced by the primes
  • Fuck you slashdot (Score:2, Informative)

    by Anonymous Coward

    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.

  • ... whatever that dude is smoking.

  • 1 is not prime (Score:3, Insightful)

    by PriNT2357 (1742498) on Thursday April 07, 2011 @02:39PM (#35748718)
    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. . ."
    • True. One is divisible by one and one...primes require distinctness of divisors. Nice catch.
      • by AP31R0N (723649)

        i thought it was that primes have TWO divisors, one AND itself (itself being something other than one). One has one divisor, and does not me the AND requirement (or the two divisors requirement). Or that's what they told us in school in the 80s.

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

      by Cyberax (705495)

      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.

      • Re:1 is a prime. (Score:5, 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.

        • by PhilHibbs (4537)

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

          Is that theorem supposed to include the prime numbers?

      • by PhilHibbs (4537)

        The way I think of it is, prime numbers are the building blocks of numbers. When you find a new prime number, you can use multiplication to make new numbers that you couldn't make before. The number 1 doesn't help making new numbers, so it isn't a multiplicational building block.

    • While it is isn't correct, I do recall being told in school that one is a prime because it is only divisble by itself.

  • Other applications. (Score:5, Interesting)

    by Toze (1668155) on Thursday April 07, 2011 @02:40PM (#35748726)
    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.
    • by jank1887 (815982)

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

    • I understand his desire to make backgrounds look large and random with a minimum of downloading images, but in a game; what's wrong with just using random numbers for critter generation?

      • by Toze (1668155)
        Nothing, assuming you just want stuff for people to kill. The plan is to generate an ecosystem of varied plants, prey, and predators that can be affected by players; over-harvesting, farming, etc. A simple model based on primes seems, at first glance, to be much more conducive to emergent gameplay than tweaking random numbers.
  • It's kind of neat that you can involve a little math in something like web design. Granted this isn't calculus, but it's still a fun little way to make neat patterns.
  • by erroneus (253617) on Thursday April 07, 2011 @03:03PM (#35749058) Homepage

    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.

    • by DeionXxX (261398)

      CSS3. Lots of cool stuff in there. Background gradients, rounded corners, animation, etc.

    • by Hooya (518216) on Thursday April 07, 2011 @03:15PM (#35749226) Homepage

      > 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 [wikipedia.org]

      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.

      • Um... If Columbus challenged his critics to stand an egg on it's tip, then why is the statue showing the egg standing on it's end?
      • I concur, this was a really cool technique, i had seen a few articles with clever use of transparency for certain effects. this one is pretty sweet though i suspect it takes quite a bit of work to make sure your layers blend in a nice way

        you also still have to avoid uinque features. for example even if you were varying width and height to make say a stone or gravel pattern, if you had one particularly unique stone in the upper layers it would stick out still. same with knots in wood.

        it might have some uses

      • by blincoln (592401)

        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, becau

        • by mrxak (727974)

          Yeah, I've used prime cycles to generate random-like occurrences before. Struck me as obvious, really, though my application of the concept isn't graphical. Anyway, it was a good read. I would love to see something like this put into video game textures for stuff like wood and stone.

          • by trb (8509)
            Ya me too, cycling sine wave frequencies with different odd/prime values in x and y to generate wobble patterns. I probably learned about this idea when I was a kid playing with a Spirograph. I still like this tiling hack though.
        • For example, you couldn't use it (at least without modification) for most 3D object textures, because it only introduces variation along one axis.

          That's true for his first two examples (only because he picked inherently non-tiling-in-the-y-direction things), but the third (the Lego army) varied in two dimensions.

        • by Sloppy (14984) on Thursday April 07, 2011 @07:15PM (#35751622) Homepage Journal

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

      • True indeed. In fact, I would go farther. I think this has the potential to become a classic textbook example of number theory.

        This is an impressive and visually interesting application of basic number theory. I would not be surprised if we began seeing the presentations modelled on the Legion of Lego [sitepoint.com] showing up in the slides of number theory lectures in the near future.

    • by Ksevio (865461)
      Up until a few months ago support was even worse. We've only recently gotten support for many useful CSS3 elements.
  • 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.
  • ...that my first thought was "Ah, someone has finally understood why Gödel numbering [wikipedia.org] is clever..."?
    • My immediate reaction was that this kind of stuff is taught in introductory CS lectures as Perlin Noise, I suppose web developers with their javascript don't need to learn real programming or the application of complex algorithms :)
  • by DrVomact (726065) on Thursday April 07, 2011 @05:03PM (#35750362) Journal

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

    • by trb (8509)
      This person is generating nice repeating patterns (like pleated curtains) with random alterations, using a small number of small image files and a small amount of computation to generate random numbers which guide the placement of those image files. Doing this with fractals would require computation that is orders of magnitude more costly.
      • by DrVomact (726065)

        This person is generating nice repeating patterns (like pleated curtains) with random alterations, using a small number of small image files and a small amount of computation to generate random numbers which guide the placement of those image files. Doing this with fractals would require computation that is orders of magnitude more costly.

        Yeeesss...I know. There I go, being elliptical again. It was a joke...albeit I was trying to draw attention to an underlying question. I sometimes wonder about predictions that were made back in [the day] that seem to have pretty much evaporated. The whole definition of what a fractal is always struck me as somewhat lacking in rigor. The popular science press of the late 80s and early 90s was full of talk about fractals, and one of the suggested applications was indeed to computationally generate super-real

        • by trb (8509)
          I don't know what happened to fractals (in landscape image generation). I remember the "the Genesis effect" [youtube.com] from back before the turn of the century. There's a wikipedia artcile on factal landscapes, but I don't know what's up with that these days.
  • by hawkfish (8978)

    Q: How do you tell a mathematician, a physicist and an engineer apart with one question?

    A: Ask them "Are all the odd numbers above 2 prime?"

    Mathematician: Well, 3 is prime, 5 is prime, 7 is prime, 9 is not prime, so NO.

    Physicist: Well, 3 is prime, 5 is prime, 7 is prime, 9 is not prime, but that is just experimental error.

    Engineer: Well, 3 is prime, 5 is prime, 7 is prime, 9 is prime, 11 is prime...

    (My father was an engineer, my brother is a physicist and I was a mathematician at one point, so this turned i

You will lose an important disk file.

Working...