Daniel Pope avatar Daniel Pope committed b33f289

New: colour map

Comments (0)

Files changed (2)

Added
New image

fractal/surface.py

+import sys
 import os
 import math
 import random
 from PIL import Image
 
+colours = Image.open('colours.png')
 
 class Surface(object):
     def __init__(self, size, fill=0):
                     pass
 
     def to_pil(self):
-        im = Image.new('L', (self.size, self.size))
+        im = Image.new(colours.mode, (self.size, self.size))
         for y in xrange(self.size):
             for x in xrange(self.size):
                 h = self[x, y]
-                im.putpixel((x, y), min(1.0, h * 0.1) * 255)
+                val = max(0, min(1.0, h * 0.1) * 255)
+                col = colours.getpixel((int(val), 0))
+                im.putpixel((x, y), col)
         return im
 
 
-SIZE = 256
-landscape = Surface(256, fill=-1)
+SIZE = 512
+landscape = Surface(256, fill=-0.25)
 
 for i in range(4):
-    d = 20 * i + 20
+    d = 25 * i + 20
     c = Surface.make_cone(d, (i + 1) * 0.2)
-
-    for i in range(50 * (5 - i)):
+    sys.stdout.write('.')
+    sys.stdout.flush()
+    for i in range(100 * (5 - i)):
         landscape.blit(c, random.randint(-d, SIZE), random.randint(-d, SIZE))
+print
 
 landscape.to_pil().save('out.png')
 os.system('gnome-open out.png')
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.