Freitag, 11. Juli 2014

Grafiken mit TIKZ

TIKZ

Ich bin dazu übergegangen, die Zeichnungen meiner Skripten mit Tikz zu erstellen, da dies,
  1. gut aussieht
  2. perfekt zu latex passt
  3. und sich somit leicht warten lässt
In  weiterer Folge werde ich hier einige Bilder mit Sourcecode posten, damit leicht nachvollzogen werden kann wie man solche Zeichnungen erstellt, und ich eine Eselsbrücke für mich habe, wie einzelne Probleme gelöst werden können. Die Zeichnungen sind grundsätzlich "straight forward" und ohne Tricks gelöst. Oft wird es bessere Lösungen geben -> ich hoffe auf Hinweise/Erläuterungen in den Kommentaren.....

Aufbau einer IP-Adresse/Netzmaske:

 

Source: (ohne Kopf)





% Aufbau einer IP-Adresse Bitmuster - Dezimaldarstellung und Netzmaske
% $Id:$

\tikzstyle{ipmatrix}=[matrix of nodes,
nodes={rectangle,minimum size=4mm,very thick,draw=black!50,font=\ttfamily,
top color=white,bottom color=black!40}]
\tikzstyle{netmask}=[matrix of nodes, below = of ip,
nodes={rectangle,minimum size=4mm,very thick,draw=blue!50,font=\ttfamily,
top color=white,bottom color=blue!40}]
\tikzstyle{decmatrix}=[matrix of nodes, above = of ip,
nodes={rectangle, inner sep=0,minimum size=8mm, very thick, draw = black!50,
font=\ttfamily, top color=white, bottom color = black!40}]
\tikzstyle{nmmatrix}=[matrix of nodes, below = of nm,
nodes={rectangle, inner sep=0,minimum size=8mm, very thick, draw = blue!50,
font=\ttfamily, top color=white, bottom color = blue!40}]

\begin{tikzpicture}

% die Oktets
\matrix (ip)[ipmatrix] {1 & 1 & 0 & 0 & 0 & 0 & 0 & 0 & 1 & 0 & 1 & 0 & 1 & 0 & 0 & 0 &
0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 & 1 & 0 & 1 & 0\\};
\matrix (nm)[netmask] {1 & 1 & 1 & 1 & 1 & 1 & 1 & 1 & 1 & 1 & 1 & 1 & 1 & 1 & 1 & 1 &
1 & 1 & 1 & 1 & 1 & 1 & 1 & 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0\\};

\matrix (bin)[decmatrix] {192 & 168 & 1 & 10\\};

\matrix (nm-dec)[nmmatrix] {255 & 255 & 255 & 0\\};
% die Dezimalnummern


%Klammern über der Bitdarstellung
\begin{scope}[decoration={brace,amplitude=1.5mm}] %scope damit immer gleiche Formatierung
\draw [decorate] (ip-1-1.north west) -- (ip-1-8.north east);
\draw [decorate] (ip-1-8.north east) -- (ip-1-16.north east);
\draw [decorate] (ip-1-16.north east) -- (ip-1-24.north east);
\draw [decorate] (ip-1-24.north east) -- (ip-1-32.north east);
\end{scope}

%Klammern zwischen den Dezimalzahlen
\begin{scope}[decoration={brace, mirror,amplitude=1.5mm}] % mirror damit nach unten
\draw [decorate] (bin-1-1.south west) -- (bin-1-1.south east);
\draw [decorate] (bin-1-2.south west) -- (bin-1-2.south east);
\draw [decorate] (bin-1-3.south west) -- (bin-1-3.south east);
\draw [decorate] (bin-1-4.south west) -- (bin-1-4.south east);
\end{scope}
%Klammern über der Netzmaske
\begin{scope}[decoration={brace, mirror,amplitude=1.5mm}] %scope damit immer gleiche Formatierung
\draw [decorate] (nm-1-1.south west) -- (nm-1-8.south east);
\draw [decorate] (nm-1-8.south east) -- (nm-1-16.south east);
\draw [decorate] (nm-1-16.south east) -- (nm-1-24.south east);
\draw [decorate] (nm-1-24.south east) -- (nm-1-32.south east);
\end{scope}

%Klammern zwischen den Dezimalzahlen der Netmask
\begin{scope}[decoration={brace, amplitude=1.5mm}] % mirror damit nach unten
\draw [decorate] (nm-dec-1-1.north west) -- (nm-dec-1-1.north east);
\draw [decorate] (nm-dec-1-2.north west) -- (nm-dec-1-2.north east);
\draw [decorate] (nm-dec-1-3.north west) -- (nm-dec-1-3.north east);
\draw [decorate] (nm-dec-1-4.north west) -- (nm-dec-1-4.north east);
\end{scope}

% Strukturierungspunkte (um 1mm noch oben verschoben)
\shade[ball color=red] (bin-1-1.south east)++(0,1mm) circle(1mm);
\shade[ball color=red] (bin-1-2.south east)++(0,1mm) circle(1mm);
\shade[ball color=red] (bin-1-3.south east)++(0,1mm) circle(1mm);
% geschwungene Verbindungslinien
\begin{scope} [<->, out=270, in=90, shorten >=1.5mm, shorten <=1.5mm, looseness=.75]
\draw(bin-1-1) to (ip-1-4.north east);
\draw(bin-1-2) to (ip-1-12.north east);
\draw(bin-1-3) to (ip-1-20.north east);
\draw(bin-1-4) to (ip-1-28.north east);
\end{scope}

\begin{scope} [<->, in=270, out=90, shorten >=6.5mm, shorten <=1.5mm, looseness=1]
\draw(nm-dec-1-1) to (nm-1-4.north east);
\draw(nm-dec-1-2) to (nm-1-12.north east);
\draw(nm-dec-1-3) to (nm-1-20.north east);
\draw(nm-dec-1-4) to (nm-1-28.north east);
\end{scope}

%Strukturierungspunkte zwischen den Octetts der Netmask
\shade[ball color=red] (nm-1-8.south east) circle(1mm);
\shade[ball color=red] (nm-1-16.south east) circle(1mm);
\shade[ball color=red] (nm-1-24.south east) circle(1mm);

\shade[ball color=red] (nm-dec-1-1.south east)++(0,1mm) circle(1mm);
\shade[ball color=red] (nm-dec-1-2.south east)++(0,1mm) circle(1mm);
\shade[ball color=red] (nm-dec-1-3.south east)++(0,1mm) circle(1mm);


% Bereichsschattierung
\begin{pgfonlayer}[background] % Ebene wechseln
\draw [fill,green!40,path, fading=north](ip-1-1.south west) -- (ip-1-24.south east) -- (nm-1-24.north east) -- (nm-1-1.north west) -- cycle;
\draw [fill,yellow!40,path, fading=north](ip-1-24.south east) -- (ip-1-32.south east) -- (nm-1-32.north east) -- (nm-1-24.north east) -- cycle;
\end{pgfonlayer}

% Beschriftung
\node (ipdec) [left = of bin] {\textbf{Nodeadresse (IP)}};
\node (netdec) [left = of nm-dec] {\textbf{Netzmaske}};
\node (netadr) [below left = 2mm and -7cm of ip] {\textbf{Netzadresse}};
\node (netadr) [below right = 2mm and -3cm of ip] {\textbf{Hostadresse}};
%Strukturierungspunkte zwischen den Octetts der IP
\shade[ball color=red] (ip-1-8.south east) circle(1mm);
\shade[ball color=red] (ip-1-16.south east) circle(1mm);
\shade[ball color=red] (ip-1-24.south east) circle(1mm);

\end{tikzpicture}