Skip to content

Instantly share code, notes, and snippets.

@paveltyavin
Created February 27, 2017 21:12
Show Gist options
  • Save paveltyavin/0614d34632a14392abbf2eef61117505 to your computer and use it in GitHub Desktop.
Save paveltyavin/0614d34632a14392abbf2eef61117505 to your computer and use it in GitHub Desktop.
from PIL import Image
from PIL import ImageDraw
from math import tanh
import random
Size = 512
im = Image.new("RGB", (Size, Size), "#fff")
draw = ImageDraw.Draw(im)
def count(z):
r = 0
a = random.randint(278, 281)
if z == 0:
return 0
while abs(z) < 1:
r += 1
z = z * z + a * 0.001
return r
for x in range(Size):
for y in range(Size):
z1 = (x + Size / 0.8) * 0.25 / Size + (y - Size / 1) * 0.25 / Size * 1j
c1 = int(255 * tanh(0.02 * count(z1)))
z2 = (Size - x + Size / 0.8) * 0.25 / Size + (Size - y - Size / 1) * 0.25 / Size * 1j
c2 = int(255 * tanh(0.02 * count(z2)))
draw.point(
(x, y),
(c1, c2, 70, 255)
)
def main():
file_name = __file__[:-2] + 'png'
im.save(file_name)
im.show()
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment