Canvas: Clipping, Masking, Pattern
Clipping:
Clipping is a way to hide unwanted parts of the shape. It just uses geometrical shapes to define the clip area, with no style effects. I2Djs createClip()
API, lets you define the clip area as shown below.
ClipInstance to be applied to the shape via 'clip-Path' style property as given below.
Masking:
Masking is a way to apply complex, detailed shapes with styles on the elements. With the masking technique, one can implement beautiful visual effects and performant alternatives to other techniques.
I2Djs createMask()
API to create mask instance. globalCompositeOperation of the maskInstance can be altered to leverage Canvas multi masking composition to create different effects. By default it is set to - 'destination-atop' composition.
Below example shows a way to define the mask using I2Djs createMask()
.
Maskinstance to be applied as a mask style property on the element as shown below.