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.
 
 

75 lines
1.8 KiB

from math import log
from PIL import Image
from serp import serp
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)
def make_triangle(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
triangle = SubPix('RGB',(2*n-1,n),np)
for row in s:
for x in range(len(row)):
xy = (c,2*(x)+off)
if row[x]:
v = p
else:
v = np
triangle.set_subpix(xy, v)
off -= 1
c += 1
triangle.image.save(r'{}\serp.png'.format(outdir))
##make_triangle(11)
def 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
try:
triangle.set_subpix(xy,v)
except:
print(xy,triangle.image.size)
off -= .5
c += 1
triangle.image.save(r'{}\serp.png'.format(outdir))
make_triangle1(6)