+
+local function make_count_texture(scale)
+ return function (location, ray_dir, normal, count, sdf)
+ return {count*scale, count*scale, count*scale}
+ end
+end
+
+local function make_flat_texture(pigment)
+ return function (location, ray_dir, normal, count, sdf)
+ return pigment(location[1], location[2])
+ end
+end
+
+local function make_solid_pigment(colour)
+ return function (x,y)
+ return colour
+ end
+end
+
+local function make_checkered_pigment(colour1, colour2)
+ return function (x,y)
+ if (x%1 < 0.5 and y%1 < 0.5) or (x%1 > 0.5 and y%1 > 0.5) then
+ return colour1
+ else
+ return colour2
+ end
+ end
+end
+
+local function make_mandelbrot_pigment(set_colour, max_iter)
+
+ 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
+ end
+
+ return function (x,y)
+ get_col(0,0,x,y,max_iter)
+ end
+end