Skip to: Site menu | Main content

Groovy 

      Download | Documentation | Developers | Community

An agile dynamic language for the Java Platform

GraphicsBuilder - Paints - MultiPaint Add comment to Wiki View in Wiki Edit Wiki page Printable Version

MultiPaints allow several paints to be applied to the same shape.

Example

The following example is taken from chapter 7 of Filthy Rich Clients where 3 gradients are applied to a circle in order to create the illusion of a sphere

def width = 200
def height = 200
renderingHint( key: 'antialiasing', value: 'antialias on' )
circle( cx: width/2, cy: height/2, radius: width/2, borderColor: false ){
   multiPaint {
      radialGradient( cx: width/2, cy: height/2, radius: width/2 ) {
         stop( offset: 0, color: color(red: 6, green: 76, blue: 160, alpha: 127) )
         stop( offset: 1, color: color(alpha: 204) )
      }
      def lighting = color(red: 64, green: 142, blue: 203, alpha: 255)
      radialGradient( cx: width/2, cy: height*1.5,
                      fx: width/2, fy: (height*1.75)+6,
                      radius: width/2 ) {
         stop( offset: 0, color: lighting )
         stop( offset: 0.8, color: lighting.derive(alpha:0) )
         transformations{ scale(y:0.5) }
      }
      radialGradient( cx: width/2, cy: height/2,
                      fx: 45, fy: 25, radius: width/1.4 ){
         stop( offset: 0, color: color('white').derive(alpha:0.4) )
         stop( offset: 0.5, color: color('white').derive(alpha:0) )
      }
   }
}