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.
...NEEEEEEieieiirrrnngngne eEEEEEEEEEEee eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeernrng!
Do daemons dream of electric sleep()?
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.
XML is a known as a key material required to create SMD: Software of Mass Destruction
"..While this is a rather rockâ(TM)nâ(TM)roll ending for our nerdy cicada, it raises an obvious question: Is it just by chance that they adopted 7, 11, or 13-ââyear life cycles, or are those numbers somehow special?" Those numbers always come up in conspiracy theories.
- "If one man can create that much hate, you can only imagine how much love we as a togetherness can create."
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. .
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
Designer discovers basic properties of the prime numbers (and confuses 1 for a prime).
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.
Democracy Now! - your daily, uncensored, corporate-free
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.
Democracy Now! - your daily, uncensored, corporate-free
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
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.
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.
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
One is itself, so it only has one factor. Really.
Confucius say, "Find worm in apple - bad. Find half a worm - worse."
...that my first thought was "Ah, someone has finally understood why Gödel numbering is clever..."?
But 1 is happy
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.
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.
Because I can't figure out the answer to this question! And whenever someone asserts that they only come every 17 years, it drives me crazy!
How many more years will slashdot have an off-by-one error on your Score in your profile?
You got truthiness in my mathematics!
This will not do. Oh no, no, no, no, no.
the preceding comment is my own and in no way reflects the opinion of the Joint Chiefs of Staff
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.
HDGary secures my bank
Remember also that there's multiple species on differing cycles.
-mrxak
Onions Will Kill You
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).
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
It's rather convenient to be able to say that every natural number has a unique factorisation. It allows you, for example, to take products over the factorisation (e.g. Euler's totient function phi(n) = n * PROD_p|n (1-1/p) which would have to be a product over "p|n AND p>1").
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.
FanFictionRecs.net
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
So one doesn't have to say "primes except 1" most of the time and can instead say "primes". It's just more convenient to exclude it.
Me: +5 Insightful.
You: -1 Redundant.
So..... why do YOU think you were modded down, and I was modded up, hmmm, asshole?
Don't be pedantic about the meaning of the word natural. You know as well as I and everyone else here what the author meant. You look like a prick when you argue semantics.
If you read the article, you would understand that the appearance of seamlessness can be achieved through overlapping prime-number repetition of patterns, as demonstrated by the photos. The point being, these images are meant to be tiled. The idea is NOT to use a random process to generate a non-repeating texture to cover the entire background. The idea is to create a small texture that can be tiled to cover a background without appearing to repeat. Do you simply not understand why a random process will fail? No, don't answer that, it was rhetorical, I KNOW you don't get it, you SAID as much.
Using prime numbers, the assure that visible components of a pattern, like the knot, do not repeat. It is not trying to achieve "random." Again, you are arguing semantics without understanding meaning. You argue the meaning of individual words taken out of context. You clearly do not understand what the article is trying to demonstrate.
Now fuck off, I said you were dismissed, that means I am done with you. Buh bye. Good day, sir. Respond all you like, your comments will be ignored by me, and most likely modded down some more by readers who DO understand what the article was saying. So please, by all means, respond, get modded down, and lose karma, hopefully to the point where you post at -1 and people don't have to even notice your existence.
In short,
Me: +5 insightful.
You: -1 redundant.
'nuff said. But maybe you could tell yourself a nice make-believe story about why all the mean people like me and hate you. Then you could continue to believe you are intelligent, despite all the evidence to the contrary.
- None can love freedom heartily, but good men; the rest love not freedom, but license. -- John Milton
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.
He's using pseudo random number generation to place images in a way that does not appear to repeat, this is pretty much exactly what Perlin Noise does, the way he composites images together is also similar to how one composites different layers of noise. The link I had in my OP also includes a specific section about NOT having each new octave be double the frequency of the last, specifically because you will get the standing wave like effect you mention. It's certainly a novel approach.
Do cicadas come every 17 years, or do they come every year?
Answer: Depends on the species.
Better Answer: Catch cicadas for 13 years and have them all identified.
Even Better: Raise a brood from each year's species and see how long they take to come out and mate.
Chrome functions fine with it?
On the one hand, that's good to know...
On the other hand, isn't having to switch to chrome to make it reliable kinda... not-very-open-sourcey? (If you'll pardon the lack of English construction in that psuedosentence, and in this fragment.)
-- IANAL, this isn't legal advice, and definitely isn't legal advice for you. Also, Squee!
hmm. I am surprised by the way people seem to be impressed by this. I though a few more /.ers would have written a hash function before.
Once you're getting to the point where your tiling algorithm is more complex than just "move right N places and place another copy of the tile" you might as well use the standard library you're given instead of reinventing the wheel (or the Monotonic Random Walk in this case).
If you wanted to generate your backgrounds on <canvas> elements with Javascript, sure, you could come up with something better using the built-in pseudo-random number generator. However, this is pretty good for a dumb, tiling CSS background pattern with a fairly large logical size but made up of relatively small elements.
Still, the key difference between this and Perlin noise is that this is formed by using short repeating patterns whereas Perlin noise relies upon an infinite pseudo-random number generator that shouldn't ever appear to repeat itself.
The pseudo-random number generation, in this case, is in the x,y offsets of the tiles, not in the data contained in the tiles themselves - the tiles themselves are static PNGs. It's basically very similar to a simple linear congruential generator determining where the data on the tiles ends up.
The images in question are bitmaps. Even on slashdot, they have integers for width and height. If you want to generalize, generalize to coprime, as other have noted.
Think global, act loco
As it turned out, flamebait would have been more fitting. Or it could be a particularly perfidious troll. Overrated was correct in any case.
So now you have three computers on your desk? because you modded it Overrated first, then posted, then modded it offtopic, that makes three.
Being a cheater indicates you have no respect for the facts, as well as no acquaintance with them.
Dude wrote a mess of code when a call to rand() would have done him solid. And then bragged about it.
Ow.
A mess of code? Did you even look at it? It was 3 static PNG images, and a CSS rule that looked like "background:url(image1.png),url(image2.png),url(image3.png);". Tiling the images was all done automatically by the browser.
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 into a family joke!)
You will not drink with us, but you would taste our steel? - Walter Matthau, The Pirates
I'm pretty sure that doesn't work, or just deleting a cookie would work. I may give it a try later. But he did say he'd moderated it more than once. Unless he was just lying.
How does putting up 3 images repeatedly forestall repetition?
Go up and click the tinyurl link I posted and see if you understand what I mean. The period of the pattern is the least common multiple of the dimensions of all 3 images, and if the dimensions of the images are prime, their LCM is relatively large.