texlive[72176] Master/texmf-dist: domaincoloring (2sep24)
commits+karl at tug.org
commits+karl at tug.org
Mon Sep 2 22:34:43 CEST 2024
Revision: 72176
https://tug.org/svn/texlive?view=revision&revision=72176
Author: karl
Date: 2024-09-02 22:34:43 +0200 (Mon, 02 Sep 2024)
Log Message:
-----------
domaincoloring (2sep24)
Modified Paths:
--------------
trunk/Master/texmf-dist/doc/lualatex/domaincoloring/Changes
trunk/Master/texmf-dist/doc/lualatex/domaincoloring/domaincoloring-doc.pdf
trunk/Master/texmf-dist/doc/lualatex/domaincoloring/domaincoloring-doc.tex
trunk/Master/texmf-dist/tex/lualatex/domaincoloring/domaincoloring-functions.lua
trunk/Master/texmf-dist/tex/lualatex/domaincoloring/domaincoloring.lua
trunk/Master/texmf-dist/tex/lualatex/domaincoloring/domaincoloring.sty
Modified: trunk/Master/texmf-dist/doc/lualatex/domaincoloring/Changes
===================================================================
--- trunk/Master/texmf-dist/doc/lualatex/domaincoloring/Changes 2024-09-02 20:34:33 UTC (rev 72175)
+++ trunk/Master/texmf-dist/doc/lualatex/domaincoloring/Changes 2024-09-02 20:34:43 UTC (rev 72176)
@@ -1,3 +1,5 @@
+0.05 2024-09-02 - added Rmax for circled images
+ - modified bgcolor option
0.04 2024-08-29 - bugfix for phi (was [0,2pi], bust must be [0,1])
0.03 2024-08-26 - use \jobname for temporary file
- added option force for not creating already existing pdf's
Modified: trunk/Master/texmf-dist/doc/lualatex/domaincoloring/domaincoloring-doc.pdf
===================================================================
(Binary files differ)
Modified: trunk/Master/texmf-dist/doc/lualatex/domaincoloring/domaincoloring-doc.tex
===================================================================
--- trunk/Master/texmf-dist/doc/lualatex/domaincoloring/domaincoloring-doc.tex 2024-09-02 20:34:33 UTC (rev 72175)
+++ trunk/Master/texmf-dist/doc/lualatex/domaincoloring/domaincoloring-doc.tex 2024-09-02 20:34:43 UTC (rev 72176)
@@ -1,4 +1,4 @@
-%% $Id: domaincoloring-doc.tex 968 2024-08-29 11:44:46Z herbert $
+%% $Id: domaincoloring-doc.tex 979 2024-09-02 16:07:29Z herbert $
%
\listfiles
@@ -53,7 +53,7 @@
\usepackage{domaincoloring}
\end{verbatim}
-The needs the following Lua modules:
+The package needs the following Lua modules:
\begin{itemize}
\item \texttt{domaincoloring.lua} the main module
@@ -61,7 +61,7 @@
\item \texttt{domaincoloring-functions.lua} for predefined complex functions
\end{itemize}
-The function module has to be managed by the user himself, if needed.
+The function module has to be managed by the user himself, if needed.
@@ -70,7 +70,8 @@
There is only one macro which does the external call of the Lua program \verb|domaincoloring.lua|.
This program creates the image which is then included into the document. The \LaTeX-run needs
the \verb|--shell-escape| option to allow the external run of the program to convert the created
-ppm-file into a png file..
+eps-file into a pdf file, which is then included by the command \Lcs{includegraphics} into
+the document.
\begin{verbatim}
@@ -78,7 +79,59 @@
\end{verbatim}
Every math function has to be preceeded by \texttt{cmath} if it has a complex argument.
+The following complex functions are supported:
+\begin{verbatim}
+complex(re,im) creates a complex number from real and imaginary components.
+re(z) real part of z
+im(z) imaginary part of z
+arg(z) argument of z
+abs(z) absolute value of z
+sqrt(z) z^0.5
+pow(x,y) x^y
+exp(z) e^z
+ln(z) e^? = z
+log(b,z) ln(z)/ln(b)
+sin(z)
+cos(z)
+tan(z)
+sinh(z)
+cosh(z)
+tanh(z)
+asin(z)
+acos(z)
+atan(z)
+atan2(y,x)
+asinh(z)
+acosh(z)
+atanh(z)
+polar(z) returns r,phi = cmath.abs(z),cmath.arg(z)
+rect(r,phi) returns a complex number from polar = r*e^(i*phi)
+diff(z) returns re(z)^2-im(z)^2
+zeta(z[,accuracy=1e4]) riemann zeta function
+lintegrate(f,H,[L=0,n=sensible for H])
+cx(string) creates a complex number from a string (e.g. "1.1-i" -> 1.1+-1i)
+cx(re,im) same as complex(re,im)
+\end{verbatim}
+
+The default trigonometrical functions can be used without a preceeding \verb|math|:
+
+\begin{verbatim}
+e=math.exp(1)
+pi=math.pi
+abs=math.abs
+exp=math.exp
+log=math.log
+cos=math.cos
+sin=math.sin
+cosh=math.cosh
+sinh=math.sinh
+sqrt=math.sqrt
+atan2=math.atan2
+\end{verbatim}
+
+
+
\subsection{Options}
\noindent
@@ -87,11 +140,11 @@
\Lkeyword{domain} & {-2,2,-2,2} & the (re,im)-coordinates for the complex system\\
\Lkeyword{resolution} & 500 & the number of steps for the re,im interval. One value will be for
both axes. Two values like \verb|{500,600}| for real axis and imaginary axis,\\
-\Lkeyword{filename} & \Lcs{jobname-tmp} & name of the created external file, must be unique\\
+\Lkeyword{Rmax} & 0 & forces a circle output if $\text{Rmax}>0$ \\
\Lkeyword{funcName} & \texttt{\{\}} & corresponding to external file\\
\Lkeyword{grfOptions} &scale=0.5 & optional arguments for \Lcs{includegraphics}\\
\Lkeyword{hsvrgb} & {phi+pi,1,r} & for the conversion into rgb\\
-\Lkeyword{bgcolor} & -1 & change color to white as background for all values $-1\le r+g+b\le\text{bgcolor}$\\
+\Lkeyword{bgcolor} & \texttt{\{0,0,0\}} & change color to value as background\\
\Lkeyword{invers} & false & inverted colors with $color=|color-255|$\\
\Lkeyword{force} & true & With \texttt{force=false} an existing pdf file will be used
without calculating a new one.\\
@@ -106,16 +159,15 @@
\subsection{The default with function $f(z)=z$ and $f(z)=1/z$}
\begin{lstlisting}
-\DomainColoring{z} % default filename \jobname-tmp.png
+\DomainColoring{z} % default filename \jobname-tmp0.png
\end{lstlisting}
\noindent
\DomainColoring{z}%\qquad
-%\DomainColoring[filename=demo2.png,bgcolor=true]{z}
-\subsection{Defining domain, color mode, resolution and filename}
+\subsection{Defining domain, color mode, resolution and Rmax}
\begin{align}
f(z) &= \cos(z)/\sin(z^4-1)
@@ -125,49 +177,80 @@
must be preceeded by \texttt{cmath.}. For real functions the prefix \texttt{math.}
can be omitted.
+
+The backgroundcolor can be set with \Lkeyword{bgcolor}\texttt{=\{R,G,B\}} (values between 0 and 255).
+This color will replace the default backgroundcolor \texttt{\{0,0,0\}}. With a negative value
+for R, eg. -10, it replaces all colors which have a sum of $R+G+B <10$ with the color defined by
+the value for G, eg. 255. A setting of \Lkeyword{bgcolor}\texttt{\{=-8,255,255\}} is the same as
+\Lkeyword{bgcolor}\texttt{\{=-8,255,0\}}, becaus the last value is not used. A given color
+\texttt{\{=3,3,1\}} will be replaced by \texttt{\{=255,255,255\}}, because $3+3+1<8$ and a color
+\texttt{\{=6,2,3\}} will be unchanged, it is greater than 8.
+
+
\begin{lstlisting}
\DomainColoring[domain={-2.5,2.5,-2.5,2.5},resolution=500,hsvrgb={phi,1,r},
-grfOptions={width=0.32\linewidth},
- filename=\jobname-tmp1a]{cmath.cos(z)/cmath.sin(z^4-1)}
+grfOptions={width=0.32\linewidth}]{cmath.cos(z)/cmath.sin(z^4-1)}
\hfill
-\frame{\DomainColoring[domain={-2.5,2.5,-2.5,2.5},resolution=500,
- bgcolor=3,hsvrgb={phi,1,r},grfOptions={width=0.32\linewidth},
- filename=\jobname-tmp1b]{cmath.cos(z)/cmath.sin(z^4-1)}}
+\frame{\DomainColoring[domain={-2.5,2.5,-2.5,2.5},resolution=500,bgcolor={-8,255,255},
+ hsvrgb={phi,1,r},grfOptions={width=0.32\linewidth}]{cmath.cos(z)/cmath.sin(z^4-1)}}
\hfill
-\frame{\DomainColoring[domain={-2.5,2.5,-2.5,2.5},resolution=500,invers=true,
- hsvrgb={phi,1,r}, grfOptions={width=0.32\linewidth},
- filename=\jobname-tmp1c]{cmath.cos(z)/cmath.sin(z^4-1)}}
+\frame{\DomainColoring[domain={-2.5,2.5,-2.5,2.5},resolution=500,invers,
+ hsvrgb={phi,1,r}, grfOptions={width=0.32\linewidth}]{cmath.cos(z)/cmath.sin(z^4-1)}}
\end{lstlisting}
\noindent
\DomainColoring[domain={-2.5,2.5,-2.5,2.5},resolution=500,hsvrgb={phi,1,r},
-grfOptions={width=0.32\linewidth},
- filename=\jobname-tmp1a]{cmath.cos(z)/cmath.sin(z^4-1)}
+grfOptions={width=0.32\linewidth}]{cmath.cos(z)/cmath.sin(z^4-1)}
\hfill
-\frame{\DomainColoring[domain={-2.5,2.5,-2.5,2.5},resolution=500,bgcolor=3,hsvrgb={phi,1,r},
-grfOptions={width=0.32\linewidth},
- filename=\jobname-tmp1b]{cmath.cos(z)/cmath.sin(z^4-1)}}
+\frame{\DomainColoring[domain={-2.5,2.5,-2.5,2.5},resolution=500,bgcolor={-8,255,255},hsvrgb={phi,1,r},
+grfOptions={width=0.32\linewidth}]{cmath.cos(z)/cmath.sin(z^4-1)}}
\hfill
-\frame{\DomainColoring[domain={-2.5,2.5,-2.5,2.5},resolution=500,invers=true,hsvrgb={phi,1,r},
-grfOptions={width=0.32\linewidth},
- filename=\jobname-tmp1c]{cmath.cos(z)/cmath.sin(z^4-1)}}
+\frame{\DomainColoring[domain={-2.5,2.5,-2.5,2.5},resolution=500,invers,hsvrgb={phi,1,r},
+grfOptions={width=0.32\linewidth}]{cmath.cos(z)/cmath.sin(z^4-1)}}
-With \Lkeyword{bgcolor}\texttt{=<int>} all RGB-combinations with a sum $R+G+B <= \text{int}$ are set to
-the color white.
+
+
+
+
+
+The optional argument \Lkeyword{Rmax} allows to crop everything around the circle with radius
+\Lkeyword{Rmax}:
+
+\begin{lstlisting}
+\DomainColoring[domain={-1,1,-1,1},resolution=500,hsvrgb={phi,1,r},
+grfOptions={width=0.32\linewidth}, Rmax=1, bgcolor={1,1,1}]{cmath.cos(z)/cmath.sin(z^4-1)}
+\hfill
+\frame{\DomainColoring[domain={-1,1,-1,1},resolution=500,bgcolor={-8,255,1},hsvrgb={phi,1,r},
+grfOptions={width=0.32\linewidth},Rmax=1]{cmath.cos(z)/cmath.sin(z^4-1)}}
+\hfill
+\frame{\DomainColoring[domain={-1,1,-1,1},resolution=500,invers=true,hsvrgb={phi,1,r},
+grfOptions={width=0.32\linewidth},Rmax=1]{cmath.cos(z)/cmath.sin(z^4-1)}}
+\end{lstlisting}
+
+\DomainColoring[domain={-1,1,-1,1},resolution=500,hsvrgb={phi,1,r},
+grfOptions={width=0.32\linewidth}, Rmax=1]{cmath.cos(z)/cmath.sin(z^4-1)}
+\hfill
+\frame{\DomainColoring[domain={-1,1,-1,1},resolution=500,bgcolor={-8,255,1},hsvrgb={phi,1,r},
+grfOptions={width=0.32\linewidth},Rmax=1]{cmath.cos(z)/cmath.sin(z^4-1)}}
+\hfill
+\frame{\DomainColoring[domain={-1,1,-1,1},resolution=500,Rmax=1,invers,hsvrgb={phi,1,r},
+grfOptions={width=0.32\linewidth}]{cmath.cos(z)/cmath.sin(z^4-1)}}
+
+
\subsection{Option for \Lcs{includegraphics}}
With \Lkeyword{grfOptions} one can define optional arguments for \Lcs{includegraphics}:
\begin{lstlisting}
-\DomainColoring[grfOptions={width=0.49\linewidth},filename=\jobname-tmp2a]{cmath.sin(z)}\hfill
+\DomainColoring[grfOptions={width=0.49\linewidth}]{cmath.sin(z)}\hfill
\hfill
-\DomainColoring[grfOptions={width=0.49\linewidth},filename=\jobname-tmp2b]{cmath.sin(0.9*z)*cmath.sin(z)}
+\DomainColoring[grfOptions={width=0.49\linewidth}]{cmath.sin(0.9*z)*cmath.sin(z)}
\end{lstlisting}
\noindent
-\DomainColoring[grfOptions={width=0.49\linewidth},filename=\jobname-tmp2a]{cmath.sin(z)}
+\DomainColoring[grfOptions={width=0.49\linewidth}]{cmath.sin(z)}
\hfill
-\DomainColoring[grfOptions={width=0.49\linewidth},filename=\jobname-tmp2b]{cmath.sin(0.9*z)*cmath.sin(z)}
+\DomainColoring[grfOptions={width=0.49\linewidth}]{cmath.sin(0.9*z)*cmath.sin(z)}
\subsection{Higher resolution}
@@ -179,17 +262,16 @@
\begin{lstlisting}
-\DomainColoring[filename=\jobname-tmp3,resolution=1000,grfOptions={width=0.49\linewidth}]{z^3-1}
+\DomainColoring[resolution=1000,grfOptions={width=0.49\linewidth}]{z^3-1}
\hfill
-\DomainColoring[filename=\jobname-tmp4,resolution=1000,
+\DomainColoring[resolution=1000,
grfOptions={width=0.49\linewidth}]{(z+1)^2*(z-1)/((z+i)*(z-i)^2)}
\end{lstlisting}
\noindent
-\DomainColoring[filename=\jobname-tmp3,resolution=1000,
- grfOptions={width=0.49\linewidth}]{z^3-1}
+\DomainColoring[resolution=1000,grfOptions={width=0.49\linewidth}]{z^3-1}
\hfill
-\DomainColoring[filename=\jobname-tmp4,resolution=1000,
+\DomainColoring[resolution=1000,
grfOptions={width=0.49\linewidth}]{cmath.sin(z)*cmath.cos(z)}
@@ -210,18 +292,18 @@
for hue. For example: \verb|hsvrgb=phi,1,r|, which gives
\begin{lstlisting}
-\DomainColoring[filename=\jobname-tmp5a,resolution=1000,
- grfOptions={width=0.49\linewidth},hsvrgb={phi,1,r}]{cmath.sin(z)*cmath.sin(0.99*z)}
+\DomainColoring[resolution=1000,grfOptions={width=0.49\linewidth},domain={-2,2,-2,2},
+ funcName=f10,hsvrgb={phi,1,r}]{}
\hfill
-\DomainColoring[filename=\jobname-tmp5b,resolution=1000,,hsvrgb={phi,r,1},
- grfOptions={width=0.49\linewidth}]{cmath.sin(z)*cmath.sin(0.99*z)} % the default
+\DomainColoring[resolution=1000,hsvrgb={phi,1,r^2/(1+r^2)},Rmax=2,domain={-2,2,-2,2},
+ grfOptions={width=0.49\linewidth}]{cmath.sin(z)*cmath.sin(0.99*z)}
\end{lstlisting}
\noindent
-\DomainColoring[filename=\jobname-tmp5a,resolution=1000,
- grfOptions={width=0.49\linewidth},funcName=f10,hsvrgb={phi,1,r}]{cmath.sin(z)*cmath.sin(0.99*z)} % the default
+\DomainColoring[resolution=1000,grfOptions={width=0.49\linewidth},domain={-2,2,-2,2},
+ funcName=f10,hsvrgb={phi,1,r}]{} % the default
\hfill
-\DomainColoring[filename=\jobname-tmp5b,resolution=1000,,hsvrgb={phi,r,1},
+\DomainColoring[resolution=1000,hsvrgb={phi,1,r^2/(1+r^2)},Rmax=2,domain={-2,2,-2,2},
grfOptions={width=0.49\linewidth}]{cmath.sin(z)*cmath.sin(0.99*z)}
%For $r$ and $\phi$ we have to use $r$ and $phi$.
@@ -229,9 +311,35 @@
phi and r in any mathematical combination. It must only be compatible to the Lua math conventions,
e.g. \texttt{hsvrgb=\{phi+2,0.5,2/r\}}
+\begin{lstlisting}
+\DomainColoring[resolution={1000,1000},
+ domain={-5,5,-5,5}, grfOptions={width=0.32\linewidth},
+ hsvrgb={0.5,r/5,5-r},funcName=f16]{}
+\hfill
+\DomainColoring[resolution={1000,1000},
+ domain={-5,5,-5,5}, grfOptions={width=0.32\linewidth},
+ hsvrgb={0.5,5-r,5/r},funcName=f16]{}
+\hfill
+\DomainColoring[resolution={1000,1000},
+ domain={-5,5,-5,5}, grfOptions={width=0.32\linewidth},
+ hsvrgb={phi,r/5,5-r},funcName=f16]{}
+\end{lstlisting}
+\noindent
+\DomainColoring[resolution={1000,1000},
+ domain={-5,5,-5,5}, grfOptions={width=0.32\linewidth},
+ hsvrgb={0.5,r/5,5-r},funcName=f16]{}
+\hfill
+\DomainColoring[resolution={1000,1000},
+ domain={-5,5,-5,5}, grfOptions={width=0.32\linewidth},
+ hsvrgb={0.5,5-r,5/r},funcName=f16]{}
+\hfill
+\DomainColoring[resolution={1000,1000},
+ domain={-5,5,-5,5}, grfOptions={width=0.32\linewidth},
+ hsvrgb={phi,r/5,5-r},funcName=f16]{}
+
\subsection{External function definition}
The already existing file \LFile{domaincoloring-functions.lua} collects sone
definitions of complex functions $f(z)$, which can be used from inside \LaTeX\
@@ -241,19 +349,19 @@
\begin{lstlisting}
\DomainColoring[domain={-1.5,1.5,-1.5,1.5},resolution={1001,1001},hsvrgb={phi,1,1/r},
- filename=\jobname-tmp4.png, grfOptions={width=0.49\linewidth},funcName=f12,bgcolor=5]{}
+ grfOptions={width=0.49\linewidth},funcName=f12,bgcolor={1,1,1}]{}
\hfill
\DomainColoring[domain={-2.5,1.5,-2,2},resolution={1001,1001},hsvrgb={phi,1,1/r},
- filename=\jobname-tmp5.png, grfOptions={width=0.49\linewidth},funcName=f13,bgcolor=5]{}
+ grfOptions={width=0.49\linewidth},funcName=f13,bgcolor={1,1,1}]{}
\end{lstlisting}
\noindent
\DomainColoring[domain={-1.5,1.5,-1.5,1.5},resolution={1001,1001},hsvrgb={phi,1,1/r},
- filename=\jobname-tmp4.png, grfOptions={width=0.49\linewidth},funcName=f12,bgcolor=5]{}
+ grfOptions={width=0.49\linewidth},funcName=f12,bgcolor={1,1,1}]{}
\hfill
\DomainColoring[domain={-2.5,1.5,-2,2},resolution={1001,1001},hsvrgb={phi,1,1/r},
- filename=\jobname-tmp5.png, grfOptions={width=0.49\linewidth},funcName=f13,bgcolor=5]{}
+ grfOptions={width=0.49\linewidth},funcName=f13,bgcolor={1,1,1}]{}
Modified: trunk/Master/texmf-dist/tex/lualatex/domaincoloring/domaincoloring-functions.lua
===================================================================
--- trunk/Master/texmf-dist/tex/lualatex/domaincoloring/domaincoloring-functions.lua 2024-09-02 20:34:33 UTC (rev 72175)
+++ trunk/Master/texmf-dist/tex/lualatex/domaincoloring/domaincoloring-functions.lua 2024-09-02 20:34:43 UTC (rev 72176)
@@ -1,4 +1,4 @@
--- $Id: domaincoloring-functions.lua 968 2024-08-29 11:44:46Z herbert $
+-- $Id: domaincoloring-functions.lua 978 2024-09-02 15:27:30Z herbert $
kpse.set_program_name("luatex")
@@ -92,4 +92,19 @@
C1 = C
end
return C
-end
\ No newline at end of file
+end
+
+function f16(z)
+ local A = z^2 - z -2
+ local B = z^2 + complex(1,1)
+ return A/B
+end
+
+function f17(z)
+ return e^(z^cmath.sin(z^cmath.tan(z^cmath.cos(z))))
+end
+
+function f18(z)
+ return (z+0.5)*(z-0.5)/z
+end
+
Modified: trunk/Master/texmf-dist/tex/lualatex/domaincoloring/domaincoloring.lua
===================================================================
--- trunk/Master/texmf-dist/tex/lualatex/domaincoloring/domaincoloring.lua 2024-09-02 20:34:33 UTC (rev 72175)
+++ trunk/Master/texmf-dist/tex/lualatex/domaincoloring/domaincoloring.lua 2024-09-02 20:34:43 UTC (rev 72176)
@@ -1,4 +1,4 @@
--- $Id: domaincoloring.lua 968 2024-08-29 11:44:46Z herbert $
+-- $Id: domaincoloring.lua 978 2024-09-02 15:27:30Z herbert $
-----------------------------------------------------------------------
-- FILE: domaincoloring.lua
@@ -9,7 +9,7 @@
--
-----------------------------------------------------------------------
-local version = 0.04
+local version = 0.05
kpse.set_program_name("luatex")
@@ -28,10 +28,10 @@
local p = v * (1 - s)
local q = v * (1 - s * f)
local t = v * (1 - s * (1 - f))
- v = math.floor(255*v) % 256
- p = math.floor(255*p) % 256
- q = math.floor(255*q) % 256
- t = math.floor(255*t) % 256
+ v = math.floor(255*v) % 256
+ p = math.floor(255*p) % 256
+ q = math.floor(255*q) % 256
+ t = math.floor(255*t) % 256
if i == 0 then return v,t,p
elseif i == 1 then return q,v,p
elseif i == 2 then return p,v,t
@@ -42,14 +42,31 @@
end
end
+--[[
+local function HSVtoRGB(h, s, v)
+ h = math.floor(h * 360)
+ local k1 = v*(1-s)
+ local k2 = v - k1
+ local r = math.min (math.max (3*math.abs (((h )/180)%2-1)-1, 0), 1)
+ local g = math.min (math.max (3*math.abs (((h -120)/180)%2-1)-1, 0), 1)
+ local b = math.min (math.max (3*math.abs (((h +120)/180)%2-1)-1, 0), 1)
+ return k1 + k2 * r * 255, k1 + k2 * g * 255, k1 + k2 * b * 255
+end
+]]
+
+
function my_color_scheme(z,hsvrgb)
r, phi = cmath.polar(z)
+-- print(r,tostring(phi))
-- phi is in -pi,+pi; change it to [0;2pi] and normalize it to [0;1]
- phi = (phi+pi)/(2*pi)
+ phi = (phi+pi)/(2*pi)
+-- phi = (phi+pi)*180/pi
h_str,s_str,v_str = hsvrgb:match("([^,]+),([^,]+),([^,]+)")
+ --print(h_str,s_str,v_str)
-- print(load("return "..h_str)(),load("return "..s_str)(),load("return "..v_str)())
R,G,B = HSVtoRGB(load("return "..h_str)(),load("return "..s_str)(),load("return "..v_str)()) -- h,s,v) -- (phi+3.14,1,r)
- return {R,G,B}
+-- print(R,G,B)
+ return {math.floor(R+0.5),math.floor(G+0.5),math.floor(B+0.5)}
end
@@ -141,7 +158,7 @@
if data[row][col][k] ~= data[row][col][k] then -- check for nan
outFile:write("FF")
else
- local num = data[row][col][k]
+ num = data[row][col][k]
if num < 16 then
hex = string.format("0%X", num)
else
@@ -245,8 +262,14 @@
--os.execute("pnmtopng apfel.ppm >"..fileName..".png") -- ppm -> png Format
end
-function plot(fString, domain, res, funcName, hsvrgb, bgColor, invers)
+function plot(fString, domain, res, maxR, funcName, hsvrgb, bgColor, invers)
print("\nLua: calculating data with "..tostring(fString).." ... ")
+ local colorBGsum = bgColor[1] -- {-30, 255, 255}
+ if colorBGsum < 0 then -- color[1]+... < 30 will be {255,255,255}
+ for i=1,3 do
+ bgColor[i] = bgColor[2]
+ end
+ end
local left = domain[1]
local right = domain[2]
local bottom = domain[3]
@@ -270,19 +293,22 @@
fz = fString(z) -- use func number from external file
else
fz = load("return "..fString)() -- for example: cmath.cos(z)/cmath.sin(z^4-1)
- end
- color = my_color_scheme(fz,hsvrgb)
+ end
+-- if fz == complex(nan,nani) then
+-- color = { 0, 0, 0}
+-- print("Complex division by zero!!")
+-- else
+ color = my_color_scheme(fz,hsvrgb)
+-- end
+ if maxR > 0 and cmath.abs(z) > maxR then color = { 0, 0, 0 } end
if invers == "true" then
for c=1,#color do
color[c] = math.abs(color[c]-255)
end
end
- if bgColor > -1 then
- if color[1] + color[2] + color[3] <= bgColor then
- color = { 255, 255, 255 }
- end
- end
--- print(x,y,color[1],color[2],color[3])
+ local colorSum = color[1]+color[2]+color[3]
+ if color == {0, 0, 0} then color = bgColor end -- only one color
+ if colorBGsum < 0 and colorSum < math.abs(colorBGsum) then color = {255,255,255} end
img[row][col] = color
end
end
@@ -296,11 +322,13 @@
Resolution: (points per Interval) xRes,yRes
funcName: true/false (see f)
]]
-function createData(jobname,f,funcName,Domain,Resolution,hsvrgb,bgColor,invers,grid)
+
+function createData(jobname,f,funcName,Domain,Resolution,maxR,hsvrgb,bgColor,invers,grid)
+ print("Lua:createData: ",jobname,f,funcName,Domain,Resolution,maxR,hsvrgb,bgColor,invers,grid)
if funcName == "" then
- img = plot(f,Domain,Resolution,false,hsvrgb,bgColor,invers)
+ img = plot(f,Domain,Resolution,maxR,false,hsvrgb,bgColor,invers)
else
- img = plot(load("return "..funcName)(),Domain,Resolution,true,hsvrgb,bgColor,invers)
+ img = plot(load("return "..funcName)(),Domain,Resolution,maxR,true,hsvrgb,bgColor,invers)
end
-- write_data("domain.ppm",img,Resolution)
write_eps_data(jobname.."-domain.eps",img,Domain,Resolution,grid)
Modified: trunk/Master/texmf-dist/tex/lualatex/domaincoloring/domaincoloring.sty
===================================================================
--- trunk/Master/texmf-dist/tex/lualatex/domaincoloring/domaincoloring.sty 2024-09-02 20:34:33 UTC (rev 72175)
+++ trunk/Master/texmf-dist/tex/lualatex/domaincoloring/domaincoloring.sty 2024-09-02 20:34:43 UTC (rev 72176)
@@ -1,4 +1,4 @@
-%% $Id: domaincoloring.sty 968 2024-08-29 11:44:46Z herbert $
+%% $Id: domaincoloring.sty 979 2024-09-02 16:07:29Z herbert $
%% This is file `domaincoloring.sty',
%%
%% Copyright (C) 2024- Herbert Voss
@@ -14,8 +14,8 @@
\RequirePackage{graphicx}
\RequirePackage{shellesc}
-\def\fileversion{0.04}
-\def\filedate{2024/08/29}
+\def\fileversion{0.05}
+\def\filedate{2024/09/02}
\message{`DCol' v\fileversion, \filedate}
\ProvidesPackage{domaincoloring}
[\filedate\ \fileversion\ package for domain coloring of complex functions]
@@ -24,9 +24,6 @@
\PackageError{shellesc}{ShellEscape not enabled! Use --shell-escape}%
\fi
-% Change ^ to normal character to describe functions with lua
-\catcode`\^=11\relax % for power symbol in Lua
-
\define at key{DCol}{domain}{\def\@domaincoloring at domain{#1}}
\define at key{DCol}{resolution}{\@domaincoloring at res@i#1,\@nil}
\def\@domaincoloring at res@i#1,#2\@nil{%
@@ -35,24 +32,30 @@
\else
\def\@domaincoloring at res{#1,#2}%
\fi}
+\define at key{DCol}{Rmax}{\def\@domaincoloring at Rmax{#1}}
\define at key{DCol}{bgcolor}{\def\@domaincoloring at bgcolor{#1}}
-\define at key{DCol}{filename}{\def\@domaincoloring at filename{#1}}
\define at key{DCol}{hsvrgb}{\def\@domaincoloring at hsvrgb{#1}}
\define at key{DCol}{funcName}{\def\@domaincoloring at funcName{#1}}
-\define at key{DCol}{invers}{\def\@domaincoloring at invers{#1}}
\define at key{DCol}{grfOptions}{\def\@domaincoloring at grf{#1}}
+\define at boolkey{DCol}[DCol@]{invers}[true]{}
\define at boolkey{DCol}[DCol@]{force}[true]{}
\define at boolkey{DCol}[DCol@]{grid}[true]{}
+\newcounter{DCol at imageCTR}
+\setcounter{DCol at imageCTR}{0}
+\def\@domaincoloring at filename{\jobname-tmp\theDCol at imageCTR}
+
+
\def\setDColkeys#1{\edef\x{\noexpand\setkeys{DCol}{#1}}\x}
\setDColkeys{
funcName={}, % corresponding to external file
hsvrgb={phi,1,1}, % given (r,phi) of the complex value
- filename=\jobname-tmp, % the external image filename
+% filename=\jobname-tmp, % the external image filename
resolution=500, % pixel per (x|y) interval
domain={-2,2,-2,2}, % x|y domain
- bgcolor=-1, % R+G+B value, changes only 0,0,0 -> 255,255,255
+ Rmax=0, % max value vor |z|. 0 is same as inactive
+ bgcolor={0,0,0}, % R+G+B value, changes only 1,1,1 -> 255,255,255
invers=false, % 0 or 1 vor inverted colors
grfOptions={scale=0.5}, % LaTeX options for the included image
force=true, % only valid for the documentation
@@ -62,7 +65,12 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\def\DomainColoring{\@ifnextchar[\DomainColoring at i{\DomainColoring at i[]}}
-\def\DomainColoring at i[#1]#2{%
+
+\begingroup
+% Change ^ to normal character to describe functions with lua
+\catcode`\^=11\relax % for power symbol in Lua
+
+\gdef\DomainColoring at i[#1]#2{%
\begingroup
\setDColkeys{#1}%
\ifDCol at force\else
@@ -73,19 +81,27 @@
require("domaincoloring-complex-numbers")
require ("domaincoloring")
createData("\jobname",
- "#2","\@domaincoloring at funcName", % user defined, function no from -functions.lua
- {\@domaincoloring at domain},{\@domaincoloring at res},
+ "#2",
+ "\@domaincoloring at funcName", % user defined, function number from file
+ % domaincoloring-functions.lua
+ {\@domaincoloring at domain},{\@domaincoloring at res},\@domaincoloring at Rmax,
"\@domaincoloring at hsvrgb",
- \@domaincoloring at bgcolor,"\@domaincoloring at invers",
- \ifDCol at grid "true" \else "false" \fi)}%
+ {\@domaincoloring at bgcolor},
+ \ifDCol at invers "true" \else "false" \fi,
+ \ifDCol at grid "true" \else "false" \fi)
+ }%
\typeout{Convert \jobname-domain.eps file to \@domaincoloring at filename.pdf}%
\ShellEscape{epstopdf \jobname-domain.eps \@domaincoloring at filename.pdf}%
\fi
%
\expandafter\includegraphics\expandafter[\@domaincoloring at grf]{\@domaincoloring at filename.pdf}%
+ \stepcounter{DCol at imageCTR}%
+ \gdef\@domaincoloring at filename{\jobname-tmp\theDCol at imageCTR}%
\endgroup
\ignorespaces
}
\catcode`\^=7\relax
+\endgroup
+
\endinput
More information about the tex-live-commits
mailing list.