> Хмм... Можно =)
#!/usr/bin/env python2
# -*- coding: utf8 -*-
from PIL import Image, ImageDraw, ImageFilter
import random
def drawKoch(draw, xa, ya, xe, ye, i, color):
if (i==0):
draw.line((xa, ya, xe, ye), fill=color, width=1)
else:
xb = xa + (xe - xa) * 1/3
yb = ya + (ye - ya) * 1/3
xd = xa + (xe - xa) * 2/3
yd = ya + (ye - ya) * 2/3
cos60 = 0.5
sin60 = -0.866 #-0.866
xc = xb + (xd - xb) * cos60 - sin60 * (yd - yb)
yc = yb + (xd - xb) * sin60 + cos60 * (yd - yb)
drawKoch(draw, xa, ya, xb, yb, i - 1, color)
drawKoch(draw, xb, yb, xc, yc, i - 1, color)
drawKoch(draw, xc, yc, xd, yd, i - 1, color)
drawKoch(draw, xd, yd, xe, ye, i - 1, color)
width=1024
height=600
size=(width, height)
white=(255,255,255,50)
images=[]
# allcolors=[(random.randint(0, 255), random.randint(0,255), random.randint(0,255), a) for a in range(100, 200, 20)]
allcolors=[(0,a,a,a) for a in range(0, 255, 40)]
i=1
for color in allcolors:
img=Image.new("RGBA", size, color=white)
pixels=img.load()
draw=ImageDraw.Draw(img)
drawKoch(draw, 0, height-2, width, height-2, i, color)
draw.line((0, height, width, height), fill=color, width=1)
ImageDraw.floodfill(img, (0, height-1), color)
images.append(img)
i+=1
first=Image.new("RGBA", size, color=(0,0,0,0))
draw1=ImageDraw.Draw(first)
for i in range(0, height):
n=int(round(i*255/height))
draw1.line((0, i, width, i), fill=(n,n,n,255), width=1)
for image in reversed(images):
first=Image.alpha_composite(first, image)
# first=first.filter(ImageFilter.BLUR)
first.save("output.png")
#!/usr/bin/env python2
# -*- coding: utf8 -*-
from PIL import Image, ImageDraw
import random
width=800
height=800
size=(width, height)
white=(255,255,255,50)
img=Image.new("RGBA", size, color=white)
images=[]
num=[1, 2, 4, 8, 16, 32, 64]
for i in num:
if (i==0): continue;
nextimg=Image.new("RGBA", size, color=white)
draw=ImageDraw.Draw(nextimg)
areasize=width/i
offset=areasize/4
...
[>>>]