diff options
author | Karl Berry <karl@freefriends.org> | 2023-10-06 20:32:01 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2023-10-06 20:32:01 +0000 |
commit | 16c976bc10db55420784d85afed1ad3fc3b384b2 (patch) | |
tree | 8f6bc0767a81826e9ae039caaa2c1c76e7b8c069 /Master/texmf-dist/tex/latex/tikz-osci | |
parent | e3cf3292412a763e0ded1b23a65dde53dfc051f3 (diff) |
tikz-osci (6oct23)
git-svn-id: svn://tug.org/texlive/trunk@68464 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/latex/tikz-osci')
-rw-r--r-- | Master/texmf-dist/tex/latex/tikz-osci/tikz-osci.sty | 204 |
1 files changed, 204 insertions, 0 deletions
diff --git a/Master/texmf-dist/tex/latex/tikz-osci/tikz-osci.sty b/Master/texmf-dist/tex/latex/tikz-osci/tikz-osci.sty new file mode 100644 index 00000000000..d2d59cd5255 --- /dev/null +++ b/Master/texmf-dist/tex/latex/tikz-osci/tikz-osci.sty @@ -0,0 +1,204 @@ +% ----------------------------------------------------------- +% This is TikZ Osci package +% +% It provides some macros to draw oscilloscope screen captures +% from math functions provided by the user. +% +% It is based on TikZ and pgfplots and is a replacement can- +% didate to the pstricks pst-osci package which is not main- +% tained anymore. +% +% Author: Thibault Giauffret +% Date: 2013/10/06 +% Version: 0.1.0 +% Licence : Released under the LaTeX Project Public License v1.3c or later, see http://www.latex-project.org/lppl.txtf +% Not an expert... Just doing it for fun. +% ----------------------------------------------------------- + +\NeedsTeXFormat{LaTeX2e} +\ProvidesPackage{tikz-osci}[2023/09/30 0.1.0 Tikz Osci package] + +% Required packages +\RequirePackage[dvipsnames]{xcolor} +\RequirePackage{pgfkeys} +\RequirePackage{pgfplots} +\RequirePackage{tikz} +\usetikzlibrary{arrows,shapes,positioning} +\usetikzlibrary{decorations.markings,decorations.pathmorphing, + decorations.pathreplacing} +\usetikzlibrary{calc,patterns,shapes.geometric} + + +% Init the keys and get the values +\pgfkeys{ + /osci/.cd, + scale/.store in=\scale, + scale=1, + second channel/.store in=\secondChannel, + second channel=0, + screen offset one/.store in=\screenOffsetOne, + screen offset one=0, + screen offset two/.store in=\screenOffsetTwo, + screen offset two=-0, + time div/.store in=\timeDiv, + time div=20, + voltage div one/.store in=\voltageDivOne, + voltage div one=1, + voltage div two/.store in=\voltageDivTwo, + voltage div two=1, + sample rate/.store in=\sampleRate, + sample rate=200, + xy mode/.store in=\xyMode, + xy mode=0, + expr one/.store in=\exprOne, + expr one=2*sin(2*180/0.020*x), + expr two/.store in=\exprTwo, + expr two=0.6*sin(2*180/0.020*x)+0.2*sin(2*180/0.040*x), + color one/.store in=\colorOne, + color one=D62626, + color two/.store in=\colorTwo, + color two=1053AF, + color xy/.store in=\colorXY, + color xy=2E8B73, + graph back color/.store in=\graphBackColor, + graph back color=FFFFFF, + info back color/.store in=\infoBackColor, + info back color=D6D6D6, + info text color/.store in=\infoTextColor, + info text color=000000, + main axis color/.store in=\mainAxisColor, + main axis color=000000, + sub axis color/.store in=\subAxisColor, + sub axis color=AAAAAA, +} + +% The main command +\newcommand\osci[1][]{ + + % Get the values + \pgfkeys{ + /osci/.cd, + #1, + } + + \scalebox{\scale}{ + % Begin the picture + \begin{tikzpicture} + + % Set the colors + \definecolor{firstcolor}{HTML}{\colorOne} + \definecolor{secondcolor}{HTML}{\colorTwo} + \definecolor{thirdcolor}{HTML}{\colorXY} + \definecolor{graphbackcolor}{HTML}{\graphBackColor} + \definecolor{infoBackColor}{HTML}{\infoBackColor} + \definecolor{infoTextColor}{HTML}{\infoTextColor} + \definecolor{mainAxisColor}{HTML}{\mainAxisColor} + \definecolor{subAxisColor}{HTML}{\subAxisColor} + + % Draw the info box + \draw[black,thick, fill= infoBackColor] + (0,0) -- + ++(10,0) {[rounded corners=10] -- + ++(0,-1.5) -- + ++(-10,0)} -- + cycle + {}; + + % Add time/div label + \draw (5,-0.15) node[anchor=north, color= infoTextColor] {\timeDiv\ ms/div}; + + % Add voltage/div label for the first channel + \draw[firstcolor,fill=firstcolor] (0.5,-0.15) rectangle (1.5,-0.6); + \draw (1,-0.1) node[anchor=north, color=white] {CH1}; + \draw (1,-0.75) node[anchor=north, color= infoTextColor] {\voltageDivOne\ V/div}; + + % Add voltage/div label for the second channel + \ifnum\secondChannel=1 + \draw[secondcolor,fill=secondcolor] (8.5,-0.15) rectangle (9.5,-0.6); + \draw (9,-0.1) node[anchor=north, color=white] {CH2}; + \draw (9,-0.75) node[anchor=north, color= infoTextColor] {\voltageDivTwo\ V/div}; + \fi + + % Add the XY mode label + \ifnum\xyMode=1 + % \draw (5,-0.75) node[anchor=north, color=thirdcolor] {XY mode}; + % Coming soon... + \fi + + % Draw the oscilloscope screen border + \draw[black,thick, fill= graphbackcolor] + (0,0) -- + ++(10,0) {[rounded corners=10] -- + ++(0,8) -- + ++(-10,0)} -- + cycle + {}; + + % Draw the oscilloscope screen graduations + \begin{scope} + + % Remove the border + \clip (0.05,0.05) rectangle (9.95,7.95); + + \begin{axis}[xmin=-5*(\timeDiv/1000), xmax=5*(\timeDiv/1000), ymin=-4, ymax=4, xtick distance = \timeDiv/1000, + axis x line=middle, axis y line=middle, + axis line style={-}, + % Draw major grid + grid=both, + xticklabels={,,}, + yticklabels={,,}, + % Add sub ticks for the x axis + minor tick num=4, + % Remove minor grid + minor grid style={line width=0pt, draw=white, draw opacity=0}, + major grid style={thick,dashed,draw=subAxisColor}, + every major tick/.append style={very thick, major tick length=6pt, color=mainAxisColor}, + every minor tick/.append style={thick, minor tick length=4pt, color=mainAxisColor}, + ] + + % Change plot width + \pgfplotsset{width=11.58cm, height=9.58cm} + % Change tick label style + \pgfplotsset{ every non boxed x axis/.append style={x axis line style=-}, + every non boxed y axis/.append style={y axis line style=-}} + + \ifnum\xyMode=1 + + % Coming soon... + + \else + + % Draw each channel separately + % First channel plot + \addplot[color=firstcolor,very thick,domain=-5*(\timeDiv/1000):5*(\timeDiv/1000), + smooth, samples=\sampleRate]{(\exprOne)/\voltageDivOne+\screenOffsetOne}; + + % If the second channel is enabled, draw it + \ifnum\secondChannel=1 + % Draw the second channel + \addplot[color=secondcolor,very thick,domain=-5*(\timeDiv/1000):5*(\timeDiv/1000), smooth, samples=\sampleRate]{(\exprTwo)/\voltageDivTwo+\screenOffsetTwo}; + \fi + \fi + + \end{axis} + + \ifnum\xyMode=0 + % Draw the first channel's screen marker + \draw[firstcolor,fill=firstcolor] (0.4, \screenOffsetOne+4) -- (0, \screenOffsetOne+4+0.3) -- (0, \screenOffsetOne+4-0.3) -- cycle; + \draw (-0.04, \screenOffsetOne+4) node[anchor=west, color=white,font=\fontsize{8}{10}\selectfont] {1}; + + % Draw the second channel's screen marker + \ifnum\secondChannel=1 + \draw[secondcolor,fill=secondcolor] (0.4, \screenOffsetTwo+4) -- (0, \screenOffsetTwo+4+0.3) -- (0, \screenOffsetTwo+4-0.3) -- cycle; + \draw (-0.04, \screenOffsetTwo+4) node[anchor=west, color=white,font=\fontsize{8}{10}\selectfont] {2}; + \fi + \fi + + \end{scope} + + \end{tikzpicture} + } +} + + + |