Advertisement
megamaz

Samuelj's Complex Plotter Fractals

Oct 25th, 2024 (edited)
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // T is used for iteration count
  2.  
  3. float dist(vec2 p) {
  4.   // returns distance from origin
  5.   return sqrt((p.x * p.x) + (p.y * p.y));
  6. }
  7.  
  8. vec2 cdot(vec2 i, vec2 j) {
  9.   // returns the dot product of
  10.   // two complex numbers, treating
  11.   // them as vectors
  12.   return vec2(i.x * j.x, i.y * j.y);
  13. }
  14.  
  15. vec2 conj(vec2 p) {
  16.   // conjugate of a complex number
  17.   return vec2(p.x, -p.y);
  18. }
  19.  
  20. vec2 cpow(vec2 value, float power)
  21. {
  22.   // courtesy of ChatGPT
  23.   // does an imaginary to the power of a real.  
  24.   float r = length(value);            
  25.   float theta = atan(value.y, value.x);    
  26.   float r_pow = pow(r, power);
  27.   float theta_pow = theta * power;
  28.   return vec2(r_pow * cos(theta_pow), r_pow * sin(theta_pow));
  29. }
  30.  
  31. vec2 mapping(vec2 z) {
  32.   vec2 c = z;
  33.   vec2 p = vec2(a.x, b.x);
  34.  
  35.   for (float i = 0.0; i < 100.0; i+=1.0) {
  36.     if(i > t.x) {break;}
  37.    
  38.     /// modify THIS line ///
  39.     z = cmul(z, z) + c;
  40.    
  41.   }
  42.  
  43.   // DISTANCE based coloring
  44.   // (needs variable h, range 0-4)
  45.   //z = cmul(vec2(pow(dist(z)+0.5, 8.0), 0.0), cpow(vec2(0, 1), h.x));
  46.  
  47.   // INCREASE CONTRAST
  48.   //z = vec2(pow(abs(z.x)+0.5, 8.0)*sign(z.x), pow(abs(z.y)+0.5, 8.0)*sign(z.y));
  49.  
  50.   return z;
  51. }
  52.  
  53. // personal favorites:
  54. // z = cdiv(vec2(z.x, c.y), cdiv(cmul(z, z), cdot(c, c)) + cmul(c, p));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement