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
56 lines
1.5 KiB
from cpython cimport array
|
|
cdef list serp(int n):
|
|
cdef list ret = []
|
|
cdef int ind
|
|
cdef int i
|
|
cdef int v
|
|
cdef array.array t = array.array('b',(1,))
|
|
|
|
for ind in range(1,n+1):
|
|
ret.append(t)
|
|
l = ret[-1]
|
|
t = array.array('b')
|
|
for i in range(-1,ind):
|
|
if i == -1 or i==ind-1:
|
|
v = 1
|
|
else:
|
|
v = l[i]^l[i+1]
|
|
t.append(v)
|
|
return ret
|
|
|
|
from PIL import Image
|
|
class SubPix:
|
|
def __init__(self,mode,size,color = 0,s=2):
|
|
self.s = s
|
|
try:
|
|
self.image = Image.new(mode,tuple(map(lambda x: int(x*s),size)),color)
|
|
except:
|
|
print(tuple(map(lambda x: x*s,size)))
|
|
def set_subpix(self,cord,v):
|
|
s=self.s
|
|
x,y = map(lambda c: int(c*s),cord)
|
|
args = tuple(map(lambda n: ((n%s+x,n//s+y),v),range(s**2)))
|
|
for i in args:
|
|
self.image.putpixel(*i)
|
|
cpdef make_triangle1(n,b_w = False,outdir = r'x:\users\Ralphie\Documents'):
|
|
n = 2**n
|
|
if b_w:
|
|
p = (255,255,255)
|
|
np = (0,0,0)
|
|
else:
|
|
np = (255,255,255)
|
|
p = (0,0,0)
|
|
s = serp(n)
|
|
c = 0
|
|
off = (n-1)/2
|
|
triangle = SubPix('RGB',(n,n),np)
|
|
for row in s:
|
|
for x in range(len(row)):
|
|
xy = (x+off,c)
|
|
if row[x]:
|
|
v = p
|
|
else:
|
|
v = np
|
|
off -= .5
|
|
c += 1
|
|
triangle.image.save(r'{}\serp.png'.format(outdir))
|