in_chainz

Untitled

Dec 3rd, 2018
479
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.31 KB | None | 0 0
  1. from math import sin, cos
  2. def shrink_rotate(x, a, coef=1., angle=0.):
  3.     c = x.real
  4.     d = x.imag
  5.     e = a.real
  6.     f = a.imag
  7.     axx = (x.real - a.real) * coef
  8.     axy = (x.imag - a.imag) * coef
  9.     x_new = axx * cos(angle) - axy * sin(angle)
  10.     y_new = axx * sin(angle) + axy * cos(angle)
  11.    
  12.     return x_new + y_new  * 1j
  13.    
  14. def shrink_rotate_conj(x, a, coef=1., angle=0.):
  15.     c = x.real
  16.     d = x.imag
  17.     e = a.real
  18.     f = a.imag
  19.     axx = (x.real - a.real) * coef
  20.     axy = (x.imag - a.imag) * coef
  21.     x_new = axx * cos(angle) - axy * sin(angle)
  22.     y_new = axx * sin(angle) + axy * cos(angle)
  23.    
  24.     if y_new < f:
  25.         y_new += 2 * abs(f - y_new)
  26.     else:
  27.         y_new -= 2 * abs(f - y_new)
  28.    
  29.     return x_new + y_new  * 1j
  30.  
  31. z = 0.5 + 0.*1j
  32. max_iter = 100000
  33. funcs = [
  34.     (lambda t: shrink_rotate(t, 0. + 1.*1j, coef=0.5, angle=0.)),
  35.     (lambda t: shrink_rotate(t, 1. + 0.*1j, coef=0.5, angle=0.)),
  36.     (lambda t: shrink_rotate(t, -1. + 0.*1j, coef=0.5, angle=0.))
  37. ]
  38.  
  39. res = np.zeros((1001, 1001), dtype=int)
  40.  
  41. for n_iter in range(max_iter):
  42.     n_func = np.random.choice(len(funcs))
  43.     z = funcs[n_func](z)
  44.     x = int(z.real * 500 + 500)
  45.     y = int(z.imag * 500 + 500)
  46.     res[1000 - y][x] = 1
  47.    
  48. plt.figure(figsize=(20, 20))
  49. plt.imshow(res, cmap='gray')
Advertisement
Add Comment
Please, Sign In to add comment