Drum Patterns mit LaTeX

Hier ein erster Entwurf, wie man mit LaTeX Drum Patters setzen kann.

\documentclass[12pt,ngerman]{scrartcl}
\usepackage[margin=1cm]{geometry}
\usepackage[T1]{fontenc}
\usepackage{babel}
\usepackage{graphicx}
\usepackage{xcolor}
\usepackage{tikz}
 
\begin{document}
 
\begin{tikzpicture}
    % Define the pattern as a comma-separated list
    \def\pattern{x,-,-,-,-,x,x,-,-,-,x,x,-,-,-,x}
    \def\cellsizex{1cm}
    \def\cellsizey{0.5cm}
 
    \node[draw, rectangle,minimum width = \cellsizex, align=left,minimum height=\cellsizey] (a) at (\cellsizex/2,\cellsizey/2){\tiny 1}; 
 
    % Loop through each character in the pattern
    \foreach \cell [count=\index from 1] in \pattern {
        % If 'x' fill the cell, otherwise leave it empty
        \if\cell x
            \fill[gray,draw=black] ({\index*\cellsizex}, 0) rectangle ++(\cellsizex, \cellsizey);
        \else
            \draw ({\index*\cellsizex}, 0) rectangle ++(\cellsizex, \cellsizey);
        \fi
    }
\end{tikzpicture}

drumbrute_pattern

Uwe

Uwe Ziegenhagen likes LaTeX and Python, sometimes even combined. Do you like my content and would like to thank me for it? Consider making a small donation to my local fablab, the Dingfabrik Köln. Details on how to donate can be found here Spenden für die Dingfabrik.

More Posts - Website