From bb9573c800572e7426b458d6551cd30cac8d1d72 Mon Sep 17 00:00:00 2001 From: Tim Vaughan Date: Thu, 23 Feb 2023 11:54:30 +0100 Subject: [PATCH] Added mandelbrot pigment. --- Textures.lua | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/Textures.lua b/Textures.lua index 1e919c7..1456f7d 100644 --- a/Textures.lua +++ b/Textures.lua @@ -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, -- 2.20.1