How can I make a slide rule in TikZ?

Logarithmic ticks can be easily plotted by iterating the function f[n,x]=n+log(x) for n>=0 and 1<=x<=9 where both n and x are integers.

\documentclass[pstricks,border=12pt,12pt]{standalone}
\psset{xunit=3cm}

\def\f(#1,#2){(#1+log(#2))}

\pstVerb{/I2P {AlgParser cvx exec} def}

\begin{document}
\begin{pspicture}(0,-1)(4,1)
    \psline[linecolor=blue](4,0)
    \psset{linecolor=red}
    \foreach \n in {0,...,3}{%
        \foreach \i in {1,...,10}{% 10 (instead of 9) is used here to make sure the last line is drawn.
            \pstVerb{/xxx {{\f(\n,\i)} exec I2P} def}%
            \psline(!xxx -1)(!xxx 1)}}
\end{pspicture}
\end{document}

enter image description here

Translation to TikZ

\documentclass[tikz,border=12pt,12pt]{standalone}

\def\f(#1,#2){#1+log10(#2)}


\begin{document}
\begin{tikzpicture}
    \draw[blue] (0,0) -- (4,0);
    \foreach \n in {0,...,3}{%
        \foreach \i in {1,...,10}{% 10 (instead of 9) is used here to make sure the last line is drawn.
            \draw[red] ({\f(\n,\i)},-1) -- ({\f(\n,\i)},1);}}
\end{tikzpicture}
\end{document}

Tags:

Tikz Pgf