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."
From TFA:
FAIL. 1 is not prime.
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
Question: Do cicadas come every 17 years, or do they come every year?
Having lived in the Deep South for 5 years I seem to remember cicadas coming every year. Wikipedia says there are "broods" and there's 2500 different species. So, was I seeing a different species every year, or did I just see a different brood every year? I think I saw 2 different species.
How many more years will slashdot have an off-by-one error on your Score in your profile?
...that my first thought was "Ah, someone has finally understood why Gödel numbering is clever..."?
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.
... there's too many of them.
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
...Are in order for the web developer community; they've discovered Perlin Noise! Aww bless! Meanwhile, game developers everywhere have been using this technique to generate anything from planetary landscapes to entire galaxies for a while now. Baby steps guys.
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
I've been using primes as max-mount-count for my ext3 filesystems to avoid checking them all at the same time for years
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
Your type of comment is the reason /. is off my bookmarks. Here some guy come up with something positive, inspirational and beautiful, but no, it has to be dead, lifeless, boring and utterly correct. BS comments and BS perspectives for keeping alive your pet dogmas and paradigms.
Thing is, I do understand it, which is why I know it's wrong.
I'm not "one of those guys who tries to prove how smart they are by attempting to find fault with the article." I am smart. I found fault with the article. Several faults, upon review.
Not being smart when complaining about my complaining being not smart makes you a hypocrite, and doesn't reduce my smartitude one bit.
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
The last time I discovered an "unwanted harmonic in pseudo-random patterns" I found that if you combine the return values from rand(3) in a certain way there's a consistent pattern to the final bit. But only in a certain way. You can't detect that periodicity just by doing a discrete fourier transform on its outputs.
Yes, a PRNG, particularly an LCRNG, depends inexorably on the lack of common factors in its coefficients. But that's an aside to what this article is implying (though if he'd gone any further he might have derived an LCRNG from his degenerate use of prime numbers; one with a strikingly low periodicity, but then he says the words "degenerate example" and I'm okay with it as an example, and reminded of Martin Gardner and Jearl Walker teaching us all how such things work back when SciAm was worth the paper it was printed on).
The fact is, using rand(3) produces a lot less periodicity than using the same 3 numbers in various combinations. And, as I said, the latter eliminates accidental periodic subpatterns that would make the output look more natural. 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).
It makes no more sense to me to use prime numbers as opposed to pi or anything else that will give you irrational numbers.
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
If this site isn't bookmarked, how did you get here?
No, he doesn't have to be "utterly correct". But being somewhere inside the ballpark on his basic premises would be a decent thing.
His attempt to make this look "positive, inspirational and beautiful" by falsely linking the reproductive cycles of a living thing to his webpage-background generator clanked. That's too bad. But, as it turns out, he clanked all over the page, so maybe it was only natural.
We've all seen capable examples of the nature-as-inspiration-for-mathematical-discovery trope (Hofstadter, Myers, Burke, Dewdney, etc. made a great genre out of them). Generally they're logical in themselves, and that's a beautiful thing. But when they're illogical it's not a beautiful thing, it's a self-conscious attempt to look like the people who can do it properly, or a failure to realize that the form is not the substance.
Have fun not reading /. I hear it's almost as enlightening as reading /.
Now you're just trolling.
You demonstrated nothing, you merely claimed something, and you were wrong about that.
I didn't say birds evolved into a boom/bust cycle. They evolved to survive boom/bust cycles, not to depend on them. It's irrelevant to them whether cicadas all appear on the same period or have mutually-prime periods of reproduction. And vice-versa. I also didn't say anything about whether the cycles were predator/prey-based or not. You're just making up things you didn't read in what I wrote.
When you find a nice set of pleated velvet curtains growing in the forest, then you can say they're natural. Otherwise you're playing childish semantic games with the word "natural".
Seamlessness of joining tiles does not rely on primeness. It only relies on having the same depth and slope of the curtain's fold on either side of the tile. What happens between those boundary conditions doesn't change that, no matter what you base the rest of the tile on.
They absolutely are using prime numbers to mimic randomness. They say so. Their goal is "when you notice a distinctive feature—for instance, a knot in some woodgrain—repeating at regular intervals, it really breaks the illusion of organic randomness. Maybe we borrow some ideas from cicadas to break that pattern?" Their illogical deduction about the cicadas and randomness aside, they use that to mimic the randomness they seek in their tiling. They could just use a random-number generator and not conflate cicadas' relative-prime cycles with randomness.
Frankly, I can't see anything you got right. So maybe when you realize you're not teaching a class so much as mouthing off from the corner with a dunce cap on, you'll apologize to the rest of us.
Wait. I forgot one thing:
Yes, I got modded down and you got modded up.
I got modded up for being "insightful", down for being "overrated", and up for being "redundant", meaning I wasn't the only one who recognized something was wrong with the article.
You got modded up by people who agreed with your assessment of my post, which is not proof that anything was wrong with my post, and couldn't be, because there was nothing wrong with my post.
So if you somehow intended your observation about the mod points to mean you're right and I'm wrong, you still didn't get anything right.
There. All better. Now go play.
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.
Hi, one of your moderator's here.
Just FYI, once you get enough karma to actually get mod points, you will find that there is no moderation for "wrong" or "horribly wrong". That's why you got "overrated". The other negative options besides "overrated" are "off topic", "flamebait", and "troll". You were on topic, weren't really flaming, and I didn't think you were trolling. I just think you aren't very bright.
Hi, no, you're not one of my moderators, unless you took the trouble to go to another IP address and log in under a different login then check the AC box. The system isn't stupid enough to let you moderate and then post because you clicked the AC box.
I don't doubt someone disagreed with me, but that's all they did. Even if they thought I was wrong doesn't mean I'm wrong, and to think so is to fall prey to the Fallacy of Appeal to Popularity. Doubly so, since "Overrated" was only one of three mod votes I got, and doesn't even therefore count as the popular choice.
If it was you who clicked "Overrated" and you thought I was wrong, you were wrong. If it wasn't you, then you get to sit there munching on your wasted life while I enjoy being right again.
Yes, yes I am.
I happen to have two computers here on my desk, and didn't want to undo my moderation by posting on the first one.
Which is how I just modded your post offtopic because it's getting pretty far afield from the topic.
Not bright at all.
This is not the prime number theorem, this is the fundamental theorem of arithmetic. There's only 2 millennia worth of mathematics between the two :).
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.
How the feck can this be considered news? The use of prime numbers have been used this way for ages (encryption and RNG to name the two most obvious).
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.
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.
I'm not him, but who's to say that he moderated it more than once? That would require him to have 3 different accounts with mod points too, anyway. And all you have to do to post anonymously in a discussion you've already moderated in is use a different browser that you aren't logged in on.
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.
He said he moderated one of your posts overrated and the other post offtopic. I don't see where he said he'd moderated more than once on the same post. And he was moderating from one computer and posting from a different computer.
I also recall hearing someone claim that the user agent is significant, so just deleting the cookie might not be adequate. I do know that I've moderated from Firefox and then posted anonymously from IE and after refreshing the page in Firefox it didn't appear that the moderation had been removed.