Created
February 8, 2014 21:31
-
-
Save krono/8890674 to your computer and use it in GitHub Desktop.
rpython fractal for 265 colors
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff -r 61a9f16c3e8b rpython/tool/ansi_mandelbrot.py | |
--- a/rpython/tool/ansi_mandelbrot.py Sat Feb 08 11:35:59 2014 +0100 | |
+++ b/rpython/tool/ansi_mandelbrot.py Sat Feb 08 22:29:41 2014 +0100 | |
@@ -14,8 +14,12 @@ | |
""" | |
-palette = [39, 34, 35, 36, 31, 33, 32, 37] | |
- | |
+import os | |
+if os.environ.get('TERM', 'dumb').find('256') > 0: | |
+ from ansiramp import ansi_ramp80 | |
+ palette = map(lambda x: "38;5;%d" % x, ansi_ramp80) | |
+else: | |
+ palette = [39, 34, 35, 36, 31, 33, 32, 37] | |
colour_range = None # used for debugging | |
diff -r 61a9f16c3e8b rpython/tool/ansiramp.py | |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 | |
+++ b/rpython/tool/ansiramp.py Sat Feb 08 22:29:41 2014 +0100 | |
@@ -0,0 +1,20 @@ | |
+#! /usr/bin/env python | |
+import colorsys | |
+ | |
+def hsv2ansi(h, s, v): | |
+ # h: 0..1, s/v: 0..1 | |
+ if s < 0.001: | |
+ return int(v * 23) + 232 | |
+ r, g, b = map(lambda x: int(x * 5), colorsys.hsv_to_rgb(h, s, v)) | |
+ return 16 + (r * 36) + (g * 6) + b | |
+ | |
+def ramp_idx(i, num): | |
+ h = 0.57 + float(i)/num | |
+ s = float(num - i) / i if i > (num * 0.85) else 1 | |
+ v = 1 | |
+ return hsv2ansi(h, s, v) | |
+ | |
+def ansi_ramp(num): | |
+ return [ramp_idx(i, num) for i in range(num)] | |
+ | |
+ansi_ramp80 = ansi_ramp(80) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment