-
Notifications
You must be signed in to change notification settings - Fork 13
/
scatter
executable file
·73 lines (60 loc) · 1.7 KB
/
scatter
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/usr/bin/env python2
import sys
import os
import locale
locale.setlocale(locale.LC_ALL, '')
scale = ' .\'\`^",:;Il!i><~+_-?][}{1)(|\/tfjrxnuvczXYUJCLQ0OZmwqpdbkhao*#MW&8%B@$'
scale_range = len(scale) - 1
if 'COLUMNS' in os.environ:
width = int(os.environ['COLUMNS'])
else:
width = 80
def asciify(val, max):
#return str(int(scale_range * val / max))
return scale[int(scale_range * val / max)]
def asciifyline(line, max):
return map(lambda val: asciify(val,max), line)
def asciifyarray(array, max):
print "".join("-" for i in range(width + 2)) + " " + str(maxY)
for line in array:
print '|' + ''.join(asciifyline(line,max)) + "|"
print "".join("-" for i in range(width + 2)) + " " + str(minY)
print "%-10.6f" % minX + "".join(" " for i in range(width + 2 - 20)) + "%10.6f" % maxX
def emptyLine():
return [0 for i in range(width)]
def emptyArray():
return [emptyLine() for i in range(width/3)]
pairs = []
minX = None
maxX = None
minY = None
maxY = None
for line in sys.stdin:
try:
(x,y) = map(locale.atof, line.strip().split())
except:
continue
if x == locale.atof("Inf") or y == locale.atof("Inf"):
continue
if x == locale.atof("-Inf") or y == locale.atof("-Inf"):
continue
if minX is None or x < minX:
minX = x
if minY is None or y < minY:
minY = y
if maxX is None or x > maxX:
maxX = x
if maxY is None or y > maxY:
maxY = y
pairs.append((x,y))
spanX = maxX - minX
spanY = maxY - minY
max = None
array = emptyArray()
for X,Y in pairs:
scaledX = int((width - 1) * (X - minX) / spanX)
scaledY = int((width/3 - 1) * (maxY - Y) / spanY)
array[scaledY][scaledX] += 1
if max is None or array[scaledY][scaledX] > max:
max = array[scaledY][scaledX]
asciifyarray(array, max)