GraphicsBuilder - Paints - LinearGradient

Creates a linear gradient of many colors.

Requires graphicsbuilder-ext-jdk6 and Java6+.

Properties

Property Default Notes
x1 0  
y1 0  
x2 100  
y2 0  
cycle 'nocycle' value must be any of ['nocycle','reflect','repeat] or any MultipleGradientPaint.CycleMethod
stretch false Scales the gradient to fit the Shape's bounds
fit true Scales the gradient retaining the aspect ratio
stops [] must define at least two stops
linkTo   a reference to a linearGradient or a radialGradient

If linkTo is used, then this gradient will reuse the referenced one's stops, new stops may be added to this gradient though.

Stops

Property Default Notes
offset   a float value in the range [0..1]
color   a Color or a color string
opacity   must be in the range [0..1]

Example

4 rectangles, each one with a diagonal gradient

def stops = {
   def offsets = [0,0.5,1]
   def colors = ['black','red','blue']
   (0..2).each{ stop( offset: offsets[it], color: colors[it] ) }
}
rect( x: 0, y: 0, width: 100, height: 100 ){
   linearGradient( x1: 0, y1: 0, x2: 50, y2: 50 ){ stops() }
}
rect( x: 100, y: 0, width: 100, height: 100 ){
   linearGradient( x1: 50, y1: 0, x2: 0, y2: 50 ){ stops() }
}
rect( x: 0, y: 100, width: 100, height: 100 ){
   linearGradient( x1: 0, y1: 50, x2: 50, y2: 0 ){ stops() }
}
rect( x: 100, y: 100, width: 100, height: 100 ){
   linearGradient( x1: 50, y1: 50, x2: 0, y2: 0 ){ stops() }
}

Different settings for fit, stretch and cycle

def stops = {
   def offsets = [0,0.5,1]
   def colors = ['black','red','blue']
   (0..2).each{ stop( offset: offsets[it], color: colors[it] ) }
}
inearGradient( x1: 0, y1: 0, x2: 50, y2: 50, id: 'g1' ){ stops() }
rect( x: 0, y: 0, width: 100, height: 100, fill: g1 )
circle( cx: 150, cy: 50, radius: 50, fill: g1 )
rect( x: 0, y: 100, width: 200, height: 100, fill: g1 )
 

Labels

 
(None)