From: Tim Vaughan Date: Thu, 23 Feb 2023 10:54:30 +0000 (+0100) Subject: Added mandelbrot pigment. X-Git-Url: https://thelambdalab.xyz/gitweb/index.cgi?a=commitdiff_plain;h=bb9573c800572e7426b458d6551cd30cac8d1d72;p=raymarcher.git Added mandelbrot pigment. --- 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,