I need to define 256 pixel colors in HEX values like this:

\definecolor{pixel 1}{HTML}{000000} ... \definecolor{pixel 256}{HTML}{FFFFFF}

Can I do that in a form of a simple loop? How?


You can define the 256 grey shades from black to white using the forloop package like this:



\forloop{loop}{0}{\value{loop}<256}{\definecolor{pixel \arabic{loop}}{RGB}{\arabic{loop},\arabic{loop},\arabic{loop}}}


\forloop[10]{loop}{0}{\value{loop}<256}{\textcolor{pixel \arabic{loop}}{pixel~\arabic{loop}} }


enter image description here

  • 1
    Thanks. I ended up doing this: \foreach \name/\n in {0,...,255}{ \pgfmathsetmacro\k{\n*0.004} \xglobal\definecolor{pixel \name}{gray}{\k} } – Rodrigo May 15 '17 at 6:24

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.