|  |  | 8.4 Gradient patterns

## 8.4 Gradient patterns

Gradient patterns allow to shade objects with continuously changing colors. This is often used for backgrounds, or to achieve the illusion of three-dimensional spheres or cylinders.

The intended use of gradients is to allow the creation of attractive symbols inside the style sheet, for backgrounds, as bullets in item lists (see next section), or simply to define attractive glassy-ball symbols and the like that can be used through the Use symbol ipelet.

The Ipe user interface does not offer any way of creating or editing gradients. If your stylesheet defines a gradient, then it is possible to fill a path object with this gradient, but getting the gradient coordinate system right is not trivial. (The trick is to draw the path object at gradient coordinates, and translate/rotate it to the final location afterwards.)

The definition of a linear (axial) gradient looks like this:

      <gradient name="linear" type="axial" extend="yes" coords="75 0 325 0">
        <stop offset="0.05" color="1 0.4 0"/>
        <stop offset="0.95" color="1 1 0.4"/>
      </gradient>

If used like this:

      <path stroke="0" fill="1" gradient="linear" pen="3">
        50 50 m 350 50 l 350 150 l 50 150 l h
      </path>

it will look like this:

A radial gradient looks like this:

      <gradient name="radial" type="radial" extend="yes"
      	    coords="200 100 0 200 100 150">
        <stop offset="0" color="1 0 0"/>
        <stop offset="0.5" color="0 0 1"/>
        <stop offset="1" color="1 0 0"/>
      </gradient>

It will look like this:

A common use of radial gradients is to define glassy balls like this:

      <gradient name="ball" type="radial" coords="-4 10 2 0 0 18">
        <stop offset="0" color="1 1 1"/>
        <stop offset="1" color="0 0 1"/>
      </gradient>

Note that the gradient is centered at 0 0, so it needs to be moved to the location where it is used:

      <path matrix="3 0 0 3 100 100" fill="1" gradient="ball">
        18 0 0 18 0 0 e
      </path>

Normally, you would define a symbol looking like a glassy ball in your style sheet:

    <ipestyle>
      <gradient name="ball" type="radial" coords="-4 10 2 0 0 18">
        <stop offset="0" color="1 1 1"/>
        <stop offset="1" color="0 0 1"/>
      </gradient>
      <symbol name="ball(x)" transformations="translations">
        <path fill="1" gradient="ball"> 18 0 0 18 0 0 e </path>
      </symbol>
    </ipestyle>

The glassy ball can then be used in the document using the Use symbol ipelet. Note that `transformations="translations"` ensures that stretching your drawing does not change the glassy ball. Adding the `(x)` suffix to the symbol name allows you to resize the glassy ball by changing the symbol size from the properties (the same selector used to change the mark size).

For the precise syntax of the gradient definition see here. The easiest method of creating gradients, though, is to use an SVG editor such as Inkscape and to convert the SVG gradient to Ipe format using Svgtoipe.