Added mandelbrot pigment.
authorTim Vaughan <timv@ughan.xyz>
Thu, 23 Feb 2023 10:54:30 +0000 (11:54 +0100)
committerTim Vaughan <timv@ughan.xyz>
Thu, 23 Feb 2023 10:54:30 +0000 (11:54 +0100)
Textures.lua

index 1e919c7..1456f7d 100644 (file)
@@ -68,6 +68,32 @@ local function make_checkered_pigment(colour1, colour2)
       end
    end
 end
+
+local function make_mandelbrot_pigment()
+
+   local maxiter = 100
+   local set_colour = {0,0,0}
+
+   local function get_col(x,y,cx,cy,iter)
+      if iter == 0 then
+         return set_colour
+      elseif x^2 + y^2 > 4 then
+         local I = iter/max_iter
+         return {I,I,1-I}
+      else
+         return get_col(x^2 - y^2 + cx,
+                        2*x*y + cy,
+                        cx, cy, iter-1)
+      end
+
+      local xp = x^2 - y^2 + cx
+      local yp = 2*x*y + cy
+   end
+
+   return function (x,y)
+      get_col(0,0,x,y,maxiter)
+   end
+end
    
 Textures = {
    make_phong_texture = make_phong_texture,