柏林噪声场如何工作?
我特别看这个例子:
http://www.airtightinteractive.com/ demos/processing_js/noisefield08.html
这是它的代码:
http://www.airtightinteractive.com/demos/processing_js/noisefield08.pjs
我我想我需要解释这些线在粒子类中的作用:
d=(noise(id,x/mouseY,y/mouseY)-0.5)*mouseX;
x+=cos(radians(d))*s;
y+=sin(radians(d))*s;
我知道噪声根据给定的坐标计算一个值,但我不明白将粒子的 x 位置除以的逻辑mouseY 或 mouseY 的 y 位置。我也不明白“id”是什么,它似乎是一个计数器代表什么,或者接下来的两行完成什么。
谢谢
I'm looking at this example in particular:
http://www.airtightinteractive.com/demos/processing_js/noisefield08.html
And here's the code for it:
http://www.airtightinteractive.com/demos/processing_js/noisefield08.pjs
I guess I need explaining for what these lines do in the particle class:
d=(noise(id,x/mouseY,y/mouseY)-0.5)*mouseX;
x+=cos(radians(d))*s;
y+=sin(radians(d))*s;
I understand that noise calculates a value based on the coordinates given, but I don't get the logic in dividing the particles' x pos by the mouseY, or the y pos by the mouseY. I also don't understand what 'id', which seems to be a counter stands for, or what the next two lines accomplish.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
d 似乎是运动方向。通过将 mouseY 和 mouseX 放入
d
的计算中,它允许基础字段依赖于鼠标位置。如果没有更好地理解函数本身,我无法准确地告诉您 mouseY 和 mouseX 对场上的影响。通过运行 cos(radians(d)) 和 sin(radians(d)),代码将角度 (d) 转换为单位向量。例如,如果 d 为 1 弧度,则 cos(radians(d)) 将为 -1,sin(radians(d)) 将为 0,因此它将角度 1 弧度转换为单位向量 (-1,0)。
因此,似乎存在一些潜在的运动场决定了粒子移动的方向。运动场由噪声函数表示,并接受粒子的当前位置、粒子 id(可能给予每个粒子独立的运动,或者可能记住粒子运动的历史并基于该历史记录未来的运动)和鼠标的当前位置。
粒子移动的实际距离是 s,它是在 2 到 7 个像素之间随机确定的。
d seems to be the direction of motion. By putting mouseY and mouseX into the calculation of
d
it allows the underlying field to depend on the mouse position. Without a better understanding of the function itself I can't tell you exactly what affect mouseY and mouseX have on the field.By running cos(radians(d)) and sin(radians(d)) the code turns an angle (d) into a unit vector. For example, if d was 1 radian then cos(radians(d)) would be -1 and sin(radians(d)) would be 0 so it turns the angle 1 radians into the unit vector (-1,0).
So it appears that there is some underlying motion field which determines the direction the particles move. The motion field is represented by the noise function and takes in the current position of the particle, the particle id (perhaps to give each particle independent motion or perhaps to remember a history of the particle's motion and base the future motion on that history) and the current position of the mouse.
The actual distance the particle moves is s which is determined randomly to be between 2 and 7 pixels.
通过运行 cos(radians(d)) 和 sin(radians(d)),代码将角度 (d) 转换为单位向量。例如,如果 d 为 1 弧度,则 cos(radians(d)) 将为 -1,sin(radians(d)) 将为 0,因此它将角度 1 弧度转换为单位向量 (-1,0)。< /em>
稍微修正一下:即旋转 pi 弧度(180 度),而不是 1 弧度(大约 57 度)。
By running cos(radians(d)) and sin(radians(d)) the code turns an angle (d) into a unit vector. For example, if d was 1 radian then cos(radians(d)) would be -1 and sin(radians(d)) would be 0 so it turns the angle 1 radians into the unit vector (-1,0).
Slight correction: that is a rotation of pi radians (180 degrees), not 1 radian (around 57 degrees).