Tutorial 2ΒΆ

[1]:
%load_ext autoreload
%autoreload 2
[2]:
import numpy as np

from tikzpics import TikzFigure
[3]:
fig = TikzFigure()

options = ["draw", "rounded corners=8pt", "line width=6"]
colors = ["purple", "blue", "purple"]

# M with thick tracing
nodes_M = [
    [0, 0],
    [0, 3.5],
    [1, 3.5],
    [1.25, 2.75],
    [1.5, 3.5],
    [2.5, 3.5],
    [2.5, 0],
    [2, 0],
    [2, 2.75],
    [1.25, 2.0],
    [0.5, 2.75],
    [0.5, 0],
]

fig.draw(
    nodes_M,
    options=options,
    layer=0,
    cycle=True,
    color=colors[0],
    fill=f"{colors[0]}!50!white",
    comment="Path for M",
)

# T with thick tracing
nodes_T = [
    [3.125, 0],
    [3.125, 4],
    [0, 4],
    [0, 4.75],
    [7, 4.75],
    [7, 4],
    [3.875, 4],
    [3.875, 0],
]

fig.draw(
    nodes_T,
    options=options,
    layer=0,
    cycle=True,
    color=colors[1],
    fill=f"{colors[1]}!50!white",
    comment="Path for T",
)

# L with thick tracing
nodes_L = [
    [4.5, 0],
    [4.5, 3.5],
    [5.25, 3.5],
    [5.25, 0.75],
    [7, 0.75],
    [7, 0],
]

fig.draw(
    nodes_L,
    options=options,
    layer=2,
    cycle=True,
    color=colors[2],
    fill=f"{colors[2]}!50!white",
    comment="Path for L",
)

xvec = np.arange(0, 7, 0.1)
yvec = np.sin(xvec) * 0.25 + 1.25

nodes_line = [(x, y) for x, y in zip(xvec, yvec)]

fig.draw(
    nodes_line,
    options=options,
    layer=1,
    color="black",
    comment="Sine wave path",
)

fig.show()
../_images/tutorials_tutorial_02_3_0.png
[4]:
# Print the tikz code
print(fig.generate_tikz())
% --------------------------------------------- %
% Tikzfigure generated by tikzpics v0.1         %
% https://github.com/max-models/tikzpics        %
% --------------------------------------------- %
\begin{tikzpicture}

    % Define the layers library
    \pgfdeclarelayer{0}
    \pgfdeclarelayer{1}
    \pgfdeclarelayer{2}
    \pgfsetlayers{0,1,2}

    % Layer 0
    \begin{pgfonlayer}{0}

        % Path for M
        \draw[draw, rounded corners=8pt, line width=6, color=purple, fill=purple!50!white] (0.0, 0.0) to (0.0, 3.5) to (1.0, 3.5) to (1.25, 2.75) to (1.5, 3.5) to (2.5, 3.5) to (2.5, 0.0) to (2.0, 0.0) to (2.0, 2.75) to (1.25, 2.0) to (0.5, 2.75) to (0.5, 0.0) -- cycle;

        % Path for T
        \draw[draw, rounded corners=8pt, line width=6, color=blue, fill=blue!50!white] (3.125, 0.0) to (3.125, 4.0) to (0.0, 4.0) to (0.0, 4.75) to (7.0, 4.75) to (7.0, 4.0) to (3.875, 4.0) to (3.875, 0.0) -- cycle;
    \end{pgfonlayer}{0}

    % Layer 2
    \begin{pgfonlayer}{2}

        % Path for L
        \draw[draw, rounded corners=8pt, line width=6, color=purple, fill=purple!50!white] (4.5, 0.0) to (4.5, 3.5) to (5.25, 3.5) to (5.25, 0.75) to (7.0, 0.75) to (7.0, 0.0) -- cycle;
    \end{pgfonlayer}{2}

    % Layer 1
    \begin{pgfonlayer}{1}

        % Sine wave path
        \draw[draw, rounded corners=8pt, line width=6, color=black] (0.0, 1.25) to (0.1, 1.274958354161707) to (0.2, 1.2996673326987653) to (0.30000000000000004, 1.3238800516653348) to (0.4, 1.3473545855771627) to (0.5, 1.3698563846510508) to (0.6000000000000001, 1.3911606183487588) to (0.7000000000000001, 1.4110544218094228) to (0.8, 1.4293390227248808) to (0.9, 1.4458317274068708) to (1.0, 1.4603677462019742) to (1.1, 1.4728018400153589) to (1.2000000000000002, 1.4830097714918067) to (1.3, 1.4908895463542982) to (1.4000000000000001, 1.496362432497115) to (1.5, 1.4993737466510135) to (1.6, 1.4998934007603764) to (1.7000000000000002, 1.4979162026131172) to (1.8, 1.4934619077195488) to (1.9000000000000001, 1.4865750219218536) to (2.0, 1.4773243567064205) to (2.1, 1.4658023416622183) to (2.2, 1.4521241009548975) to (2.3000000000000003, 1.43642630304418) to (2.4000000000000004, 1.4188657951377877) to (2.5, 1.399618036025989) to (2.6, 1.378875342955366) to (2.7, 1.3568449700584575) to (2.8000000000000003, 1.3337470375389762) to (2.9000000000000004, 1.3098123323034956) to (3.0, 1.2852800020149668) to (3.1, 1.2603951656083225) to (3.2, 1.235406464143105) to (3.3000000000000003, 1.2105635764641878) to (3.4000000000000004, 1.1861147244932921) to (3.5, 1.162304193077595) to (3.6, 1.139369889176287) to (3.7, 1.1175409647728767) to (3.8000000000000003, 1.0970355272643202) to (3.9000000000000004, 1.0780584602040064) to (4.0, 1.060799376173018) to (4.1000000000000005, 1.0454307222338972) to (4.2, 1.032106056896603) to (4.3, 1.0209585158126362) to (4.4, 1.012099481527621) to (4.5, 1.0056174705837257) to (4.6000000000000005, 1.001577249091634) to (4.7, 1.0000191856089748) to (4.800000000000001, 1.0009588477910398) to (4.9, 1.004386846843917) to (5.0, 1.0102689313342155) to (5.1000000000000005, 1.018546329418067) to (5.2, 1.0291363360699617) to (5.300000000000001, 1.0419331394440248) to (5.4, 1.0568088781110032) to (5.5, 1.073614918607402) to (5.6000000000000005, 1.09218334053192) to (5.7, 1.1123286143505906) to (5.800000000000001, 1.1338494551465608) to (5.9, 1.156530833792441) to (6.0, 1.1801461254502685) to (6.1000000000000005, 1.2044593739319762) to (6.2, 1.229227649295626) to (6.300000000000001, 1.2542034751210875) to (6.4, 1.2791373012126235) to (6.5, 1.303779997021954) to (6.6000000000000005, 1.3278853408783446) to (6.7, 1.3512124801541496) to (6.800000000000001, 1.3735283377846523) to (6.9, 1.39460994109705);
    \end{pgfonlayer}{1}
\end{tikzpicture}