Advertisement
Guest User

Untitled

a guest
Jun 30th, 2017
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.02 KB | None | 0 0
  1. from PIL import Image, ImageDraw
  2. import numpy as np
  3.  
  4. dim = (500, 500)
  5.  
  6. img = Image.new('RGBA', dim, (255, 255, 255, 0))
  7. pixels = img.load()
  8.  
  9. def func(x, y, cR, cI):
  10.     return x**2.0 - y**2.0 * -1 + cR, (x * y) * 2.0 + cI
  11.  
  12. def drawCircle():
  13.     cR = 0.4
  14.     cI = 0.6
  15.     maxIter = 255
  16.     xmin, xmax = -4.0, 4.0
  17.     xstep = (xmax - xmin) / dim[0]
  18.     ymin, ymax = -4.0, 4.0
  19.     ystep = (ymax - ymin) / dim[1]
  20.     raxis = []
  21.     iaxis = []
  22.  
  23.     u = xmin
  24.     while u < xmax:
  25.         raxis += [u]
  26.         u += xstep
  27.     u = ymin
  28.     while u < ymax:
  29.         iaxis += [u]
  30.         u += ystep
  31.  
  32.     for xa in range(dim[0]):
  33.         for ya in range(dim[1]):
  34.             x, y = raxis[xa], iaxis[ya]
  35.             i = 0
  36.             bounded = True
  37.             while i < maxIter and bounded:
  38.                 x, y = func(x, y, cR, cI)
  39.                 i += 1
  40.                 if x < -10.0 or x > 10.0 or y < -10.0 or y > 10.0: bounded = False
  41.             pixels[xa, ya] = (i * 20 % maxIter, 0, 0)
  42. drawCircle()
  43. img.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement