lilypond-learning: The color property
The ‘color’ property
....................
Finally let us try making the bar lines invisible by coloring them
white. (There is a difficulty with this in that the white bar line may
or may not blank out the staff lines where they cross. You may see in
some of the examples below that this happens unpredictably. The details
of why this is so and how to control it are covered in
(lilypond-notation)Painting objects white. But at the moment we are
learning about color, so please just accept this limitation for now.)
The ‘grob-interface’ specifies that the color property value is a
list, but there is no explanation of what that list should be. The list
it requires is actually a list of values in internal units, but, to
avoid having to know what these are, several ways are provided to
specify colors. The first way is to use one of the ‘normal’ colors
listed in the first table in (lilypond-notation)List of colors.
To set the bar lines to white we write:
{
\time 12/16
\override Staff.BarLine.color = #white
c4 b8 c d16 c d8 |
g,8 a16 b8 c d4 e16 |
e8
}
[image src="" alt="[image of music]" text="image of music" ]
and again, we see the bar lines are not visible. Note that _white_ is
not preceded by an apostrophe – it is not a symbol, but a _variable_.
When evaluated, it provides the list of internal values required to set
the color to white. The other colors in the normal list are variables
too. To convince yourself this is working you might like to change the
color to one of the other variables in the list.
The second way of changing the color is to use the list of X11 color
names in the second list in (lilypond-notation)List of colors.
However, these are mapped to the actual values by the function
‘x11-color’ which converts X11 color symbols into the list of internal
values like this:
{
\time 12/16
\override Staff.BarLine.color = #(x11-color 'white)
c4 b8 c d16 c d8 |
g,8 a16 b8 c d4 e16 |
e8
}
[image src="" alt="[image of music]" text="image of music" ]
Note that in this case the function ‘x11-color’ takes a symbol as an
argument, so the symbol must be preceded by an apostrophe to keep it
from being evaluated as a variable, and the whole function call has to
be enclosed in parentheses.
There is another function, one which converts RGB values into
internal colors – the ‘rgb-color’ function. This takes three arguments
giving the intensities of the red, green and blue colors. These take
values in the range 0 to 1. So to set the color to red the value should
be ‘(rgb-color 1 0 0)’ and to white it should be ‘(rgb-color 1 1 1)’:
{
\time 12/16
\override Staff.BarLine.color = #(rgb-color 1 1 1)
c4 b8 c d16 c d8 |
g,8 a16 b8 c d4 e16 |
e8
}
[image src="" alt="[image of music]" text="image of music" ]
Finally, there is also a grey scale available as part of the X11 set
of colors. These range from black, ‘'grey0’, to white, ‘'grey100’, in
steps of 1. Let’s illustrate this by setting all the layout objects in
our example to various shades of grey:
{
\time 12/16
\override Staff.StaffSymbol.color = #(x11-color 'grey30)
\override Staff.TimeSignature.color = #(x11-color 'grey60)
\override Staff.Clef.color = #(x11-color 'grey60)
\override Voice.NoteHead.color = #(x11-color 'grey85)
\override Voice.Stem.color = #(x11-color 'grey85)
\override Staff.BarLine.color = #(x11-color 'grey10)
c4 b8 c d16 c d8 |
g,8 a16 b8 c d4 e16 |
e8
}
[image src="" alt="[image of music]" text="image of music" ]
Note the contexts associated with each of the layout objects. It is
important to get these right, or the commands will not work! Remember,
the context is the one in which the appropriate engraver is placed. The
default context for engravers can be found by starting from the layout
object, going from there to the engraver which produces it, and on the
engraver page in the IR it tells you in which context the engraver will
normally be found.