MeshGradient
A two-dimensional gradient defined by a 2D grid of positioned colors.
Declaration
type MeshGradient =
| { width: number; height: number; bezierPoints: MeshGradientBezierPoint[]; colors: Color[]; background?: Color; smoothsColors?: boolean; colorSpace?: GradientColorSpace; }
| { width: number; height: number; bezierPoints: MeshGradientBezierPoint[]; resolvedColors: ColorResolved[]; background?: Color; smoothsColors?: boolean; colorSpace?: GradientColorSpace; }
| { width: number; height: number; locations: MeshGradientLocations; colors: MeshGradientColors; background?: Color; smoothsColors?: boolean; colorSpace?: GradientColorSpace; }
| { width: number; height: number; points: [ x: number, y: number ][]; colors: Color[]; background?: Color; smoothsColors?: boolean; colorSpace?: GradientColorSpace; }
| { width: number; height: number; points: [ x: number, y: number ][]; resolvedColors: ColorResolved[]; background?: Color; smoothsColors?: boolean; colorSpace?: GradientColorSpace; };nonisolated struct MeshGradientOverview
Each vertex has a position, a color and four surrounding Bezier control points (leading, top, trailing, bottom) that define the tangents connecting the vertex with its four neighboring vertices. (Vertices on the corners or edges of the mesh have less than four neighbors, they ignore their extra control points.) Control points may either be specified explicitly or implicitly.
When rendering, a tessellated sequence of Bezier patches are created, and vertex colors are interpolated across each patch, either linearly, or via another set of cubic curves derived from how the colors change between neighbors -- the latter typically gives smoother color transitions.
MeshGradient(width: 3, height: 3, points: [
.init(0, 0), .init(0.5, 0), .init(1, 0),
.init(0, 0.5), .init(0.5, 0.5), .init(1, 0.5),
.init(0, 1), .init(0.5, 1), .init(1, 1)
], colors: [
.red, .purple, .indigo,
.orange, .white, .blue,
.yellow, .green, .mint
])From Apple’s SwiftUI documentation. Code samples there are Swift.
See also
More in Drawing and shapes.
- AngleA geometric angle whose value you access in either radians or degrees.
- AngularGradientAn angular gradient.
- AnyGradientA color gradient.
- BlendModeModes for compositing a view with overlapping content.
- ButtonBorderShapeA shape used to draw a button's border.
- ColorMatrixA matrix to use in an RGBA color transformation.
- ConcentricRectangleAnimatableDataThe type defining the data to animate.
- ContainerRelativeShapeA shape that is replaced by an inset version of the current container shape. If no container shape was defined, is replaced by a rectangle.
- ContentShapeKindsA kind for the content shape of a view.
- CoordinateSpaceProtocolA frame of reference within the layout system.
- DefaultGlassEffectShapeThe default shape applied by glass effects, a capsule.
- EllipticalGradientA radial gradient that draws an ellipse.