# Drawing a B/W grating

I'm trying to create a .tif or .jpg image that will be used in full screen mode. The image should be filled with black and white thick lines. I need to set a width variable so I can create different images with different line thickness. I can't figure out how to do it. Any ideas ?

• Welcome to TeX.SX! What has this to do with TeX/LaTeX? In telling us that you should provide some sample code. Commented Mar 1, 2015 at 16:49
• Hello :) I'm just trying to learn the language and i wanted to start with some simple example to compare with other languages and understand well how it works! I started to learn a bit but i wanted some example to compare with somethign i already done with other languages. Commented Mar 1, 2015 at 17:01
• Which language exactly? You have an answer which uses TiKZ and LaTeX. But there are, of course, other possibilities. Note that drawing graphics is not TeX's strength i.e. this is not something at the heart of what TeX itself was/is designed to do. So you are beginning by trying to figure out how to complete a task which is somewhat alien to the system you are trying to learn. This suggests to me that you would be better advised to do a little more background reading first....
– cfr
Commented Mar 1, 2015 at 18:07
• I did something very similar to this on MATLAB. Sometimes I have some tasks that consist of creating images with geometrical figures with exact size ( usually very small sizes).As on MATLAB it's not such an easy task I'm tring to find some other viable alternatives. ( MATLAB core is statistical analysis and plotting ) Commented Mar 1, 2015 at 18:13
• @cfr You think I can use it for this purpose? In some cases the thickness of some lines of the image can get to 0,15 mm Commented Mar 1, 2015 at 18:25

Some thing like this?

\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\foreach \x in {2,4,6,...,48}{
\draw[line width=1mm] (\x mm,0) -- (\x mm, 2);
}
\begin{scope}[yshift=3cm]
\foreach \x in {3,6,...,48}{
\draw[line width=1.5mm] (\x mm,0) -- (\x mm, 2);
}
\end{scope}
\end{tikzpicture}
\end{document}


To get it in .jpg format, compile this code:

\documentclass[tikz,convert=jpg]{standalone}
\begin{document}
\begin{tikzpicture}
\foreach \x in {2,4,6,...,48}{
\draw[line width=1mm] (\x mm,0) -- (\x mm, 2);
}
\end{tikzpicture}
\end{document}


with imagemagick installed and -shell-escape option enabled.

To use it in full screen, compile this code

\documentclass[tikz,convert=jpg]{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\foreach \x in {2,4,6,...,48}{
\draw[line width=1mm] (\x mm,0) -- (\x mm, 2);
}
\end{tikzpicture}
\end{document}


and put it in full screen (press ctrl+L)

• That works perfectly! thank you:) is there any function to plot it full screen ( from beginning to end of the screen ) and get it on .jpg or similar file ? Commented Mar 1, 2015 at 17:06
• I'm used to work with MATLAB and I created something similar to this but with a slight difference. Once the code was executed it would create a .tif image that was filled by those b/w lines. The first column would start at the beginning of the screen and the last column at the end of the screen. Commented Mar 1, 2015 at 17:22
• Yes exactly this. How can I start drwaing from the beginning till the end of the screen ? Thank you for your help. Commented Mar 1, 2015 at 17:32
• The effect of ctrl + L will depend on your viewer and OS, of course...
– cfr
Commented Mar 1, 2015 at 18:03
• The problem in doing like this is that in Full Screen mode the width of the lines is different from actual one because it's like i'm zooming. Commented Mar 1, 2015 at 18:05