You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

56 lines
1.5 KiB

7 years ago
  1. from cpython cimport array
  2. cdef list serp(int n):
  3. cdef list ret = []
  4. cdef int ind
  5. cdef int i
  6. cdef int v
  7. cdef array.array t = array.array('b',(1,))
  8. for ind in range(1,n+1):
  9. ret.append(t)
  10. l = ret[-1]
  11. t = array.array('b')
  12. for i in range(-1,ind):
  13. if i == -1 or i==ind-1:
  14. v = 1
  15. else:
  16. v = l[i]^l[i+1]
  17. t.append(v)
  18. return ret
  19. from PIL import Image
  20. class SubPix:
  21. def __init__(self,mode,size,color = 0,s=2):
  22. self.s = s
  23. try:
  24. self.image = Image.new(mode,tuple(map(lambda x: int(x*s),size)),color)
  25. except:
  26. print(tuple(map(lambda x: x*s,size)))
  27. def set_subpix(self,cord,v):
  28. s=self.s
  29. x,y = map(lambda c: int(c*s),cord)
  30. args = tuple(map(lambda n: ((n%s+x,n//s+y),v),range(s**2)))
  31. for i in args:
  32. self.image.putpixel(*i)
  33. cpdef make_triangle1(n,b_w = False,outdir = r'x:\users\Ralphie\Documents'):
  34. n = 2**n
  35. if b_w:
  36. p = (255,255,255)
  37. np = (0,0,0)
  38. else:
  39. np = (255,255,255)
  40. p = (0,0,0)
  41. s = serp(n)
  42. c = 0
  43. off = (n-1)/2
  44. triangle = SubPix('RGB',(n,n),np)
  45. for row in s:
  46. for x in range(len(row)):
  47. xy = (x+off,c)
  48. if row[x]:
  49. v = p
  50. else:
  51. v = np
  52. off -= .5
  53. c += 1
  54. triangle.image.save(r'{}\serp.png'.format(outdir))