How to use Tikz to calculate and use successive color values with text?
up vote
8
down vote
favorite
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:
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
New contributor
add a comment |
up vote
8
down vote
favorite
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:
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
New contributor
add a comment |
up vote
8
down vote
favorite
up vote
8
down vote
favorite
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:
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
New contributor
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:
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
tikz-pgf color
New contributor
New contributor
New contributor
asked Nov 21 at 15:28
Roxy
2824
2824
New contributor
New contributor
add a comment |
add a comment |
4 Answers
4
active
oldest
votes
up vote
8
down vote
accepted
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}
add a comment |
up vote
6
down vote
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}
add a comment |
up vote
5
down vote
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:
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}
add a comment |
up vote
4
down vote
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}
add a comment |
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
8
down vote
accepted
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}
add a comment |
up vote
8
down vote
accepted
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}
add a comment |
up vote
8
down vote
accepted
up vote
8
down vote
accepted
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}
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}
answered Nov 21 at 15:33
marmot
78.4k487166
78.4k487166
add a comment |
add a comment |
up vote
6
down vote
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}
add a comment |
up vote
6
down vote
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}
add a comment |
up vote
6
down vote
up vote
6
down vote
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}
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}
answered Nov 21 at 19:48
Ignasi
90.3k4163302
90.3k4163302
add a comment |
add a comment |
up vote
5
down vote
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:
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}
add a comment |
up vote
5
down vote
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:
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}
add a comment |
up vote
5
down vote
up vote
5
down vote
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:
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}
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:
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}
answered Nov 21 at 15:42
AndréC
6,24711140
6,24711140
add a comment |
add a comment |
up vote
4
down vote
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}
add a comment |
up vote
4
down vote
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}
add a comment |
up vote
4
down vote
up vote
4
down vote
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}
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}
answered Nov 21 at 15:45
BambOo
2,9661526
2,9661526
add a comment |
add a comment |
Roxy is a new contributor. Be nice, and check out our Code of Conduct.
Roxy is a new contributor. Be nice, and check out our Code of Conduct.
Roxy is a new contributor. Be nice, and check out our Code of Conduct.
Roxy is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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