Files
nand2tetris/TeX/Xor.tex
2023-06-17 11:57:10 +02:00

190 lines
5.0 KiB
TeX

%!tikz editor 1.0
\documentclass{article}
\usepackage{tikz}
\usepackage[graphics, active, tightpage]{preview}
\usepackage{circuitikz}
\PreviewEnvironment{tikzpicture}
%!tikz preamble begin
\usetikzlibrary{circuits.logic.IEC, positioning}
\usepackage[utf8]{inputenc}
\makeatletter
\def\grd@save@target#1{%
\def\grd@target{#1}}
\def\grd@save@start#1{%
\def\grd@start{#1}}
\tikzset{
grid with coordinates/.style={
to path={%
\pgfextra{%
\edef\grd@@target{(\tikztotarget)}%
\tikz@scan@one@point\grd@save@target\grd@@target\relax
\edef\grd@@start{(\tikztostart)}%
\tikz@scan@one@point\grd@save@start\grd@@start\relax
\draw[minor help lines] (\tikztostart) grid (\tikztotarget);
\draw[major help lines] (\tikztostart) grid (\tikztotarget);
\grd@start
\pgfmathsetmacro{\grd@xa}{\the\pgf@x/1cm}
\pgfmathsetmacro{\grd@ya}{\the\pgf@y/1cm}
\grd@target
\pgfmathsetmacro{\grd@xb}{\the\pgf@x/1cm}
\pgfmathsetmacro{\grd@yb}{\the\pgf@y/1cm}
\pgfmathsetmacro{\grd@xc}{\grd@xa + \pgfkeysvalueof{/tikz/grid with coordinates/major step}}
\pgfmathsetmacro{\grd@yc}{\grd@ya + \pgfkeysvalueof{/tikz/grid with coordinates/major step}}
\foreach \x in {\grd@xa,\grd@xc,...,\grd@xb}
\node[anchor=north] at (\x,\grd@ya) {\pgfmathprintnumber{\x}};
\foreach \y in {\grd@ya,\grd@yc,...,\grd@yb}
\node[anchor=east] at (\grd@xa,\y) {\pgfmathprintnumber{\y}};
}
}
},
minor help lines/.style={
help lines,
step=\pgfkeysvalueof{/tikz/grid with coordinates/minor step}
},
major help lines/.style={
help lines,
line width=\pgfkeysvalueof{/tikz/grid with coordinates/major line width},
step=\pgfkeysvalueof{/tikz/grid with coordinates/major step}
},
grid with coordinates/.cd,
minor step/.initial=.2,
major step/.initial=1,
major line width/.initial=1pt,
}
\tikzset{
declare function={% in case of CVS which switches the arguments of atan2
atan3(\a,\b)=ifthenelse(atan2(0,1)==90, atan2(\a,\b), atan2(\b,\a));
},
kinky cross radius/.initial=+.125cm,
@kinky cross/.initial=+,
kinky crosses/.is choice,
kinky crosses/left/.style={@kinky cross=-},
kinky crosses/right/.style={@kinky cross=+},
kinky cross/.style args={(#1)--(#2)}{
to path={
let \p{@kc@}=($(\tikztotarget)-(\tikztostart)$),
\n{@kc@}={atan3(\p{@kc@})+180} in
-- ($(intersection of \tikztostart--{\tikztotarget} and #1--#2)!%
\pgfkeysvalueof{/tikz/kinky cross radius}!(\tikztostart)$)
arc [ radius =\pgfkeysvalueof{/tikz/kinky cross radius},
start angle=\n{@kc@},
delta angle=\pgfkeysvalueof{/tikz/@kinky cross}180 ]
-- (\tikztotarget)
}
}
}
\makeatother
%!tikz preamble end
\begin{document}
%!tikz source begin
\begin{tikzpicture}[scale=1.3, transform shape,circuit logic IEC]
\tikzstyle{branch}=[fill,shape=circle,minimum size=3pt,inner sep=0pt]
\draw (0,0) to[grid with coordinates] (10,5);
% Koordinaten für Kreuzpunkte
\coordinate (A) at (0.95,2.75);
\fill (A) circle (1pt);% node{A};
\coordinate (B) at (0.95,0.5);
\fill (B) circle (1pt);
\coordinate (C) at (0.55,2.75);
%temp
\fill (C) circle (1pt) node{\tiny{C}};
\coordinate (D) at (2.5,1.4);
%temp
%\fill (D) circle (1pt) node{\tiny{D}};
\coordinate (E) at (0.75,0.5);
\fill (E) circle (1pt) node[above]{\tiny{E}};
\coordinate (F) at (2.5,1.8);
%temp
\fill (F) circle (1pt) node{\tiny{F}};
\coordinate (G) at (4.2,2.58);
%temp
%\fill (G) circle (1pt) node{G};
\coordinate (H) at (4.2,0.666);
%temp
%\fill (H) circle (1pt) node{H};
\coordinate (I) at (6,1.6);
%temp
\fill (I) circle (1pt) node{I};
\coordinate (J) at (0.75,1.8);
\fill (J) circle (1pt) node[above]{\tiny{J}};
% Eingangsvariablen
\node (x2) at (0.2,0.5) {b};
\node (x1) at (0.2,2.75) {a};
% Ausgangsvariable
\node (y) at (6.35, 1.62) {out};
% Gatter
\node[nand gate] at (1.5,0.5) (n1) {\tiny{N1}};
\node[nand gate] at (1.5,2.75) (n2) {};
\node[nand gate] at (3.45,2.58) (n4) {};
\node[nand gate] at (3.45,0.666) (n3) {};
\node[nand gate] at (5,1.6) (n5) {};
% Verbindungen
\draw(x1) -- (A);
\draw(x2) -- (B);
\draw(A) |- (n2.input 1);
\draw(A) |- (n2.input 2);
\draw(B) |- (n1.input 1);
\draw(B) |- (n1.input 2);
\draw(n1.output) -- (n3.input 2);
\draw(n2.output) -- (n4.input 1);
\draw(C) |- (D);
\draw(D) |- (n3.input 1);
%\draw(E) |- (F);
%\draw(F) |- (n4.input 2);
\draw(n4.output) -- (G);
\draw(G) |- (n5.input 1);
\draw(n3.output) -- (H);
\draw(H) |- (n5.input 2);
\draw(n5.output) -- (I);
%\node at (ORa.in 2)
%[
% below,
% jump crossing,
% rotate=-90,
% scale=1.3
%](X){\tiny{X}};
% \draw(n1.output) to [short,l=\footnotesize{nandout}, -] (A);
% \draw(1,-1) to[short] (1,1) (0,0) to[crossing] (2,0);
% \draw(C) |- (D) (E) to[crossing] (J);
% \draw (E) to [kinky cross=(C)--(D), kinky crosses=right](J); % /
\end{tikzpicture}
%!tikz source end
\end{document}