1. Frederic De Groef
  2. perlin-noise

Commits

Frederic De Groef  committed 20508ba

tested PIL demo

  • Participants
  • Parent commits 994ddef
  • Branches default

Comments (0)

Files changed (2)

File src/demo_pil.py

View file
  • Ignore whitespace
 
 from PIL import Image
 import noise
+import os
 
 
 
 
 def make_batch():
     PREFIX="./"
-    outdir = PREFIX+"gradient_perlin_out\\"
+    outdir = PREFIX+"gradient_perlin_out/"
      
     try:
         os.mkdir(outdir)
     for p in [0.1, 0.25, 0.5, 0.75, 1.0]:
         for n in range(1, 10):
             values = noise.make_perlin_noise(w, h, p, n)
-            values /= values.max()
+            #values /= values.max()
             make_image2D(values, n, p, outdir)
 
 
     PREFIX="./"
     outdir = PREFIX+"gradient_perlin_out/"
 
+    try:
+        os.mkdir(outdir)
+    except:
+        pass
+
     w, h = 256, 256
     p = 0.5
     n = 4
     make_image2D(values, n, p, outdir)
 
 if __name__ == '__main__':
-    make_one()
+    #make_one()
+    make_batch()

File src/noise.py

View file
  • Ignore whitespace
 
 gradients2D = []
 for i in [0, m.pi/2, m.pi, 3*m.pi/2, m.pi/4, 3*m.pi/4, 5*m.pi/4, 7*m.pi/4]:
-    gradients.append((m.cos(i), m.sin(i)))
+    gradients2D.append((m.cos(i), m.sin(i)))
 
 
 
 def get_gradient2D(i, j):
     I, J = i & 0xff , j & 0xff
   
-    idx = p[(I + p[J])&0xff] % len(gradients)
+    idx = p[(I + p[J])&0xff] % len(gradients2D)
     return gradients2D[idx]
 
 
     array = []
     for i in range(h):
         array.append([0]*w)
+    return array
 
 
 def make_perlin_noise(w, h, p, n):