Coding Challenge #33: Poisson-disc Sampling

In this Coding Challenge, I implement a “Poisson-disc Sampling” algorithm to evenly (but randomly) distribute a set of seed points throughoutt a canvas. The algorithm is implemented in JavaScript using p5.js.

Support this channel on Patreon:

Send me your questions and coding challenges!:


Links discussed in this video:
Jason Davies’ reference:
Robert Bridson’s paper on the subject:

Source Code for the Video Lessons:


For More Coding Challenges:

Help us caption & translate this video!






36 responses to “Coding Challenge #33: Poisson-disc Sampling”

  1. Yannick Bergs Avatar

    Great video! Please someone try to convince me that I should use Python rather than Java Can't understand why everybody seems to use Python today

  2. ning wang Avatar

    you can add "break" after the line "ok = false" to save some time….

  3. Bradley Hull Avatar

    You have taught me from the ground up, everything about p5!! Thank you for everything!! CHOO CHOO!!

  4. Maxwell Goulding Avatar

    Could you make a video showing how to set up P5.js from the beginning?

  5. Kim Avatar

    Bridson is awesome! He did some Fluid Simulation Stuff! His Book is 70 EUR, though…

  6. clemente ferrer Avatar

    Have you considered implementing a convex hull algorithm in a video? I think this would be interesting in either processing or p5

  7. René van Emelen Avatar

    if not found error 404 xD

  8. Chris Nelson Avatar

    Dammit Shiffman why are you so awesome?

  9. nabiddy badiddy Avatar

    love the 1 second goodbyes at the end 😀

  10. Sebastian Dreijer Avatar

    You are very likable. Your voice reminds me of Mitchell's from Modern Family.

  11. PsyNeur Avatar

    13:12 "its more readable this way" how is for (var i = 0; i < grid.length; i++) more readable than grid.forEach(function (cell) {})

  12. peabrainiac Avatar

    Do you know a good graphics library for c++ on windows? I couldn't find one

  13. ZhootSe Avatar

    The break you have on line 68 @ 38:24 – As you said youself, the pattern would generate faster if you skipp the break. I would've skipped it instead of doing the for total thing 😉

  14. Shockszzbyyous Avatar

    hsv is awesome for creating nice pallets 😀

  15. stropheum Avatar

    I love the ends of the video when you play around with stuff. It's so annoying how you always tend to rush through that stuff because you feel like you're dragging the video on for too long, though. I think it might be a cool thing to have something like coding challenge aftermath videos, where after the challenge is done, you're just fiddling with different ways to play with the code. It's super interesting to me (and i assume others) and will make the actual challenge videos a lot more concise

  16. Flo Mo Avatar

    MORE SOUNDBOARD, love it.

  17. Nulono Avatar

    It'd be nice to see not just the active points, but the ones currently looking around them.

  18. Toxi Core Avatar

    why don't you use "const" and "let" ? =(

  19. Tordek Avatar

    Hey, Daniel, there's a small issue with the part of your generator where you try to check the validity of a point: you only check the grid [-1,+1] places away, but strictly speaking you need to check [-2,+2], because it's possible that, even though all of the immediate neighbors are empty, there is a point too close two grid spots away.

    That point could be as close as r/sqrt(n) (which is obviously less than r), so there's a (slim) chance that you could generate two points less than r away.

  20. peron smurf Avatar

    nice video, you deserve much more for your effort. 2d array for active points ([] []) would have made it so easy

  21. AJ JANA Avatar

    your videos are just awesome. could you implement this algorithm and make an interesting code out of this algorithm.

  22. Thomas Ingram Avatar

    When you do the annulus sampling your method isn't uniform is it? You get a denser distribution closer to r.
    You'd want:
    theta = 360 * random(TWO_PI);
    dist = sqrt(random()*(pow(R1,2)-pow(R2,2))+pow(R2,2));

    vs naïve:

  23. Johnny Avatar

    Hey Daniel, can you do JavaScript tutorials?, you make your videos so much fun, and if you have fun learning you learn faster. If you can, try to cover as if you're teaching new students :P. Would be really helpful <3 <3 <3

  24. Daniele Scotece Avatar

    got the printed version of the nature of code and I must say Really Good Stuff Sir

  25. Dickhead Records Avatar

    can you read all of my academic papers for me? thanks

  26. Kyle Amoroso Avatar

    Wow this was a really interesting video! I think making a Grid object could have made the code a little more clear, but I learned a lot from this, thank you!

  27. abeechr Avatar

    Where can I get a coding rainbow sticker?!

  28. Manuel Bonet Avatar

    Bootyful? Are you sure?

  29. legotechnic27 Avatar

    also, I might be commenting prematurely, but with your 1d array storing 3d data, it will wrap around when going to the side, instead of returning undifined.

  30. legotechnic27 Avatar

    I would love to see a video about quadtree things. I am actually making my own 2d physics engine (as a fun challenge) and am using a cell system like this to store my bodies. I have read a lot about quadtrees on the internet though, and don't see the benefit of them.

  31. Everest Ev10 Avatar

    hi daniel ! can you actually make programs with p5.js that you can sell or you do them just for fun? can i make this types of things in javascript (drawing objects.etc) without using p5 program?

  32. yonatan linik Avatar

    wasn't this already uploaded?

Leave a Reply

Your email address will not be published. Required fields are marked *