How to use Tikz to calculate and use successive color values with text?












8















I'd like to use Tikz to algorithmically generate some text that has a color value based on calculations. Take the following, for example:



  documentclass{standalone}
usepackage{tikz}
begin{document}
begin{tikzpicture}
foreach i in {0, 1, ..., 10} {
draw (i, 0) node {textcolor[gray]{0.5}A};
}
end{tikzpicture}
end{document}


This displays a row of "A"s in a gray:



enter image description here



How do I go about calculating the 0.5 value to, for example, display this set of "A"s in varying levels of gray, such as a black to white gradient? Could I use this same method to calculate arbitrary RGB values?










share|improve this question



























    8















    I'd like to use Tikz to algorithmically generate some text that has a color value based on calculations. Take the following, for example:



      documentclass{standalone}
    usepackage{tikz}
    begin{document}
    begin{tikzpicture}
    foreach i in {0, 1, ..., 10} {
    draw (i, 0) node {textcolor[gray]{0.5}A};
    }
    end{tikzpicture}
    end{document}


    This displays a row of "A"s in a gray:



    enter image description here



    How do I go about calculating the 0.5 value to, for example, display this set of "A"s in varying levels of gray, such as a black to white gradient? Could I use this same method to calculate arbitrary RGB values?










    share|improve this question

























      8












      8








      8


      1






      I'd like to use Tikz to algorithmically generate some text that has a color value based on calculations. Take the following, for example:



        documentclass{standalone}
      usepackage{tikz}
      begin{document}
      begin{tikzpicture}
      foreach i in {0, 1, ..., 10} {
      draw (i, 0) node {textcolor[gray]{0.5}A};
      }
      end{tikzpicture}
      end{document}


      This displays a row of "A"s in a gray:



      enter image description here



      How do I go about calculating the 0.5 value to, for example, display this set of "A"s in varying levels of gray, such as a black to white gradient? Could I use this same method to calculate arbitrary RGB values?










      share|improve this question














      I'd like to use Tikz to algorithmically generate some text that has a color value based on calculations. Take the following, for example:



        documentclass{standalone}
      usepackage{tikz}
      begin{document}
      begin{tikzpicture}
      foreach i in {0, 1, ..., 10} {
      draw (i, 0) node {textcolor[gray]{0.5}A};
      }
      end{tikzpicture}
      end{document}


      This displays a row of "A"s in a gray:



      enter image description here



      How do I go about calculating the 0.5 value to, for example, display this set of "A"s in varying levels of gray, such as a black to white gradient? Could I use this same method to calculate arbitrary RGB values?







      tikz-pgf color






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 21 '18 at 15:28









      RoxyRoxy

      3565




      3565






















          4 Answers
          4






          active

          oldest

          votes


















          8














          Yes, you can vary the gray levels, and the following can be used also to general non-gray colors.



          documentclass{standalone}
          usepackage{tikz}
          begin{document}
          begin{tikzpicture}
          foreach i [evaluate=i as j using {int(i*10)}] in {0, 1, ..., 10} {
          draw (i, 0) node[text=gray!j!white] {A};
          }
          end{tikzpicture}
          end{document}


          enter image description here






          share|improve this answer































            6














            Just for fun, another foreach solution:



            documentclass{standalone}
            usepackage{tikz}
            begin{document}
            begin{tikzpicture}
            foreach i [count=j] in {0, 10, ..., 100} {
            draw (j, 0) node[text=blue!i!red] {A};
            }
            end{tikzpicture}
            end{document}


            enter image description here






            share|improve this answer































              5














              You can evaluate a variable within the foreach loop itself (see page 904 of 3.0.1a manual).



              Here since you want to go from black to white, you can do:



              result



              documentclass{standalone}
              usepackage{tikz}
              begin{document}
              begin{tikzpicture}
              foreach i [evaluate=i as gradient using 100-i*10] in {0, 1, ..., 10} {
              draw (i, 0) node[text=black!gradient] {A};
              }
              end{tikzpicture}
              end{document}





              share|improve this answer































                4














                A slightly different syntax than what marmot proposed, but with the same effects



                documentclass[tikz,border=3.14pt]{standalone}
                begin{document}
                begin{tikzpicture}
                draw foreach i [evaluate=i as j using {int(i*10)}] in {0, 1, ..., 10} {
                (i, 0) node[text=gray!j!white] {A}
                };
                end{tikzpicture}
                end{document}





                share|improve this answer
























                  Your Answer








                  StackExchange.ready(function() {
                  var channelOptions = {
                  tags: "".split(" "),
                  id: "85"
                  };
                  initTagRenderer("".split(" "), "".split(" "), channelOptions);

                  StackExchange.using("externalEditor", function() {
                  // Have to fire editor after snippets, if snippets enabled
                  if (StackExchange.settings.snippets.snippetsEnabled) {
                  StackExchange.using("snippets", function() {
                  createEditor();
                  });
                  }
                  else {
                  createEditor();
                  }
                  });

                  function createEditor() {
                  StackExchange.prepareEditor({
                  heartbeatType: 'answer',
                  autoActivateHeartbeat: false,
                  convertImagesToLinks: false,
                  noModals: true,
                  showLowRepImageUploadWarning: true,
                  reputationToPostImages: null,
                  bindNavPrevention: true,
                  postfix: "",
                  imageUploader: {
                  brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
                  contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
                  allowUrls: true
                  },
                  onDemand: true,
                  discardSelector: ".discard-answer"
                  ,immediatelyShowMarkdownHelp:true
                  });


                  }
                  });














                  draft saved

                  draft discarded


















                  StackExchange.ready(
                  function () {
                  StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f461139%2fhow-to-use-tikz-to-calculate-and-use-successive-color-values-with-text%23new-answer', 'question_page');
                  }
                  );

                  Post as a guest















                  Required, but never shown

























                  4 Answers
                  4






                  active

                  oldest

                  votes








                  4 Answers
                  4






                  active

                  oldest

                  votes









                  active

                  oldest

                  votes






                  active

                  oldest

                  votes









                  8














                  Yes, you can vary the gray levels, and the following can be used also to general non-gray colors.



                  documentclass{standalone}
                  usepackage{tikz}
                  begin{document}
                  begin{tikzpicture}
                  foreach i [evaluate=i as j using {int(i*10)}] in {0, 1, ..., 10} {
                  draw (i, 0) node[text=gray!j!white] {A};
                  }
                  end{tikzpicture}
                  end{document}


                  enter image description here






                  share|improve this answer




























                    8














                    Yes, you can vary the gray levels, and the following can be used also to general non-gray colors.



                    documentclass{standalone}
                    usepackage{tikz}
                    begin{document}
                    begin{tikzpicture}
                    foreach i [evaluate=i as j using {int(i*10)}] in {0, 1, ..., 10} {
                    draw (i, 0) node[text=gray!j!white] {A};
                    }
                    end{tikzpicture}
                    end{document}


                    enter image description here






                    share|improve this answer


























                      8












                      8








                      8







                      Yes, you can vary the gray levels, and the following can be used also to general non-gray colors.



                      documentclass{standalone}
                      usepackage{tikz}
                      begin{document}
                      begin{tikzpicture}
                      foreach i [evaluate=i as j using {int(i*10)}] in {0, 1, ..., 10} {
                      draw (i, 0) node[text=gray!j!white] {A};
                      }
                      end{tikzpicture}
                      end{document}


                      enter image description here






                      share|improve this answer













                      Yes, you can vary the gray levels, and the following can be used also to general non-gray colors.



                      documentclass{standalone}
                      usepackage{tikz}
                      begin{document}
                      begin{tikzpicture}
                      foreach i [evaluate=i as j using {int(i*10)}] in {0, 1, ..., 10} {
                      draw (i, 0) node[text=gray!j!white] {A};
                      }
                      end{tikzpicture}
                      end{document}


                      enter image description here







                      share|improve this answer












                      share|improve this answer



                      share|improve this answer










                      answered Nov 21 '18 at 15:33









                      marmotmarmot

                      113k5144273




                      113k5144273























                          6














                          Just for fun, another foreach solution:



                          documentclass{standalone}
                          usepackage{tikz}
                          begin{document}
                          begin{tikzpicture}
                          foreach i [count=j] in {0, 10, ..., 100} {
                          draw (j, 0) node[text=blue!i!red] {A};
                          }
                          end{tikzpicture}
                          end{document}


                          enter image description here






                          share|improve this answer




























                            6














                            Just for fun, another foreach solution:



                            documentclass{standalone}
                            usepackage{tikz}
                            begin{document}
                            begin{tikzpicture}
                            foreach i [count=j] in {0, 10, ..., 100} {
                            draw (j, 0) node[text=blue!i!red] {A};
                            }
                            end{tikzpicture}
                            end{document}


                            enter image description here






                            share|improve this answer


























                              6












                              6








                              6







                              Just for fun, another foreach solution:



                              documentclass{standalone}
                              usepackage{tikz}
                              begin{document}
                              begin{tikzpicture}
                              foreach i [count=j] in {0, 10, ..., 100} {
                              draw (j, 0) node[text=blue!i!red] {A};
                              }
                              end{tikzpicture}
                              end{document}


                              enter image description here






                              share|improve this answer













                              Just for fun, another foreach solution:



                              documentclass{standalone}
                              usepackage{tikz}
                              begin{document}
                              begin{tikzpicture}
                              foreach i [count=j] in {0, 10, ..., 100} {
                              draw (j, 0) node[text=blue!i!red] {A};
                              }
                              end{tikzpicture}
                              end{document}


                              enter image description here







                              share|improve this answer












                              share|improve this answer



                              share|improve this answer










                              answered Nov 21 '18 at 19:48









                              IgnasiIgnasi

                              95.5k4175319




                              95.5k4175319























                                  5














                                  You can evaluate a variable within the foreach loop itself (see page 904 of 3.0.1a manual).



                                  Here since you want to go from black to white, you can do:



                                  result



                                  documentclass{standalone}
                                  usepackage{tikz}
                                  begin{document}
                                  begin{tikzpicture}
                                  foreach i [evaluate=i as gradient using 100-i*10] in {0, 1, ..., 10} {
                                  draw (i, 0) node[text=black!gradient] {A};
                                  }
                                  end{tikzpicture}
                                  end{document}





                                  share|improve this answer




























                                    5














                                    You can evaluate a variable within the foreach loop itself (see page 904 of 3.0.1a manual).



                                    Here since you want to go from black to white, you can do:



                                    result



                                    documentclass{standalone}
                                    usepackage{tikz}
                                    begin{document}
                                    begin{tikzpicture}
                                    foreach i [evaluate=i as gradient using 100-i*10] in {0, 1, ..., 10} {
                                    draw (i, 0) node[text=black!gradient] {A};
                                    }
                                    end{tikzpicture}
                                    end{document}





                                    share|improve this answer


























                                      5












                                      5








                                      5







                                      You can evaluate a variable within the foreach loop itself (see page 904 of 3.0.1a manual).



                                      Here since you want to go from black to white, you can do:



                                      result



                                      documentclass{standalone}
                                      usepackage{tikz}
                                      begin{document}
                                      begin{tikzpicture}
                                      foreach i [evaluate=i as gradient using 100-i*10] in {0, 1, ..., 10} {
                                      draw (i, 0) node[text=black!gradient] {A};
                                      }
                                      end{tikzpicture}
                                      end{document}





                                      share|improve this answer













                                      You can evaluate a variable within the foreach loop itself (see page 904 of 3.0.1a manual).



                                      Here since you want to go from black to white, you can do:



                                      result



                                      documentclass{standalone}
                                      usepackage{tikz}
                                      begin{document}
                                      begin{tikzpicture}
                                      foreach i [evaluate=i as gradient using 100-i*10] in {0, 1, ..., 10} {
                                      draw (i, 0) node[text=black!gradient] {A};
                                      }
                                      end{tikzpicture}
                                      end{document}






                                      share|improve this answer












                                      share|improve this answer



                                      share|improve this answer










                                      answered Nov 21 '18 at 15:42









                                      AndréCAndréC

                                      10.5k11548




                                      10.5k11548























                                          4














                                          A slightly different syntax than what marmot proposed, but with the same effects



                                          documentclass[tikz,border=3.14pt]{standalone}
                                          begin{document}
                                          begin{tikzpicture}
                                          draw foreach i [evaluate=i as j using {int(i*10)}] in {0, 1, ..., 10} {
                                          (i, 0) node[text=gray!j!white] {A}
                                          };
                                          end{tikzpicture}
                                          end{document}





                                          share|improve this answer




























                                            4














                                            A slightly different syntax than what marmot proposed, but with the same effects



                                            documentclass[tikz,border=3.14pt]{standalone}
                                            begin{document}
                                            begin{tikzpicture}
                                            draw foreach i [evaluate=i as j using {int(i*10)}] in {0, 1, ..., 10} {
                                            (i, 0) node[text=gray!j!white] {A}
                                            };
                                            end{tikzpicture}
                                            end{document}





                                            share|improve this answer


























                                              4












                                              4








                                              4







                                              A slightly different syntax than what marmot proposed, but with the same effects



                                              documentclass[tikz,border=3.14pt]{standalone}
                                              begin{document}
                                              begin{tikzpicture}
                                              draw foreach i [evaluate=i as j using {int(i*10)}] in {0, 1, ..., 10} {
                                              (i, 0) node[text=gray!j!white] {A}
                                              };
                                              end{tikzpicture}
                                              end{document}





                                              share|improve this answer













                                              A slightly different syntax than what marmot proposed, but with the same effects



                                              documentclass[tikz,border=3.14pt]{standalone}
                                              begin{document}
                                              begin{tikzpicture}
                                              draw foreach i [evaluate=i as j using {int(i*10)}] in {0, 1, ..., 10} {
                                              (i, 0) node[text=gray!j!white] {A}
                                              };
                                              end{tikzpicture}
                                              end{document}






                                              share|improve this answer












                                              share|improve this answer



                                              share|improve this answer










                                              answered Nov 21 '18 at 15:45









                                              BambOoBambOo

                                              3,0811527




                                              3,0811527






























                                                  draft saved

                                                  draft discarded




















































                                                  Thanks for contributing an answer to TeX - LaTeX Stack Exchange!


                                                  • Please be sure to answer the question. Provide details and share your research!

                                                  But avoid



                                                  • Asking for help, clarification, or responding to other answers.

                                                  • Making statements based on opinion; back them up with references or personal experience.


                                                  To learn more, see our tips on writing great answers.




                                                  draft saved


                                                  draft discarded














                                                  StackExchange.ready(
                                                  function () {
                                                  StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f461139%2fhow-to-use-tikz-to-calculate-and-use-successive-color-values-with-text%23new-answer', 'question_page');
                                                  }
                                                  );

                                                  Post as a guest















                                                  Required, but never shown





















































                                                  Required, but never shown














                                                  Required, but never shown












                                                  Required, but never shown







                                                  Required, but never shown

































                                                  Required, but never shown














                                                  Required, but never shown












                                                  Required, but never shown







                                                  Required, but never shown







                                                  Popular posts from this blog

                                                  鏡平學校

                                                  ꓛꓣだゔៀៅຸ໢ທຮ໕໒ ,ໂ'໥໓າ໼ឨឲ៵៭ៈゎゔit''䖳𥁄卿' ☨₤₨こゎもょの;ꜹꟚꞖꞵꟅꞛေၦေɯ,ɨɡ𛃵𛁹ޝ޳ޠ޾,ޤޒޯ޾𫝒𫠁သ𛅤チョ'サノބޘދ𛁐ᶿᶇᶀᶋᶠ㨑㽹⻮ꧬ꧹؍۩وَؠ㇕㇃㇪ ㇦㇋㇋ṜẰᵡᴠ 軌ᵕ搜۳ٰޗޮ޷ސޯ𫖾𫅀ल, ꙭ꙰ꚅꙁꚊꞻꝔ꟠Ꝭㄤﺟޱސꧨꧼ꧴ꧯꧽ꧲ꧯ'⽹⽭⾁⿞⼳⽋២៩ញណើꩯꩤ꩸ꩮᶻᶺᶧᶂ𫳲𫪭𬸄𫵰𬖩𬫣𬊉ၲ𛅬㕦䬺𫝌𫝼,,𫟖𫞽ហៅ஫㆔ాఆఅꙒꚞꙍ,Ꙟ꙱エ ,ポテ,フࢰࢯ𫟠𫞶 𫝤𫟠ﺕﹱﻜﻣ𪵕𪭸𪻆𪾩𫔷ġ,ŧآꞪ꟥,ꞔꝻ♚☹⛵𛀌ꬷꭞȄƁƪƬșƦǙǗdžƝǯǧⱦⱰꓕꓢႋ神 ဴ၀க௭எ௫ឫោ ' េㇷㇴㇼ神ㇸㇲㇽㇴㇼㇻㇸ'ㇸㇿㇸㇹㇰㆣꓚꓤ₡₧ ㄨㄟ㄂ㄖㄎ໗ツڒذ₶।ऩछएोञयूटक़कयँृी,冬'𛅢𛅥ㇱㇵㇶ𥄥𦒽𠣧𠊓𧢖𥞘𩔋цѰㄠſtʯʭɿʆʗʍʩɷɛ,əʏダヵㄐㄘR{gỚṖḺờṠṫảḙḭᴮᵏᴘᵀᵷᵕᴜᴏᵾq﮲ﲿﴽﭙ軌ﰬﶚﶧ﫲Ҝжюїкӈㇴffצּ﬘﭅﬈軌'ffistfflſtffतभफɳɰʊɲʎ𛁱𛁖𛁮𛀉 𛂯𛀞నఋŀŲ 𫟲𫠖𫞺ຆຆ ໹້໕໗ๆทԊꧢꧠ꧰ꓱ⿝⼑ŎḬẃẖỐẅ ,ờỰỈỗﮊDžȩꭏꭎꬻ꭮ꬿꭖꭥꭅ㇭神 ⾈ꓵꓑ⺄㄄ㄪㄙㄅㄇstA۵䞽ॶ𫞑𫝄㇉㇇゜軌𩜛𩳠Jﻺ‚Üမ႕ႌႊၐၸဓၞၞၡ៸wyvtᶎᶪᶹစဎ꣡꣰꣢꣤ٗ؋لㇳㇾㇻㇱ㆐㆔,,㆟Ⱶヤマފ޼ޝަݿݞݠݷݐ',ݘ,ݪݙݵ𬝉𬜁𫝨𫞘くせぉて¼óû×ó£…𛅑הㄙくԗԀ5606神45,神796'𪤻𫞧ꓐ㄁ㄘɥɺꓵꓲ3''7034׉ⱦⱠˆ“𫝋ȍ,ꩲ軌꩷ꩶꩧꩫఞ۔فڱێظペサ神ナᴦᵑ47 9238їﻂ䐊䔉㠸﬎ffiﬣ,לּᴷᴦᵛᵽ,ᴨᵤ ᵸᵥᴗᵈꚏꚉꚟ⻆rtǟƴ𬎎

                                                  Why https connections are so slow when debugging (stepping over) in Java?