5

I try to generate with tikz a header for each page with a binary matrix code. as:

enter image description here

currently my working code

\RequirePackage[svgnames]{xcolor}
\RequirePackage{tikz}
\RequirePackage{kpfonts}
\RequirePackage[explicit]{titlesec}
\newcommand*\chapterlabel{}
\titleformat{\chapter}
  {\gdef\chapterlabel{}
   \normalfont\sffamily\Huge\bfseries\scshape}
  {\gdef\chapterlabel{\thechapter\ }}{0pt}
  {\begin{tikzpicture}[remember picture,overlay]
\node[yshift=-3cm] at (current page.north west)
{
    \begin{tikzpicture}[remember picture, overlay]
        \draw[fill=Black] (0,0) rectangle (\paperwidth,3cm);
  \foreach \x in {0.0,2.0, ..., 25.0}{\foreach \y in {1, ..., 4.0} \node[draw=none,color=green] at (\x,\y) {\tiny A};};
  \foreach \x in {1.0,3.0, ..., 25.0}{\foreach \y in {1, ..., 4.0}  \node[draw=none,color=cyan] at (\x,\y) {\tiny T};};
        \node[anchor=east,xshift=.9\paperwidth,rectangle,rounded corners=20pt,inner sep=11pt,fill=MidnightBlue]
        {\color{white}\partlabel#1};
    \end{tikzpicture}
};

\end{tikzpicture} } \titlespacing*{\chapter}{0pt}{50pt}{-60pt}

current result: result

Edit: Finally I found a conrrect way to display matrix of 1 and 0. I need to found how to randomize the number to print and when is 0 set white color ant 1 green colors. I updated the code not the picture

4

Here is a suggestion using the random function:

\documentclass[svgnames]{report}

\usepackage{tikz}
\colorlet{Random0}{white}
\colorlet{Random1}{green}
\usepackage{kpfonts}
\usepackage[explicit]{titlesec}
\newcommand*\chapterlabel{}
\titleformat{\chapter}
  {\gdef\chapterlabel{}
   \normalfont\sffamily\Huge\bfseries\scshape}
  {\gdef\chapterlabel{\thechapter\ }}{0pt}
  {\begin{tikzpicture}[remember picture,overlay,shift={(current page.north west)},yshift=-3cm]
        \path[fill=Black] (0,0) rectangle(\paperwidth,3cm);
        \foreach \x in {0,1, ..., 70}{
          \foreach \y in {0, ...,7} 
            \pgfmathsetmacro\Random{random(0,1)}
            \node[draw=none,color=Random\Random,anchor=south west,font=\tiny,xshift=-.05cm] 
              at (\x*.3cm,\y*.33cm) 
              {\Random};};
        \node[anchor=east,xshift=.9\paperwidth,rectangle,
              rounded corners=20pt,inner sep=11pt,
              fill=MidnightBlue]
              {\color{white}\chapterlabel#1};
   \end{tikzpicture}
  }
\titlespacing*{\chapter}{0pt}{50pt}{-60pt}
\begin{document}
\chapter{First chapter}
\end{document}

enter image description here

enter image description here

4

For fun, here is a solution in ConTeXt. Some remarks:

  1. I use OCR-A font to match the font used in the movie.
  2. I use three shades of green. Colors are defined in the HSV colorspace and the three colors just have different saturation values.
  3. I use a TABLE for typesetting for ease of use. One could have used a simple \halign as well.
  4. For ConTeXt users, this code also shows how to use the interfaces.definecommand function to define macros at the lua end.
\definecolor[green]      [h=120,s=1,v=0.75]
\definecolor[darkgreen]  [h=120,s=1,v=0.5]
\definecolor[brightgreen][h=120,s=1,v=1]

\startsetups matrix
  \setupTABLE[style={\definedfont[name:ocraextended]}, background=color, backgroundcolor=black]
  \setupTABLE[frame=off, offset=none]
\stopsetups

\setupbodyfont[dejavu]

\startluacode
  local colors = { "green", "darkgreen", "brightgreen" }
  local showNumber = function()
    local color  = math.random(3)
    local number = math.random(2) - 1
    context.style({color=colors[color]}, number)
  end

  local printMatrix = function(rows,cols)
    context.bTABLE{setups="matrix"}
      for i = 1,cols do
        context.bTR()
        for j = 1,rows do
          context.bTD()
            showNumber() 
          context.eTD()
        end
        context.eTR()
      end
    context.eTABLE()
  end

  interfaces.definecommand {
    name = "printMatrix",
    arguments = {
      { "option", "number" },
      { "option", "number" },
    },
    macro = printMatrix,
  }
\stopluacode

\starttext

\startTEXpage[offset=1mm]
\printMatrix[40][40]
\stopTEXpage

\stoptext

which gives

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.