We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi guys,
I'm having a hard time trying to display points pseudo-randomly on the screen using Perlin noise. Ideally I would like those points to form small clusters as they get close to each other (higher density). Quite like the dark areas of a texture generated by noise.
Do you have an idea how I could do that ?
My failed attempt:
def setup():
size(800, 600)
background(255)
t = 0
for x in range(0, width, 10):
for y in range(0, height, 10):
t += .001
p = PVector(x, y)
n = map(noise(p.x + t, p.y + t), 0, 1, 0, 10)
p.mult(n)
strokeWeight(2)
point(p.x, p.y)
Please note that I'm writing in Python here but the question is open to everyone and any help (ideas, suggestions, Java code) is welcomed.
Answers
I came up with this idea but it's certainly not the best solution: combining noise texture algorithm with a probabilistic function + add some randomness.
By tweaking the variables and computing Delaunay triangulations you can get interesting shapes
Anyway, if you have better suggestions, I would love to hear it.
@solub --
Hi @jeremydouglass.
What's important to me is the final result. Ideally I'd like to see the point density decreasing as points get farther away from the center of the "cluster" they belong to. In the Delaunay picture above you can see a clear and sudden separation between the clusters, there's no such gradation.
imagine a grid of potential l points -- e.g. 1 per pixel, or 1 per 2x2 pixels, etc.
each square is populated with a 2D Perlin noise value. the output value range of Processing's Perlin
noise()
is 0-1.0.map this to e.g. 255-128 to draw light and dark areas, and draw it as a colored pixel.
map this against a range of probabilities of drawing a point. E.g. (0.0001) to (0.3) to indicate low probability of drawing a point vs. high probability of drawing a point.
generate an independent
random()
number.... if the number is lower than thenoise()
number, draw a point!Now you can draw randomized clouds of points with density corresponding to 2D Perlin noise. Play with the probability parameters to get the kinds of point clouds that you want.
...in addition, as you have done above, you can drift the point when you place it.
Note that in your example,
What you have done is taken a low-pass filter on the perlin noise, leaving yourself fixed black blobs. You have then thinned the points in those blobs by a fixed thinning threshold (0.95, or 1/20). This means you are throwing almost all the randomness out and thinning a small slice of the data by a fixed amount -- I'm suggesting that you use all the randomness, populating by a variable amount. The downside of this approach is that there is a small chance you could get a point absolutely anywhere -- but you can fix this with a much smaller pass filter, throwing away the 10-20% of the Perlin noise you want to be white space (rather than throwing away almost all of the noise and then scattering the few the remaining points out by random(10)).
...there is another way to do this, which in some cases will have different behavior based on settings:
Note that if you get very large tiles or have dramatically different tiles (very dark or very light) next to each other, this will create a visible fencing effect, and you will see the bins.
Sorry, I think I have some language issue. I'm not sure to grasp the meaning of step 4: to "map [the noise value] against a range of probabilities". Do you think the following is an accurate translation of your explanation ?
@solub -- You are correct!
Your starter example takes the top half the noise map (128-255) and fills that with between 0 and 1/3 pixel density:
Try instead taking the top quarter of the noise map and scaling up to 1/5 density:
Or try other values for different visual results:
If you use randomSeed() at the beginning of draw to make each pass of random numbers deterministic then you can explore parameters interactively.
Here is an interactive example of your sketch with mouseX mapped against density, and mouseY mapped against your high-pass filter. Explore the space with your mouse to see what settings do to the output.
Notice that the sweet spot -- the exact kinds of dispersion or density you are hoping for -- may be extremely particular, and would have been very hard to find by just plugging in values and rerunning the sketch.
Also notice that these rates of dispersion all rely on the slope of the Perlin noise output, no matter how you scale it. If you want blobs have very dense centers and very broad sparse perimeters (like a fried egg), or if you want blobs that have elliptical outlines, et cetera... then you could use a similar process, but you don't want to use Perlin noise specifically.
Fantastic ! Many thanks for always providing super comprehensive answers and clever tips.