简体   繁体   English

使用1D perlin噪音创建粗略/不稳定的线条

[英]create sketchy / wobbly line using 1D perlin noise

Could somebody help me get started with pseudo code or steps to use the 1D perlin noise to draw sketchy/wobbly lines as depicted in the page 有人可以帮助我开始使用伪代码或步骤使用1D perlin噪声来绘制粗略/不稳定的行,如页面所示

http://freespace.virgin.net/hugo.elias/models/m_perlin.htm http://freespace.virgin.net/hugo.elias/models/m_perlin.htm

摇摇晃晃的圈子
(source: virgin.net ) (来源: virgin.net

I did find that aforge.net has functions for 1D and 2D perlin noise functions. 我确实发现aforge.net具有1D和2D perlin噪声功能的功能。 It shows an example ofusing the 2D noise to generate clouds. 它显示了使用2D噪声生成云的示例。

http://www.aforgenet.com/framework/docs/html/f2f36ce1-ddab-389e-b538-0ccaca81fa87.htm http://www.aforgenet.com/framework/docs/html/f2f36ce1-ddab-389e-b538-0ccaca81fa87.htm

But am not sure how to go about using it to generate wobbly lines. 但我不确定如何使用它来产生不稳定的线条。

Only difference you need to make going from 1D to 2D is to calculate the slope. 只需要从1D到2D进行差异即可计算出斜率。 Once you have the slope and the 1D noise, just add that noise in the direction perpendicular to the direction of slope. 一旦得到斜率和1D噪声,只需在垂直于斜率方向的方向上添加噪声。

I saw your question hoping for pseudocode as an answer. 我看到你的问题希望伪代码作为答案。 I ended up not using the gradient (I already have a simplex noise function that would be difficult to make compatible) but doing something else. 我最终没有使用渐变(我已经有一个难以兼容的单面噪声函数)但是做了其他事情。

The idea is to choose an interval length (unity is fine, but larger ones will yield less rounding error) and using a random seed consider the noise interval [s, s + I] where I is the interval length and s is the seed. 我们的想法是选择一个区间长度(单位是好的,但是较大的那些将产生较少的舍入误差)并且使用随机种子考虑噪声区间[s, s + I]其中I是区间长度而s是种子。 You then "wrap" it around a circle by mapping an angle theta to I / (2 * Pi) * theta . 然后,通过将角度θ映射到I / (2 * Pi) * theta ,将其“环绕”圆圈。 However, you need to make sure that the noise values of s and s + I are the same, else you would have a discontinuity in the circle. 但是,您需要确保ss + I的噪声值相同,否则您将在圆圈中出现不连续性。 This is easy, however; 然而,这很容易; given x in [s, s + I] , just do this: [s, s + I]给出x ,只需这样做:

interpolate(x, s, I)
  mid <- noise(s) - noise(s + I)
  out <- noise(x)
  out <- out + (x - s) / I * mid
  out <- out - (s + I - x) / I * mid
  return out

Note that if x = s , we subtract mid , and if x = s + I , we add mid . 注意,如果x = s ,我们减去mid ,如果x = s + I ,我们加上mid

We now have a mapping from an angle to a noise value. 我们现在有一个从角度到噪声值的映射。 Given the radius we wish our circle to have, we can set the minimum and maximum values of the noise then, for any theta we wish to evaluate, just add the corresponding value to the radius of the circle. 给定我们希望我们的圆所具有的半径,我们可以设置噪声的最小值和最大值,然后,对于我们想要评估的任何θ,只需将相应的值添加到圆的半径。 In polar coordinates, this looks like: 在极坐标中,这看起来像:

radius(theta)
  s <- randomDouble
  I <- 1
  theta <- theta / (2 * pi)
  dr <- interpolate(theta, s, I)
  dr <- dr * (noisemax - noisemin) / 2 + (noisemax + noisemin) / 2
  return dr + r

assuming you already have your average radius ( r ) and the variance you want ( noisemin , noisemax ), and that your noise function outputs values in [-1, 1] . 假设您已经具有平均半径( r )和所需的方差( noiseminnoisemax ),并且您的噪声函数输出[-1, 1] You will want a tight spread between noisemax and noisemin, else your circle will be mostly wobble. 你需要在noisemax和noisemin之间进行紧密的传播,否则你的圈子将会大部分摆动。

For a square the process it the same but you do not need any controls or interpolation, just the scaling factors and an interval square side length. 对于正方形,它的过程相同,但您不需要任何控制或插值,只需缩放因子和间隔方边长。

You can get fancy and do a nonlinear interpolation but I don't really see the need, and it might mess up the simplex noise. 你可以得到想象力并进行非线性插值,但我真的没有看到它的需要,它可能会弄乱单纯形噪声。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM