Pages

Monday, February 15, 2010

Bring the (Perlin) Noise

If you just want the source code: The JavaScript Perlin noise generator code is here.

I mentioned in a previous post that I was working on a Perlin noise generator for Art Evolver.

Perlin noise is a function of (x, y) that produces a random-ish pattern. It's not completely random because it has smooth hills and valleys, but the distribution of those hills and valleys is random.

A side note about this algorithm: Usually if you're a computer scientist and you come up with a clever algorithm to solve a particular problem, you get an award from a university, or a CS-centric professional organization like the ACM or IEEE. Perlin got an Academy Award for this noise function. As in, the Oscar kind of Academy Award.  For an algorithm, something not usually consider artsy.  I found that interesting.

Anyways, rather than dive into Perlin's impenetrable description of how the algorithm works, I set out to find an existing JavaScript implementation. That let me to this message board, and specifically this example.

Unfortunately that implementation has some pretty serious directional artifacts:

Note the horizontal and vertical stripes.  There's almost an upside down cross in the lower right. SAAAATAAAAN!

Rather than try to fix that source code (which the author apparently closureized (making it very difficult to understand)) I kept searching.

From the main Wikipedia entry on Perlin noise, I ran across a variant called Simplex noise.  This is an improvement on the original algorithm, also written by Ken Perlin, in 2001.  That Wikipedia page linked to a paper by Stefan Gustavson(pdf) that explains both classical and Simplex Perlin noise in a much easier to grok way than anything I've read by Perlin himself.  I highly recommend Gustavson's paper if you found Perlin difficult.

I took the Java source code in Gustavson's paper and ported it to JavaScript, and the results are here on github.

I ran some performance comparisons between the classical and Simplex algorithms, and for 2-D I only saw a ~10% improvement with Simplex.  Granted, the latter is supposed to be faster in higher dimensions (classical is O(N^2) vs. simplex O(N) where N is the number of dimensions) so it doesn't matter much for my purposes.

Classical Perlin noise

Simplex Perlin noise

Subjectively I think I prefer the Simplex noise to classical, so I'll probably go with that for Art Evolver.

Again, the source code is here.

59 comments:

  1. Thank you for sharing with good, useful, helpful review. If you are looking for cheap insurance quotes, it necessary to know that when you get cheap house insurance, you save much more on rates from home insurers.

    ReplyDelete
    Replies
    1. A IEEE project is an interrelated arrangement of exercises, having a positive beginning and end point and bringing about an interesting result in Engineering Colleges for a particular asset assignment working under a triple limitation - time, cost and execution. Final Year Project Domains for CSE In Engineering Colleges, final year IEEE Project Management requires the utilization of abilities and information to arrange, plan, plan, direct, control, screen, and assess a final year project for cse. The utilization of Project Management to accomplish authoritative objectives has expanded quickly and many engineering colleges have reacted with final year IEEE projects Project Centers in Chennai for CSE to help students in learning these remarkable abilities.


      Spring Framework has already made serious inroads as an integrated technology stack for building user-facing applications. Spring Framework Corporate TRaining the authors explore the idea of using Java in Big Data platforms.
      Specifically, Spring Framework provides various tasks are geared around preparing data for further analysis and visualization. Spring Training in Chennai

      Delete
  2. Hi, Sean -

    I'm using your code for 2D simplex noise in JavaScript and trying to get it to reproduce something like the image you have posted above. I can get noise, but it is very pixelated, with none of the larger scale features you have above.

    All I am doing is creating a blank image data, setting each pixel to rgba(255,0,0,1.0), and running each pixel through the noise function. I set noise = (noise+1)/2 to bring it back to a [0,1] range and multiply it by the r channel and the alpha channel.

    Clearly, I'm doing something wrong. Would you be willing to share the code you used to generate the simplex photo? I'm happy to share my own, but won't poison your blog with it unasked.

    /ejt

    ReplyDelete
  3. Classic perlin noise is O(2^n) complexity and simplex perlin noise is O(n^2) complexity. Definitely not O(n) :)

    ReplyDelete
  4. Thank you for sharing some good, useful, useful comments. If you're looking for cheap insurance quotes, it is necessary to know, when you get cheap home insurance, you save more about rate from insurance companies.
    jerseys cheap

    ReplyDelete
  5. Thank you for taking the time to provide us with your valuable information. We strive to provide our candidates with excellent care.As always, we appreciate your confidence and trust in us..
    SAP Training in chennai

    ReplyDelete
  6. Thanks a lot for all your valuable article! We are really happy about the your...
    SAP Training in chennai

    ReplyDelete
  7. Interesting Article

    JavaScript Training in CHennai HTML5 Training in Chennai HTML5 Training in Chennai JQuery Training in Chennai JQuery Training in Chennai JavaScript Training in Chennai JavaScript Training in Chennai

    JavaScript Training in CHennai JavaScript Training in CHennai JQuery Online Training JQuery Online Training

    ReplyDelete
  8. Thanks for the informative article. This is one of the best resources I have found in quite some time. Nicely written and great info. I really cannot thank you enough for sharing.
    rpa training in Chennai | rpa training in bangalore

    ReplyDelete
  9. Great job.... Awesome list, just starting a blog and this is going to be a massive help. Thank you!

    Node JS Training in Chennai
    Node JS Training

    ReplyDelete
  10. You have a good point here!I totally agree with what you have said!!Thanks for sharing your views...hope more people will read this article!!!
    Haroon Ullah

    ReplyDelete
  11. I think this is one of the most significant information for me. And i’m glad reading your article. But should remark on some general things, The web site style is perfect, the articles is really great : D. Good job, cheers Click here

    ReplyDelete
  12. Hi, This is nice article you shared great information i have read it thanks for giving such a wonderful Blog for reader.
    fence repair jacksonville

    ReplyDelete
  13. Very nice bro, thanks for sharing this with us. Keep up the good work and Thank you for sharing information
    fence repair jacksonville

    ReplyDelete
  14. Thanks for a wonderful share. Your article has proved your hard work and experience you have got in this field. Brilliant .i love it reading.
    bathroom remodel broward county

    ReplyDelete
  15. This comment has been removed by the author.

    ReplyDelete
  16. Thanks for a wonderful share. Your article has proved your hard work and experience you have got in this field. Brilliant .i love it reading.
    fort lauderdale remodeling contractors

    ReplyDelete
  17. You have a good point here!I totally agree with what you have said!!Thanks for sharing your views...hope more people will read this article!!! vinyl fence tampa

    ReplyDelete
  18. Hi, This is nice article you shared great information i have read it thanks for giving such a wonderful Blog for reader.
    tile reglazing atlanta

    ReplyDelete
  19. I think this is one of the most significant information for me. And i’m glad reading your article.emergency water removal services miami

    ReplyDelete
  20. Hi, This is nice article you shared great information i have read it thanks for giving such a wonderful Blog for reader.
    bathtub refinishing and fiberglass expert los angeles

    ReplyDelete
  21. Superbly written article, if only all bloggers offered the same content as you, the internet would be a far better place. mold remediation companies miami

    ReplyDelete
  22. i have read it thanks for giving such a wonderful Blog for reader.
    phoenix remodeling contractors

    ReplyDelete
  23. Excellent experienced for me to read your great blog, I really impressed. I eagerly waiting for your future updates..
    safari hotel lahore

    ReplyDelete
  24. Finally I found a great post with interesting topic.
    123movie

    ReplyDelete