-
Notifications
You must be signed in to change notification settings - Fork 3
/
ptrip.py
49 lines (43 loc) · 1.23 KB
/
ptrip.py
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
# generate pythagorean triples as svg picture
import sys
points = {}
pmax=[0,0]
pmin=[0,0]
# print 'generating',
for r in range(0,30):
if r % 100 == 1: pass
# print '.',
# sys.stdout.flush()
for s in range(0,30):
x = r*r - s*s
y = 2 * r * s
z = r*r + s*s
# print x,y,z, ' => ', x*x+y*y, '=?=' , z*z
points[str(x)+','+str(y)] = [x,y]
pmax = [max(pmax[0],x),max(pmax[1],y)]
pmin = [min(pmin[0],x),min(pmin[1],y)]
# print points
#print '. . count: ',len(points)
#print pmin, pmax
def sqr(x): return x*x
maxw = pmax[0] - pmin[0]
maxh = pmax[1] - pmin[1]
w = h = 1000
scale = '1'
r = '1'
print '<svg xmlns="http://www.w3.org/2000/svg" width="'+str(w)+'" height="'+str(h)+'">'
print '<g transform="scale('+scale+')" style="stroke: black; fill: none;">'
#print '<path d=" M0 0 '
for p in points:
x=float(points[p][0])/maxw * w + w/2
y=float(points[p][1])/maxh * h
xs,ys=str(x),str(y)
# s='<circle cx="'+xs+'" cy="'+ys+'" r="'+xs+'"/>'
# s='<circle cx="'+xs+'" cy="'+ys+'" r="'+str( x+y / 580.0)+'"/>'
# s='<circle cx="'+xs+'" cy="'+ys+'" r="'+str( 18 )+'"/>'
s='<rect x="'+xs+'" y="'+ys+'" width="'+str( 1 )+'" height="'+str ( 1 ) +'"/>'
#s = 'L' + x + ' ' + y + ' ' # fill='none'
print s
print '"/>'
print '</g>'
print '</svg>'