--
-- math functions to generate decorative image patterns
-- star flower
-- by Kaneyuki Miwa
-- (use Radians)

and2(x,y) = x when y=0,1)
boundize(x) = (x/(1+abs(x))+1)*0.5

--- Calculation of Wierestrass' P-function:
--  basis of period are 1 and (-1+sqrt(-3))/2

P(x,y) = z2r:=x^2-y^2,z2i:=2*x*y,
         z4r:=z2r^2-z2i^2,z4i:=2*z2r*z2i,
         z6r:=z2r*z4r-z2i*z4i,z6i:=z2r*z4i+z2i*z4r,
         z6invr:=(z6r-1)/((z6r-1)^2+z6i^2),z6invi:=-z6i/((z6r-1)^2+z6i^2),
         f1r:=42+36*z6invr,f1i:=36*z6invi,
         u:=f1r*z6invr-f1i*z6invi+7,f1i:=f1r*z6invi+f1i*z6invr,f1r:=u,
         fr:=-0.004787942+0.000267894*z6r,fi:=0.000267894*z6i,
         u:=fr*z6r-fi*z6i+0.106039689,fi:=fr*z6i+fi*z6r,fr:=u,
         u:=fr*z6r-fi*z6i-0.684841533,fi:=fr*z6i+fi*z6r,fr:=u,
         {((f1r*z2r+f1i*z2i)/(z2r^2+z2i^2)+(fr*z4r-fi*z4i))/5.898343969,
          ((f1i*z2r-f1r*z2i)/(z2r^2+z2i^2)+(fi*z4r+fr*z4i))/5.898343969}

--- Imaging function
f(x,y) = w:=P(x,y),
   1-and2(and2(tex1_3(boundize(w[1])),
   tex1_3(boundize((sqrt(3)*w[2]-w[1])/2))),
   tex1_3(boundize(-(w[1]+sqrt(3)*w[2])/2)))

--- Imaging domain
Xmin = -0.5; Xmax = 0.5; Ymin = -sqrt(3)/2; Ymax = sqrt(3)/2

--- Imaging resolution
 xpixels = 97; ypixels = 168

--- Imaging 
Zmin = 0;Zmax = 1
F[i,j] = f(Xmin+(i-0.5)/xpixels*(Xmax-Xmin),
           Ymin+(j-0.5)/ypixels*(Ymax-Ymin)) dim[xpixels,ypixels]
image F