Advertisement
coopco

Domain colouring

Feb 4th, 2020
2,287
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Julia 1.24 KB | None | 0 0
  1. using Colors, Images
  2.  
  3. x_max = 1.2
  4. x_min = -x_max
  5. y_max = x_max
  6. y_min = -y_max
  7. width = 1920
  8. height = width
  9.  
  10. function f(z)
  11.     return z^5 + im*z^6*conj(z) - z^3/(conj(z)^2) + im*z^7*conj(z)^6
  12. end
  13.  
  14. function coloured(z)
  15.     θ = angle(z)
  16.     # Convert from [-pi,pi] to [0,2pi]
  17.     if θ < 0
  18.         θ += 2pi
  19.     end
  20.  
  21.     h = 180/pi*θ % 360
  22.     s = 1
  23.     # Circles
  24.     v1 = abs(z)%1*0.2 + 0.8
  25.     # Radial lines
  26.     v2 = (θ/2pi)%0.125 + 0.875
  27.     # Uncomment for more contrast
  28.     v1 = abs(z)%1
  29.     v2 = (θ/2pi)%0.125 *8
  30.     v = (v1+v2)/2
  31.    
  32.     return HSV(h,s,v)
  33. end
  34.  
  35.  
  36. image = Array{Union{Nothing,HSV}}(nothing, height, width)
  37.  
  38. for j in 1:height
  39.     for i in 1:width
  40.         x = (x_max-x_min)*(j-width/2)/width
  41.         y = (y_max-y_min)*(i-height/2)/height
  42.  
  43.         # Iterate function
  44.         pt = x + y*im
  45.         for k in 1:1 # only iterating once for now
  46.             pt = f(pt)
  47.         end
  48.         colour = coloured(pt)
  49.  
  50.         # Incase we divide by zero
  51.         if isnan(colour.h)
  52.             colour = HSV(0, colour.s, colour.v)
  53.         end
  54.  
  55.         if isnan(colour.v)
  56.             colour = HSV(colour.h, colour.s, 0)
  57.         end
  58.  
  59.         image[i, j] = colour
  60.     end
  61. end
  62.  
  63. save("out.png", image)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement