Welcome to mirror list, hosted at ThFree Co, Russian Federation.

Noise.py « doc « api2_2x « python « blender « source - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 122fdd3eda18d437fd7223207bf1e84ea2528c8f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
# Blender.Noise submodule

"""
The Blender.Noise submodule.

Noise and Turbulence
====================

This module can be used to generate noise of various types.  This can be used
for terrain generation, to create textures, make animations more 'animated',
object deformation, etc.  As an example, this code segment when scriptlinked
to a framechanged event, will make the camera sway randomly about, by changing
parameters this can look like anything from an earthquake to a very nervous or
maybe even drunk cameraman... (the camera needs an ipo with at least one Loc &
Rot key for this to work!):

Example::
  from Blender import Get, Scene, Noise
  ####################################################
  # This controls jitter speed
  sl = 0.025
  # This controls the amount of position jitter
  sp = 0.1
  # This controls the amount of rotation jitter
  sr = 0.25
  ####################################################

  time = Get('curtime')
  ob = Scene.GetCurrent().getCurrentCamera()
  ps = (sl*time, sl*time, sl*time)
  # To add jitter only when the camera moves, use this next line instead
  #ps = (sl*ob.LocX, sl*ob.LocY, sl*ob.LocZ)
  rv = Noise.vTurbulence(ps, 3, 0, Noise.NoiseTypes.NEWPERLIN)
  ob.dloc = (sp*rv[0], sp*rv[1], sp*rv[2])
  ob.drot = (sr*rv[0], sr*rv[1], sr*rv[2])

@type NoiseTypes: readonly dictionary
@var NoiseTypes: The available noise types.
    - BLENDER
    - STDPERLIN
    - NEWPERLIN
    - VORONOI_F1
    - VORONOI_F2
    - VORONOI_F3
    - VORONOI_F4
    - VORONOI_F2F1
    - VORONOI_CRACKLE
    - CELLNOISE

@type DistanceMetrics: readonly dictionary
@var DistanceMetrics: The available distance metrics values for Voronoi.
    - DISTANCE
    - DISTANCE_SQUARED
    - MANHATTAN
    - CHEBYCHEV
    - MINKOVSKY_HALF
    - MINKOVSKY_FOUR
    - MINKOVISKY
"""

NoiseTypes = {'BLENDER':0, 'STDPERLIN':1}

DistanceMetrics = {'DISTANCE':0}

def random ():
  """
  Returns a random floating point number."
  @rtype: float
  @return: a random number in [0, 1).
  """

def randuvec ():
  """
  Returns a random unit vector.
  @rtype: 3-float list
  @return: a list of three floats.
  """

def setRandomSeed (seed):
  """
  Initializes the random number generator.
  @type seed: int
  @param seed: the seed for the random number generator.  If seed = 0, the
      current time will be used as seed, instead.
  """

def noise (xyz, type = NoiseTypes['STDPERLIN']):
  """
  Returns general noise of the optional specified type.
  @type xyz: tuple of 3 floats
  @param xyz: (x,y,z) float values.
  @type type: int
  @param type: the type of noise to return.  See L{NoiseTypes}.
  @rtype: float
  @return: the generated noise value.
  """

def vNoise (xyz, type = NoiseTypes['STDPERLIN']):
  """
  Returns noise vector of the optional specified type.
  @type xyz: tuple of 3 floats
  @param xyz: (x,y,z) float values.
  @type type: int
  @param type: the type of noise to return.  See L{NoiseTypes}.
  @rtype: 3-float list 
  @return: the generated noise vector.
  """

def turbulence (xyz, octaves, hard, basis = NoiseTypes['STDPERLIN'],
    ampscale = 0.5, freqscale = 2.0):
  """
  Returns general turbulence value using the optional specified noise 'basis'
  function.
  @type xyz: 3-float tuple
  @param xyz: (x,y,z) float values.
  @type octaves: int
  @param octaves: number of noise values added.
  @type hard: bool
  @param hard: noise hardness: 0 - soft noise; 1 - hard noise.  (Returned value
      is always positive.)
  @type basis: int
  @param basis: type of noise used for turbulence, see L{NoiseTypes}.
  @type ampscale: float
  @param ampscale: amplitude scale value of the noise frequencies added.
  @type freqscale: float
  @param freqscale: frequency scale factor.
  @rtype: float
  @return: the generated turbulence value.
  """

def vTurbulence (xyz, octaves, hard, basis = NoiseTypes['STDPERLIN'], ampscale = 0.5, freqscale = 2.0):
  """
  Returns general turbulence vector using the optional specified noise basis function.
  @type xyz: 3-float tuple
  @param xyz: (x,y,z) float values.
  @type octaves: int
  @param octaves: number of noise values added.
  @type hard: bool
  @param hard: noise hardness: 0 - soft noise; 1 - hard noise.  (Returned
      vector is always positive.)
  @type basis: int
  @param basis: type of noise used for turbulence, see L{NoiseTypes}.
  @type ampscale: float
  @param ampscale: amplitude scale value of the noise frequencies added.
  @type freqscale: float
  @param freqscale: frequency scale factor.
  @rtype: 3-float list
  @return: the generated turbulence vector.
  """

def fBm (xyz, H, lacunarity, octaves, basis = NoiseTypes['STDPERLIN']):
  """
  Returns Fractal Brownian Motion noise value (fBm).
  @type xyz: 3-float tuple
  @param xyz: (x,y,z) float values.
  @type H: float
  @param H: the fractal increment parameter.
  @type lacunarity: float
  @param lacunarity: the gap between successive frequencies.
  @type octaves: float
  @param octaves: the number of frequencies in the fBm.
  @type basis: int
  @param basis: type of noise used for the turbulence, see L{NoiseTypes}.
  @rtype: float
  @return: the generated noise value.
  """

def multiFractal (xyz, H, lacunarity, octaves, basis = NoiseTypes['STDPERLIN']):
  """
  Returns Multifractal noise value.
  @type xyz: 3-float tuple
  @param xyz: (x,y,z) float values.
  @type H: float
  @param H: the highest fractal dimension.
  @type lacunarity: float
  @param lacunarity: the gap between successive frequencies.
  @type octaves: float
  @param octaves: the number of frequencies in the fBm.
  @type basis: int
  @param basis: type of noise used for the turbulence, see L{NoiseTypes}.
  @rtype: float
  @return: the generated noise value.
  """

def vlNoise (xyz, distortion, type1 = NoiseTypes['STDPERLIN'],
    type2 = NoiseTypes['STDPERLIN']):
  """
  Returns Variable Lacunarity Noise value, a distorted variety of noise.
  @type xyz: 3-float tuple
  @param xyz: (x,y,z) float values.
  @type distortion: float
  @param distortion: the amount of distortion.
  @type type1: int
  @type type2: int
  @param type1: sets the noise type to distort.
  @param type2: sets the noise type used for the distortion.
  @rtype: float
  @return: the generated noise value.
  """

def heteroTerrain (xyz, H, lacunarity, octaves, offset,
    basis = NoiseTypes['STDPERLIN']):
  """
  Returns Heterogeneous Terrain value.
  @type xyz: 3-float tuple
  @param xyz: (x,y,z) float values.
  @type H: float
  @param H: fractal dimension of the roughest areas.
  @type lacunarity: float
  @param lacunarity: gap between successive frequencies.
  @type octaves: float
  @param octaves: number of frequencies in the fBm.
  @type offset: float
  @param offset: it raises the terrain from 'sea level'.
  @type basis: int
  @param basis: noise basis determines the type of noise used for the
      turbulence, see L{NoiseTypes}.
  @rtype: float
  @return: the generated value.
  """

def hybridMFractal (xyz, H, lacunarity, octaves, offset, gain,
    basis = NoiseTypes['STDPERLIN']):
  """
  Returns Hybrid Multifractal value.
  @type xyz: 3-float tuple
  @param xyz: (x,y,z) float values.
  @type H: float
  @param H: fractal dimension of the roughest areas.
  @type lacunarity: float
  @param lacunarity: gap between successive frequencies.
  @type octaves: float
  @param octaves: number of frequencies in the fBm.
  @type offset: float
  @param offset: it raises the terrain from 'sea level'.
  @type gain: float
  @param gain: scale factor.
  @type basis: int
  @param basis: noise basis determines the type of noise used for the
      turbulence, see L{NoiseTypes}.
  @rtype: float
  @return: the generated value.
  """

def ridgedMFractal (xyz, H, lacunarity, octaves, offset, gain,
    basis = NoiseTypes['STDPERLIN']):
  """
  Returns Ridged Multifractal value.
  @type xyz: 3-float tuple
  @param xyz: (x,y,z) float values.
  @type H: float
  @param H: fractal dimension of the roughest areas.
  @type lacunarity: float
  @param lacunarity: gap between successive frequencies.
  @type octaves: float
  @param octaves: number of frequencies in the fBm.
  @type offset: float
  @param offset: it raises the terrain from 'sea level'.
  @type gain: float
  @param gain: scale factor.
  @type basis: int
  @param basis: noise basis determines the type of noise used for the
      turbulence, see L{NoiseTypes}.
  @rtype: float
  @return: the generated value.
  """

def voronoi(xyz, distance_metric = DistanceMetrics['DISTANCE'], exponent = 2.5):
  """
  Returns Voronoi diagrams-related data.
  @type xyz: 3-float tuple
  @param xyz: (x,y,z) float values.
  @type distance_metric: int
  @param distance_metric: see L{DistanceMetrics}
  @type exponent: float
  @param exponent: only used with MINKOVSKY, default is 2.5.
  @rtype: list
  @return: a list containing a list of distances in order of closest feature,
  and a list containing the positions of the four closest features.
  """

def cellNoise (xyz):
  """
  Returns cellnoise.
  @type xyz: 3-float tuple
  @param xyz: (x,y,z) float values.
  @rtype: float
  @return: the generated value.
  """

def cellNoiseV (xyz):
  """
  Returns cellnoise vector/point/color.
  @type xyz: 3-float tuple
  @param xyz: (x,y,z) float values.
  @rtype: 3-float list
  @return: the generated vector.
  """