I'm trying to draw a ishihara in code ( like this http://en.wikipedia.org/wiki/Ishihara_colourblindness_test ). And am having trouble with generating the random pattern of dots.
Basically I need to create random size dots that more or less fill the area, but don't overlap. I'm sure there is some clever way of doing this, but I don't know how.
My current approach is brute force. Create a dots at a random location, then check if it overlaps with those drawn previously. If it does, I skip it, and draw a new one. Repeat a 100.000 times or so. It's close to working, but it's hard to get a completely dense pattern, and there are more small dots than big ones, as they are less likely to overlap (and it's extremely slow...but that's not a big issue).
I'm thinking one of two ways should be possible:
1. Recursive function, that work a little bit like paint bucket fill tool. I've done some code like this in the past (can't find it), but it get's more complex with random size dots and no grid pattern.
2. Procedural texture style. Using worley or cell or something. I've used these in 3D software, but they may be a bit too complex for me to get my head around in code. I'm no math expert. :)
Any suggestions on how to approach this?
Doesn't matter in which language, I'm currently writing it in php and outputing svg. But BlitzMax/Blitz3D would work just as fine.
Ragnar
Basically I need to create random size dots that more or less fill the area, but don't overlap. I'm sure there is some clever way of doing this, but I don't know how.
My current approach is brute force. Create a dots at a random location, then check if it overlaps with those drawn previously. If it does, I skip it, and draw a new one. Repeat a 100.000 times or so. It's close to working, but it's hard to get a completely dense pattern, and there are more small dots than big ones, as they are less likely to overlap (and it's extremely slow...but that's not a big issue).
I'm thinking one of two ways should be possible:
1. Recursive function, that work a little bit like paint bucket fill tool. I've done some code like this in the past (can't find it), but it get's more complex with random size dots and no grid pattern.
2. Procedural texture style. Using worley or cell or something. I've used these in 3D software, but they may be a bit too complex for me to get my head around in code. I'm no math expert. :)
Any suggestions on how to approach this?
Doesn't matter in which language, I'm currently writing it in php and outputing svg. But BlitzMax/Blitz3D would work just as fine.
Ragnar