Commits

Armin Rigo committed 8d9c305 Merge

Merged in krono/pypy/camelot (pull request #205)

Essential! Thanks Tobias.

  • Participants
  • Parent commits 61a9f16, 3be1ce5

Comments (0)

Files changed (2)

File rpython/tool/ansi_mandelbrot.py

 """
 
 
-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
 

File rpython/tool/ansiramp.py

+#! /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)