Index: /data/contentcreation/orx_artists/SilvanNellen/moonsurface/ANTLandscapeVCol103_10-2005.py
===================================================================
--- /data/contentcreation/orx_artists/SilvanNellen/moonsurface/ANTLandscapeVCol103_10-2005.py	(revision 4790)
+++ /data/contentcreation/orx_artists/SilvanNellen/moonsurface/ANTLandscapeVCol103_10-2005.py	(revision 4790)
@@ -0,0 +1,868 @@
+#!BPY 
+""" 
+Name: 'A.N.T.Landscape v.1.03' 
+Blender: 234 
+Group: 'Add' 
+Tip: 'Create a landscape mesh.' 
+""" 
+
+
+##########################################################################
+##        : A.N.T.(Another Noise Tool) Landscape 1.03 VCol.
+##        : Jimmy Hazevoet  : Jan./Oct. 2005
+##########################################################################
+#------------------------------------------------------------------------#
+## v.1.03 : NEW: Mesh 'VertexColor' gradient.
+##             : Use new 'Mesh Modifier' (Blender2.38+) for SubSurf.
+##             : Some new Effect and Filter stuff.
+#------------------------------------------------------------------------#
+##########################################################################
+
+import Blender
+from Blender import *
+from Blender.Noise import *
+from math import *
+from Blender.Draw import *
+from Blender.BGL import *
+from Blender import Scene
+sc=Scene.getCurrent()
+
+# color stuff #------------------------------
+#############################################
+vcolours = Create(1)
+ColScreen = Create(0)
+preGrad = Create(0)
+newheight = Create(0.50)
+EVB_H      = 125
+EVB_R      = 150
+EVB_G      = 200
+EVB_B      = 250
+EVB_DEL    = 300
+EV_NEW     = 5
+EV_NOEVENT = 1
+colorcontrols=[]
+
+colors = (
+      #default ### [ h, r, g, b] ###
+      [[ 1.0, 227, 228, 231], [ 0.70, 96, 98, 97], [ 0.003, 76, 99, 27], [ 0.20, 96, 74, 23], [ 0.0,  11, 35, 84], [-1.0,  11, 35, 84]],
+      #natural
+      [[ 1.00, 200, 200, 200], [ 0.70, 159, 159, 159], [ 0.20, 157, 131, 67], [ 0.003, 85, 108, 67], [0.0, 3, 71, 109], [-1.0,  2, 39,  89]],
+      #dry
+      [[ 1.00, 169, 115, 54], [ 0.1, 187, 146, 37], [ 0.0, 132, 137, 54], [-1.0, 132, 137, 54]],
+      #red
+      [ [ 1.0 , 249, 225, 163],[ 0.5 , 239, 195, 103], [ 0.25, 214, 115,  72], [ 0.0, 100, 40,  25], [ -1.0,   0,  0,  0]],
+      #stone
+      [[ 1.0 , 236, 219, 196], [ 0.7, 190, 179,  171], [ 0.35, 174, 180,  170], [ 0.0, 114, 114,  114], [ -1.0,   0,  0,  0]],
+      #grayscale
+      [[ 1.0, 255, 255, 255], [ 0.0, 0, 0, 0], [-1.0, 0, 0, 0]]
+      )
+
+# Linear color gradient computation from: BDi_0.0.3.py
+def col_gradient(value, col1, col2):
+    delta = (value-col1[0]) / (col2[0]-col1[0])
+    jitter = random() * 0.05 * delta
+    if (delta+jitter)<1.0:  delta = delta+jitter
+    else:                   delta = delta-jitter
+    gg=col1[2]+(col2[2]-col1[2])*delta
+    bb=col1[3]+(col2[3]-col1[3])*delta
+    rr=col1[1]+(col2[1]-col1[1])*delta
+    return ( NMesh.Col(int(round(rr)),int(round(gg)),int(round(bb))) ), ( ((round(rr)),(round(gg)),(round(bb))) )
+
+######################################################
+#------------------------------
+def reset():
+   global NSize, iScale, invert, FalTyp, Fall, FalHard, offset, slev, plev, pslope, platnoise, edgesatsea
+   global RaPos, RaSiz, RaHgh, RaCha, RaTyp, Noise_Type, Noise_Basis
+   global Distortion_Noise, Damnt, VFunc, VExp, VDep
+   global Ha, La, Oc, Of, Ga, Ri, Ri_S, Ri_B, Depth, Hard, Amp, Freq, Lx, Ly, Lz, Sx, Sy
+   global FX, EffectZ, FXnoise, FXblend, Flt, FilterZ, filtF, filtG, lower, upper
+   global fxSize, fxSx, fxSy, fxLx, fxLy, fxIntens, fxOfst, fxgrad, fxA, fxB, fxC, fxD
+
+   RaPos = Create(1); RaSiz = Create(0); RaHgh = Create(0); RaCha = Create(0); RaTyp = Create(0)
+   FalTyp = Create( 2 ); Fall = Create( 1.0 ); FalHard = Create( 1.0 )
+   plev = Create( 1.0 ); slev = Create( 0.0 ); edgesatsea = Create(0); pslope = Create(0); platnoise = Create(0)
+   NSize = Create(1.0); iScale = Create(0.25); invert = Create(0); offset = Create(0.0)
+   Sx = Create(1.0); Sy = Create(1.0); Lx = Create(0.0); Ly = Create(0.0); Lz = Create(0.0)
+   Noise_Type = Create(3); Noise_Basis = Create(0)
+   Oc = Create(5.0); La = Create(3.0); Ha = Create(1.0); Ga = Create(1.0); Of = Create(1.0)
+   Ri = Create(1.0); Ri_S = Create(1.0); Ri_B = Create(0)
+   Depth = Create(2); Hard = Create(0); Amp = Create(0.5); Freq = Create(2.0)
+   Distortion_Noise = Create(0); Damnt = Create(2.0)
+   VFunc = Create(0); VExp  = Create(2.5); VDep  = Create(0)
+   FX = Create(0); EffectZ = Create(0); fxgrad = Create(0); fxA = Create(2); fxB = Create(0); fxC = Create(1.0); fxD = Create(2.0)
+   fxSize = Create(1.0); fxSx = Create(1.0); fxSy = Create(1.0); fxLx = Create(0.0); fxLy = Create(0.0)
+   fxIntens= Create(0.25);  fxOfst  = Create(0.0); FXnoise  = Create(0); FXblend  = Create(1)
+   Flt = Create(0); FilterZ = Create(0); filtF = Create(1.0); filtG = Create(0.25); lower = Create(0.0); upper = Create(1.0)
+reset()
+#------------------------------
+def resetMe():
+   global MEName, preset, pview, Auto_Update, Quality, resolution, Q_T, smooth, Rseed, RanMod
+   MEName = Create("Landscape"); preset = Create(0); pview = Create(0)
+   Auto_Update = Create(1); Quality = Create(3); resolution = Create(50)
+   Q_T = Create(0); smooth = Create(0)
+   RanMod = Create(0); Rseed = Create(0)
+resetMe()
+
+### Presets ----------------------------------
+#------------------------------
+def Preset_Noise():
+   global preset, NSize, Lx, Ly, Lz, Sx, Sy, iScale, invert, offset, slev, plev, pslope, platnoise, FalTyp, Fall, FalHard
+   global Noise_Type, Noise_Basis, Distortion_Noise, Damnt, Distortion_Noise
+   global Ha, La, Oc, Of, Ga, Depth, Hard, Amp, Freq, VFunc, VDep, Ri, Ri_S, Ri_B
+   global FX, EffectZ, FXblend, FXnoise, FXblend, FilterZ, filtF, filtG, Flt
+   global fxSize, fxSx, fxSy, fxLx, fxLy, fxIntens, fxOfst
+
+   if preset.val >2: ## randomise position ##
+      Lx = Create( 0.0+(random() * 1000 ) ); Ly = Create( 0.0+(random() * 1000 ) ); Lz = Create( 0.0+(random() * 1000 ) )
+   if preset.val == 2: # Original
+      Noise_Type = Create(5); NSize = Create(0.25); iScale = Create(0.1); FalTyp = Create(0); Oc = Create(2.0); La = Create(2.0)
+   elif preset.val == 3: # Blender hills
+      Noise_Type = Create(5); Depth = Create(2)
+   elif preset.val == 4: # Stones hills
+      NSize = Create(0.5); Of = Create(0.9); FX = Create(1); EffectZ = Create(8); FXblend = Create(9); fxIntens = Create(0.125); fxOfst = Create(0.1); fxSize = Create(3.0)
+   elif preset.val == 5: # Round hills
+      Noise_Type = Create(6); VFunc = Create(1); iScale = Create(0.5); invert = Create(1); offset = Create(-0.25); NSize = Create(0.5)
+   elif preset.val == 6: # Plateau
+      Noise_Basis = Create(3); NSize = Create(0.5); iScale = Create(0.5); plev = Create(0.25); pslope = Create(1); slev = Create(-0.25); FalTyp = Create(1) 
+      EffectZ = Create(7); FXblend  = Create(2); platnoise = Create(1)
+   elif preset.val == 7: # Shattered
+      Noise_Type  = Create(2); Noise_Basis = Create(7); Of = Create(2.0); Ga = Create(2.0); NSize = Create(0.25); offset = Create(-0.25); FalHard = Create(2.5) 
+   elif preset.val == 8: # Chaotic
+      NSize  = Create(0.25); Oc = Create(6.0); La = Create(2.0); Ha = Create(0.8); Of = Create(0.4)
+   elif preset.val == 9: # RidgedMF
+      Noise_Type = Create(1); La = Create(2.0); Ha = Create(0.8); Ga = Create(2.5)
+   elif preset.val == 10: # Distorted hTerrain
+      Noise_Type = Create(13); Ri = Create(-1.0); Ri_S = Create(0.75); Ri_B = Create(3)
+   elif preset.val == 11: # Cauliflower
+      Noise_Type = Create(2); Noise_Basis = Create(3); La = Create(5.0); Ga = Create(5.0); iScale = Create(0.35); invert = Create(1); NSize = Create(0.5); FalTyp = Create(1)
+   elif preset.val == 12: # Ridges
+      Noise_Type = Create(4); Noise_Basis = Create(3); NSize = Create(0.5); iScale = Create(0.5); offset = Create(0.1); Ha = Create(1.5)
+   elif preset.val == 13: # Crystalline
+      Noise_Type = Create(2); Noise_Basis = Create(4); iScale = Create(0.75); invert = Create(1); offset = Create(0.25)
+   elif preset.val == 14: # Warped
+      NSize  = Create(0.5); Of = Create(0.5); Flt = Create(1); FilterZ = Create(1)
+   elif preset.val == 15: # ChebyTech
+      Noise_Type = Create(6); VFunc = Create(3); VDep = Create(1); FalTyp = Create(0); plev = Create(0.2); NSize  = Create(0.25); iScale = Create(0.6)
+   elif preset.val == 16: # CellNoise
+      Noise_Type  = Create(5); Noise_Basis = Create(9); FalHard = Create(10.0)
+   elif preset.val == 17: # Canyon
+      NSize = Create(0.5); plev = Create(0.25); platnoise = Create(1); FalHard = Create(2.5); iScale = Create(0.5); offset = Create(-0.25); FilterZ = Create(3)
+   elif preset.val == 18: # Ring o Rock
+      Noise_Type = Create(2); Noise_Basis = Create(7); Of = Create(2.0); Ga = Create(2.0); NSize = Create(0.5); offset = Create(-0.6)
+      iScale = Create(0.5); FX = Create(1); EffectZ = Create(2); FXblend = Create(2)
+   elif preset.val == 19: # xtreme Peaks
+      Noise_Type = Create(10); iScale = Create(0.5); Flt = Create(1); FilterZ = Create(2)
+   elif preset.val == 20: # hardturb
+      Noise_Type = Create(5); Hard = Create(1); Depth = Create(3); Amp = Create(0.65); invert = Create(1); offset = Create(0.5); iScale = Create(0.5); FalTyp = Create(1)
+   elif preset.val == 21: # Cliff
+      FalTyp = Create(0); platnoise = Create(1); iScale = Create(0.5); FX = Create(1); EffectZ = Create(4); FXblend = Create(2)
+      fxIntens= Create(1.0); fxSx  = Create(0.0); fxSy  = Create(0.5)
+
+## Randomise ------------------------------------------------------
+###-----------------------------------
+def Random_N():
+   global iScale, invert, offset, NSize
+   global RaPos, RaSiz, RaCha, RaHgh, RaTyp, Rseed
+   global Noise_Type, Noise_Basis, Distortion_Noise, VFunc
+   global Lx, Ly, Lz, Sx, Sy, Ha, La, Oc, Of, Ga, Ri, Ri_S, Ri_B
+   global Depth, Hard, Amp, Freq, Damnt, VExp, VDep
+
+   setRandomSeed(Rseed.val)
+   inv1=inv2=1
+   randinv_one = int( random() * 2)
+   if randinv_one == 1:   inv1=-1
+   randinv_two = int( random() * 2)
+   if randinv_two == 1:   inv2=-1
+   # randomise Position #--------------------------------
+   if RaPos.val == 1:
+      Lx = Create( (random() * 1000.0 ) * inv1 ); Ly = Create( (random() * 1000.0 ) * inv2 ); Lz = Create( (random() * 1000.0 ) * inv2 )
+   # randomise Size #------------------------------------
+   if RaSiz.val == 1:
+      NSize = Create( 0.1+(random() * 1.0 ) ); Sx = Create( 1.0+(random() * 0.5 ) ); Sy = Create( 1.0+(random() * 0.5 ) )
+   # randomise Height #----------------------------------
+   if RaHgh.val == 1:
+      iScale = Create( 0.1+( random() * 1.0 ) ); invert = Create( int( random() * 2) ); offset = Create( (random() * 0.10 ) * inv2 )
+   # randomise Character #--------------------------------
+   if RaCha.val == 1:
+      Oc = Create( 1.0+( random() * 7.0 ) ); La = Create( 1.0+( random() * 5.0 ) ); Ga = Create( 0.5+( random() * 5.5 ) ); Ha = Create( 0.5+( random() * 1.5 ) ); Of = Create( 0.5+( random() * 1.0 ) )
+      Ri = Create( 0.2+( random() * 1.0 ) * inv1); Ri_S = Create( 0.3+( random() * 0.9 ) ); Ri_B = Create( int( random() * 10) )
+      Depth = Create( int( random() * 10) ); Hard = Create( int( random() * 2) ); Amp = Create( 0.25+( random() * 1.0 ) ); Freq = Create( 0.5+( random() * 2.5 ) )
+      Distortion_Noise = Create( int( random() * 10) ); Damnt = Create( 0.5+( random() * 3.0 ) )
+      VFunc = Create( int( random() * 7) ); VDep = Create( int( random() * 3) ); VExp = Create( ( random() * 10.0 ) )
+   # randomise Type #-----------------------------------
+   if RaTyp.val == 1:
+      Noise_Type = Create( int( random() * 10) ); Noise_Basis = Create( int( random() * 10) )
+
+## Noise --------------------------------------------------------
+###-----------------------------------
+def Noise_func(x,y,z):
+   global iScale, invert, offset, NSize, Sx, Sy, Lx, Ly, Lz, Noise_Type, Noise_Basis
+   global Distortion_Noise, Damnt, VFunc, VExp, VDep
+   global Ha, La, Oc, Of, Ga, Ri, Ri_S, Ri_B, Depth, Hard, Amp, Freq
+
+   x1 = ( x / Sx.val / NSize.val + Lx.val )
+   y1 = ( y / Sy.val / NSize.val + Ly.val )
+   z1 = ( z * 1.0 + Lz.val )
+   Basis = Noise_Basis.val
+   if Basis == 9:   Basis = 14
+   if Noise_Type.val == 0:
+         nz = multiFractal((x1,y1,z1),Ha.val, La.val, Oc.val, Basis)
+   elif Noise_Type.val == 1:
+         nz = ridgedMFractal((x1,y1,z1),Ha.val, La.val, Oc.val, Of.val, Ga.val, Basis)
+   elif Noise_Type.val == 2:
+         nz = hybridMFractal((x1,y1,z1),Ha.val, La.val, Oc.val, Of.val, Ga.val, Basis)
+   elif Noise_Type.val == 3:
+         nz = heteroTerrain((x1,y1,z1),Ha.val, La.val, Oc.val, Of.val, Basis)
+   elif Noise_Type.val == 4:
+         nz = fBm((x1,y1,z1),Ha.val, La.val, Oc.val, Basis)
+   elif Noise_Type.val == 5:
+         nz = turbulence((x1,y1,z1),1+Depth.val, Hard.val, Basis,Amp.val,Freq.val)+1.0
+   elif Noise_Type.val == 6:
+         nz = voronoi((x1,y1,z1),VFunc.val,VExp.val)[0][VDep.val]
+   elif Noise_Type.val == 7:
+         vlBasis = Distortion_Noise.val
+         if vlBasis == 9:   vlBasis = 14
+         distortion = Damnt.val
+         nz = vlNoise((x1,y1,z1), distortion, vlBasis, Basis)+1
+   elif Noise_Type.val == 8:
+         nz = noise((x1,y1,z1),Basis)
+   elif Noise_Type.val == 9:
+         nz = cellNoise((x1,y1,z1))
+   elif Noise_Type.val == 10:
+         ht = heteroTerrain((x1,y1,z1),Ha.val, La.val, Oc.val, Of.val, Basis)
+         nz = (Dist( ( ht**2),( ht**2) )**2)*0.025
+   elif Noise_Type.val == 11:
+         ht = heteroTerrain((x1,y1,z1),Ha.val, La.val, Oc.val, Of.val, Basis)
+         ca = WaveFunc( ht , Ri.val , (0.1/Ri.val*pi) , 1 )
+         nz = BModFunc( ht , ca , 1 )*2.0
+   elif Noise_Type.val == 12:
+         ribasis = Ri_B.val
+         if ribasis == 9: ribasis = 14
+         nz = heteroTerrain((x1,y1,z1),Ha.val, La.val, Oc.val, Of.val, Basis)
+         nz += Ri.val*ridgedMFractal((x1/Ri_S.val,y1/Ri_S.val,z1),Ha.val,La.val,Oc.val,Of.val,Ga.val,ribasis)
+   elif Noise_Type.val == 13:
+         ribasis = Ri_B.val
+         if ribasis == 9: ribasis = 14
+         vlBasis = Distortion_Noise.val
+         if vlBasis == 9:   vlBasis = 14
+         distortion = Damnt.val
+         nz = heteroTerrain((x1,y1,z1),Ha.val, La.val, Oc.val, Of.val, Basis)
+         nz += Ri.val*vlNoise((x1/Ri_S.val,y1/Ri_S.val,z1),distortion,vlBasis,ribasis)
+   else:
+         nt1 = (turbulence(( x1 , y1 , z1), 0, 1, 1, 0.5, 2.0 )*5-0.25)
+         nt2 = (turbulence(( x1 , y1 , z1),1+Depth.val, Hard.val, Basis,Amp.val,Freq.val)*0.1)
+         nz  = ( ClipFunc( nt1, 0.0, 0.25 ) +  (nt1*0.05) + nt2 )*4.0
+   if invert.val == 1:
+      nz *= iScale.val/2
+      z = -nz + iScale.val
+   else:   z = nz * iScale.val/2
+   z += offset.val
+
+   return x,y,z
+
+## Effects  -----------------------------------------------
+###------------------------------------------
+def StonesFunc(x,y,z):
+   return x,y, ClipFunc( (noise((10*x,10*y,z),1)*0.75-0.25), 0.0, 0.25 )
+def SparseCracksFunc(x,y,z):
+   return x,y, ClipFunc( (turbulence((x*2,y*2,z),0,1,1,0.5,2.0 )*4-0.25), 0.0, 0.25 )
+def CratersFunc(x,y,z):
+   return x,y,  ClipFunc( (noise((2*x,2*y,z),3)*1.0+0.5), -0.5, 0.0 )
+def SawFunc(x,y,z):
+   wa1 = WaveFunc( x+y , 1.0 , 1.0, 3 )
+   wa2 = WaveFunc( (y+wa1*0.5) , 1.0 , 1.0, 3 )
+   return x,y, BModFunc( x*wa2, y*wa1, 7 )
+def Dist(x,y):
+   return sqrt( (x*x)+(y*y) )
+def ClipFunc( input, ClipMin, ClipMax ):
+   if ( input < ClipMin ):  input = ClipMin
+   if ( input > ClipMax ):  input = ClipMax
+   return input
+def maxFunc( c1, c2 ):
+   if ( c1 > c2 ): c2 = c1
+   return c2
+def minFunc( c1, c2 ):
+   if ( c1 < c2 ): c2 = c1
+   return c2
+###-----------------------------------
+def BModFunc( c1, c2, bmod ):
+   if   bmod == 0:  return  ( c2 )                      #0  c2
+   elif bmod == 1:  return  ( c1*(1.0-0.5) + c2*0.5 )   #1  blend
+   elif bmod == 2:  return  ( c1 + c2 )                 #2  add
+   elif bmod == 3:  return  ( c1 - c2 )                 #3  subtract
+   elif bmod == 4:  return  ( c1 * c2 )                 #4  multiply
+   elif bmod == 5:  return  (abs( c1 - c2 ))            #5  difference
+   elif bmod == 6:  return  1.0-((1.0-c1)*(1.0-c2)/1.0) #6  screen
+   elif bmod == 7:  return  ( c1 + c2 ) % 1.0           #7  add modulo
+   elif bmod == 8:  return  minFunc( c1, c2 )           #8  min
+   elif bmod == 9:  return  maxFunc( c1, c2 )           #9  max
+   #### elif bmod == 10:                                #10 warp
+   else:            return  ( c1 )                      #11 c1
+###-----------------------------------
+def WaveFunc( input, numb, scale, type ):
+   if   type == 1:  return  (  sin( input * numb*pi ) * scale )
+   elif type == 2:  return  (  cos( input * numb*pi ) * scale )
+   elif type == 3:  return  (  ( input * numb ) % 1.0 * scale )
+   elif type == 4:  return  (  int( input * numb ) * scale ) / ( numb )
+   else:            return  (  ( input * numb*pi ) * scale )
+
+###-----------------------------------
+def Z_Effect(x,y,z):
+   global EffectZ, FXnoise, FXblend
+   global fxSize, fxSx, fxSy, fxLx, fxLy, fxIntens, fxOfst, fxgrad, fxA, fxB, fxC, fxD
+
+   basis = FXnoise.val
+   if basis == 9: basis = 14
+   Nfunc = Noise_func(x,y,z)
+   if EffectZ.val == 0:  z = Nfunc[2]
+   else:
+      phi = 3.14159265359
+      x2 = ( x * fxSize.val * fxSx.val - fxLx.val )
+      y2 = ( y * fxSize.val * fxSy.val - fxLy.val )
+      if   EffectZ.val == 1:  ez = ( x * sin( Dist( x2,y2 ) * phi*2 ) - y * cos( Dist( x2,y2 ) * phi*2 ) )
+      elif EffectZ.val == 2:  ez = sin( -Dist( x2,y2 ) * phi*2 )
+      elif EffectZ.val == 3:  ez = sin( ( x2 * phi ) + sin( y2 * phi ) )
+      elif EffectZ.val == 4:  ez = sin( x2*phi + y2*phi )
+      elif EffectZ.val == 5:  ez = cos( x2 * phi ) * sin( y2 * phi )
+      elif EffectZ.val == 6:  ez = BModFunc(WaveFunc(y2,1.0,1.0,3), WaveFunc(x2,1.0,1.0,3), 1 )
+      elif EffectZ.val in [7,8,9,10]:
+         if   EffectZ.val == 7:  nz = SawFunc(x2,y2,0.0)
+         elif EffectZ.val == 8:  nz = StonesFunc(x2,y2,0.0)
+         elif EffectZ.val == 9:  nz = CratersFunc(x2,y2,0.0)
+         elif EffectZ.val == 10: nz = SparseCracksFunc(x2,y2,0.0)
+         ez = nz[2]
+      elif EffectZ.val == 11:
+         ez = turbulence((x2+2.0,y2-2.0,0.0),1+fxA.val, fxB.val, basis, 0.5,2.0)+1.0
+      elif EffectZ.val == 12:
+         ez = multiFractal((x2,y2,0.0),fxC.val, fxD.val, fxA.val, basis)
+      elif EffectZ.val == 13:
+         bs = fxA.val
+         if bs == 9: bs = 14
+         ez = vlNoise((x2,y2,0.0), fxC.val, bs, basis)+1
+      elif EffectZ.val == 14:
+         value = (x2*x2 + y2*y2)/0.5
+         if value > 1.0:  radg = 0.0
+         radg = 1.0 - value
+         grad = [ x2, -x2, y2, -y2, radg ]
+         ez = grad[ fxgrad.val ]
+      elif EffectZ.val == 15:
+         ez = ( fxSize.val * random() )
+
+      ez *= fxIntens.val
+      ez += fxOfst.val
+      Nfunc=Noise_func(x,y,z)
+      if FXblend.val == 10:
+         Wfunc = Noise_func( x-ez, y-ez, 0.0 )
+         z = Wfunc[2]
+      else:
+         z = BModFunc( Nfunc[2], ez , FXblend.val )
+   return x,y,z
+
+## Filters -------------------------
+###-----------------------------------
+def  Z_Filter(x,y,z):
+   global Flt, FilterZ, filtF, filtG, lower, upper
+
+   Efunc = Z_Effect(x,y,z)
+   if  FilterZ.val == 0:  z = Efunc[2]
+   elif FilterZ.val == 1:
+      zn    = Z_Effect(x,y,z)
+      Sfunc = Z_Effect(x-(zn[2]*filtF.val+filtG.val), y-(zn[2]*filtF.val+filtG.val), z )
+      z = Sfunc[2]
+   elif FilterZ.val == 2:
+      z = (Dist( (Efunc[2]**2),(Efunc[2]**2) )**2)*2.0
+   elif FilterZ.val in [3,4,5,6,7]:
+      canion1      = ( Efunc[2], (filtF.val*10.0), (0.1/(filtF.val*10.0)*pi), 2 , Efunc[2], 2 )
+      canion2      = ( (Dist( Efunc[2]**2 ,Efunc[2]**2 )**2),(filtF.val*10.0),(0.1/(filtF.val*10.0)*pi),1 , (Dist( Efunc[2]**2 ,Efunc[2]**2 )**2),2 )
+      sawf         = ( Efunc[2], filtF.val*1.0, filtG.val , 3 , 0, 0 )
+      poster       = ( Efunc[2]*2.0, filtF.val*20.0 , filtG.val*2.0 ,4 , 0, 0)
+      posternoise  = ( Efunc[2]*2.0, filtF.val*20.0 , filtG.val*2.0 ,4 ,  Efunc[2]*2.0, 1)
+      FiltType = ( 0,0,0, canion1, canion2, sawf, poster, posternoise )
+      FTyp     = FiltType[ FilterZ.val ]
+      Wa  = WaveFunc( FTyp[0], FTyp[1], FTyp[2], FTyp[3] )
+      z   = BModFunc( FTyp[4] , Wa , FTyp[5] )
+   elif FilterZ.val == 8:
+      z = SmoothStep( Efunc[2], lower.val, upper.val )*filtF.val
+   return x,y,z
+###-----------------------------------
+def SmoothStep( input, low, up ):
+   value = input
+   if value < low:  return 0.0
+   elif value > up: return 1.0
+   else:
+      delta = up - low
+      if fabs(delta) > 0.000001:
+         value = (value - low) / delta
+         return value * value * (3.0 - 2.0 * value)
+      else:
+         if value > up:
+            return 1.0
+
+## Limit height --------------------------------------------------------
+###-----------------------------------
+def Z_Limit(x,y,z):
+   global FalTyp, Fall, FalHard, slev, edgesatsea, plev, pslope, platnoise
+
+   plateau  = plev.val; sealevel = slev.val
+   if edgesatsea.val == 1:
+       edgesatsealevel = slev.val
+   else:
+       edgesatsealevel = 0.0
+
+   Ffunc  = Z_Filter(x,y,z)
+   height = Ffunc[2] - edgesatsealevel
+   if FalTyp.val != 0:
+      if FalTyp.val == 2: fha = 2*FalHard.val
+      else:               fha = 1*FalHard.val
+      distype = ( sqrt((x*x + y*y)**fha), sqrt((x*x)**fha+(y*y)**fha), sqrt(y*y)**fha, sqrt(x*x)**fha )
+      dist = distype[ FalTyp.val-1 ]
+      height = Ffunc[2] - edgesatsealevel
+      radius = 1.0 * Fall.val
+      if( dist <  radius ):
+         dist = dist / radius
+         dist = ( (dist) * (dist) * ( 3-2*(dist) ) )
+         z = ( height - height * dist ) + edgesatsealevel
+      else:  z = edgesatsealevel
+   else:     z = Ffunc[2]
+
+   Nfunc = Noise_func(x,y,z)
+   flatnoise = Nfunc[2] * 0.1
+   slope = abs( (x/pi-1)*(y/pi+1) )
+   if pslope.val == 1:
+      if platnoise.val == 1:
+         if ( z > plateau * slope + flatnoise ):  z = plateau * slope + flatnoise
+      else:
+         if ( z > plateau * slope ):              z = plateau * slope
+   if pslope.val == 0:
+      if platnoise.val == 1:
+         if ( z > plateau + flatnoise ):  z = plateau + flatnoise
+      else:
+         if ( z > plateau ):              z = plateau
+   if ( z < sealevel ):  z = sealevel
+
+   return x,y,z
+
+## Mesh -----------------------------------------------------------
+###-----------------------------------
+def Crea(): 
+   global MEName, Quality, resolution, Q_T, smooth, submode, sub, vcolours, preGrad
+
+   reso = ( 32+1, 50+1, 64+1, 100+1, 128+1, 150+1, 200+1, 256+1, 512+1, resolution.val+1 )
+   n = reso[ Quality.val ]
+
+   try:
+      o=Object.Get('Terrainn')
+      me=o.getData()
+      UPDATE=1	
+   except:
+      o=Object.New('Mesh','Terrainn')
+      sc.link(o)
+      me = NMesh.GetRaw()
+      UPDATE=0
+
+   me.verts=[]
+   me.faces=[]
+   COL=[]
+   height = 0
+   # Vertices -----------------------------------
+   i=j=h=0.0
+   for i in range(0, n, 1):
+      i = i-(n-1)/2
+      i = i*2.0/(n-1)
+      for j in range(0, n, 1):
+         j = j-(n-1)/2
+         j = j*2.0/(n-1)
+         Result = Z_Limit(i,j,h)
+         height = Result[2]
+         v=NMesh.Vert(i, j, height)
+         me.verts.append(v)
+         #-----------------------------------
+         for cc in range(len(colors[ preGrad.val ])):
+              if ( height  > colors[ preGrad.val ][cc][0]):
+                      COL.append( col_gradient( height ,colors[ preGrad.val ][cc],colors[ preGrad.val ][cc-1])[0] )
+                      break
+   me.hasVertexColours(1)
+   ##--------------------------------------
+   if Q_T.val == 1:
+      for i in range(n-1):
+         for j in range(n-1):
+            f = NMesh.Face()
+            f.v.append(me.verts[n*i+j])
+            f.v.append(me.verts[n*(i+1)+j])
+            f.v.append(me.verts[n*i+(j+1)])
+            if vcolours.val !=0:
+               f.col.append(COL[n*i+j])
+               f.col.append(COL[n*(i+1)+j])
+               f.col.append(COL[n*i+(j+1)])
+            f.smooth = smooth.val
+            me.faces.append(f)
+            f = NMesh.Face()
+            f.v.append(me.verts[n*i+(j+1)])
+            f.v.append(me.verts[n*(i+1)+j])
+            f.v.append(me.verts[n*(i+1)+(j+1)])
+            if vcolours.val !=0:
+               f.col.append(COL[n*i+(j+1)])
+               f.col.append(COL[n*(i+1)+j])
+               f.col.append(COL[n*(i+1)+(j+1)])
+            f.smooth = smooth.val
+            me.faces.append(f)
+   else:
+      for i in range(n-1):
+         for j in range(n-1):
+            f= NMesh.Face()
+            f.v.append(me.verts[i*n+j])
+            f.v.append(me.verts[(i+1)*n+j])
+            f.v.append(me.verts[(i+1)*n+j+1])
+            f.v.append(me.verts[i*n+j+1])
+            if vcolours.val !=0:
+               f.col.append(COL[i*n+j])
+               f.col.append(COL[(i+1)*n+j])
+               f.col.append(COL[(i+1)*n+j+1])
+               f.col.append(COL[i*n+j+1])
+            f.smooth = smooth.val
+            me.faces.append(f)
+
+   if UPDATE :
+      me.update()
+   else :
+      o.link(me)
+   o.makeDisplayList()
+   Blender.Redraw()
+
+
+### G.U.I.  ,   Preview  --------------------------- 
+#---------------------------------------------------------------------- 
+def Preview_Noise():
+   global pview, preGrad
+   for x in range(-64, 64):
+      for y in range(-64, 64):
+         poco = Z_Limit(x/64.0, y/64.0, 0.0)
+         if pview.val == 1:
+            r,g,b = (poco[2]+1)/2 , (poco[2]+1)/2 , (poco[2]+1)/2
+            glColor3f(r,g,b)
+         elif pview.val == 2:
+            r,g,b = (poco[2]) , (poco[2]) , (poco[2])
+            glColor3f(r,g,b)
+         elif pview.val == 3:
+            for cc in range(len(colors[ preGrad.val ])):
+               if ( poco[2]  > colors[ preGrad.val ][cc][0]):
+                  r,g,b = (col_gradient( poco[2] ,colors[ preGrad.val ][cc],colors[ preGrad.val ][cc-1] )[1] )
+                  break
+            glColor3f(r/255.0,g/255.0,b/255.0)
+
+         glRecti(x+135, y+307, x+136, y+308)
+#------------------------------------
+def ColBox(x,y, w, h, r, g, b):
+   glColor3f(r, g, b)
+   glRecti(x, y, w, h)
+###----------------------------------- 
+def GUI():
+   global MEName, preset, pview, Auto_Update, Quality, resolution, Q_T, smooth, submode, sub
+   global NSize, iScale, invert, FalTyp, Fall, FalHard, offset, Lx, Ly, Lz, Sx, Sy, slev, plev
+   global RaPos, RaSiz, RaHgh, RaCha, RaTyp, Rseed, RanMod, Flt, FilterZ, filtF, filtG, lower, upper
+   global Noise_Type, Noise_Basis, Distortion_Noise, Damnt, VFunc, VExp, VDep
+   global Ha, La, Oc, Of, Ga, Ri, Ri_S, Ri_B, Depth, Hard, Amp, Freq
+   global FX, EffectZ, FXnoise, FXblend, fxSize, fxSx, fxSy, fxLx, fxLy
+   global fxIntens, fxOfst, fxgrad, fxA, fxB, fxC, fxD
+   global pslope, platnoise, edgesatsea
+   global vcolours, ColScreen, colorcontrols, colsel, curcol, preGrad, newheight
+
+   BGL.glClearColor(0.66, 0.66, 0.66, 1)
+   BGL.glClear(BGL.GL_COLOR_BUFFER_BIT)
+   glColor3f(0.73,0.73,0.73)
+   glRecti(5, 5, 265, 227)
+   glColor3f(0.61,0.61,0.61)
+   if pview.val !=0:
+      glRecti(5, 225, 265, 390)
+      Preview_Noise()
+   else:
+      glRecti(5, 225, 265, 242)
+   glColor3f(1.0,1.0,1.0)
+   glRasterPos2d(140, 230)
+   Text("A.N.T.Landscape 1.03",'small')
+
+   colorcontrols = [[], [], [], []]
+   ## Colors ##-----------------------------------
+   if ( ColScreen.val == 1 ):
+      ColScreen = Toggle("Col.",EV_NOEVENT, 160,205, 30,15, ColScreen.val,"Change colors")
+      Button("Update", 103, 195, 205, 45, 15,"Update mesh.")
+      #----------------------------------------------
+      glColor3f(1.0,0.0,0.0); glRasterPos2d(10, 190);  Text("Red",'small')
+      glColor3f(0.0,1.0,0.0); glRasterPos2d(60, 190);  Text("Green",'small')
+      glColor3f(0.0,0.0,1.0); glRasterPos2d(110, 190); Text("Blue",'small')
+      glColor3f(0.0,0.0,0.0); glRasterPos2d(195, 190); Text("Height",'small')
+      #----------------------------------------------
+      for c in range ( len(colors[ preGrad.val ]) ):
+         #- Height ---------------------------------------
+         if ( c != ( len(colors[ preGrad.val ]) -1 ) ):
+            ccontrol = Create(colors[ preGrad.val ][c][0])
+            ccontrol = Number("", EVB_H+c, 195, 170-20*c, 45, 15, ccontrol.val, -1.0, 1.0, "Color above this Height")
+            colorcontrols[0].append(ccontrol)
+         #- Red ---------------------------------------
+         ccontrol = Create(colors[ preGrad.val ][c][1])
+         ccontrol = Number("", EVB_R+c, 10, 170-20*c, 45, 15, ccontrol.val, 0, 255, "Red")
+         colorcontrols[1].append(ccontrol)
+         #- Green ---------------------------------------
+         ccontrol = Create(colors[ preGrad.val ][c][2])
+         ccontrol = Number("", EVB_G+c, 60, 170-20*c, 45, 15, ccontrol.val, 0, 255, "Green")
+         colorcontrols[2].append(ccontrol)
+         #- Blue ---------------------------------------
+         ccontrol = Create(colors[ preGrad.val ][c][3])
+         ccontrol = Number("", EVB_B+c, 110, 170-20*c, 45, 15, ccontrol.val, 0, 255, "Blue")
+         colorcontrols[3].append(ccontrol)
+         #- Col -------------------------------------
+         ColBox( 160,185-20*c, 190,170-20*c, (colors[ preGrad.val ][c][1])/255.0, (colors[ preGrad.val ][c][2])/255.0, (colors[ preGrad.val ][c][3])/255.0 )
+         #- Delete ----------------------------------
+         if (c!=0) and (c!=(len(colors[ preGrad.val ])-1)):
+            PushButton("X", EVB_DEL+c , 245,170-20*c, 15,15, "Remove color")
+
+      #- Add New ------------------------------------
+      Button("Add",EV_NEW, 60, 205, 45, 15, "Add new color at given height")
+      newheight = Number("", EV_NOEVENT+c, 110, 205, 45, 15, newheight.val, -1.0, 1.0, "Height for new color")
+      #- Preset grad's ------------------------------
+      gradsmnu = "Gradients %t|Default %x0|Natural %x1|Dry %x2|Red %x3|Stone %x4|Greyscale %x5"
+      preGrad = Menu(gradsmnu,EV_NOEVENT, 10,205, 45,15, preGrad.val,"Preset gradients")
+   else:
+      ColScreen = Toggle("Colors",EV_NOEVENT, 140,205, 60,15, ColScreen.val,"Change colors")
+      vcolours = Toggle("VertCol.", 102,210,205,50,15, vcolours.val,"Faces : Enable VertexColors.")
+      ## Noise ##
+      FX = Toggle( "Effects" ,31,10,205,60,15,FX.val,"Effects")
+      Flt = Toggle( "Filters" ,32,70,205,60,15,Flt.val,"Filter")
+      nbasis = "Noise Basis%t|Blender Original%x0|Original Perlin%x1|Improved Perlin%x2|Voronoi_F1%x3|Voronoi_F2%x4|Voronoi_F3%x5|Voronoi_F4%x6|Voronoi_F2-F1%x7|Voronoi Crackle%x8|CellNoise%x9"
+      ntype  = "Noise Type's %t|multiFractal %x0|ridgedMFractal %x1|hybridMFractal %x2|heteroTerrain %x3|fBm %x4|turbulence %x5|Voronoi %x6|DistortedNoise %x7|noise %x8|cellNoise %x9| %l|Peaked hTerrain %x10|Layered hTerrain %x11|hTerrain + ridgedMF %x12|hTerrain + DistortedN %x13|turbulence Cracks %x14"
+      votype = "Voronoi%t|Distance %x0|Distance Squared %x1|Manhattan %x2|Chebychev %x3|Minkovsky 1/2 %x4|Minkovsky 4 %x5|Minkovsky %x6"
+      if FX.val !=1 and Flt.val !=1:
+         Noise_Type = Menu(ntype,102,10,60,120,20, Noise_Type.val, "Noise Type")
+         if Noise_Type.val == 6:
+            VFunc = Menu(votype, 102, 10,85,120,15, VFunc.val)
+         elif Noise_Type.val != 9:
+            Noise_Basis = Menu(nbasis,102,10,85, 120, 15, Noise_Basis.val, "Noise Basis")
+         if Noise_Type.val in [0,1,2,3,4, 10,11,12,13]:
+            Oc = Slider("Octs: ", 102, 10,180,120,15, Oc.val,0.0,8.0 ,0, "Musgrave:  Octaves")
+            La = Slider("Lacu: ", 102, 10,165,120,15, La.val,0.0,6.0 ,0, "Musgrave:  Lacunarity")
+            Ha = Slider("H: ", 102, 10,150,120,15, Ha.val,0.0,2.0 ,0, "Musgrave:  H")
+            if Noise_Type.val in [1,2,12]:
+               Ga = Slider("Gain: ", 102, 10,120,120,15, Ga.val,0.0,6.0 ,0, "Musgrave:  Gain")
+            if Noise_Type.val in [1,2,3,10,11,12,13]:
+               Of = Slider("Ofst: ", 102, 10,135,120,15, Of.val,0.0,6.0 ,0, "Musgrave:  Offset")
+            if Noise_Type.val == 11:
+               Ri = Number("Layers:", 102, 10,120,120,15, Ri.val,0.0,10.0 ,"number of Layers")
+            if Noise_Type.val == 12:
+               Ri = Number(":", 102, 10,105,50,15, Ri.val,-2.0,2.0 ,"ridgedMF intensity")
+               Ri_S = Number(":", 102, 60,105,50,15, Ri_S.val,0.001,10.0 ,"ridgedMF Size")
+               Ri_B = Menu(nbasis, 102, 110,105,20,15, Ri_B.val,"ridgedMF Noise basis"+" = "+str(int(Ri_B.val)) )
+            elif Noise_Type.val == 13:
+               Ri = Number(":", 102, 10,105,40,15, Ri.val,-2.0,2.0 ,"Distortion intensity")
+               Ri_S = Number(":", 102, 50,105,40,15, Ri_S.val,0.001,10.0 ,"Distortion Size")
+               Damnt = Number("Distortion: ",102,90,105,40,15, Damnt.val, 0.0,10.0,"Distortion amount")
+               Ri_B = Menu(nbasis, 102, 10,120,60,15, Ri_B.val,"Distortion Noise basis")
+               Distortion_Noise = Menu(nbasis ,102,70,120,60,15, Distortion_Noise.val, "Distortion Noise")
+         elif Noise_Type.val in [5,14]:
+            if Hard.val == 0: Hardtext ="Soft"
+            elif Hard.val == 1: Hardtext ="Hard"
+            Hard = Toggle( Hardtext , 102, 10,135,60,15,Hard.val, "Turbulence:  Soft noise / Hard noise")
+            Amp = Slider("Amp:", 102,10,165,120,15,Amp.val,0.0,10.0, 0, "Turbulence: Ampscale ")
+            Freq = Slider("Freq:", 102,10,150,120,15,Freq.val,0.0,10.0, 0, "Turbulence:  Freqscale")
+            Depth = Number("Depth:", 102,70,135,60,15,Depth.val,0.0,10.0, "Turbulence:  Octaves")
+         elif Noise_Type.val == 6:
+            VDep = Number("Depth:",102,10,165,120,15,VDep.val,0,3, "Voronoi:  Depth")
+            if (VFunc.val == 6):
+               VExp = Slider("Exp:",102,10,150,120,15,VExp.val,0.0,10.0, 0, "Voronoi:  Minkovsky exponent")
+         elif Noise_Type.val == 7:
+            Distortion_Noise = Menu(nbasis ,102,10,150,120,15, Distortion_Noise.val, "DistortedNoise:  Distortion Noise")
+            Damnt = Slider("Dist:",102,10, 165, 120, 15, Damnt.val, 0.0,10.0, 0, "DistortedNoise:  Distortion amount")
+      elif FX.val ==1:
+         glColor3f(0.61,0.61,0.61)   ##  Effects ##
+         glRecti(8, 55, 132, 200)
+         efxmnu = "Effect Type's %t|None %x0|Spiral %x1|Ring %x2|ZigZag %x3|Wave %x4|Bumps %x5|Sawteeth %x6|Saw-irregular %x7|Stones %x8|Craters %x9|Cracks %x10|Turbulence %x11|multiFractal %x12|DistortedNoise %x13|Gradient %x14|Random %x15"
+         EffectZ = Menu(efxmnu,102,10,180,60,15, EffectZ.val, "Effect Types")
+         if EffectZ.val !=0:
+            blfxmnu = "Blend Type's %t|None   (Effect only) %x0|Blend %x1|Add %x2|Subtract %x3|Multiply %x4|Difference %x5|Screen %x6|Add modulo %x7|Min %x8|Max %x9|Warp %x10"
+            FXblend = Menu(blfxmnu,102,70,180,60,15, FXblend.val, "Mix Effect with Noise")
+            fxIntens = Number("i:",102,10,110,60,15,fxIntens.val,-10.0,10.0, "Intensity")
+            fxOfst = Number("z:",102,70,110,60,15,fxOfst.val,-10.0,10.0, "Offset")
+            if EffectZ.val < 15:
+               fxSx = Number("x:",102,10,160,60,15,fxSx.val,0.0,25.0, "Freq.X")
+               fxSy = Number("y:",102,70,160,60,15,fxSy.val,0.0,25.0, "Freq.Y")
+               fxLx = Number("x:",102,10,130,60,15,fxLx.val,-25.0,25.0, "Position X")
+               fxLy = Number("y:",102,70,130,60,15,fxLy.val,-25.0,25.0, "Position Y")
+               if EffectZ.val in [11,12,13]:
+                  FXnoise = Menu(nbasis,102,10,60,120,15,FXnoise.val, "Noise Basis" )
+               if EffectZ.val == 11:
+                  fxB = Toggle("Hard:",102,70,75,60,15,fxB.val)
+                  fxA = Number("Oct:",102,10,75,60,15,fxA.val,0,10)
+               if EffectZ.val == 12:
+                  fxA = Number("Oct:",102,10,75,60,15,fxA.val,0,10)
+                  fxC = Number("H:",102,70,75,60,15,fxC.val,0.0,6.0)
+                  fxD = Number("La:",102,70,90,60,15,fxD.val,0.0,6.0)
+               if EffectZ.val == 13:
+                  fxA = Menu(nbasis,102,10,75,60,15,fxA.val, "Noise Basis" )
+                  fxC = Number("Dst:",102,70,75,60,15,fxC.val,0.0,10.0)
+               if EffectZ.val < 14:
+                  fxSize = Number("Freq:",102,10,145,120,15,fxSize.val,0.0,25.0, "Frequency")
+            if EffectZ.val == 14:
+               fxgradmnu = "Gradient's %t|x %x0|-x %x1|y %x2|-y %x3|Radial %x4"
+               fxgrad = Menu(fxgradmnu,102,10,145,120,15, fxgrad.val)
+            if EffectZ.val == 15:
+               fxSize = Number("R: ",102,10,145,120,15,fxSize.val,0.0,25.0, "Random")
+      elif Flt.val ==1:
+         glColor3f(0.61,0.61,0.61)   ## Filters ##
+         glRecti(8, 55, 132, 200)
+         filtmnu = "Filter Type's%t|None %x0|Warp %x1|Peaks %x2|Layers %x3|Peaks and Layers %x4|Saw %x5|Posterise %x6|blended Posterise %x7|SmoothStep %x8"
+         FilterZ = Menu(filtmnu,102,10,180,120,15,  FilterZ.val,"Filter Type's")
+         if FilterZ.val !=0:
+            if FilterZ.val in [1,3,4,5,6,7]:
+               filtF = Number(":",102,10,160,60,15,filtF.val, -25.0,25.0 , "Intensity" )
+            if FilterZ.val in [1,5,6,7]:
+               filtG = Number(":",102,70,160,60,15,filtG.val, -25.0,25.0 , "Offset" )
+            if FilterZ.val == 8:
+               lower = Number(":",102,10,160,60,15,lower.val, -1.0,1.0 , "Lower" )
+               upper = Number(":",102,70,160,60,15,upper.val, -1.0,1.0 , "Upper" )
+               filtF = Number(":",102,10,140,60,15,filtF.val, -25.0,25.0 , "Intensity" )
+
+      Lx = Number("",102,140,50,60,15,Lx.val,-1000.0,1000.0,"Noise x position" )
+      Ly = Number("",102,200,50,60,15,Ly.val,-1000.0,1000.0,"Noise y position" )
+      Lz = Number("",102,200,35,60,15,Lz.val,-1000.0,1000.0,"Noise z position" )
+      NSize = Number("NoiseSize: ",102,140,70, 120, 20, NSize.val, 0.001, 10.0, "Noise size")
+      Sx = Number("x",102,140,90,60,15,Sx.val,0.001,10.0,"Noise x size")
+      Sy = Number("y",102,200,90,60,15,Sy.val,0.001,10.0,"Noise y size")
+      iScale = Number("iScale: ",102,140, 110, 90, 20, iScale.val, -10.0,10.0, "Height:  Noise intensity")
+      invert = Toggle("I",102,230,110,30,20, invert.val,"Height: Invert noise intensity")
+      offset = Number("Offset: ",102,140,130,120,15,offset.val,-10.0,10.0, "Height: Noise z offset")
+      plev = Number("Max.:",102,140,180,90,15,plev.val, slev.val,1.0, "Plateau: Clip z Max.")
+      pslope   = Toggle("S",102,230,180,15,15, pslope.val, "Plateau:  Set Flat  /  Set Slope")
+      platnoise = Toggle("N",102,245,180,15,15, platnoise.val, "Plateau:  Set Flat  /  Set Noise ( +0.1*noise ) ")
+      falmnu = "Falloff Type's %t|None %x0|Round %x1|Square %x2|y Linear %x3|x Linear %x4"
+      if FalTyp.val !=0:
+         slev = Number("Min.:",102,140,165,90,15,slev.val, -0.999,plev.val, "Sealevel: Clip z Min.")
+         edgesatsea = Toggle("E",102,230,165,30,15, edgesatsea.val, "Edge Falloff:  Set Edge's at Sealevel")
+         FalTyp = Menu(falmnu,102,230,150,30,15, FalTyp.val,"Edge Falloff Type's")
+         Fall = Number(":",102,140,150,45,15,Fall.val,0.0,10.0,"Edge Falloff : Radius")
+         FalHard = Number(":",102,185,150,45,15,FalHard.val,0.0,25.0,"Edge Falloff : Hardness")
+      else:
+         FalTyp = Menu(falmnu,102,140,150,120,15, FalTyp.val,"Edge Falloff type's")
+         slev = Number("Min.:",102,140,165,120,15,slev.val, -0.999,plev.val, "Sealevel: Clip z Min.")
+
+      RaPos = Toggle("P",105,10,35,20,15, RaPos.val,"Random Noise Position.")
+      RaSiz = Toggle("S",105,30,35,20,15, RaSiz.val,"Random Noise Size.")
+      RaHgh = Toggle("H",105,50,35,20,15, RaHgh.val,"Random Noise Height.")
+      RaCha = Toggle("C",105,70,35,20,15, RaCha.val,"Random Noise Character.")
+      RaTyp = Toggle("T",105,90,35,20,15, RaTyp.val,"Random Noise Type.")
+      semnu = "Random Mode %t|Random %x0|Seed %x1"
+      RanMod = Menu(semnu,222,110,35,20,15, RanMod.val,"Random Mode")
+      if RanMod.val == 0:
+         Button("Random", 69, 80, 10, 50, 20,"Randomise Noise ( P,S,H,C,T ).")
+         Rseed = Create(0)
+      else:
+         Rseed = Number(":",69,80,10,50,20,Rseed.val,0,255,"Random seed ( P,S,C,H,T )")
+
+      resmnu = "Mesh Quality%t|32 %x0|50 %x1|64 %x2|100 %x3|128 %x4|150 %x5|200 %x6|256 %x7|512 %x8|Manual %x9"
+      if Quality.val == 9:
+         resolution = Number(":",102,140,25,40,15, resolution.val, 2,512,"Mesh resolution ( n*n )")
+         Quality = Menu(resmnu,102,140,10,40,15, Quality.val, "Mesh Quality")
+      else:
+         Quality = Menu(resmnu,102,140,10,40,15, Quality.val, "Mesh Quality")
+      Q_T = Toggle("Faces",102,220,10,40,15,Q_T.val,"Faces : Set Quads / Set Triangles")
+      smooth = Toggle("Smooth",102,180,10,40,15,smooth.val,"Faces : Set Solid / Set Smooth")
+      Auto_Update = Toggle("A",105,60,10,20,20, Auto_Update.val,"Automatic mesh update.")
+      Button("Update", 103, 10, 10, 50, 20,"Update mesh.")
+
+   pvi = "Preview %t|None %x0|Grey %x1|Original %x2|Coloured %x3"
+   pview = Menu(pvi,111, 10,226,20,15, pview.val, "Preview")
+   Button("P", 888, 35, 226, 15, 15,"Presets")
+   Button("X", 999, 245, 226, 15, 15,"Reset / Exit")
+
+### do_it ----------------------------------- 
+###----------------------------------- 
+def do_it():
+   Blender.Window.WaitCursor(1)
+   Crea()
+   Blender.Window.WaitCursor(0)
+   Redraw()
+def do_it_random():
+   Blender.Window.WaitCursor(1)
+   Random_N()
+   Crea()
+   Blender.Window.WaitCursor(0)
+   Redraw()
+###-----------------------------------
+def event(evt, val):
+   if (evt== ESCKEY and not val):
+      Exit()
+def bevent(evt):
+   global Auto_Update, preset, preGrad, colorcontrols, colors
+
+   if (evt== 999):
+      name = "OK ?%t|Exit %x1|Reset %x2"
+      result = Blender.Draw.PupMenu(name)
+      if result == 2:
+         resetMe()
+         reset()
+         do_it()
+      elif result == 1:
+         Exit()
+
+   if (evt == EV_NOEVENT):
+      Draw()
+
+   if (evt == EV_NEW ):
+      colors[ preGrad.val ].append([newheight.val, 128, 128, 128])
+      colors[ preGrad.val ].sort()
+      colors[ preGrad.val ].reverse()
+      Draw()
+   else:
+      for c in range( len(colors[ preGrad.val ]) ):
+         if (evt == EVB_H+c):
+            colors[ preGrad.val ][c][0] = colorcontrols[0][c].val
+         elif (evt == EVB_R+c):
+            colors[ preGrad.val ][c][1] = colorcontrols[1][c].val
+         elif (evt == EVB_G+c):
+            colors[ preGrad.val ][c][2] = colorcontrols[2][c].val
+         elif (evt == EVB_B+c):
+            colors[ preGrad.val ][c][3] = colorcontrols[3][c].val
+         elif (evt == EVB_DEL+c):
+            del(colors[ preGrad.val ][c])
+      colors[ preGrad.val ].sort()
+      colors[ preGrad.val ].reverse()
+      Draw()
+
+   if (evt == 888):
+      pre="Default %x1|Original %x2|Blender hills %x3|Stones hills %x4|Round hills %x5|Plateau %x6|Shattered %x7|Chaotic %x8|RidgedMF %x9|Dist.hTerrain %x10|Cauliflower %x11|Ridges %x12|Crystalline %x13||Warped hT. %x14|ChebyTech %x15|CellNoise %x16|Canyonised %x17|Ring o Rock %x18|Xtreme Peaks %x19|HardTurb %x20|Cliff %x21"
+      result = Blender.Draw.PupMenu(pre,7)
+      if result > 0:
+         preset.val = result
+         if Auto_Update.val == 1:
+            reset()
+            Preset_Noise()
+            do_it()
+         else:
+            reset()
+            Preset_Noise()
+         Draw()
+
+   if (evt in [ 111 , 222 ] ):
+      Draw()
+   if (evt == 103):
+      do_it()
+   if Auto_Update.val == 1:
+      if (evt == 102):
+         do_it()
+      elif (evt == 69):
+         do_it_random()
+   if Auto_Update.val == 0:
+      if (evt == 69):
+         Random_N()
+         Draw()
+      elif (evt == 102):
+         Draw()
+
+   if (evt == 31):
+      if FX.val ==1:
+         Flt.val = 0
+         Draw()
+   if (evt == 32):
+      if Flt.val ==1:
+         FX.val = 0
+         Draw()
+
+Register(GUI, event, bevent)
Index: /data/contentcreation/orx_artists/SilvanNellen/moonsurface/ANTLandscape_104a_9-2006.py
===================================================================
--- /data/contentcreation/orx_artists/SilvanNellen/moonsurface/ANTLandscape_104a_9-2006.py	(revision 4790)
+++ /data/contentcreation/orx_artists/SilvanNellen/moonsurface/ANTLandscape_104a_9-2006.py	(revision 4790)
@@ -0,0 +1,1547 @@
+#!BPY
+"""
+Name: 'A.N.T.Landscape v.1.04a'
+Blender: 241
+Group: 'Add'
+Tip: 'Create landscape mesh.'
+"""
+
+
+#
+##  Execute Script: Alt P
+#
+
+################################################################################################################
+# Another Noise Tool 'Landscape' v.1.04  ( build and tested in Blender 2.41 )
+# Jimmy Hazevoet April/May 2006
+# license: Do whatever you want with it.
+################################################################################################################
+
+################################################################################################################
+## BugFix: Sept./2006  v.1.04a
+# _ Image Effect did not worked well with tiled mesh.
+# Fixed (now use Freq. and Loc. buttons to scale and position image).
+##
+################################################################################################################
+
+################################################################################################################
+# Readme:
+#
+#   v.1.04:
+# _ New G.U.I.
+#
+# _ New noise types like: Double_Terrain, StatsByAlt_Terrain, slickRock, ditorted_heteroTerrain, vlNoise_turbulence, and many more.
+#
+# _ New fractalized Effect functions.
+#      Effect types such as: gradient, waves and bumps, dome, piramide, squares, grid, shattered rocks, lunar, and many more.
+#      Bias types: Sin, Cos, Tri, Saw, and Default(no bias).
+#      For example the 'Rings' effect with 'Sin Bias' makes 'Rings' and 'Default Bias' makes 'Dome'.
+# _ The Effect 'Mix factor' Slider gives control over how much of the Effect is vissible, -1.0=noise, 0.0=average, 1.0=effect
+#      this slider controls also the 'Warp amount' if mix type 'Warp' is selected.
+#
+# _ Image effect: mix image with noise
+#
+# _ IPOCurve Filter: use Ipo curve to filter terrain height.
+#      I know it's a bit strange to use animation curves for landscape modelling, (actualy i want a curves panel in my G.U.I. but i dont know how to do that)
+#      the downside of this method is that you have this 'Empty' moving around in your scene, so put it on another layer and 'Pin' the Ipo block so that it stays visible.
+#     Usage:
+#      Add one 'Empty' Object to your scene, now add one Loc Key at Frame 1, go to Frame 101 (UpArrow ten times),
+#      move the 'Empty' +100 units in X+ direction and add another Loc Key, open the Ipo Curve Editor Window, rename this IpoBlock if you want,
+#      Copie the first curve to buffer and Paste it in the empty slots (from top to bottom), now you can edit the curves freely.
+#      (use the 'Pin' option to keep the curves visible while other objects are selected)
+#      Set the CurveLength and CurveHeight Button value's according to the length and height of the selected curve.
+#      A curve filter is very versatile when it comes to 'height' filtering.
+#
+# _ PreView in UV/Image Editor Window:
+#      The preview image is now rendered as Blender.Image and will be saved to file directory as 'ANTview_size.tga'
+#      you have to select 'ANTview_size.tga' in the UV/Image Editor Window
+#      now it's posible to render and save a large HeightMap image (you can also create nice texture images when the VertCol gradient is enabled),
+#      ! If you Change the preview image Size a New Blender.Image object is created. (one for size 256, one for size 512 one for.....) !
+#
+# _ VertexColours: use any image as colour gradient.
+#      This function actualy uses one 'row' of pixels from a image to produce the color gradient,
+#      Make one or more custom gradient images with the Gimp or any other graphics software, the gradients must go from left to right (left is bottom and right is top.
+#      you only need one row of pixels so you can put 10 gradients in a 256*10 image.(higher resolutions like 512*n or 1024*n gives smoother result) 
+#      Set Window DrawMode 'Textured' , and set the 'VCol Paint' option in the Materials panel !
+#
+# _ Mesh Tiles: Create large scale terrains.
+#
+# _ Vertices Selection: select flat areas.
+#
+# _ Keyboard HotKeys:
+#      SPACE = Update mesh.
+#      R = Randomise.
+#      V = Redraw preview.
+#
+# _ and more...
+#
+################################################################################################################
+
+
+import Blender
+from Blender import * 
+from math import *
+from Blender.Noise import * 
+from Blender.Draw import *
+from Blender.BGL import *
+from Blender import Image
+import string
+import BPyMathutils
+from BPyMathutils import genrand
+scene = Scene.getCurrent()
+
+
+###---------------------------------------------------------------------------
+##--------------------------------------------------------------------------
+# Customise: ---------------------------------------------------------------
+
+# G.U.I.:
+guitabs = [ Create( 0 ), Create( 1 ), Create( 0 ), Create( 0 ), Create( 0 ) ]  # G.U.I. Tabs
+FullScreen = Create( 1 )            # FullScreen
+size_x  = 320                       # gui x size 
+size_y  = 280                       # gui y size 
+lightgrey  = [ 0.76, 0.76, 0.76 ]   # gui col.
+grey       = [ 0.6, 0.6, 0.6 ]      # panel col.
+background = [ 0.7, 0.7, 0.7, 1.0 ] # background col.
+black      = [ 0.0, 0.0, 0.0 ]      # text col.
+
+# Names:
+TerName     = Create( 'Terrain' )   # Terrain Name
+previewname = Create( 'ANTview' )   # Preview / Heightmap Image Name
+
+# Mesh Resolutions:
+resolution = [ '16','32', '40', '64', '80', '100', '128', '160', '200', '256', '320', '400', '512', '640', '800', '960', '1024' ]
+
+## Mesh Tiles: ##
+#
+# Tiles: Number of Positions is Number of Tiles:
+# 3 tiles:
+tiles_3 = [ ( 0 , 0 ), ( -1 , 0 ), ( +1 , 0 ) ]
+# 3*3: 9 tiles:
+tiles_9 = [ ( 0 , 0 ), ( -1 , 0 ), ( +1 , 0 ), ( -1 , -1 ), ( 0 , -1 ), ( +1 , -1 ), ( -1 , +1 ), ( 0 , +1 ), ( +1 , +1 ) ]
+# 5*5: 25 tiles:
+tiles_25 = [ ( 0 , 0 ), ( -2 , -2 ), ( -1 , -2 ), ( 0 , -2 ), ( +1 , -2 ) , ( +2 , -2 ), ( -2 , -1 ), ( -1 , -1 ), ( 0 , -1 ), ( +1 , -1 ), ( +2 , -1 ), ( -2 , 0 ), ( -1 , 0 ), ( +1 , 0 ) , ( +2 , 0 ), ( -2 , +1 ), ( -1 , +1 ), ( 0 , +1 ), ( +1 , +1 ), ( +2 , +1 ), ( -2 , +2 ), ( -1 , +2 ), ( 0 , +2 ) , ( +1 , +2 ), ( +2 , +2 ) ]
+
+# list of tile positions to choose from:
+tiles_positions = [ tiles_3, tiles_9, tiles_25 ]
+
+# re-scale (for falloff and preview) set this according to the x number of tiles:
+tile_rescale = [ 3 , 3 , 5 ]
+
+#---------------------------------------------------------------------------
+##--------------------------------------------------------------------------
+###---------------------------------------------------------------------------
+
+columns = 10  # gui columns
+rows    = 13  # gui rows
+
+effect_image  = 'Load and Select image.'
+colgrad_image = 'Load and Select gradient image.'
+
+ipoblockname = ''
+thiscurve = []
+selectedcurve = 0
+
+phi = 3.14159265359
+
+No_Evt   = 1
+Btn_Evt  = 2
+Upd_Evt  = 3
+Rndm_Evt = 4
+Load_Evt = 5
+Sel_Evt  = 6
+Grad_Sel_Evt = 61
+Save_Evt = 7
+Rend_Evt = 8
+End_Evt  = 9
+Scrn_Evt = 15
+Im_Evt   = 16
+gt0_Evt  = 10
+gt1_Evt  = 11
+gt2_Evt  = 12
+gt3_Evt  = 13
+gt4_Evt  = 14
+
+noisetypemenu  = "Noise type: %t|multiFractal %x0|ridgedMFractal %x1|hybridMFractal %x2|heteroTerrain %x3|fBm %x4|turbulence %x5|Voronoi turb. %x6|vlNoise turb. %x7|noise %x8|cellNoise %x9| %l|Marble %x10|lava_multiFractal %x11|slopey_noise %x12|duo_multiFractal %x13|distorted_heteroTerrain %x14|slickRock %x15|terra_turbulence %x16|rocky_fBm %x17|StatsByAlt_Terrain %x18|Double_Terrain %x19"
+noisebasismenu = "Basis %t|Blender Original%x0|Original Perlin%x1|Improved Perlin%x2|Voronoi_F1%x3|Voronoi_F2%x4|Voronoi_F3%x5|Voronoi_F4%x6|Voronoi_F2-F1%x7|Voronoi Crackle%x8|CellNoise%x9"
+voronitypemenu = "Voronoi type %t|Distance %x0|Distance Squared %x1|Manhattan %x2|Chebychev %x3|Minkovsky 1/2 %x4|Minkovsky 4 %x5|Minkovsky %x6"
+tBasismodemenu = "Terrain basis mode: %t|noise %x0|ridged noise %x1|vlNoise %x2|ridged vlNoise %x3"
+
+effecttypemenu = ['Effect Type %t','No Effect %x0','Image %x1','Turbulence %x2','vlNoise %x3','Marble %x4','Gradient %x5','Waves and Bumps %x6','ZigZag %x7','Wavy %x8','Sine Bump %x9','Dots %x10','Rings / Dome %x11','Spiral %x12','Square / Piramide %x13','Blocks %x14','Grid %x15','Tech %x16','Crackle %x17','Sparse Cracks %x18','Shattered Rocks %x19','Lunar %x20','Cosine noise %x21','Spike noise %x22','Stone noise %x23','Flat Turb %x24','Flat Voroni %x25' ]
+mixtypemenu = ['Mix Type %t','Effect only %x0','%l','Mix %x1','Add %x2','Subtract %x3','Multiply %x4','Difference %x5','Screen %x6','addmodulo %x7','Minimum %x8','Maximum %x9','%l','Warp Effect %x10','Warp Noise %x11']
+
+biastypemenu  = "Bias %t|Sin bias %x0|Cos bias %x1|Tri bias %x2|Saw bias %x3|Default (no bias)%x4"
+sharptypemenu = "Sharpen %t|Soft %x0|Sharp %x1|Sharper %x2"
+
+filtermodemenu = "Filter Mode %t|No Filter %x0| %l|Default Filters %x1|IPOCurve Filter %x2"
+filtertypemenu = "Filter Type %t|Default Terrace %x0|Sharper Terrace %x1|Rounded Terrace %x2|Posterise Mixed %x3|Posterise %x4|Layered Peaks %x5|Peaked %x6|Smooth-thing %x7|Sin bias %x8|Cos bias %x9|Tri bias %x10|Saw bias %x11"
+falloftypemenu = "Edge Falloff %t|No Edge Falloff %x0| %l|Soft Falloff %x1|Default Falloff %x2|Hard Falloff %x3|Linear Falloff Y %x4|Linear Falloff X %x5|Diagonal Falloff + %x6|Diagonal Falloff - %x7|Square %x8|Round %x9"
+
+randomtypemenu = "Random type: %t|setRandomSeed() : Blender.Noise %x0|Rand() : Blender.Mathutils %x1|genrand() : BPyMathutils MersenneTwister %x2"
+
+##--------------------------------------------------
+def Set_ReSet_Values():
+	global Quality, Quad_Tri, Smooth, vSelRange, maketiles
+	global iScale, Offset, Invert, NSize, Sx, Sy, Lx, Ly
+	global NType, Basis, musgr, vlnoi, vlnoiTwo, voron, turbOne, turbTwo, marbleOne, marbleTwo, tBasismod
+	global Effect_Ctrl, Min, Max, Falloff, Filter_Mode, Def_Filter_Ctrl, Ipo_Filter_Ctrl
+	global RandMod, RSeed, rand_H, rand_S, rand_L
+	global AutoUpd, PreView, ViewiScale, vcolours, vcolGradRow, gradScale
+	
+	AutoUpd  = Create( 0 )
+	PreView = [ Create( 0 ), Create( 7 ), Create( 0 ) ]
+	ViewiScale = Create( 1.0 )
+	vcolours = Create( 0 )
+	vcolGradRow = Create( 0 )
+	gradScale = Create( 1.0 )
+	## Mesh controls:
+	Quality  = Create( 7 )
+	Quad_Tri = Create( 0 )
+	Smooth   = Create( 0 )
+	vSelRange = Create( 0.0 )
+	maketiles = [ Create( 0 ), Create( 0 ) ]
+	## Coords controls:
+	iScale = [ Create( 1.0 ), Create( 1.0 ), Create( 0.25) ]
+	Offset = [ Create( 0.0 ), Create( 0.0), Create( 0.0) ]
+	Invert = [ Create( 0 ), Create( 0 ), Create( 0 ) ]
+	NSize = [ Create( 1.0 ), Create( 2.0 ) ]
+	Sx = [ Create( 1.0 ), Create( 1.0 ) ]
+	Sy = [ Create( 1.0 ), Create( 1.0 ) ]
+	Lx = [ Create( 0.0 ), Create( 0.0 ) ]
+	Ly = [ Create( 0.0 ), Create( 0.0 ) ]
+	## Noise controls:
+	NType = Create( 0 )
+	Basis = [ Create( 0 ), Create( 0 ) ]
+	musgr = [ Create( 1.0 ), Create( 2.0 ), Create( 8 ), Create( 1.0 ), Create( 1.0 ), Create( 0.5 ) ]
+	vlnoi = [ Create( 1.0 ), Create( 0 ) ]
+	vlnoiTwo = [ Create( 1.0 ), Create( 0 ) ]
+	voron = [ Create( 0 ), Create( 2.5 ) ]
+	turbOne = [ Create( 3 ), Create( 0 ), Create( 0.5 ), Create( 2.0 ) ]
+	turbTwo = [ Create( 3 ), Create( 0 ), Create( 0.5 ), Create( 2.0 ) ]
+	marbleOne = [ Create( 6 ), Create( 0 ), Create( 2.0 ), Create( 0 ), Create( 0 ), Create( 1.0 ) ]
+	marbleTwo = [ Create( 6 ), Create( 0 ), Create( 2.0 ), Create( 0 ), Create( 0 ), Create( 1.0 ) ]
+	tBasismod = Create(0)
+	## Effect controls:
+	Effect_Ctrl = [ Create( 0 ), Create( 2 ), Create( 0.0 ), Create( 0 ), Create( 0.0 )  , Create( 0 ), Create( 2.0 )  , Create( 0.5 ) ]
+	## Filter controls:
+	Min = Create( 0.0 )
+	Max = Create( 1.0 )
+	Falloff = [ Create( 0 ), Create( 1.0 ), Create( 1.0 ), Create( 0 ) , Create( 0 ) ]
+	Filter_Mode = Create( 0 )
+	Def_Filter_Ctrl = [ Create( 0 ), Create( 3.0 ) ]
+	Ipo_Filter_Ctrl = [ Create( "ObIpo" ), Create( 0 ), Create( 100.0 ), Create( 100.0 ) ]
+	## Randomise noise buttons:
+	RandMod = Create( 1 )
+	RSeed   = Create( 0 )
+	rand_H  = Create( 0 )
+	rand_S  = Create( 0 )
+	rand_L  = Create( 1 )
+
+##-------------------------
+
+Set_ReSet_Values()
+
+##-------------------------
+
+###---------------------------------------------------------------------------
+## Randomise:
+##-------------------------
+
+# Generate random numbers:
+def randnum(low,high):
+	global RandMod, RSeed
+	if RandMod.val == 0:
+		# Noise.random setRandomSeed
+		s = setRandomSeed( RSeed.val )
+		num = random()
+		num = num*(high-low)
+		num = num+low
+	elif RandMod.val == 1:
+		# Mathutils.Rand
+		num = Mathutils.Rand( 0.0, 1.0 )
+		num = num*(high-low)
+		num = num+low
+	else:
+		# BPyMathutils  Mersenne Twister genrand
+		num = genrand()
+		num = num*(high-low)
+		num = num+low
+	return num
+
+# Randomise noise: height, size and location:
+def randomiseNoise():
+	global rand_H, rand_S, rand_L, NSize, iScale, Offset, Invert, Lx, Ly, Sx, Sy
+	if rand_H.val !=0:
+		iScale[2] = Create( randnum( 0.1  , 1.0 ) )
+		Offset[2] = Create( randnum(-0.25 , 0.25 ) )
+		#Invert[2] = Create( randnum( 0 , 2 ) )		
+	if rand_S.val !=0:
+		NSize[0]  = Create( randnum( 0.2 , 3.0 ) )
+		#Sx[0]     = Create( randnum( 0.75 , 1.25 ) )
+		#Sy[0]     = Create( randnum( 0.75 , 1.25 ) )
+	if rand_L.val !=0:
+		Lx[0]     = Create( randnum( -1000 , 1000 ) )
+		Ly[0]     = Create( randnum( -1000 , 1000 ) )
+
+
+###----------------------------------------------------------------------------------------------------
+## G.U.I.: text,backpanel,panel and frame
+#--------------------------------------------------
+def draw_Text( ( x, y ), text, color, size ):
+	glColor3f( color[0],color[1],color[2] )
+	glRasterPos2d(x,y)
+	txtsize = 'small', 'normal', 'large'
+	Text( text, txtsize[ size ] )
+def draw_BackPanel( text, x, y, w, h, colors ):
+	glColor3f( colors[0]*0.76, colors[1]*0.76, colors[2]*0.76 )
+	glRecti( x, h, w, h+20 )
+	glColor3f( colors[0], colors[1], colors[2] )
+	glRecti( x, y, w, h )
+	glColor3f( colors[0], colors[1], colors[2] )
+	glRasterPos2d( x+10, h+5 )
+	Text( text, 'small' )
+def draw_Panel( x, y, w, h, colors ):
+	glColor3f( colors[0], colors[1], colors[2] )
+	glRecti( x,y, w,h )
+def draw_Frame( text, x, y, w, h, color ):
+   glColor3f( color[0], color[1], color[2] )
+   glRasterPos2i(x+3,h-3)
+   Text(text ,'small')
+   stringwidth = GetStringWidth( text,'small' )
+   glColor3f( color[0], color[1], color[2]  )
+   glBegin(Blender.BGL.GL_LINE_STRIP)
+   glVertex2i(x,h)
+   glVertex2i(x,y)
+   glVertex2i(w,y)
+   glVertex2i(w,h)
+   glVertex2i(x+stringwidth+10,h)
+   glEnd()
+
+
+###----------------------------------------------------------------------------------------------------
+## Buttons:
+#----------------------------------------------------------------------------------------------------
+
+###-------------------------
+## Mesh Buttons:
+#
+def MeshButtons( col, row, width, height ):
+	global TerName, AutoUpd, Quality, Quad_Tri, Smooth, vSelRange, maketiles
+
+	draw_Text( ( col[2], row[1] ), 'Make Duplicate: [ Shift D ] in 3D View.', black, 0 )
+	TerName = String( "OB:", No_Evt,     col[2], row[3], width[5], height[2] ,TerName.val,20, "Object name. (New name generates new mesh)" )
+	Quality  = Menu( 'Vertices:  Resolution  n*n %t|' + '|'.join( resolution ), No_Evt ,col[2], row[5], width[5], height[2], Quality.val, "Verts: Number of Vertices ( n*n )" )
+	smoothmnu = "Faces: %t|Solid %x0|Smooth %x1"
+	Smooth   = Menu( smoothmnu, No_Evt ,col[2], row[6], width[2], height[1], Smooth.val, "Faces: SetSmooth / SetSolid" )
+	facemnu   = "Faces: %t|Quads %x0|Triangles %x1"
+	Quad_Tri = Menu( facemnu,   No_Evt ,col[5], row[6], width[2], height[1], Quad_Tri.val, "Faces: Quads / Triangles" )
+	vSelRange = Slider( "VertSel:", No_Evt, col[2], row[8], width[5], height[2], vSelRange.val,  0.0, 10.0, 0 , "Vertices Selection: Select flat areas (higher value selects more slopes)" )
+	if maketiles[0].val !=0:
+		maketiles[1] = Number("" , No_Evt, col[6], row[10], width[1], height[2], maketiles[1].val,   0, len(tiles_positions)-1 , "Tiles: Select Number of tiles" )
+		maketiles[0] = Toggle( str(len(tiles_positions[maketiles[1].val])) + " Tiles",    No_Evt, col[2], row[10], width[3], height[2], maketiles[0].val, "Tiled Mesh: Generate Terrain Tiles (for making large scale terrain)")
+	else:
+		maketiles[0] = Toggle("Tiles", No_Evt, col[2], row[10], width[5], height[2], maketiles[0].val, "Tiled Mesh: Generate Terrain Tiles (for making large scale terrain)")
+
+###-------------------------
+## Noise Buttons:
+#
+def NoiseButtons( col, row, width, height ):
+	global NSize, iScale, Offset, Invert, Lx, Ly, Sx, Sy
+	global Ha, La, Oc, Of, Ga, Basis, NType, musgr, vlnoi, voron, turbOne, tBasismod 
+	global Depth, Hard, Amp, Freq, vlBasis, Distort, VFunc, VExp, VDep, marbleOne
+	global RandMod, RSeed, rand_H, rand_S, rand_L
+	
+	bth = height[1]/2+5
+	iScale[0] = Number("iScale:", Btn_Evt, col[5], row[2]+bth, width[3], height[1], iScale[0].val,   -10.0, 10.0 , "Noise: Intensity Scale. ( To scale terrain height, use 'HeightScale' in the Height panel )" )
+	Invert[0] = Toggle("Inv.",    Btn_Evt, col[9], row[2]+bth, width[0], height[1], Invert[0].val, "Noise: Invert")
+	Offset[0] = Number("Offset:", Btn_Evt, col[5], row[3]+bth, width[4], height[1], Offset[0].val,   -10.0, 10.0 , "Noise: Offset " )
+	NSize[0] = Number("Noise Size:",Btn_Evt, col[5], row[5], width[4], height[2], NSize[0].val, 0.001, 10.0 , "Noise Size" )
+	Sx[0]    = Number("Size X:", Btn_Evt, col[5], row[6], width[4], height[1], Sx[0].val,    0.001, 10.0 , "Size X" )
+	Sy[0]    = Number("Size Y:", Btn_Evt, col[5], row[7], width[4], height[1], Sy[0].val,    0.001, 10.0 , "Size Y" )
+	Lx[0]    = Number("Loc X:",  Btn_Evt, col[5], row[9], width[4], height[1], Lx[0].val,  -1000.0, 1000.0 , "Loc X" )
+	Ly[0]    = Number("Loc Y:",  Btn_Evt, col[5], row[10],width[4], height[1], Ly[0].val,  -1000.0, 1000.0 , "Loc Y" )
+
+	NType = Menu( noisetypemenu,        Btn_Evt, col[0], row[2], width[4], height[2], NType.val, "Noise type" )
+	if NType.val == 6:
+		voron[0] = Menu( voronitypemenu,    Btn_Evt, col[0], row[3], width[4], height[1], voron[0].val, "Voronoi type" )
+	else:
+		Basis[0] = Menu( noisebasismenu,    Btn_Evt, col[0], row[3], width[4], height[1], Basis[0].val, "Noise Basis" )
+
+	if NType.val in [0,1,2,3,4,11,12,13,14,15,17,18,19]:
+		musgr[0] = Slider( "H: ",     Btn_Evt, col[0], row[5], width[4], height[1], musgr[0].val,  0.0, 3.0, 0 ,  "H" )
+		musgr[1] = Slider( "Lacu: ",  Btn_Evt, col[0], row[6], width[4], height[1], musgr[1].val,  0.0, 6.0, 0 ,  "Lacunarity" )
+		musgr[2] = Slider( "Octs: ",  Btn_Evt, col[0], row[4], width[4], height[1], musgr[2].val,    0, 12,  0 , "Octaves" )
+	if NType.val in [1,2,3,13,14,15,18,19]:
+		musgr[3] = Slider( "Offst: ", Btn_Evt, col[0], row[7], width[4], height[1], musgr[3].val,  0.0, 6.0, 0 ,  "Offset" )
+	if NType.val in [1,2,13,15,18]:
+		musgr[4] = Slider( "Gain: ",  Btn_Evt, col[0], row[8], width[4], height[1], musgr[4].val,  0.0, 6.0, 0 ,  "Gain" )
+	if NType.val == 19:
+		musgr[5] = Slider( "Thresh: ",  Btn_Evt, col[0], row[8], width[4], height[1], musgr[5].val,  0.001, 2.0, 0 ,  "Threshold" )
+	if NType.val in [5,6,7,16]:
+		turbOne[0] = Number(  "Depth:",   Btn_Evt, col[0], row[4], width[4], height[1], turbOne[0].val, 0, 12, "Octaves")
+		turbOne[1] = Toggle("Hard noise", Btn_Evt, col[0], row[5], width[4], height[1], turbOne[1].val,        "Soft noise / Hard noise")
+		turbOne[2] = Slider(    "Amp:",   Btn_Evt, col[0], row[6], width[4], height[1], turbOne[2].val, 0.0, 3.0, 0, "Ampscale ")
+		turbOne[3] = Slider(   "Freq:",   Btn_Evt, col[0], row[7], width[4], height[1], turbOne[3].val, 0.0, 6.0, 0, "Freqscale")
+	if NType.val in [18,19]:
+		tBasismod = Menu( tBasismodemenu, Btn_Evt, col[0], row[9], width[4], height[1], tBasismod.val, "Terrain basis mode.")
+	if NType.val == 6:
+		if voron[0].val == 6:
+			voron[1] = Slider( "Exp: ", Btn_Evt, col[0], row[8], width[4], height[1], voron[1].val, 0.0,10.0, 0, "Minkovsky exponent")
+	if NType.val in [7,11,12,14]:
+		vlnoi[0] = Slider( "Dist: ",   Btn_Evt, col[0], row[8], width[4], height[1], vlnoi[0].val,  0.0, 10.0, 0 , "Distort" )
+	if NType.val == 7:
+		vlnoi[1] = Menu(noisebasismenu,Btn_Evt, col[0], row[9], width[4], height[1], vlnoi[1].val, "Distortion Noise")
+	if NType.val == 10:
+		marbleOne[0] = Number(  "Depth: ", Btn_Evt, col[0], row[6], width[4], height[1], marbleOne[0].val, 0, 12, "Octaves")
+		marbleOne[2] = Slider(  "Turb: ",  Btn_Evt, col[0], row[7], width[4], height[1], marbleOne[2].val,  0.0,20.0, 0, "Turbulence ")
+		marbleOne[3] = Menu( biastypemenu, Btn_Evt ,col[0], row[4], width[4], height[1], marbleOne[3].val, "Bias")
+		marbleOne[5] = Slider(  "ReScale: ",  Btn_Evt, col[0], row[8], width[4], height[1], marbleOne[5].val,  0.0,20.0, 0, "ReScale")
+		if marbleOne[3].val != 4:
+			marbleOne[4] = Menu(sharptypemenu, Btn_Evt ,col[0], row[5], width[4], height[1], marbleOne[4].val, "Sharpen")
+
+	RandMod = Menu( randomtypemenu, No_Evt, col[0], row[10], width[1], height[1], RandMod.val, "Random Type" )
+	rand_H = Toggle("H",No_Evt ,col[2], row[10], width[0], height[1], rand_H.val, "Randomise Terrain Height ( in Height panel )")
+	rand_S = Toggle("S",No_Evt ,col[3], row[10], width[0], height[1], rand_S.val, "Randomise Noise Size")
+	rand_L = Toggle("L",No_Evt ,col[4], row[10], width[0], height[1], rand_L.val, "Randomise Noise Location")
+
+###-------------------------
+## Effect Buttons:
+#
+def EffectButtons( col, row, width, height ):
+	global Effect_Type, Effect_Ctrl, Blend_Effect
+	global NSize, iScale, Offset, Invert, Lx, Ly, Sx, Sy
+	global BasisTwo, turbTwo, marbleTwo, vlnoiTwo
+	
+	Effect_Ctrl[0] = Menu( '|'.join( effecttypemenu ), Btn_Evt, col[0], row[2], width[4], height[2], Effect_Ctrl[0].val, "Effect: Type" )
+	if Effect_Ctrl[0].val != 0:
+		Effect_Ctrl[1] = Menu( '|'.join( mixtypemenu ),    Btn_Evt, col[5], row[2], width[4], height[2], Effect_Ctrl[1].val, "Mix: Type" )
+		Effect_Ctrl[2] = Slider("Mix: ", Btn_Evt, col[5], row[3], width[4], height[1], Effect_Ctrl[2].val, -1.0, 1.0, 0, "Mix factor / Warp amount" )
+		iScale[1] = Number("iScale:", Btn_Evt, col[5], row[4], width[3], height[1], iScale[1].val,   -20.0, 20.0 , "Effect: Intensity Scale " )
+		Invert[1] = Toggle("Inv.",    Btn_Evt, col[9], row[4], width[0], height[1], Invert[1].val, "Effect: Invert")
+		Offset[1] = Number("Offset:", Btn_Evt, col[5], row[5], width[4], height[1], Offset[1].val,   -20.0, 20.0 , "Effect: Offset " )
+		NSize[1] = Number("Frequency:",    Btn_Evt, col[5], row[6], width[4], height[1], NSize[1].val, 0.001, 100.0, "Effect Frequency ( Scale )" )
+		Sx[1]    = Number("Freq X:",  Btn_Evt, col[5], row[7], width[4], height[1],  Sx[1].val,    -50.0, 50.0 , "Effect Frequency X ( ScaleX )" )
+		Sy[1]    = Number("Freq Y:",  Btn_Evt, col[5], row[8], width[4], height[1],  Sy[1].val,    -50.0, 50.0 , "Effect Frequency Y ( ScaleY )" )
+		Lx[1]    = Number("Loc X:",   Btn_Evt, col[5], row[9], width[4], height[1],  Lx[1].val, -1000.0, 1000.0 , "Effect Loc X" )
+		Ly[1]    = Number("Loc Y:",   Btn_Evt, col[5], row[10], width[4], height[1], Ly[1].val, -1000.0, 1000.0 , "Effect Loc Y" )
+
+		if Effect_Ctrl[0].val == 1:
+			PushButton("Load Image",   Load_Evt, col[0], row[4], width[4], height[2] , "Load Image")
+			PushButton("Select Image", Sel_Evt,  col[0], row[6], width[4], height[3] , "Select Image")
+			draw_Text( ( col[0]+5, row[7] ), effect_image, black, 1 )
+		
+		if Effect_Ctrl[0].val in [2,3,4]:
+				Basis[1] = Menu( noisebasismenu,   Btn_Evt, col[0], row[3], width[4], height[1], Basis[1].val, "Basis" )
+		if Effect_Ctrl[0].val == 2:
+				turbTwo[0] = Number(  "Depth:",   Btn_Evt, col[0], row[4], width[4], height[1], turbTwo[0].val, 1, 12, "Octaves")
+				turbTwo[1] = Toggle("Hard noise", Btn_Evt, col[0], row[5], width[4], height[1], turbTwo[1].val,        "Hard noise")
+				turbTwo[2] = Slider(    "Amp:",   Btn_Evt, col[0], row[6], width[4], height[1], turbTwo[2].val, 0.0, 3.0, 0, "Ampscale ")
+				turbTwo[3] = Slider(   "Freq:",   Btn_Evt, col[0], row[7], width[4], height[1], turbTwo[3].val, 0.0, 6.0, 0, "Freqscale")
+		if Effect_Ctrl[0].val == 3:
+				vlnoiTwo[1] = Menu(noisebasismenu,Btn_Evt, col[0], row[4], width[4], height[1], vlnoiTwo[1].val, "Distortion Noise")
+				vlnoiTwo[0] = Slider( "Dist: ",   Btn_Evt, col[0], row[5], width[4], height[1], vlnoiTwo[0].val,  0.0, 10.0, 0 , "Distort" )
+		if Effect_Ctrl[0].val == 4:
+				marbleTwo[0] = Number(  "Depth: ", Btn_Evt, col[0], row[6], width[4], height[1], marbleTwo[0].val, 1, 12, "Octaves")
+				marbleTwo[2] = Slider(  "Turb: ",  Btn_Evt, col[0], row[7], width[4], height[1], marbleTwo[2].val,  0.0,20.0, 0, "Turbulence")
+				marbleTwo[3] = Menu( biastypemenu, Btn_Evt ,col[0], row[4], width[4], height[1], marbleTwo[3].val, "Bias")
+				marbleTwo[5] = Slider(  "ReScale: ",  Btn_Evt, col[0], row[8], width[4], height[1], marbleTwo[5].val,  0.0,20.0, 0, "ReScale")
+				if marbleTwo[3].val != 4:
+					marbleTwo[4] = Menu( sharptypemenu,Btn_Evt ,col[0], row[5], width[4], height[1], marbleTwo[4].val, "Sharpen")
+		if Effect_Ctrl[0].val > 4:
+				Effect_Ctrl[5] = Number("Depth:",  Btn_Evt, col[0], row[4], width[4], height[1], Effect_Ctrl[5].val,   0, 12   ,  "Fractalize Effect: Octaves" )
+				Effect_Ctrl[4] = Number("Distort:",Btn_Evt, col[0], row[7], width[4], height[1], Effect_Ctrl[4].val, 0.0, 10.0 ,  "Distort Effect: Distortion amount" )
+				Effect_Ctrl[6] = Slider("Freq:",   Btn_Evt, col[0], row[5], width[4], height[1], Effect_Ctrl[6].val, 0.0, 6.0, 0, "Fractalize Effect: Frequency" )
+				Effect_Ctrl[7] = Slider("Amp:",    Btn_Evt, col[0], row[6], width[4], height[1], Effect_Ctrl[7].val, 0.0, 3.0, 0, "Fractalize Effect: Amplitude" )
+				if Effect_Ctrl[0].val < 17:
+					Effect_Ctrl[3] = Menu( biastypemenu, Btn_Evt ,col[0], row[3], width[4], height[1], Effect_Ctrl[3].val, "Effect bias")
+
+
+
+###-------------------------
+## Filter Buttons:
+#
+def FilterButtons( col, row, width, height ):
+	global iScale, Offset, Invert, Min, Max, Falloff
+	global Filter_Mode, Def_Filter_Ctrl, Ipo_Filter_Ctrl
+
+	iScale[2] = Number("Height:", Btn_Evt, col[5], row[2], width[3], height[2], iScale[2].val,   -10.0, 10.0 , "Terrain Height:  Scale" )
+	Invert[2] = Toggle("Inv.",    Btn_Evt, col[9], row[2], width[0], height[2], Invert[2].val, "Terrain Height:  Invert")
+	Offset[2] = Number("Offset:", Btn_Evt, col[5], row[3], width[4], height[1], Offset[2].val,   -10.0, 10.0 , "Terrain Height:  Offset" )
+	Falloff[0] = Menu( falloftypemenu, Btn_Evt ,col[5], row[5], width[4], height[2], Falloff[0].val, "Terrain Height:  Edge falloff")
+	if Falloff[0].val !=0:
+		Falloff[1] = Number("X:",   Btn_Evt, col[5], row[6], width[1], height[1], Falloff[1].val , 0.01, 10.0 , "Edge falloff:  X Size" )		
+		Falloff[2] = Number("Y:",   Btn_Evt, col[8], row[6], width[1], height[1], Falloff[2].val , 0.01, 10.0 , "Edge falloff:  Y Size" )
+		Falloff[4] = Toggle("Inv.", Btn_Evt, col[7], row[6], width[0], height[1], Falloff[4].val, "Edge falloff:  Invert")
+		Falloff[3] = Toggle("Edge At Sealevel", Btn_Evt, col[5], row[7], width[4], height[1], Falloff[3].val, "Edge falloff:  Edge at Sealevel")
+	Max = Number("Plateau:", Btn_Evt, col[5], row[8], width[4], height[1], Max.val, Min.val, 1.0 , "Terrain Height:  Clamp Max. ( Plateau )" )
+	Min = Number("Sealevel:", Btn_Evt, col[5], row[9], width[4], height[1], Min.val, -1.0, Max.val , "Terrain Height:  Clamp Min. ( Sealevel )" )
+	Filter_Mode = Menu( filtermodemenu, No_Evt ,col[0], row[2], width[4], height[2], Filter_Mode.val, "Filter:  Mode")
+	if Filter_Mode.val ==1:
+		Def_Filter_Ctrl[0] = Menu( filtertypemenu, Btn_Evt ,col[0], row[4], width[4], height[2], Def_Filter_Ctrl[0].val, "Filter:  Type")
+		Def_Filter_Ctrl[1] = Number("Amount: ",    Btn_Evt, col[0], row[5], width[4], height[1], Def_Filter_Ctrl[1].val, 0.1, 25.0 , "Filter:  Amount" )
+	elif Filter_Mode.val ==2:
+		Ipo_Filter_Ctrl[0] = String("IP:",             No_Evt,  col[0], row[4], width[4], height[2], Ipo_Filter_Ctrl[0].val,20, "Ipo datablock name" )
+		Ipo_Filter_Ctrl[1] = Number("Selected Curve:", No_Evt, col[0], row[6], width[4], height[3], Ipo_Filter_Ctrl[1].val, 0, 29, "Selected curve" )
+		Ipo_Filter_Ctrl[2] = Number("Curve Length:", No_Evt, col[0], row[7], width[4], height[1], Ipo_Filter_Ctrl[2].val, 0.0, 1000.0, "X: Length (number of frames) of the selected curve." )
+		Ipo_Filter_Ctrl[3] = Number("Curve Height:", No_Evt, col[0], row[8], width[4], height[1], Ipo_Filter_Ctrl[3].val, 0.0, 1000.0, "Y: Height (offset) of the selected curve." )
+
+###-------------------------
+## Option Buttons:
+#
+def OptionButtons( col, row, width, height ):
+	global PreView, previewname, ViewiScale, vcolours, vcolGradRow, gradScale
+
+	PreView[0] = Toggle("Preview Image", No_Evt, col[0], row[2], width[4], height[2], PreView[0].val, "Preview image: On/Off (See image in UV/Image Editor Window)")
+	if PreView[0].val !=0:	
+		previewname = String( "IM:", No_Evt,     col[0], row[3], width[2], height[1] ,previewname.val, 8, "Preview / HeightMap Image Name." )
+		ViewiScale = Number("", No_Evt,      col[0], row[4], width[1], height[1], ViewiScale.val, 0.0, 10.0, "Preview image: intensity scale ( brightness )")
+		PushButton( "Redraw",  Im_Evt, col[2], row[4], width[2], height[1] , "Preview: Generate/Update image ( KEY: V )")
+		PreView[1] = Menu( 'Preview_size: %t|' + '|'.join( resolution ), No_Evt ,col[3], row[3], width[1], height[1], PreView[1].val, "Preview image size.(Every image size will generate its own image object)")
+		draw_Text( ( col[5], row[1] ), 'Select the preview image', black, 0 )
+		draw_Text( ( col[5], row[2] ), 'IM: ' + previewname.val + '_' + resolution[PreView[1].val-1] + '.tga', black, 0 )
+		draw_Text( ( col[5], row[3] ), 'in UV/Image Editor Window.', black, 0 )
+	
+	draw_Frame( 'Vertex Colour:', col[1], row[10], col[9]-5, row[5], black )
+	draw_Text( ( col[2], row[6] ), 'Selected: '+colgrad_image , black, 0 )
+	PushButton(          "Load",                     Load_Evt,     col[2], row[7], width[2], height[1] , "VertCol: Load colour gradient image")
+	PushButton(          "Select",                   Grad_Sel_Evt, col[5], row[7], width[2], height[1] , "VertCol: Select colour gradient image")
+	vcolours    = Toggle("Enable 'VertCol' Gradient",No_Evt,      col[2], row[8], width[5], height[1], vcolours.val, "VertCol: Enable VertexColours gradient ( Set Window DrawMode 'Textured', and set Material 'VCol Paint' on! )")
+	if vcolours.val !=0:
+		vcolGradRow = Number("Select Row:",     Btn_Evt,      col[2], row[9], width[2], height[1], vcolGradRow.val, 0, 1024 , "VertCol: Select row of pixels")
+		gradScale = Number("Scale:",            Btn_Evt,      col[5], row[9], width[2], height[1], gradScale.val, 0.01, 10.0, "VertCol: Scale gradient")
+
+
+###---------------------------------------------------------------------------
+###--------------------------------------------------------------------------
+## Draw G.U.I. -------------------------------------------------------------
+#--------------------------------------------------------------------------
+
+def drawgui():
+	global guitabs
+	global FullScreen, AutoUpd, RandMod, RSeed
+
+	glClearColor(background[0],background[1],background[2],background[3])
+	glClear(GL_COLOR_BUFFER_BIT)
+	scissorbox=Buffer(GL_FLOAT,4)
+	glGetFloatv(GL_SCISSOR_BOX,scissorbox)
+	scissbleft=int(scissorbox[0])
+	scissbbase=int(scissorbox[1])
+	scissbwidth=int(scissorbox[2])
+	scissbheight=int(scissorbox[3])
+	xstart = 5
+	ystart = 5
+	xgap = 5
+	ygap = 5
+	if FullScreen.val==1:
+		guiwidth  = scissbwidth-10
+		guiheight = scissbheight-25
+		if guiwidth < size_x/2:
+			guiwidth = size_x/2
+		if guiheight < size_y/2:
+			guiheight = size_y/2
+	else:
+		guiwidth = size_x
+		guiheight = size_y
+	col,row = [],[]
+	xpart = ( ( guiwidth-xstart ) / columns )
+	ypart = ( ( guiheight-ystart ) / rows )
+	width = []
+	for c in range( columns ):
+		col.append( xgap + xpart * c + xstart )
+		width.append( xpart*(c+1)-xgap )
+	height = [ (ypart-ygap)/2 , ypart-ygap, (ypart*3-ygap)/2, ypart*2-ygap, (ypart*5-ygap)/2  ]
+	for r in range( rows ):
+		row.append( ygap + ypart * r + ystart )
+	row.reverse()
+
+	###-------------------------
+	## Draw:
+	draw_BackPanel( 'A.N.T. Landscape 1.04a', xstart, ystart, guiwidth, guiheight + ygap, lightgrey )
+	FullScreen = Toggle("", Scrn_Evt, guiwidth-32, guiheight+ygap+3, 15, 15, FullScreen.val ,"FullScreen" )
+	PushButton( "X",        End_Evt, guiwidth-16, guiheight+ygap+3, 15, 15, "Exit" )
+
+	guitabs[0] = Toggle("Mesh",    gt0_Evt, col[0], row[0], width[1], height[1], guitabs[0].val ,"Mesh settings" )
+	guitabs[1] = Toggle("Noise",   gt1_Evt, col[2], row[0], width[1], height[1], guitabs[1].val ,"Noise settings" )
+	guitabs[2] = Toggle("Effect",  gt2_Evt, col[4], row[0], width[1], height[1], guitabs[2].val ,"Add Effect" )
+	guitabs[3] = Toggle("Height",  gt3_Evt, col[6], row[0], width[1], height[1], guitabs[3].val ,"Height Filter" )
+	guitabs[4] = Toggle("Options", gt4_Evt, col[8], row[0], width[1], height[1], guitabs[4].val ,"Options" )
+
+	if  guitabs[0].val !=0:
+		MeshButtons( col, row, width, height )
+	elif  guitabs[1].val !=0:
+		NoiseButtons( col, row, width, height )
+	elif  guitabs[2].val !=0:
+		EffectButtons( col, row, width, height )
+	elif  guitabs[3].val !=0:
+		FilterButtons( col, row, width, height )
+	elif  guitabs[4].val !=0:	
+		OptionButtons( col, row, width, height )
+	else:
+		funnycol = [ randnum(0.0,1.0), randnum(0.0,1.0), randnum(0.0,1.0) ]
+		funnypos = int( randnum(1,11) )
+		draw_Text( ( col[0]+10, row[ funnypos ] ), 'Another Noise Tool "Landscape"  v.1.04 May/2006', funnycol, 1 )
+	
+	AutoUpd = Toggle("Auto", No_Evt, col[3], row[12], width[1], height[2], AutoUpd.val ,"Automatic update" )
+	PushButton("Generate", Upd_Evt, col[5], row[12], width[4], height[2] , "Generate / Update Mesh. ( KEY: SPACE )")
+	if RandMod.val in [1,2]:
+		PushButton("Randomise",    Rndm_Evt, col[0], row[12], width[2], height[2] , "Randomise Noise ( KEY: R )")
+	else:
+		RSeed	= Number("Seed: ",  Rndm_Evt, col[0], row[12], width[2], height[2], RSeed.val,  0, 255 , "Random Seed: If seed = 0, the current time will be used as seed." )
+
+
+###---------------------------------------------------------------------------
+###---------------------------------------------------------------------------
+## Events:
+def events(evt, val):
+	global PreView
+	
+	if (evt == QKEY and not val):
+		Exit()
+
+	if (evt == SPACEKEY and not val):
+		do_it()
+	if (evt in [ RKEY ] and not val):
+		if AutoUpd.val == 0:
+			randomiseNoise()
+			Draw()
+		elif AutoUpd.val == 1:
+			do_it_random()
+	if PreView[0].val == 1:
+		if (evt in [ VKEY, RKEY ] and not val):
+			do_it_preview()
+
+###---------------------------------------------------------------------------
+## Button events:
+def bevents(evt):
+	global effect_image, colgrad_image, PreView
+	global Filter_Mode, Ipo_Filter_Ctrl, iponame, thiscurve, selectedcurve
+
+	if (evt == End_Evt ):
+		name = "OK ?%t|Reset %x1|Quit %x2"
+		result = Blender.Draw.PupMenu(name)
+		if result==1:
+			Set_ReSet_Values()
+			Draw()
+		if result==2:
+			Exit()
+
+	if (evt in [No_Evt, Scrn_Evt] ):
+		Draw()
+			
+	if (evt == Upd_Evt ):
+		do_it()
+
+	if AutoUpd.val == 1:
+		if (evt == Btn_Evt ):
+			do_it()
+		elif (evt == Rndm_Evt ):
+			do_it_random()
+
+	if AutoUpd.val == 0:
+		if (evt == Rndm_Evt ):
+			randomiseNoise()
+			Draw()
+		elif (evt == Btn_Evt ):
+			Draw()
+
+	if PreView[0].val != 0:
+			if (evt in [ Im_Evt, Btn_Evt, Rndm_Evt ] ):
+				do_it_preview()		
+
+	if (evt == gt0_Evt ):
+		if guitabs[0].val == 1:
+			guitabs[1].val = ( 0 )
+			guitabs[2].val = ( 0 )
+			guitabs[3].val = ( 0 )
+			guitabs[4].val = ( 0 )
+		Draw()
+	if (evt == gt1_Evt ):
+		if guitabs[1].val == 1:
+			guitabs[0].val = ( 0 )
+			guitabs[2].val = ( 0 )
+			guitabs[3].val = ( 0 )
+			guitabs[4].val = ( 0 )
+		Draw()
+	if (evt == gt2_Evt ):
+		if guitabs[2].val == 1:
+			guitabs[0].val = ( 0 )
+			guitabs[1].val = ( 0 )
+			guitabs[3].val = ( 0 )
+			guitabs[4].val = ( 0 )
+		Draw()
+	if (evt == gt3_Evt ):
+		if guitabs[3].val == 1:
+			guitabs[0].val = ( 0 )
+			guitabs[1].val = ( 0 )
+			guitabs[2].val = ( 0 )
+			guitabs[4].val = ( 0 )
+		Draw()
+	if (evt == gt4_Evt ):
+		if guitabs[4].val == 1:
+			guitabs[0].val = ( 0 )
+			guitabs[1].val = ( 0 )
+			guitabs[2].val = ( 0 )
+			guitabs[3].val = ( 0 )
+		Draw()
+
+	###---------------------------------------------------------
+	## get IPOCurve to use as Filter:
+	if Filter_Mode.val == 2:
+		try:
+			ipoblockname  = Ipo.Get( Ipo_Filter_Ctrl[0].val )
+			thiscurve     = ipoblockname.getCurves()
+			selectedcurve = thiscurve[ Ipo_Filter_Ctrl[1].val ]
+		except:
+			pass
+	###---------------------------------------------------------
+	## Effect and Gradient Image Load/Select:
+	if (evt == Load_Evt ):
+		Blender.Window.FileSelector ( load_image, 'LOAD IMAGE')
+	if (evt == Sel_Evt ):
+		try:
+			effect_image = Image_Menu()
+		except:
+			pass
+		Draw()
+	if (evt == Grad_Sel_Evt ):
+		try:
+			colgrad_image = Image_Menu()
+		except:
+			pass
+		Draw()	
+
+###-------------------------------------------------------------------------------------
+### Functions:
+###-------------------------------------------------------------------------------------
+
+## Load Image:
+def load_image( ImageFileName ):
+	Image.Load( ImageFileName )
+
+## Select Image Menu:
+def Image_Menu():
+	try:
+		names=[]
+		imagelist = Image.Get()
+		imagelist.reverse()
+		for numbers, obnames in enumerate( imagelist ):
+			n = obnames.getName()
+			names.append( n )
+		imlistText = string.join( [ '|' + str(names[key]) + '%x' + str(key)  for key in range(numbers+1) ], '' )
+		image_menu = Blender.Draw.PupMenu( "Images: %t" + imlistText )
+		if image_menu == -1:
+			return ''
+		return imagelist[ image_menu ].getName()
+	except:
+		return 'No image found!'
+
+
+
+#*# Get Image Pixels:
+def Image_Func( x,y ):
+	try:
+		pic  = Image.Get( effect_image )
+	except:
+		return 0.0
+	w, h = pic.getSize()
+	x, y = x,-y
+	x = int(w * ((x + 1.0) % 2.0) / 2.0)
+	y = int((h-1) - h * ((y + 1.0) % 2.0) / 2.0)	
+	c = pic.getPixelF( x,y )
+	return ( c[0] + c[1] + c[2] ) / 3.
+
+
+
+## Pixel color gradient:
+def pixlGrad( hght, pixelrow, gradScale ):
+	gradimage = Image.Get( colgrad_image )
+	imgsiz = gradimage.getSize()
+	imgsizhold = imgsiz[0]-1
+	pxl=[]
+	imgsiz[0] = int( imgsiz[0] * gradScale )
+	if pixelrow >= imgsiz[1]:
+		pixelrow = 0
+	for i in range( imgsiz[0]-1 ):
+		hght = int( (imgsiz[0]-1) * hght )
+		if hght < 0:
+			hght = 0
+		if hght > imgsizhold:
+			hght = imgsizhold
+		grad = gradimage.getPixelF( hght, imgsiz[1]-1-pixelrow )
+		r,g,b = grad[0], grad[1], grad[2]
+		pxl.append( (r,g,b) )
+		return NMesh.Col(int(pxl[i][0]*255),int(pxl[i][1]*255),int(pxl[i][2]*255)) , (pxl[i][0],pxl[i][1],pxl[i][2])
+
+##-------------------------------------------------------------------------------------
+
+# Transpose noise coords:
+def Trans((x,y,z), size, loc  ):
+	x = ( x / size[1] / size[0] + loc[0] )
+	y = ( y / size[2] / size[0] + loc[1] )
+	z = 0.0
+	return x,y,z
+
+# Transpose effect coords:
+def Trans_Effect((x,y,z), size, loc  ):
+	x = ( x * size[1] * size[0] + loc[0] )
+	y = ( y * size[2] * size[0] + loc[1] )
+	z = 0.0
+	return x,y,z
+
+# Height scale:
+def HeightScale( input, iscale, offset, invert ):
+	if invert !=0:
+		return (1.0-input) * iscale + offset
+	else:
+		return input * iscale + offset
+
+# dist.
+def Dist(x,y):
+	return sqrt( (x*x)+(y*y) )
+
+##-----------------------------------
+# bias types:
+def no_bias(a):
+	return a
+def sin_bias(a):
+	return 0.5 + 0.5 * sin(a)
+def cos_bias(a):
+	return 0.5 + 0.5 * cos(a)
+def tri_bias(a):
+	b = 2 * phi
+	a = 1 - 2 * abs(floor((a * (1/b))+0.5) - (a*(1/b)))
+	return a
+def saw_bias(a):
+	b = 2 * phi
+	n = int(a/b)
+	a -= n * b
+	if a < 0:
+		a += b
+	return a / b
+
+# sharpen types:
+def soft(a):
+	return a
+def sharp(a):
+	return a**0.5
+def sharper(a):
+	return sharp(sharp(a))
+
+Bias_Types  = [ sin_bias, cos_bias, tri_bias, saw_bias, no_bias ]
+Sharp_Types = [ soft, sharp, sharper ]
+
+##-----------------------------------
+# Mix modes
+
+def maximum( a, b ):
+	if ( a > b ): b = a
+	return b
+def minimum( a, b ):
+	if ( a < b ): b = a
+	return b
+
+def Mix_Modes( (i,j),(x,y,z) , a, b, mixfactor, mode ):
+	a = a * ( 1.0 + mixfactor )
+	b = b * ( 1.0 - mixfactor )
+	if   mode == 0:  return  ( a )                     #0  a
+	elif mode == 1:  return  ( a*(1.0-0.5) + b*0.5 )   #1  mix
+	elif mode == 2:  return  ( a + b )                 #2  add
+	elif mode == 3:  return  ( a - b )                 #3  sub.
+	elif mode == 4:  return  ( a * b )                 #4  mult.
+	elif mode == 5:  return  (abs( a - b ))            #5  abs diff.
+	elif mode == 6:  return  1.0-((1.0-a)*(1.0-b)/1.0) #6  screen
+	elif mode == 7:  return  ( a + b ) % 1.0           #7  addmodulo
+	elif mode == 8:  return  minimum( a, b )           #8  min.
+	elif mode == 9:  return  maximum( a, b )           #9  max.
+	elif mode == 10:                                   #10 warp: effect
+		noise =  mixfactor * Noise_Function(x,y,z)
+		return    Effects( (i,j),(x+noise,y+noise,z) )
+	elif mode == 11:                                   #11 warp: noise
+		effect = mixfactor * Effects( (i,j),(x,y,z) )
+		return   Noise_Function( x+effect, y+effect, z )
+	else: return b	
+
+###----------------------------------------------------------------------
+# Effect functions:
+
+# Effect_Basis_Function:
+def Effect_Basis_Function((x,y), type, bias ):
+
+	iscale = 1.0
+	offset = 0.0
+	## gradient:
+	if type == 0:
+		effect = offset + iscale * ( Bias_Types[ bias ]( x + y ) )
+	## waves / bumps:
+	if type == 1:
+		effect = offset + iscale * 0.5 * ( Bias_Types[ bias ]( x*phi ) + Bias_Types[ bias ]( y*phi ) )
+	## zigzag:
+	if type == 2:
+		effect = offset + iscale * Bias_Types[ bias ]( offset + iscale * sin( x*phi + sin( y*phi ) ) )
+	## wavy:	
+	if type == 3:
+		effect = offset + iscale * ( Bias_Types[ bias ]( cos( x ) + sin( y ) + cos( x*2+y*2 ) - sin( -x*4+y*4) ) )
+	## sine bump:	
+	if type == 4:
+		effect =   offset + iscale * 1-Bias_Types[ bias ](( sin( x*phi ) + sin( y*phi ) ))
+	## dots:
+	if type == 5:
+		effect = offset + iscale * ( Bias_Types[ bias ](x*phi*2) * Bias_Types[ bias ](y*phi*2) )-0.5
+	## rings / dome:
+	if type == 6:
+		effect = offset + iscale * ( Bias_Types[ bias ]( 1.0-(x*x+y*y) ) )
+	## spiral:
+	if type == 7:
+		effect = offset + iscale * Bias_Types[ bias ](( x*sin( x*x+y*y ) + y*cos( x*x+y*y ) ))*0.5
+	## square / piramide:
+	if type == 8:
+		effect = offset + iscale * Bias_Types[ bias ](1.0-sqrt( (x*x)**10 + (y*y)**10 )**0.1)
+	## blocks:	
+	if type == 9:
+		effect = ( 0.5-max( Bias_Types[ bias ](x*phi) , Bias_Types[ bias ](y*phi) ))
+		if effect > 0.0: effect = 1.0
+		effect = offset + iscale * effect
+	## grid:	
+	if type == 10:
+		effect = ( 0.025-min( Bias_Types[ bias ](x*phi) , Bias_Types[ bias ](y*phi) ))
+		if effect > 0.0: effect = 1.0
+		effect = offset + iscale * effect
+	## tech:
+	if type == 11:
+		a = ( max( Bias_Types[ bias ](x*pi) , Bias_Types[ bias ](y*pi) ))
+		b = ( max( Bias_Types[ bias ](x*pi*2+2) , Bias_Types[ bias ](y*pi*2+2) ))
+		effect = ( min( Bias_Types[ bias ](a) , Bias_Types[ bias ](b) ))*3.0-2.0
+		if effect > 0.5: effect = 1.0
+		effect = offset + iscale * effect
+
+	## crackle:	
+	if type == 12:
+		t = turbulence(( x, y, 0 ), 6, 0, 0 ) * 0.25
+		effect = vlNoise(( x, y, t ), 0.25, 0, 8 )
+		if effect > 0.5: effect = 0.5
+		effect = offset + iscale * ( effect )
+	## sparse cracks noise:
+	if type == 13:
+		effect = 2.5 * abs( noise((x*0.5,y*0.5, 0 ), 1 ) )-0.1
+		if effect > 0.25: effect = 0.25
+		effect = offset + iscale * ( effect * 2.5 )
+	## shattered rock noise:
+	if type == 14:
+		effect = 0.5 + noise((x,y,0), 7 )
+		if effect > 0.75: effect = 0.75
+		effect = offset + iscale * effect
+	## lunar noise:
+	if type == 15:
+		effect = 0.25 + 1.5 * voronoi(( x+2, y+2, 0 ), 1 )[0][0]
+		if effect > 0.5: effect = 0.5
+		effect = offset + iscale * ( effect * 2.0 )
+	## cosine noise:
+	if type == 16:
+		effect = cos( 5*noise(( x, y, 0 ), 0 ) )
+		effect = offset + iscale * ( effect*0.5 )
+	## spikey noise:
+	if type == 17:
+		n = 0.5 + 0.5 * turbulence(( x*5, y*5, 0 ), 8, 0, 0 )
+		effect = ( ( n*n )**5 )
+		effect = offset + iscale * effect
+	## stone noise:
+	if type == 18:
+		effect = offset + iscale *( noise((x*2,y*2, 0 ), 0 ) * 1.5 - 0.75)
+	## Flat Turb:
+	if type == 19:
+		t = turbulence(( x, y, 0 ), 6, 0, 0 )
+		effect = t*2.0
+		if effect > 0.25: effect = 0.25
+		effect = offset + iscale * ( effect )
+	## Flat Voroni:
+	if type == 20:
+		t = 1-noise(( x, y, 0 ), 3 )
+		effect = t*2-1.75
+		if effect > 0.25: effect = 0.25
+		effect = offset + iscale * ( effect )
+
+	if effect < 0.0: effect = 0.0
+	return effect
+
+# fractalize Effect_Basis_Function: ------------------------------ 
+def Effect_Function((x,y), type,bias, turb, depth,frequency,amplitude ):
+
+	## turbulence:
+	if turb != 0.0:
+		t = turb * ( 0.5 + 0.5 * turbulence(( x, y, 0 ), 6, 0, 0 ))
+		x = x + t
+		y = y + t
+
+	result = Effect_Basis_Function((x,y), type, bias )
+	## fractalize:
+	if depth != 0:
+		i=0
+		for i in range( depth ):
+			i+=1
+			x *= frequency
+			y *= frequency
+			amplitude = amplitude / i
+			result += Effect_Basis_Function( (x,y), type, bias ) * amplitude
+
+	return result
+
+
+###--------------------------------------------------
+## Effect Selector:
+def Effects( (i,j),(x,y,z) ):
+	global Effect_Type, Effect_Ctrl, twister_amount, iScale, Offset, Invert
+	global Quality, NSize, Lx, Ly, Lz, Sx, Sy, Sz, marbleTwo, turbTwo, vlnoiTwo, Basis
+		
+	x,y,z = Trans_Effect((x,y,z),( NSize[1].val, Sx[1].val, Sy[1].val, 0 ),( Lx[1].val, Ly[1].val, 0 )  )
+
+	basis = Basis[1].val
+	if basis == 9: basis = 14
+
+	if Effect_Ctrl[0].val == 1:
+		try:
+			effect  = Image_Func( x,y )
+		except:
+			effect =	0.0
+
+	elif Effect_Ctrl[0].val == 2:
+		effect = 0.5+0.5*turbulence(( x,y,z ),turbTwo[0].val, turbTwo[1].val, basis, turbTwo[2].val, turbTwo[3].val )
+	elif Effect_Ctrl[0].val == 3:
+		effect = 0.5+0.5*vlNoise(( x,y,z ),vlnoiTwo[0].val, vlnoiTwo[1].val, basis )
+	elif Effect_Ctrl[0].val == 4:
+		effect =	 0.5*marbleNoise((x,y,z), marbleTwo[0].val, basis, marbleTwo[2].val, marbleTwo[3].val, marbleTwo[4].val, marbleTwo[5].val )
+	else:
+		effect = Effect_Function((x,y), Effect_Ctrl[0].val-5,  Effect_Ctrl[3].val,  Effect_Ctrl[4].val,  Effect_Ctrl[5].val,  Effect_Ctrl[6].val, Effect_Ctrl[7].val )
+
+	effect = HeightScale( effect, iScale[1].val , Offset[1].val, Invert[1].val )
+
+	return  effect
+
+
+
+###----------------------------------------------------------------------
+# Noise:
+##-----------------------------------
+
+## voronoi_turbulence:
+def voroTurbMode((x,y,z), voro, mode ):
+	if mode == 0: # soft
+		return voronoi(( x,y,z ),voro[0], voro[1] )[0][0]
+	if mode == 1: # hard
+		return ( abs( 0.5-voronoi(( x,y,z ),voro[0], voro[1] )[0][0] ) )+0.5
+def voronoi_turbulence((x,y,z), voro, tur ):
+	result = voroTurbMode((x,y,z), voro, tur[1] )
+	depth  = tur[0]
+	amp    = tur[2]
+	freq   = tur[3]
+	i=0
+	for i in range( depth ):
+		i+=1
+		result += voroTurbMode( ( x*(freq*i), y*(freq*i), z ), voro, tur[1] )* ( amp*0.5/i )
+	return (result*4.0-2.0)
+
+## DistortedNoise / vlNoise_turbulence:
+def vlnTurbMode((x,y,z), vlno, basis, mode ):
+	if mode == 0: # soft
+		return vlNoise(( x,y,z ),vlno[0], vlno[1], basis )
+	if mode == 1: # hard
+		return ( abs( -vlNoise(( x,y,z ),vlno[0], vlno[1], basis ) ) )
+def vlNoise_turbulence((x,y,z), vlno, tur, basis ):
+	result = vlnTurbMode((x,y,z), vlno, basis, tur[1] )
+	depth  = tur[0]
+	amp    = tur[2]
+	freq   = tur[3]
+	i=0
+	for i in range( depth ):
+		i+=1
+		result += vlnTurbMode( ( x*(freq*i), y*(freq*i), z ), vlno, basis, tur[1] ) * ( amp*0.5/i )
+	return result*2.0+0.5
+
+## marbleNoise:
+def marbleNoise( (x,y,z), depth, basis, turb, bias, sharpnes, rescale ):
+	m = ( x * rescale + y * rescale + z ) * 5
+	height = m + turb * turbulence( ( x ,y ,z ), depth, 0, basis, 0.5, 2.0 )
+	height = Bias_Types[ bias ]( height )
+	if bias != 4:
+		height = Sharp_Types[ sharpnes ]( height )
+	return height*2.0
+
+## lava_multiFractal:
+def lava_multiFractal( ( x,y,z ),Ha, La, Oc, distort, Basis ):
+	m  = multiFractal( ( x,y,z ), Ha, La, Oc, Basis)
+	d = m * distort
+	m2 = 0.5 * multiFractal( ( x+d,y+d,d*0.5 ), Ha, La, Oc, Basis)
+	return (m * m2)**0.5
+
+## slopey_noise:
+def slopey_noise((x,y,z), H, lacunarity, octaves, distort, basis ):
+	turb = fBm((x,y,z), H, lacunarity, octaves, 2 ) * 0.5
+	map = 0.5 + noise( ( x+turb, y+turb, z ), basis )
+	result = map + turb * distort
+	return result
+
+## duo_multiFractal:
+def double_multiFractal((x,y,z), H, lacunarity, octaves, offset, gain, basis ):
+	n1 = multiFractal( (x*1.5+1,y*1.5+1,z), 1.0, 1.0, 1.0, basis ) * offset
+	n2 = multiFractal( (x-1,y-1,z), H, lacunarity, octaves, basis ) * gain
+	result = ( n1*n1 + n2*n2 )*0.5
+	return result
+
+## distorted_heteroTerrain:
+def distorted_heteroTerrain((x,y,z), H, lacunarity, octaves, offset, distort, basis ):
+	h1 = ( heteroTerrain((x,y,z), 1.0, 2.0, 1.0, 1.0, basis ) * 0.5 )
+	h2 = ( heteroTerrain(( x, y, h1*distort ), H, lacunarity, octaves, offset, basis ) * 0.25 )
+	result = ( h1*h1 + h2*h2 )
+	return  result
+
+## SlickRock:
+def SlickRock((x,y,z), H, lacunarity, octaves, offset, gain, basis ):
+	n = multiFractal( (x,y,z), 1.0, 2.0, 1.0, basis )
+	r = ridgedMFractal((x,y,n*0.5), H, lacunarity, octaves, offset, gain, basis )*0.5
+	return n+(n*r)
+
+## terra_turbulence:
+def terra_turbulence((x,y,z), depth, hard, basis, amp, freq ):
+	t2 = turbulence( ( x, y, z ), depth,  hard , basis, amp, freq )
+	return (t2*t2*t2)+0.5
+
+## rocky_fBm:
+def rocky_fBm((x,y,z), H, lacunarity, octaves, basis ):
+	turb = fBm((x,y,z), H, lacunarity, octaves, 2 ) * 0.25
+	coords = ( x+turb, y+turb, z )
+	map = noise( coords, 7 )
+	result = map + fBm( coords, H, lacunarity, octaves, basis ) + 1.0
+	return result
+
+####---------------------------------------.
+### StatsByAlt, double terrain  basis mode:
+def TerrainBasisMode((x,y,z), basis, mode ):
+	if mode == 0: # noise
+		return noise((x,y,z),basis)
+	if mode == 1: # noise ridged
+		return ( 1.0-abs( noise((x,y,z),basis) ) )-0.5
+	if mode == 2: # vlNoise
+		return vlNoise((x,y,z), 1.0, 0, basis )
+	else:         # vlNoise ridged
+		return ( 1.0-abs( vlNoise((x,y,z), 1.0, 0, basis ) ) )-0.5
+
+#### StatsByAlt terrain:
+def StatsByAltTerrain((x,y,z), exp, lacu, octs, offset, amp, basis, mode ):
+	result = 0.5 * (offset + TerrainBasisMode((x,y,z), basis, mode ) )
+	octs = int( octs )
+	i = 0
+	for i in range( 1, octs ):
+		i += 1
+		result += result * amp * 0.5 * (offset + TerrainBasisMode((x,y,z), basis, mode ) )
+		x *= lacu
+		y *= lacu
+		amp /= ( exp * 0.5 ) * i		
+	return result
+
+##### double terrain:
+def doubleTerrain((x,y,z), exp, lacu, octs, offset, threshold, basis, mode ):
+	result = amp = freq = 1.0
+	octs = int( octs )
+	i = 1
+	signal = result = 0.5 * (offset + TerrainBasisMode((x,y,z), basis, mode ) )
+	for i in range( i, octs ):
+		i -= 1
+		x = x * lacu
+		y = y * lacu
+		freq *= lacu
+		amp = pow( freq, -exp )
+		if i < 1.0: amp *= i
+		weight = signal / threshold
+		if weight > 1.0: weight = 1.0
+		if weight < 0.0: weigth = 0.0
+		signal = weight * 0.5 * ( offset + TerrainBasisMode((x,y,z), basis, mode ) )
+		result += amp * signal
+	return result * 2.0
+
+##------------------------------------------------------------
+# Noise Functions:
+def Noise_Function(x,y,z):
+	global Basis, NType, musgr, vlnoi, voron, turbOne, marbleOne, tBasismod
+	global vlBasis, Distort, VFunc, VExp, VDep
+	global iScale, Offset, Invert, NSize, Lx, Ly, Sx, Sy
+	
+	x,y,z = Trans((x,y,z),( NSize[0].val, Sx[0].val, Sy[0].val, 0 ),( Lx[0].val, Ly[0].val, 0 )  )
+
+	basis = Basis[0].val
+	if basis == 9: basis = 14
+	vbasis = vlnoi[0].val
+	if vbasis == 9: vbasis = 14
+	
+	if   NType.val == 0:	z = multiFractal((   x,y,z ),musgr[0].val, musgr[1].val, musgr[2].val, basis )
+	elif NType.val == 1:	z = ridgedMFractal(( x,y,z ),musgr[0].val, musgr[1].val, musgr[2].val, musgr[3].val, musgr[4].val, basis )
+	elif NType.val == 2:	z = hybridMFractal(( x,y,z ),musgr[0].val, musgr[1].val, musgr[2].val, musgr[3].val, musgr[4].val, basis )
+	elif NType.val == 3:	z = heteroTerrain((  x,y,z ),musgr[0].val, musgr[1].val, musgr[2].val, musgr[3].val, basis )*0.5
+	elif NType.val == 4:	z = fBm((            x,y,z ),musgr[0].val, musgr[1].val, musgr[2].val, basis )+0.5
+	elif NType.val == 5:	z = turbulence((     x,y,z ),turbOne[0].val, turbOne[1].val, basis, turbOne[2].val, turbOne[3].val )*0.5+0.5
+	elif NType.val == 6:	z = voronoi_turbulence((x,y,z),(voron[0].val,voron[1].val),(turbOne[0].val,turbOne[1].val,turbOne[2].val,turbOne[3].val) )*0.5+0.5
+	elif NType.val == 7:	z = vlNoise_turbulence((x,y,z),(vlnoi[0].val,vlnoi[1].val), (turbOne[0].val,turbOne[1].val,turbOne[2].val,turbOne[3].val), basis )*0.5+0.5
+	elif NType.val == 8:	z = noise((          x,y,z ),basis )+0.5
+	elif NType.val == 9:	z = cellNoise((      x,y,z ))+0.5
+	elif NType.val == 10: z = marbleNoise((         x,y,z), marbleOne[0].val, basis, marbleOne[2].val, marbleOne[3].val, marbleOne[4].val, marbleOne[5].val )
+	elif NType.val == 11: z = lava_multiFractal((  x,y,z ), musgr[0].val, musgr[1].val, musgr[2].val, vlnoi[0].val, basis )
+	elif NType.val == 12: z = slopey_noise((         x,y,z), musgr[0].val, musgr[1].val, musgr[2].val, vlnoi[0].val, basis )+0.5
+	elif NType.val == 13: z = double_multiFractal(( x,y,z), musgr[0].val, musgr[1].val, musgr[2].val, musgr[3].val, musgr[4].val, basis )
+	elif NType.val == 14: z = distorted_heteroTerrain((x,y,z), musgr[0].val, musgr[1].val, musgr[2].val, musgr[3].val, vlnoi[0].val, basis )
+	elif NType.val == 15: z = SlickRock((           x,y,z), musgr[0].val, musgr[1].val, musgr[2].val, musgr[3].val, musgr[4].val, basis )
+	elif NType.val == 16: z = terra_turbulence((  x,y,z), turbOne[0].val, turbOne[1].val, basis, turbOne[2].val, turbOne[3].val )
+	elif NType.val == 17: z = rocky_fBm((           x,y,z ),musgr[0].val, musgr[1].val, musgr[2].val, basis )
+	elif NType.val == 18: z = StatsByAltTerrain(   (x,y,z), musgr[0].val, musgr[1].val, musgr[2].val, musgr[3].val, musgr[4].val*0.5, basis, tBasismod.val )
+	elif NType.val == 19: z = doubleTerrain(       (x,y,z), musgr[0].val, musgr[1].val, musgr[2].val, musgr[3].val, musgr[5].val, basis, tBasismod.val )
+	else:	z = 0.0
+	return HeightScale( z, iScale[0].val , Offset[0].val, Invert[0].val )
+
+
+##----------------------------------------------------------------------
+##-----------------------------------
+# Filter functions:
+
+# Filters: terrace / posterise / peaked / bias:
+def Def_Filter((x,y,z), input, numb, type ):
+	if   type == 0:
+		s = ( sin( input*numb*phi ) * ( 0.1/numb*phi ) )
+		return ( input * (1.0-0.5) + s*0.5 ) * 2.0
+	elif type == 1:
+		s = -abs( sin( input*(numb*0.5)*phi ) * ( 0.1/(numb*0.5)*phi ) )
+		return ( input * (1.0-0.5) + s*0.5 ) * 2.0
+	elif type == 2:
+		s = abs( sin( input*(numb*0.5)*phi ) * ( 0.1/(numb*0.5)*phi ) )
+		return ( input * (1.0-0.5) + s*0.5 ) * 2.0
+	elif type == 3:
+		numb = numb*0.5
+		s = ( int( input*numb ) * 1.0/numb )
+		return ( input * (1.0-0.5) + s*0.5 ) * 2.0
+	elif type == 4:
+		numb = numb*0.5
+		s = ( int( input*numb ) * 1.0/numb )
+		return ( s ) * 2.0
+	elif type == 5:
+		s = ( sin( input*(2*numb)*phi ) * ( 0.1/(2*numb)*phi ) )
+		l = ( input * (1.0-0.5) + s*0.5 ) * 2.0
+		p = ( ( l*numb*0.25 ) * ( l*numb*0.25 ) )**2
+		return ( l * (1.0-0.5) + p*0.5 ) * 2.0
+	elif type == 6:
+		return ( input*numb*0.25 )**4
+	elif type == 7:
+		return 2.0-exp( 1.0-(input*numb/3.0) )
+	elif type == 8:
+		return sin_bias( input*numb )*2.0
+	elif type == 9:
+		return cos_bias( input*numb )*2.0
+	elif type == 10:
+		return tri_bias( input*numb )*2.0
+	else:
+		return saw_bias( input*numb )*2.0
+
+# Filter: Clamp height
+def Clamp_Max( height, max ):
+   if ( height > max ): height = max
+   return height
+def Clamp_Min( height, min ):
+   if ( height < min ): height = min
+   return height
+
+# Filter: Edge falloff
+def EdgeFalloff( (x,y,z), height, type ):
+	global Falloff, maketiles
+	
+	x = x / Falloff[1].val
+	y = y / Falloff[2].val
+	if maketiles[0].val !=0:
+		x = x / tile_rescale[ maketiles[1].val ]
+		y = y / tile_rescale[ maketiles[1].val ]
+	if Falloff[3].val != 0:
+		sealevel = Min.val*2.0/iScale[2].val
+	else:
+		sealevel = 0.0
+	falltypes = ( 0, sqrt(x*x+y*y), sqrt((x*x)**2+(y*y)**2), sqrt((x*x)**10+(y*y)**10), sqrt(y*y), sqrt(x*x), abs(x-y), abs(x+y), ((x*x)**10+(y*y)**10)**0.1, ((x*x)+(y*y)) )
+	dist = falltypes[ type ]
+	if Falloff[4].val != 0:
+		dist = 1.0 - dist
+	radius = 1.0
+	height = height - sealevel
+	if( dist < radius ):
+		dist = dist / radius
+		dist = ( (dist) * (dist) * ( 3-2*(dist) ) )
+		height = ( height - height * dist ) + sealevel
+	else:
+		height = sealevel
+	if Falloff[3].val != 0:
+		height = Clamp_Min( height, sealevel )
+	else:
+		height = Clamp_Min( height, Min.val )
+	
+	return  height
+
+
+#####-------------------------------------------------------------------------------------#####
+####-------------------------------------------------------------------------------------####
+### Combine Functions: (get noise, Add effect, filter height and return result)         ###
+##-------------------------------------------------------------------------------------##
+
+def Combine_Functions( (i,j),(x,y,z) ):
+	global Quality, Effect_Ctrl, Blend_Effect, Filter_Mode, Def_Filter_Ctrl, Ipo_Filter_Ctrl
+	global iScale, Offset, Invert, Min, Max, Falloff
+
+	# get noise height:
+	height = Noise_Function(x,y,0.0)
+	
+	# mix noise with effect:
+	if Effect_Ctrl[0].val !=0:
+		height = Mix_Modes( (i,j),(x,y,z) , Effects( (i,j),(x,y,z) ), height, Effect_Ctrl[2].val, Effect_Ctrl[1].val )
+
+	# edge fallof:
+	if Falloff[0].val !=0:
+		height = EdgeFalloff( (x,y,z), height, Falloff[0].val )
+
+	# height filter 
+	if Filter_Mode.val !=0:
+		# height Def_Filter (Terrace/peaked/bias):
+		if Filter_Mode.val ==1:
+			if Def_Filter_Ctrl[ 0 ].val != 12:
+				height = Def_Filter((x,y,z), height, Def_Filter_Ctrl[ 1 ].val, Def_Filter_Ctrl[ 0 ].val )
+			
+		## 'IPOCurve' height filter:
+		elif Filter_Mode.val ==2:
+			try:
+				height = selectedcurve.evaluate( 1 + ( height*Ipo_Filter_Ctrl[2].val/2 ) )*2.0/Ipo_Filter_Ctrl[3].val
+			except:
+				height = height
+		
+	# height scale:	
+	height = HeightScale( height, 0.5*iScale[2].val , Offset[2].val, Invert[2].val )
+	
+	# clamp height min. max.:
+	if Falloff[0].val !=1:
+		height = Clamp_Min( height, Min.val )
+	height = Clamp_Max( height, Max.val )
+	
+	# return height:
+	return height
+
+
+#--------------------------------------------------------------------------------
+#--------------------------------------------------------------------------------
+# Make preview image:
+
+#----------------------
+# resize pixels #----------------------
+def resizepixels( (i,j),(x,y), res ):
+	global Quality, maketiles
+	size = int( resolution[ Quality.val-1 ] )
+	i = int( i * ( 1.0 * size / 1.0 ) / res )
+	j = int( j * ( 1.0 * size / 1.0 ) / res )
+	if maketiles[0].val !=0:
+		x = x * tile_rescale[ maketiles[1].val ]
+		y = y * tile_rescale[ maketiles[1].val ]
+	return Combine_Functions( (i,j),(x,y,0.0) )
+
+#----------------------
+# render image #----------------------
+def heightMap():
+	global PreView, previewname, ViewiScale, vcolours, vcolGradRow, gradScale
+
+	imsize = resolution[ PreView[1].val-1 ]
+	iname = previewname.val + '_' + imsize + '.tga'
+	res = int( imsize )
+	##------------------------------
+	try:
+		pic = Image.Get( iname )
+	except:
+		pic = Image.New( iname, res, res ,24 )
+	#------------------------------
+	for i in range( 0, res ):
+		for j in range( 0, res ):
+			x = i - (res) / 2.0
+			y = j - (res) / 2.0
+			x = (x*2.0) / (res)
+			y = (y*2.0) / (res)
+			#
+			height = resizepixels( (i,j),(x,y), res )
+			height *= ViewiScale.val
+			##
+			if vcolours.val == 1:
+				try:
+					r,g,b = pixlGrad( height, vcolGradRow.val, gradScale.val )[1]
+				except:
+					r,g,b = height, height, height
+			else:
+				r,g,b = height, height, height
+
+			###
+			if r > 1.0: r = 1.0
+			if g > 1.0: g = 1.0
+			if b > 1.0: b = 1.0
+			if r < 0.0: r = 0.0
+			if g < 0.0: g = 0.0
+			if b < 0.0: b = 0.0
+			####
+			pic.setPixelF( i, j, ( r, g, b, 1.0 ) )
+	
+	# get dir. to save to:
+	filepath = Blender.Get( 'filename' )
+	dirpath = Blender.sys.dirname( filepath )
+	# Set name and save image:
+	pic.setFilename( dirpath+'/'+iname )
+	pic.save()
+	#-------------------------------------------------------
+
+#------------------------------------------------------------------------
+## Make Mesh -----------------------------------------------------------
+###--------------------------------------------------------------------
+
+#------------------------------------------------------------------------
+# VertSelect: select flat areas:
+def Flat_Vert_Select(me, res, slope_range ):
+	for y in range( 1, res[1]-1 ):
+		for x in range( 1, res[0]-1 ):
+			a = x + y * res[0]
+			try:
+				s = max(abs(me.verts[a].co.z - me.verts[a + res[0] + 1].co.z), abs(me.verts[a + res[0]].co.z - me.verts[a + 1].co.z))
+				if ( s < (slope_range / res[0]) ):
+					me.verts[a].sel = 1
+			except: pass
+
+#------------------------------------------------------------------------
+def Make_Mesh( tiles ): 
+	global TerName, Quality, Quad_Tri, Smooth, maketiles, vSelRange, vcolours, vcolGradRow, gradScale
+
+	n = int( resolution[ Quality.val-1 ] )
+
+	try:
+		o = Object.Get( TerName.val + '_' + str( tiles) )
+		me = o.getData()
+		UPDATE = 1	
+	except:
+		o = Object.New('Mesh', TerName.val + '_' + str( tiles) )
+		scene.link(o)
+		me = NMesh.GetRaw()
+		UPDATE = 0
+
+	me.verts=[]
+	me.faces=[]
+	COL=[]
+	# Vertices -----------------------------------
+	for i in range( 0, n ):
+		for j in range( 0, n ):
+			# Tile size and position:
+			x = i - (n-1) / 2.0 
+			x = x * 2.0 / (n-1) + ( tiles_positions[maketiles[1].val][ tiles ][0] * 2 )
+			y = j - (n-1) / 2.0
+			y = y * 2.0 / (n-1) + ( tiles_positions[maketiles[1].val][ tiles ][1] * 2 )
+			z = 0.0
+			# height:
+			height = Combine_Functions( (i,j),(x,y,z) )
+			v = NMesh.Vert( x, y, height )
+			me.verts.append(v)
+
+			# VertCol -----------------------------------
+			if vcolours.val == 1:
+				try:
+					COL.append( pixlGrad( height, vcolGradRow.val, gradScale.val )[0] )
+				except:
+					pass
+
+	## Vertices: Select Flat Areas --------------------------------------
+	if vSelRange.val !=0.0:
+		Flat_Vert_Select(me, [n,n], vSelRange.val )
+
+	##--------------------------------------
+	me.hasVertexColours( vcolours.val )
+
+	## Faces --------------------------------------
+	if Quad_Tri.val == 1:
+		## make triangles
+		for i in range(n-1):
+			for j in range(n-1):
+				f = NMesh.Face()
+				f.v.append(me.verts[n*i+j])
+				f.v.append(me.verts[n*(i+1)+j])
+				f.v.append(me.verts[n*i+(j+1)])
+				if vcolours.val !=0:
+					f.col.append(COL[n*i+j])
+					f.col.append(COL[n*(i+1)+j])
+					f.col.append(COL[n*i+(j+1)])
+				f.smooth = Smooth.val
+				me.faces.append(f)
+				f = NMesh.Face()
+				f.v.append(me.verts[n*i+(j+1)])
+				f.v.append(me.verts[n*(i+1)+j])
+				f.v.append(me.verts[n*(i+1)+(j+1)])
+				if vcolours.val !=0:
+					f.col.append(COL[n*i+(j+1)])
+					f.col.append(COL[n*(i+1)+j])
+					f.col.append(COL[n*(i+1)+(j+1)])
+				f.smooth = Smooth.val
+				me.faces.append(f)
+	else:
+		## make quads
+		for i in range(n-1):
+			for j in range(n-1):
+				f= NMesh.Face()
+				f.v.append(me.verts[i*n+j])
+				f.v.append(me.verts[(i+1)*n+j])
+				f.v.append(me.verts[(i+1)*n+j+1])
+				f.v.append(me.verts[i*n+j+1])
+				if vcolours.val !=0:
+					f.col.append(COL[i*n+j])
+					f.col.append(COL[(i+1)*n+j])
+					f.col.append(COL[(i+1)*n+j+1])
+					f.col.append(COL[i*n+j+1])
+				f.smooth = Smooth.val
+				me.faces.append(f)
+	##
+	if UPDATE ==1:
+		me.update(1)
+	else :
+		o.link(me)
+	#o.select(1)
+	o.layers = Window.ViewLayers()
+	o.makeDisplayList()
+
+
+###----------------------------------------------------------------------------------------------------
+## Do_it:
+#--------------------------------------
+def do_it():
+	global maketiles
+	in_editmode = Window.EditMode()
+	if in_editmode: Window.EditMode(0)
+	Blender.Window.WaitCursor(1)
+	if maketiles[0].val !=0:
+		for mt in range( len(tiles_positions[maketiles[1].val]) ):
+			Make_Mesh( mt )
+	else:
+		Make_Mesh( 0 )
+	Blender.Window.WaitCursor(0)
+	if in_editmode: Window.EditMode(1)
+	#Redraw()
+#--------------------------------------
+def do_it_random():
+	global maketiles
+	in_editmode = Window.EditMode()
+	if in_editmode: Window.EditMode(0)
+	Blender.Window.WaitCursor(1)
+	randomiseNoise()
+	if maketiles[0].val !=0:
+		for mt in range( len(tiles_positions[ maketiles[1].val ]) ):
+			Make_Mesh( mt )
+	else:
+		Make_Mesh( 0 )
+	Blender.Window.WaitCursor(0)
+	if in_editmode: Window.EditMode(1)
+	#Redraw()
+#--------------------------------------
+def do_it_preview():
+	heightMap()
+	Window.RedrawAll()
+
+##----------------------------------------------------------------------------------------------------
+# Register:
+
+Register( drawgui, events, bevents )
+
+###----------------------------------------------------------------------------------------------------
Index: /data/contentcreation/orx_artists/SilvanNellen/moonsurface/BPyMathutils.py
===================================================================
--- /data/contentcreation/orx_artists/SilvanNellen/moonsurface/BPyMathutils.py	(revision 4790)
+++ /data/contentcreation/orx_artists/SilvanNellen/moonsurface/BPyMathutils.py	(revision 4790)
@@ -0,0 +1,212 @@
+# $Id: BPyMathutils.py,v 1.6 2006/12/14 14:53:32 campbellbarton Exp $
+#
+# --------------------------------------------------------------------------
+# helper functions to be used by other scripts
+# --------------------------------------------------------------------------
+# ***** BEGIN GPL LICENSE BLOCK *****
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software Foundation,
+# Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+#
+# ***** END GPL LICENCE BLOCK *****
+# --------------------------------------------------------------------------
+
+import Blender
+from Blender.Mathutils import *
+
+# ------ Mersenne Twister - start
+
+# Copyright (C) 1997 Makoto Matsumoto and Takuji Nishimura.
+# Any feedback is very welcome. For any question, comments,
+# see http://www.math.keio.ac.jp/matumoto/emt.html or email
+# matumoto@math.keio.ac.jp
+
+# The link above is dead, this is the new one:
+# http://www.math.sci.hiroshima-u.ac.jp/m-mat/MT/emt.html
+# And here the license info, from Mr. Matsumoto's site:
+# Until 2001/4/6, MT had been distributed under GNU Public License,
+# but after 2001/4/6, we decided to let MT be used for any purpose, including
+# commercial use. 2002-versions mt19937ar.c, mt19937ar-cok.c are considered
+# to be usable freely.
+#
+# So from the year above (1997), this code is under GPL.
+
+# Period parameters
+N = 624
+M = 397
+MATRIX_A = 0x9908b0dfL   # constant vector a
+UPPER_MASK = 0x80000000L # most significant w-r bits
+LOWER_MASK = 0x7fffffffL # least significant r bits
+
+# Tempering parameters
+TEMPERING_MASK_B = 0x9d2c5680L
+TEMPERING_MASK_C = 0xefc60000L
+
+def TEMPERING_SHIFT_U(y):
+    return (y >> 11)
+
+def TEMPERING_SHIFT_S(y):
+    return (y << 7)
+
+def TEMPERING_SHIFT_T(y):
+    return (y << 15)
+
+def TEMPERING_SHIFT_L(y):
+    return (y >> 18)
+
+mt = []   # the array for the state vector
+mti = N+1 # mti==N+1 means mt[N] is not initialized
+
+# initializing the array with a NONZERO seed
+def sgenrand(seed):
+  # setting initial seeds to mt[N] using
+  # the generator Line 25 of Table 1 in
+  # [KNUTH 1981, The Art of Computer Programming
+  #    Vol. 2 (2nd Ed.), pp102]
+
+  global mt, mti
+
+  mt = []
+  
+  mt.append(seed & 0xffffffffL)
+  for i in xrange(1, N + 1):
+    mt.append((69069 * mt[i-1]) & 0xffffffffL)
+
+  mti = i
+# end sgenrand
+
+
+def genrand():
+  global mt, mti
+  
+  mag01 = [0x0L, MATRIX_A]
+  # mag01[x] = x * MATRIX_A  for x=0,1
+  y = 0
+  
+  if mti >= N: # generate N words at one time
+    if mti == N+1:   # if sgenrand() has not been called,
+      sgenrand(4357) # a default initial seed is used
+
+    for kk in xrange((N-M) + 1):
+      y = (mt[kk]&UPPER_MASK)|(mt[kk+1]&LOWER_MASK)
+      mt[kk] = mt[kk+M] ^ (y >> 1) ^ mag01[y & 0x1]
+
+    for kk in xrange(kk, N):
+      y = (mt[kk]&UPPER_MASK)|(mt[kk+1]&LOWER_MASK)
+      mt[kk] = mt[kk+(M-N)] ^ (y >> 1) ^ mag01[y & 0x1]
+
+    y = (mt[N-1]&UPPER_MASK)|(mt[0]&LOWER_MASK)
+    mt[N-1] = mt[M-1] ^ (y >> 1) ^ mag01[y & 0x1]
+
+    mti = 0
+
+  y = mt[mti]
+  mti += 1
+  y ^= TEMPERING_SHIFT_U(y)
+  y ^= TEMPERING_SHIFT_S(y) & TEMPERING_MASK_B
+  y ^= TEMPERING_SHIFT_T(y) & TEMPERING_MASK_C
+  y ^= TEMPERING_SHIFT_L(y)
+
+  return ( float(y) / 0xffffffffL ) # reals
+
+#------ Mersenne Twister -- end 
+
+
+
+
+""" 2d convexhull
+Based from Dinu C. Gherman's work,
+modified for Blender/Mathutils by Campell Barton
+"""
+######################################################################
+# Public interface
+######################################################################
+from Blender.Mathutils import DotVecs
+def convexHull(point_list_2d):
+	"""Calculate the convex hull of a set of vectors
+	The vectors can be 3 or 4d but only the Xand Y are used.
+	returns a list of convex hull indicies to the given point list
+	"""
+
+	######################################################################
+	# Helpers
+	######################################################################
+
+	def _myDet(p, q, r):
+		"""Calc. determinant of a special matrix with three 2D points.
+
+		The sign, "-" or "+", determines the side, right or left,
+		respectivly, on which the point r lies, when measured against
+		a directed vector from p to q.
+		"""
+		return (q.x*r.y + p.x*q.y + r.x*p.y)  -  (q.x*p.y + r.x*q.y + p.x*r.y)
+	
+	def _isRightTurn((p, q, r)):
+		"Do the vectors pq:qr form a right turn, or not?"
+		#assert p[0] != q[0] and q[0] != r[0] and p[0] != r[0]
+		if _myDet(p[0], q[0], r[0]) < 0:
+			return 1
+		else:
+			return 0
+
+	# Get a local list copy of the points and sort them lexically.
+	points = [(p, i) for i, p in enumerate(point_list_2d)]
+	
+	try:	points.sort(key = lambda a: (a[0].x, a[0].y))
+	except:	points.sort(lambda a,b: cmp((a[0].x, a[0].y), (b[0].x, b[0].y)))
+
+	# Build upper half of the hull.
+	upper = [points[0], points[1]] # cant remove these.
+	for i in xrange(len(points)-2):
+		upper.append(points[i+2])
+		while len(upper) > 2 and not _isRightTurn(upper[-3:]):
+			del upper[-2]
+
+	# Build lower half of the hull.
+	points.reverse()
+	lower = [points.pop(0), points.pop(1)]
+	for p in points:
+		lower.append(p)
+		while len(lower) > 2 and not _isRightTurn(lower[-3:]):
+			del lower[-2]
+	
+	# Concatenate both halfs and return.
+	return [p[1] for ls in (upper, lower) for p in ls]
+
+
+def plane2mat(plane, normalize= False):
+	'''
+	Takes a plane and converts to a matrix
+	points between 0 and 1 are up
+	1 and 2 are right
+	assumes the plane has 90d corners
+	'''
+	cent= (plane[0]+plane[1]+plane[2]+plane[3] ) /4.0
+
+	
+	up= cent - ((plane[0]+plane[1])/2.0)
+	right= cent - ((plane[1]+plane[2])/2.0)
+	z= CrossVecs(up, right)
+	
+	if normalize:
+		up.normalize()
+		right.normalize()
+		z.normalize()
+	
+	mat= Matrix(up, right, z)
+	
+	# translate
+	mat.resize4x4()
+	tmat= Blender.Mathutils.TranslationMatrix(cent)
+	return mat * tmat
