[pypy-commit] pypy camelot: Color change for mandelbrot on 256 color terminals
krono
noreply at buildbot.pypy.org
Sat Feb 8 23:12:20 CET 2014
Author: Tobias Pape <tobias at netshed.de>
Branch: camelot
Changeset: r69102:3be1ce5533b4
Date: 2014-02-08 22:50 +0100
http://bitbucket.org/pypy/pypy/changeset/3be1ce5533b4/
Log: Color change for mandelbrot on 256 color terminals
diff --git a/rpython/tool/ansi_mandelbrot.py b/rpython/tool/ansi_mandelbrot.py
--- a/rpython/tool/ansi_mandelbrot.py
+++ b/rpython/tool/ansi_mandelbrot.py
@@ -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 --git a/rpython/tool/ansiramp.py b/rpython/tool/ansiramp.py
new file mode 100755
--- /dev/null
+++ b/rpython/tool/ansiramp.py
@@ -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)
More information about the pypy-commit
mailing list