Advertisement
Guest User

Untitled

a guest
Jul 7th, 2014
266
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.72 KB | None | 0 0
  1. #!/usr/bin/python
  2.  
  3. import itertools
  4. from fractions import Fraction
  5.  
  6. open('__init__.py','w')
  7. import symbols
  8.  
  9. def verify(self, n, f):
  10.     self.ns_v = 0,0,n,n
  11.     for ([x1,y1],[x2,y2]) in f():
  12.         for x in [x1,y1,x2,y2]:
  13.             if Fraction(x).denominator!=1:
  14.                 return False
  15.     return True
  16.  
  17. def search(self, f):
  18.     for i in itertools.count(start=1):
  19.         if verify(self, i, f):
  20.             return i
  21.  
  22. def gen(self,n, f,fname):
  23.     def toStr(a,b):
  24.         num = Fraction(int(a), b)
  25.         s = '%s' % num
  26.         if s == '0': return ' 0'
  27.         if '/' in s: s = s+'.'
  28.         if '-' in s: return s
  29.         return '+'+s
  30.     def l(n): return 4*(n+1)
  31.  
  32.     self.ns_v = 0,0,n,n
  33.     print ' '*l(0)+'def %s(self):' % fname
  34.     print ' '*l(1)+'x,y,x2,y2 = self.ns(%s)' % self.ns_w
  35.     print ' '*l(1)+'return [ [x+x2*ax, y+y2*ay], [x+x2*bx, y+y2*by]) \\'
  36.     print ' '*l(2)+'for ([ax,ay],[bx,by]) in ['
  37.     for ([x1,y1],[x2,y2]) in f():
  38.         lst = (x1,y1,x2,y2)
  39.         lst = tuple([toStr(x,n) for x in lst])
  40.         print ' '*l(2)+'([%-6s,%-6s],[%-6s,%-6s]),' % lst
  41.     print ' '*l(1)+']]'
  42.  
  43. def fix(Class):
  44.     print '# Fix: %s' % Class.__name__
  45.     def empty(self):
  46.         pass
  47.     def ns(self, w=1):
  48.         if w==1: w = ''
  49.         self.ns_w = w
  50.         return self.ns_v
  51.     Class.__init__ = empty
  52.     Class.ns       = ns
  53.  
  54.     obj = Class()
  55.     for i in dir(Class):
  56.         if '__' in i: continue
  57.         if 'ns' == i: continue
  58.         if 'ns_v' == i: continue
  59.         if 'ns_w' == i: continue
  60.         method = getattr(obj, i)
  61.         gen(obj,search(obj, method), method, i)
  62.  
  63. import sys
  64. sys.stdout = open('symbols.py.fix','w')
  65. fix(symbols.Text_TXT)
  66. fix(symbols.Text_arch)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement