Merge branch 'master' into blender2.8
[blender-addons.git] / ant_landscape / ant_noise.py
blobfdec9b87a7bc780caab90397e56ac7e1fc9058b7
1 # ##### BEGIN GPL LICENSE BLOCK #####
3 # This program is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU General Public License
5 # as published by the Free Software Foundation; either version 2
6 # of the License, or (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software Foundation,
15 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 # ##### END GPL LICENSE BLOCK #####
19 # Another Noise Tool - Noise and Effects
20 # Jimmy Hazevoet
22 import bpy
23 from mathutils.noise import (
24 seed_set,
25 noise,
26 turbulence,
27 turbulence_vector,
28 fractal,
29 hybrid_multi_fractal,
30 multi_fractal,
31 ridged_multi_fractal,
32 hetero_terrain,
33 random_unit_vector,
34 variable_lacunarity,
35 voronoi,
37 from math import (
38 floor, sqrt,
39 sin, cos, pi,
42 # ------------------------------------------------------------
43 # Height scale:
44 def Height_Scale(input, iscale, offset, invert):
45 if invert != 0:
46 return (1.0 - input) * iscale + offset
47 else:
48 return input * iscale + offset
51 # Functions for marble_noise and effects:
53 def Dist(x, y):
54 return sqrt((x * x) + (y * y))
57 def sin_bias(a):
58 return 0.5 + 0.5 * sin(a)
61 def cos_bias(a):
62 return 0.5 + 0.5 * cos(a)
65 def tri_bias(a):
66 b = 2 * pi
67 a = 1 - 2 * abs(floor((a * (1 / b)) + 0.5) - (a * (1 / b)))
68 return a
71 def saw_bias(a):
72 b = 2 * pi
73 n = int(a / b)
74 a -= n * b
75 if a < 0:
76 a += b
77 return a / b
80 def soft(a):
81 return a
84 def sharp(a):
85 return a**0.5
88 def sharper(a):
89 return sharp(sharp(a))
92 def no_bias(a):
93 return a
96 def shapes(x, y, z, shape=0):
97 p = pi
98 if shape is 1:
99 # ring
100 x = x * p
101 y = y * p
102 s = cos(x**2 + y**2) / (x**2 + y**2 + 0.5)
103 elif shape is 2:
104 # swirl
105 x = x * p
106 y = y * p
107 s = ((x * sin(x * x + y * y) + y * cos(x * x + y * y)) / (x**2 + y**2 + 0.5))
108 elif shape is 3:
109 # bumps
110 x = x * p
111 y = y * p
112 z = z * p
113 s = 1 - ((cos(x * p) + cos(y * p) + cos(z * p)) - 0.5)
114 elif shape is 4:
115 # wave
116 x = x * p * 2
117 y = y * p * 2
118 s = sin(x + sin(y))
119 elif shape is 5:
120 # z grad.
121 s = (z * p)
122 elif shape is 6:
123 # y grad.
124 s = (y * p)
125 elif shape is 7:
126 # x grad.
127 s = (x * p)
128 else:
129 # marble default
130 s = ((x + y + z) * 5)
131 return s
134 # marble_noise
135 def marble_noise(x, y, z, origin, size, shape, bias, sharpnes, turb, depth, hard, basis, amp, freq):
137 s = shapes(x, y, z, shape)
138 x += origin[0]
139 y += origin[1]
140 z += origin[2]
141 value = s + turb * turbulence_vector((x, y, z), depth, hard, basis)[1]
143 if bias is 1:
144 value = cos_bias(value)
145 elif bias is 2:
146 value = tri_bias(value)
147 elif bias is 3:
148 value = saw_bias(value)
149 else:
150 value = sin_bias(value)
152 if sharpnes is 1:
153 value = 1.0 - sharp(value)
154 elif sharpnes is 2:
155 value = 1.0 - sharper(value)
156 elif sharpnes is 3:
157 value = soft(value)
158 elif sharpnes is 4:
159 value = sharp(value)
160 elif sharpnes is 5:
161 value = sharper(value)
162 else:
163 value = 1.0 - soft(value)
165 return value
168 # vl_noise_turbulence:
169 def vlnTurbMode(coords, distort, basis, vlbasis, hardnoise):
170 # hard noise
171 if hardnoise:
172 return (abs(-variable_lacunarity(coords, distort, basis, vlbasis)))
173 # soft noise
174 else:
175 return variable_lacunarity(coords, distort, basis, vlbasis)
178 def vl_noise_turbulence(coords, distort, depth, basis, vlbasis, hardnoise, amp, freq):
179 x, y, z = coords
180 value = vlnTurbMode(coords, distort, basis, vlbasis, hardnoise)
182 for i in range(depth):
183 i+=1
184 value += vlnTurbMode((x * (freq * i), y * (freq * i), z * (freq * i)), distort, basis, vlbasis, hardnoise) * (amp * 0.5 / i)
185 return value
188 ## duo_multiFractal:
189 def double_multiFractal(coords, H, lacunarity, octaves, offset, gain, basis, vlbasis):
190 x, y, z = coords
191 n1 = multi_fractal((x * 1.5 + 1, y * 1.5 + 1, z * 1.5 + 1), 1.0, 1.0, 1.0, basis) * (offset * 0.5)
192 n2 = multi_fractal((x - 1, y - 1, z - 1), H, lacunarity, octaves, vlbasis) * (gain * 0.5)
193 return (n1 * n1 + n2 * n2) * 0.5
196 ## distorted_heteroTerrain:
197 def distorted_heteroTerrain(coords, H, lacunarity, octaves, offset, distort, basis, vlbasis):
198 x, y, z = coords
199 h1 = (hetero_terrain((x, y, z), 1.0, 2.0, 1.0, 1.0, basis) * 0.5)
200 d = h1 * distort
201 h2 = (hetero_terrain((x + d, y + d, z + d), H, lacunarity, octaves, offset, vlbasis) * 0.25)
202 return (h1 * h1 + h2 * h2) * 0.5
205 ## SlickRock:
206 def slick_rock(coords, H, lacunarity, octaves, offset, gain, distort, basis, vlbasis):
207 x, y, z = coords
208 n = multi_fractal((x,y,z), 1.0, 2.0, 2.0, basis) * distort * 0.25
209 r = ridged_multi_fractal((x + n, y + n, z + n), H, lacunarity, octaves, offset + 0.1, gain * 2, vlbasis)
210 return (n + (n * r)) * 0.5
213 ## vlhTerrain
214 def vl_hTerrain(coords, H, lacunarity, octaves, offset, basis, vlbasis, distort):
215 x, y, z = coords
216 ht = hetero_terrain((x, y, z), H, lacunarity, octaves, offset, basis ) * 0.25
217 vl = ht * variable_lacunarity((x, y, z), distort, basis, vlbasis) * 0.5 + 0.5
218 return vl * ht
221 # another turbulence
222 def ant_turbulence(coords, depth, hardnoise, nbasis, amp, freq, distortion):
223 x, y, z = coords
224 t = turbulence_vector((x/2, y/2, z/2), depth, 0, nbasis, amp, freq) * 0.5 * distortion
225 return turbulence((t[0], t[1], t[2]), 2, hardnoise, 3) * 0.5 + 0.5
228 # rocks noise
229 def rocks_noise(coords, depth, hardnoise, nbasis, distortion):
230 x,y,z = coords
231 p = turbulence((x, y, z), 4, 0, 0) * 0.125 * distortion
232 xx, yy, zz = x, y, z
233 a = turbulence((xx + p, yy + p, zz), 2, 0, 7)
234 pa = a * 0.1875 * distortion
235 b = turbulence((x, y, z + pa), depth, hardnoise, nbasis)
236 return ((a + 0.5 * (b - a)) * 0.5 + 0.5)
239 # shattered_hterrain:
240 def shattered_hterrain(coords, H, lacunarity, octaves, offset, distort, basis):
241 x, y, z = coords
242 d = (turbulence_vector(coords, 6, 0, 0)[0] * 0.5 + 0.5) * distort * 0.5
243 t1 = (turbulence_vector((x + d, y + d, z + d), 0, 0, 7)[0] + 0.5)
244 t2 = (hetero_terrain((x * 2, y * 2, z * 2), H, lacunarity, octaves, offset, basis) * 0.5)
245 return ((t1 * t2) + t2 * 0.5) * 0.5
248 # strata_hterrain
249 def strata_hterrain(coords, H, lacunarity, octaves, offset, distort, basis):
250 x, y, z = coords
251 value = hetero_terrain((x, y, z), H, lacunarity, octaves, offset, basis) * 0.5
252 steps = (sin(value * (distort * 5) * pi) * (0.1 / (distort * 5) * pi))
253 return (value * (1.0 - 0.5) + steps * 0.5)
256 # Planet Noise by: Farsthary
257 # https://farsthary.com/2010/11/24/new-planet-procedural-texture/
258 def planet_noise(coords, oct=6, hard=0, noisebasis=1, nabla=0.001):
259 x, y, z = coords
260 d = 0.001
261 offset = nabla * 1000
262 x = turbulence((x, y, z), oct, hard, noisebasis)
263 y = turbulence((x + offset, y, z), oct, hard, noisebasis)
264 z = turbulence((x, y + offset, z), oct, hard, noisebasis)
265 xdy = x - turbulence((x, y + d, z), oct, hard, noisebasis)
266 xdz = x - turbulence((x, y, z + d), oct, hard, noisebasis)
267 ydx = y - turbulence((x + d, y, z), oct, hard, noisebasis)
268 ydz = y - turbulence((x, y, z + d), oct, hard, noisebasis)
269 zdx = z - turbulence((x + d, y, z), oct, hard, noisebasis)
270 zdy = z - turbulence((x, y + d, z), oct, hard, noisebasis)
271 return (zdy - ydz), (zdx - xdz), (ydx - xdy)
274 ###----------------------------------------------------------------------
275 # v.1.04 Effect functions:
277 def maximum(a, b):
278 if (a > b): b = a
279 return b
282 def minimum(a, b):
283 if (a < b): b = a
284 return b
287 def Mix_Modes(a, b, mixfactor, mode):
288 mode = int(mode)
289 a = a * (1.0 - mixfactor)
290 b = b * (1.0 + mixfactor)
291 #1 mix
292 if mode == 0:
293 return (a * (1.0 - 0.5) + b * 0.5)
294 #2 add
295 elif mode == 1:
296 return (a + b)
297 #3 sub.
298 elif mode == 2:
299 return (a - b)
300 #4 mult.
301 elif mode == 3:
302 return (a * b)
303 #5 abs diff.
304 elif mode == 4:
305 return (abs(a - b))
306 #6 screen
307 elif mode == 5:
308 return 1.0 - ((1.0 - a) * (1.0 - b) / 1.0)
309 #7 addmodulo
310 elif mode == 6:
311 return (a + b) % 1.0
312 #8 min.
313 elif mode == 7:
314 return minimum(a, b)
315 #9 max.
316 elif mode == 8:
317 return maximum(a, b)
318 else:
319 return 0
322 Bias_Types = [sin_bias, cos_bias, tri_bias, saw_bias, no_bias]
323 Sharp_Types = [soft, sharp, sharper]
326 # Transpose effect coords:
327 def Trans_Effect(coords, size, loc):
328 x, y, z = coords
329 x = (x * 2.0 / size + loc[0])
330 y = (y * 2.0 / size + loc[1])
331 return x, y, z
334 # Effect_Basis_Function:
335 def Effect_Basis_Function(coords, type, bias):
336 bias = int(bias)
337 type = int(type)
338 x, y, z = coords
339 iscale = 1.0
340 offset = 0.0
342 ## gradient:
343 if type == 1:
344 effect = offset + iscale * (Bias_Types[bias](x + y))
345 ## waves / bumps:
346 elif type == 2:
347 effect = offset + iscale * 0.5 * (Bias_Types[bias](x * pi) + Bias_Types[bias](y * pi))
348 ## zigzag:
349 elif type == 3:
350 effect = offset + iscale * Bias_Types[bias](offset + iscale * sin(x * pi + sin(y * pi)))
351 ## wavy:
352 elif type == 4:
353 effect = offset + iscale * (Bias_Types[bias](cos(x) + sin(y) + cos(x * 2 + y * 2) - sin(-x * 4 + y * 4)))
354 ## sine bump:
355 elif type == 5:
356 effect = offset + iscale * 1 - Bias_Types[bias]((sin(x * pi) + sin(y * pi)))
357 ## dots:
358 elif type == 6:
359 effect = offset + iscale * (Bias_Types[bias](x * pi * 2) * Bias_Types[bias](y * pi * 2)) - 0.5
360 ## rings:
361 elif type == 7:
362 effect = offset + iscale * (Bias_Types[bias ](1.0 - (x * x + y * y)))
363 ## spiral:
364 elif type == 8:
365 effect = offset + iscale * Bias_Types[bias]( (x * sin(x * x + y * y) + y * cos(x * x + y * y)) / (x**2 + y**2 + 0.5)) * 2
366 ## square / piramide:
367 elif type == 9:
368 effect = offset + iscale * Bias_Types[bias](1.0 - sqrt((x * x)**10 + (y * y)**10)**0.1)
369 ## blocks:
370 elif type == 10:
371 effect = (0.5 - max(Bias_Types[bias](x * pi) , Bias_Types[bias](y * pi)))
372 if effect > 0.0:
373 effect = 1.0
374 effect = offset + iscale * effect
375 ## grid:
376 elif type == 11:
377 effect = (0.025 - min(Bias_Types[bias](x * pi), Bias_Types[bias](y * pi)))
378 if effect > 0.0:
379 effect = 1.0
380 effect = offset + iscale * effect
381 ## tech:
382 elif type == 12:
383 a = max(Bias_Types[bias](x * pi), Bias_Types[bias](y * pi))
384 b = max(Bias_Types[bias](x * pi * 2 + 2), Bias_Types[bias](y * pi * 2 + 2))
385 effect = min(Bias_Types[bias](a), Bias_Types[bias](b)) * 3.0 - 2.0
386 if effect > 0.5:
387 effect = 1.0
388 effect = offset + iscale * effect
389 ## crackle:
390 elif type == 13:
391 t = turbulence((x, y, 0), 6, 0, 0) * 0.25
392 effect = variable_lacunarity((x, y, t), 0.25, 0, 8)
393 if effect > 0.5:
394 effect = 0.5
395 effect = offset + iscale * effect
396 ## sparse cracks noise:
397 elif type == 14:
398 effect = 2.5 * abs(noise((x, y, 0), 1)) - 0.1
399 if effect > 0.25:
400 effect = 0.25
401 effect = offset + iscale * (effect * 2.5)
402 ## shattered rock noise:
403 elif type == 15:
404 effect = 0.5 + noise((x, y, 0), 7)
405 if effect > 0.75:
406 effect = 0.75
407 effect = offset + iscale * effect
408 ## lunar noise:
409 elif type == 16:
410 effect = 0.25 + 1.5 * voronoi((x, y, 0), 1)[0][0]
411 if effect > 0.5:
412 effect = 0.5
413 effect = offset + iscale * effect * 2
414 ## cosine noise:
415 elif type == 17:
416 effect = cos(5 * noise((x, y, 0), 0))
417 effect = offset + iscale * (effect * 0.5)
418 ## spikey noise:
419 elif type == 18:
420 n = 0.5 + 0.5 * turbulence((x * 5, y * 5, 0), 8, 0, 0)
421 effect = ((n * n)**5)
422 effect = offset + iscale * effect
423 ## stone noise:
424 elif type == 19:
425 effect = offset + iscale * (noise((x * 2, y * 2, 0), 0) * 1.5 - 0.75)
426 ## Flat Turb:
427 elif type == 20:
428 t = turbulence((x, y, 0), 6, 0, 0)
429 effect = t * 2.0
430 if effect > 0.25:
431 effect = 0.25
432 effect = offset + iscale * effect
433 ## Flat Voronoi:
434 elif type == 21:
435 t = 1 - voronoi((x, y, 0), 1)[0][0]
436 effect = t * 2 - 1.5
437 if effect > 0.25:
438 effect = 0.25
439 effect = offset + iscale * effect
440 else:
441 effect = 0.0
443 if effect < 0.0:
444 effect = 0.0
446 return effect
449 # fractalize Effect_Basis_Function: ------------------------------
450 def Effect_Function(coords, type, bias, turb, depth, frequency, amplitude):
452 x, y, z = coords
453 ## turbulence:
454 if turb > 0.0:
455 t = turb * ( 0.5 + 0.5 * turbulence(coords, 6, 0, 0))
456 x = x + t
457 y = y + t
458 z = z + t
460 result = Effect_Basis_Function((x, y, z), type, bias) * amplitude
461 ## fractalize:
462 if depth != 0:
464 for i in range(depth):
465 i+=1
466 x *= frequency
467 y *= frequency
468 result += Effect_Basis_Function((x, y, z), type, bias) * amplitude / i
470 return result
473 # ------------------------------------------------------------
474 # landscape_gen
475 def noise_gen(coords, props):
477 terrain_name = props[0]
478 cursor = props[1]
479 smooth = props[2]
480 triface = props[3]
481 sphere = props[4]
482 land_mat = props[5]
483 water_mat = props[6]
484 texture_name = props[7]
485 subd_x = props[8]
486 subd_y = props[9]
487 meshsize_x = props[10]
488 meshsize_y = props[11]
489 meshsize = props[12]
490 rseed = props[13]
491 x_offset = props[14]
492 y_offset = props[15]
493 z_offset = props[16]
494 size_x = props[17]
495 size_y = props[18]
496 size_z = props[19]
497 nsize = props[20]
498 ntype = props[21]
499 nbasis = int(props[22])
500 vlbasis = int(props[23])
501 distortion = props[24]
502 hardnoise = int(props[25])
503 depth = props[26]
504 amp = props[27]
505 freq = props[28]
506 dimension = props[29]
507 lacunarity = props[30]
508 offset = props[31]
509 gain = props[32]
510 marblebias = int(props[33])
511 marblesharpnes = int(props[34])
512 marbleshape = int(props[35])
513 height = props[36]
514 height_invert = props[37]
515 height_offset = props[38]
516 maximum = props[39]
517 minimum = props[40]
518 falloff = int(props[41])
519 edge_level = props[42]
520 falloffsize_x = props[43]
521 falloffsize_y = props[44]
522 stratatype = props[45]
523 strata = props[46]
524 addwater = props[47]
525 waterlevel = props[48]
526 vert_group = props[49]
527 remove_double = props[50]
528 fx_mixfactor = props[51]
529 fx_mix_mode = props[52]
530 fx_type = props[53]
531 fx_bias = props[54]
532 fx_turb = props[55]
533 fx_depth = props[56]
534 fx_frequency = props[57]
535 fx_amplitude = props[58]
536 fx_size = props[59]
537 fx_loc_x = props[60]
538 fx_loc_y = props[61]
539 fx_height = props[62]
540 fx_offset = props[63]
541 fx_invert = props[64]
543 x, y, z = coords
545 # Origin
546 if rseed is 0:
547 origin = x_offset, y_offset, z_offset
548 origin_x = x_offset
549 origin_y = y_offset
550 origin_z = z_offset
551 o_range = 1.0
552 else:
553 # Randomise origin
554 o_range = 10000.0
555 seed_set(rseed)
556 origin = random_unit_vector()
557 ox = (origin[0] * o_range)
558 oy = (origin[1] * o_range)
559 oz = (origin[2] * o_range)
560 origin_x = (ox - (ox / 2)) + x_offset
561 origin_y = (oy - (oy / 2)) + y_offset
562 origin_z = (oz - (oz / 2)) + z_offset
564 ncoords = (x / (nsize * size_x) + origin_x, y / (nsize * size_y) + origin_y, z / (nsize * size_z) + origin_z)
566 # Noise basis type's
567 if nbasis == 9:
568 nbasis = 14 # Cellnoise
569 if vlbasis == 9:
570 vlbasis = 14
572 # Noise type's
573 if ntype in [0, 'multi_fractal']:
574 value = multi_fractal(ncoords, dimension, lacunarity, depth, nbasis) * 0.5
576 elif ntype in [1, 'ridged_multi_fractal']:
577 value = ridged_multi_fractal(ncoords, dimension, lacunarity, depth, offset, gain, nbasis) * 0.5
579 elif ntype in [2, 'hybrid_multi_fractal']:
580 value = hybrid_multi_fractal(ncoords, dimension, lacunarity, depth, offset, gain, nbasis) * 0.5
582 elif ntype in [3, 'hetero_terrain']:
583 value = hetero_terrain(ncoords, dimension, lacunarity, depth, offset, nbasis) * 0.25
585 elif ntype in [4, 'fractal']:
586 value = fractal(ncoords, dimension, lacunarity, depth, nbasis)
588 elif ntype in [5, 'turbulence_vector']:
589 value = turbulence_vector(ncoords, depth, hardnoise, nbasis, amp, freq)[0]
591 elif ntype in [6, 'variable_lacunarity']:
592 value = variable_lacunarity(ncoords, distortion, nbasis, vlbasis)
594 elif ntype in [7, 'marble_noise']:
595 value = marble_noise(
596 (ncoords[0] - origin_x + x_offset),
597 (ncoords[1] - origin_y + y_offset),
598 (ncoords[2] - origin_z + z_offset),
599 (origin[0] + x_offset, origin[1] + y_offset, origin[2] + z_offset), nsize,
600 marbleshape, marblebias, marblesharpnes,
601 distortion, depth, hardnoise, nbasis, amp, freq
603 elif ntype in [8, 'shattered_hterrain']:
604 value = shattered_hterrain(ncoords, dimension, lacunarity, depth, offset, distortion, nbasis)
606 elif ntype in [9, 'strata_hterrain']:
607 value = strata_hterrain(ncoords, dimension, lacunarity, depth, offset, distortion, nbasis)
609 elif ntype in [10, 'ant_turbulence']:
610 value = ant_turbulence(ncoords, depth, hardnoise, nbasis, amp, freq, distortion)
612 elif ntype in [11, 'vl_noise_turbulence']:
613 value = vl_noise_turbulence(ncoords, distortion, depth, nbasis, vlbasis, hardnoise, amp, freq)
615 elif ntype in [12, 'vl_hTerrain']:
616 value = vl_hTerrain(ncoords, dimension, lacunarity, depth, offset, nbasis, vlbasis, distortion)
618 elif ntype in [13, 'distorted_heteroTerrain']:
619 value = distorted_heteroTerrain(ncoords, dimension, lacunarity, depth, offset, distortion, nbasis, vlbasis)
621 elif ntype in [14, 'double_multiFractal']:
622 value = double_multiFractal(ncoords, dimension, lacunarity, depth, offset, gain, nbasis, vlbasis)
624 elif ntype in [15, 'rocks_noise']:
625 value = rocks_noise(ncoords, depth, hardnoise, nbasis, distortion)
627 elif ntype in [16, 'slick_rock']:
628 value = slick_rock(ncoords,dimension, lacunarity, depth, offset, gain, distortion, nbasis, vlbasis)
630 elif ntype in [17, 'planet_noise']:
631 value = planet_noise(ncoords, depth, hardnoise, nbasis)[2] * 0.5 + 0.5
633 elif ntype in [18, 'blender_texture']:
634 if texture_name != "" and texture_name in bpy.data.textures:
635 value = bpy.data.textures[texture_name].evaluate(ncoords)[3]
636 else:
637 value = 0.0
638 else:
639 value = 0.5
641 # Effect mix
642 val = value
643 if fx_type in [0,"0"]:
644 fx_mixfactor = -1.0
645 fxval = val
646 else:
647 fxcoords = Trans_Effect((x, y, z), fx_size, (fx_loc_x, fx_loc_y))
648 effect = Effect_Function(fxcoords, fx_type, fx_bias, fx_turb, fx_depth, fx_frequency, fx_amplitude)
649 effect = Height_Scale(effect, fx_height, fx_offset, fx_invert)
650 fxval = Mix_Modes(val, effect, fx_mixfactor, fx_mix_mode)
651 value = fxval
653 # Adjust height
654 value = Height_Scale(value, height, height_offset, height_invert)
656 # Edge falloff:
657 if not sphere:
658 if falloff:
659 ratio_x, ratio_y = abs(x) * 2 / meshsize_x, abs(y) * 2 / meshsize_y
660 fallofftypes = [0,
661 sqrt(ratio_y**falloffsize_y),
662 sqrt(ratio_x**falloffsize_x),
663 sqrt(ratio_x**falloffsize_x + ratio_y**falloffsize_y)
665 dist = fallofftypes[falloff]
666 value -= edge_level
667 if(dist < 1.0):
668 dist = (dist * dist * (3 - 2 * dist))
669 value = (value - value * dist) + edge_level
670 else:
671 value = edge_level
673 # Strata / terrace / layers
674 if stratatype not in [0, "0"]:
675 if stratatype in [1, "1"]:
676 strata = strata / height
677 strata *= 2
678 steps = (sin(value * strata * pi) * (0.1 / strata * pi))
679 value = (value * 0.5 + steps * 0.5) * 2.0
681 elif stratatype in [2, "2"]:
682 strata = strata / height
683 steps = -abs(sin(value * strata * pi) * (0.1 / strata * pi))
684 value = (value * 0.5 + steps * 0.5) * 2.0
686 elif stratatype in [3, "3"]:
687 strata = strata / height
688 steps = abs(sin(value * strata * pi) * (0.1 / strata * pi))
689 value = (value * 0.5 + steps * 0.5) * 2.0
691 elif stratatype in [4, "4"]:
692 strata = strata / height
693 value = int( value * strata ) * 1.0 / strata
695 elif stratatype in [5, "5"]:
696 strata = strata / height
697 steps = (int( value * strata ) * 1.0 / strata)
698 value = (value * (1.0 - 0.5) + steps * 0.5)
700 # Clamp height min max
701 if (value < minimum):
702 value = minimum
703 if (value > maximum):
704 value = maximum
706 return value