1e41f4b71Sopenharmony_ci# Color Effect
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ci
4e41f4b71Sopenharmony_ci## Color
5e41f4b71Sopenharmony_ci
6e41f4b71Sopenharmony_ciYou can use the color gradient APIs to apply a background color gradient effect to a component.
7e41f4b71Sopenharmony_ci
8e41f4b71Sopenharmony_ci| API| Description|
9e41f4b71Sopenharmony_ci| -------- | -------- |
10e41f4b71Sopenharmony_ci| [linearGradient](../reference/apis-arkui/arkui-ts/ts-universal-attributes-gradient-color.md#lineargradient) | Applies a linear gradient to the component.|
11e41f4b71Sopenharmony_ci| [sweepGradient](../reference/apis-arkui/arkui-ts/ts-universal-attributes-gradient-color.md#sweepgradient) | Applies a sweep gradient effect to the component.|
12e41f4b71Sopenharmony_ci| [radialGradient](../reference/apis-arkui/arkui-ts/ts-universal-attributes-gradient-color.md#radialgradient) | Applies a radial gradient effect to the component.|
13e41f4b71Sopenharmony_ci
14e41f4b71Sopenharmony_ci
15e41f4b71Sopenharmony_ci## Applying Linear Gradient Effect
16e41f4b71Sopenharmony_ci
17e41f4b71Sopenharmony_ci
18e41f4b71Sopenharmony_ci```ts
19e41f4b71Sopenharmony_ci@Entry
20e41f4b71Sopenharmony_ci@Component
21e41f4b71Sopenharmony_cistruct LinearGradientDemo {
22e41f4b71Sopenharmony_ci  build() {
23e41f4b71Sopenharmony_ci    Grid() {
24e41f4b71Sopenharmony_ci      GridItem() {
25e41f4b71Sopenharmony_ci        Column() {
26e41f4b71Sopenharmony_ci          Text('angle: 180')
27e41f4b71Sopenharmony_ci            .fontSize(15)
28e41f4b71Sopenharmony_ci        }
29e41f4b71Sopenharmony_ci        .width(100)
30e41f4b71Sopenharmony_ci        .height(100)
31e41f4b71Sopenharmony_ci        .justifyContent(FlexAlign.Center)
32e41f4b71Sopenharmony_ci        .borderRadius(10)
33e41f4b71Sopenharmony_ci        .linearGradient({
34e41f4b71Sopenharmony_ci          // A positive value indicates a clockwise rotation from the origin, (0, 0). The default value of the linear gradient start angle is 180°.
35e41f4b71Sopenharmony_ci          colors: [
36e41f4b71Sopenharmony_ci            [0xf56c6c, 0.0], // Color and weight of color stop 1, corresponding to the start position of the component in the 180° direction.
37e41f4b71Sopenharmony_ci            [0xffffff, 1.0], // Color and weight of color stop 2, corresponding to the end position of the component in the 180° direction.
38e41f4b71Sopenharmony_ci          ]
39e41f4b71Sopenharmony_ci        })
40e41f4b71Sopenharmony_ci      }
41e41f4b71Sopenharmony_ci
42e41f4b71Sopenharmony_ci      GridItem() {
43e41f4b71Sopenharmony_ci        Column() {
44e41f4b71Sopenharmony_ci          Text('angle: 45')
45e41f4b71Sopenharmony_ci            .fontSize(15)
46e41f4b71Sopenharmony_ci        }
47e41f4b71Sopenharmony_ci        .width(100)
48e41f4b71Sopenharmony_ci        .height(100)
49e41f4b71Sopenharmony_ci        .justifyContent(FlexAlign.Center)
50e41f4b71Sopenharmony_ci        .borderRadius(10)
51e41f4b71Sopenharmony_ci        .linearGradient({
52e41f4b71Sopenharmony_ci          angle: 45, // Set the linear gradient start angle to 45°.
53e41f4b71Sopenharmony_ci          colors: [
54e41f4b71Sopenharmony_ci            [0xf56c6c, 0.0],
55e41f4b71Sopenharmony_ci            [0xffffff, 1.0],
56e41f4b71Sopenharmony_ci          ]
57e41f4b71Sopenharmony_ci        })
58e41f4b71Sopenharmony_ci      }
59e41f4b71Sopenharmony_ci
60e41f4b71Sopenharmony_ci      GridItem() {
61e41f4b71Sopenharmony_ci        Column() {
62e41f4b71Sopenharmony_ci          Text('repeat: true')
63e41f4b71Sopenharmony_ci            .fontSize(15)
64e41f4b71Sopenharmony_ci        }
65e41f4b71Sopenharmony_ci        .width(100)
66e41f4b71Sopenharmony_ci        .height(100)
67e41f4b71Sopenharmony_ci        .justifyContent(FlexAlign.Center)
68e41f4b71Sopenharmony_ci        .borderRadius(10)
69e41f4b71Sopenharmony_ci        .linearGradient({
70e41f4b71Sopenharmony_ci          repeating: true, // Repeat the gradients of the area from 0 to 0.3 in the area from 0.3 to 1.0.
71e41f4b71Sopenharmony_ci          colors: [
72e41f4b71Sopenharmony_ci            [0xf56c6c, 0.0],
73e41f4b71Sopenharmony_ci            [0xE6A23C, .3],
74e41f4b71Sopenharmony_ci          ]
75e41f4b71Sopenharmony_ci        })
76e41f4b71Sopenharmony_ci      }
77e41f4b71Sopenharmony_ci
78e41f4b71Sopenharmony_ci      GridItem() {
79e41f4b71Sopenharmony_ci        Column() {
80e41f4b71Sopenharmony_ci          Text('repeat: fasle')
81e41f4b71Sopenharmony_ci            .fontSize(15)
82e41f4b71Sopenharmony_ci        }
83e41f4b71Sopenharmony_ci        .width(100)
84e41f4b71Sopenharmony_ci        .height(100)
85e41f4b71Sopenharmony_ci        .justifyContent(FlexAlign.Center)
86e41f4b71Sopenharmony_ci        .borderRadius(10)
87e41f4b71Sopenharmony_ci        .linearGradient({
88e41f4b71Sopenharmony_ci          colors: [
89e41f4b71Sopenharmony_ci            [0xf56c6c, 0.0], // As repeating is not specified, the default value false is used. In this case, only the area from 0 to 0.3 in the component have the color gradient effect.
90e41f4b71Sopenharmony_ci            [0xE6A23C, .3],
91e41f4b71Sopenharmony_ci          ]
92e41f4b71Sopenharmony_ci        })
93e41f4b71Sopenharmony_ci      }
94e41f4b71Sopenharmony_ci    }
95e41f4b71Sopenharmony_ci    .columnsGap(10)
96e41f4b71Sopenharmony_ci    .rowsGap(10)
97e41f4b71Sopenharmony_ci    .columnsTemplate('1fr 1fr')
98e41f4b71Sopenharmony_ci    .rowsTemplate('1fr 1fr 1fr')
99e41f4b71Sopenharmony_ci    .width('100%')
100e41f4b71Sopenharmony_ci    .height('100%')
101e41f4b71Sopenharmony_ci  }
102e41f4b71Sopenharmony_ci}
103e41f4b71Sopenharmony_ci```
104e41f4b71Sopenharmony_ci
105e41f4b71Sopenharmony_ci![en-us_image_0000001641176829](figures/en-us_image_0000001641176829.png)
106e41f4b71Sopenharmony_ci
107e41f4b71Sopenharmony_ci
108e41f4b71Sopenharmony_ci## Applying Sweep Gradient Effect
109e41f4b71Sopenharmony_ci
110e41f4b71Sopenharmony_ci
111e41f4b71Sopenharmony_ci```ts
112e41f4b71Sopenharmony_ci@Entry
113e41f4b71Sopenharmony_ci@Component
114e41f4b71Sopenharmony_cistruct SweepGradientDemo {
115e41f4b71Sopenharmony_ci  build() {
116e41f4b71Sopenharmony_ci    Grid() {
117e41f4b71Sopenharmony_ci      GridItem() {
118e41f4b71Sopenharmony_ci        Column() {
119e41f4b71Sopenharmony_ci          Text('center: 50')
120e41f4b71Sopenharmony_ci            .fontSize(15)
121e41f4b71Sopenharmony_ci        }
122e41f4b71Sopenharmony_ci        .width(100)
123e41f4b71Sopenharmony_ci        .height(100)
124e41f4b71Sopenharmony_ci        .justifyContent(FlexAlign.Center)
125e41f4b71Sopenharmony_ci        .borderRadius(10)
126e41f4b71Sopenharmony_ci        .sweepGradient({
127e41f4b71Sopenharmony_ci          center: [50, 50], // Center point of the sweep gradient.
128e41f4b71Sopenharmony_ci          start: 0, // Start point of the sweep gradient.
129e41f4b71Sopenharmony_ci          end: 360, // End point of the sweep gradient.
130e41f4b71Sopenharmony_ci          repeating: true, // The gradients are repeated.
131e41f4b71Sopenharmony_ci          colors: [
132e41f4b71Sopenharmony_ci          // Based on the center point, start point, and end point settings,
133e41f4b71Sopenharmony_ci          // the color changes from color stop 1 to color stop 2 in the area within angles from 0 to 0.125;
134e41f4b71Sopenharmony_ci          // the color changes from color stop 2 to color stop 3 in the area within angles from 0.125 to 0.25;
135e41f4b71Sopenharmony_ci          // the color gradients of the area within angles from 0 to 0.25 are repeated in the area within angles from 0.25 to 1.
136e41f4b71Sopenharmony_ci            [0xf56c6c, 0], // Color and weight of color stop 1. The corresponding angle is 0° (0 x 360°), and the corner is the center point.
137e41f4b71Sopenharmony_ci            [0xffffff, 0.125], // Color and weight of color stop 2.
138e41f4b71Sopenharmony_ci            [0x409EFF, 0.25] // Color and weight of color stop 3.
139e41f4b71Sopenharmony_ci          ]
140e41f4b71Sopenharmony_ci        })
141e41f4b71Sopenharmony_ci      }
142e41f4b71Sopenharmony_ci
143e41f4b71Sopenharmony_ci      GridItem() {
144e41f4b71Sopenharmony_ci        Column() {
145e41f4b71Sopenharmony_ci          Text('center: 0')
146e41f4b71Sopenharmony_ci            .fontSize(15)
147e41f4b71Sopenharmony_ci        }
148e41f4b71Sopenharmony_ci        .width(100)
149e41f4b71Sopenharmony_ci        .height(100)
150e41f4b71Sopenharmony_ci        .justifyContent(FlexAlign.Center)
151e41f4b71Sopenharmony_ci        .borderRadius(10)
152e41f4b71Sopenharmony_ci        .sweepGradient({
153e41f4b71Sopenharmony_ci          center: [0, 0], // Center point of the sweep gradient, which is the coordinate of the upper left corner of the component in this example.
154e41f4b71Sopenharmony_ci          start: 0,
155e41f4b71Sopenharmony_ci          end: 360,
156e41f4b71Sopenharmony_ci          repeating: true,
157e41f4b71Sopenharmony_ci          colors: [
158e41f4b71Sopenharmony_ci          // In the current component, the sweep gradient center is the upper left corner of the component. Therefore, the angle range from color stop 1 to color stop 3 can cover the entire component.
159e41f4b71Sopenharmony_ci            [0xf56c6c, 0], // Color and weight of color stop 1. The corresponding angle is 0° (0 x 360°)
160e41f4b71Sopenharmony_ci            [0xffffff, 0.125], // Color and weight of color stop 2. The corresponding angle is 45° (0.125 x 360°).
161e41f4b71Sopenharmony_ci            [0x409EFF, 0.25] // Color and weight of color stop 3. The corresponding angle is 90° (0.25 x 360°).
162e41f4b71Sopenharmony_ci          ]
163e41f4b71Sopenharmony_ci        })
164e41f4b71Sopenharmony_ci      }
165e41f4b71Sopenharmony_ci
166e41f4b71Sopenharmony_ci      GridItem() {
167e41f4b71Sopenharmony_ci        Column() {
168e41f4b71Sopenharmony_ci          Text('repeat: true')
169e41f4b71Sopenharmony_ci            .fontSize(15)
170e41f4b71Sopenharmony_ci        }
171e41f4b71Sopenharmony_ci        .width(100)
172e41f4b71Sopenharmony_ci        .height(100)
173e41f4b71Sopenharmony_ci        .justifyContent(FlexAlign.Center)
174e41f4b71Sopenharmony_ci        .borderRadius(10)
175e41f4b71Sopenharmony_ci        .sweepGradient({
176e41f4b71Sopenharmony_ci          center: [50, 50],
177e41f4b71Sopenharmony_ci          start: 0,
178e41f4b71Sopenharmony_ci          end: 360,
179e41f4b71Sopenharmony_ci          repeating: true,
180e41f4b71Sopenharmony_ci          colors: [
181e41f4b71Sopenharmony_ci            [0xf56c6c, 0],
182e41f4b71Sopenharmony_ci            [0xffffff, 0.125],
183e41f4b71Sopenharmony_ci            [0x409EFF, 0.25]
184e41f4b71Sopenharmony_ci          ]
185e41f4b71Sopenharmony_ci        })
186e41f4b71Sopenharmony_ci      }
187e41f4b71Sopenharmony_ci
188e41f4b71Sopenharmony_ci      GridItem() {
189e41f4b71Sopenharmony_ci        Column() {
190e41f4b71Sopenharmony_ci          Text('repeat: false')
191e41f4b71Sopenharmony_ci            .fontSize(15)
192e41f4b71Sopenharmony_ci        }
193e41f4b71Sopenharmony_ci        .width(100)
194e41f4b71Sopenharmony_ci        .height(100)
195e41f4b71Sopenharmony_ci        .justifyContent(FlexAlign.Center)
196e41f4b71Sopenharmony_ci        .borderRadius(10)
197e41f4b71Sopenharmony_ci        .sweepGradient({
198e41f4b71Sopenharmony_ci          center: [50, 50],
199e41f4b71Sopenharmony_ci          start: 0,
200e41f4b71Sopenharmony_ci          end: 360,
201e41f4b71Sopenharmony_ci          repeating: false, // The color gradient effect is generated only within the coverage of the color stop angles.
202e41f4b71Sopenharmony_ci          colors: [
203e41f4b71Sopenharmony_ci            [0xf56c6c, 0],
204e41f4b71Sopenharmony_ci            [0xffffff, 0.125],
205e41f4b71Sopenharmony_ci            [0x409EFF, 0.25]
206e41f4b71Sopenharmony_ci          ]
207e41f4b71Sopenharmony_ci        })
208e41f4b71Sopenharmony_ci      }
209e41f4b71Sopenharmony_ci    }
210e41f4b71Sopenharmony_ci    .columnsGap(10)
211e41f4b71Sopenharmony_ci    .rowsGap(10)
212e41f4b71Sopenharmony_ci    .columnsTemplate('1fr 1fr')
213e41f4b71Sopenharmony_ci    .rowsTemplate('1fr 1fr 1fr')
214e41f4b71Sopenharmony_ci    .width('100%')
215e41f4b71Sopenharmony_ci    .height(437)
216e41f4b71Sopenharmony_ci  }
217e41f4b71Sopenharmony_ci}
218e41f4b71Sopenharmony_ci```
219e41f4b71Sopenharmony_ci
220e41f4b71Sopenharmony_ci![en-us_image_0000001641177073](figures/en-us_image_0000001641177073.png)
221e41f4b71Sopenharmony_ci
222e41f4b71Sopenharmony_ci
223e41f4b71Sopenharmony_ci## Applying Radial Gradient Effect
224e41f4b71Sopenharmony_ci
225e41f4b71Sopenharmony_ci
226e41f4b71Sopenharmony_ci```ts
227e41f4b71Sopenharmony_ci@Entry
228e41f4b71Sopenharmony_ci@Component
229e41f4b71Sopenharmony_cistruct radialGradientDemo {
230e41f4b71Sopenharmony_ci  build() {
231e41f4b71Sopenharmony_ci    Grid() {
232e41f4b71Sopenharmony_ci      GridItem() {
233e41f4b71Sopenharmony_ci        Column() {
234e41f4b71Sopenharmony_ci          Text('center: 50')
235e41f4b71Sopenharmony_ci            .fontSize(15)
236e41f4b71Sopenharmony_ci        }
237e41f4b71Sopenharmony_ci        .width(100)
238e41f4b71Sopenharmony_ci        .height(100)
239e41f4b71Sopenharmony_ci        .justifyContent(FlexAlign.Center)
240e41f4b71Sopenharmony_ci        .borderRadius(10)
241e41f4b71Sopenharmony_ci        .radialGradient({
242e41f4b71Sopenharmony_ci          center: [50, 50], // Center point of the radial gradient.
243e41f4b71Sopenharmony_ci          radius: 100, // Radius of the radial gradient.
244e41f4b71Sopenharmony_ci          repeating: true, // The gradients are repeated outside the specified range to fill the entire component.
245e41f4b71Sopenharmony_ci          colors: [
246e41f4b71Sopenharmony_ci            // With [50, 50] as the center point, the gradient changes from color stop 1 to color stop 2 within the range of radius 0 to 12.5;
247e41f4b71Sopenharmony_ci            // the gradient changes from color stop 2 to color stop 3 within the range of radius 12.5 to 25;
248e41f4b71Sopenharmony_ci            // the gradients in the range of radius 0 to 25 are repeated to fill the entire component.
249e41f4b71Sopenharmony_ci            [0xf56c6c, 0], // Color and weight of color stop 1. The corresponding radius is 0 (0 x 100).
250e41f4b71Sopenharmony_ci            [0xffffff, 0.125], // Color and weight of color stop 2. The corresponding radius is 12.5 (0.125 x 100).
251e41f4b71Sopenharmony_ci            [0x409EFF, 0.25] // Color and weight of color stop 3. The corresponding radius is 25 (0.25 x 100).
252e41f4b71Sopenharmony_ci          ]
253e41f4b71Sopenharmony_ci        })
254e41f4b71Sopenharmony_ci      }
255e41f4b71Sopenharmony_ci
256e41f4b71Sopenharmony_ci      GridItem() {
257e41f4b71Sopenharmony_ci        Column() {
258e41f4b71Sopenharmony_ci          Text('center: 0')
259e41f4b71Sopenharmony_ci            .fontSize(15)
260e41f4b71Sopenharmony_ci        }
261e41f4b71Sopenharmony_ci        .width(100)
262e41f4b71Sopenharmony_ci        .height(100)
263e41f4b71Sopenharmony_ci        .justifyContent(FlexAlign.Center)
264e41f4b71Sopenharmony_ci        .borderRadius(10)
265e41f4b71Sopenharmony_ci        .radialGradient({
266e41f4b71Sopenharmony_ci          center: [0, 0], // Center point of the radial gradient, which is the coordinate of the upper left corner of the component in this example.
267e41f4b71Sopenharmony_ci          radius: 100,
268e41f4b71Sopenharmony_ci          repeating: true,
269e41f4b71Sopenharmony_ci          colors: [
270e41f4b71Sopenharmony_ci            [0xf56c6c, 0],
271e41f4b71Sopenharmony_ci            [0xffffff, 0.125],
272e41f4b71Sopenharmony_ci            [0x409EFF, 0.25]
273e41f4b71Sopenharmony_ci          ]
274e41f4b71Sopenharmony_ci        })
275e41f4b71Sopenharmony_ci      }
276e41f4b71Sopenharmony_ci
277e41f4b71Sopenharmony_ci      GridItem() {
278e41f4b71Sopenharmony_ci        Column() {
279e41f4b71Sopenharmony_ci          Text('repeat: true')
280e41f4b71Sopenharmony_ci            .fontSize(15)
281e41f4b71Sopenharmony_ci        }
282e41f4b71Sopenharmony_ci        .width(100)
283e41f4b71Sopenharmony_ci        .height(100)
284e41f4b71Sopenharmony_ci        .justifyContent(FlexAlign.Center)
285e41f4b71Sopenharmony_ci        .borderRadius(10)
286e41f4b71Sopenharmony_ci        .radialGradient({
287e41f4b71Sopenharmony_ci          center: [50, 50],
288e41f4b71Sopenharmony_ci          radius: 100,
289e41f4b71Sopenharmony_ci          repeating: true,
290e41f4b71Sopenharmony_ci          colors: [
291e41f4b71Sopenharmony_ci            [0xf56c6c, 0],
292e41f4b71Sopenharmony_ci            [0xffffff, 0.125],
293e41f4b71Sopenharmony_ci            [0x409EFF, 0.25]
294e41f4b71Sopenharmony_ci          ]
295e41f4b71Sopenharmony_ci        })
296e41f4b71Sopenharmony_ci      }
297e41f4b71Sopenharmony_ci
298e41f4b71Sopenharmony_ci      GridItem() {
299e41f4b71Sopenharmony_ci        Column() {
300e41f4b71Sopenharmony_ci          Text('repeat: false')
301e41f4b71Sopenharmony_ci            .fontSize(15)
302e41f4b71Sopenharmony_ci        }
303e41f4b71Sopenharmony_ci        .width(100)
304e41f4b71Sopenharmony_ci        .height(100)
305e41f4b71Sopenharmony_ci        .justifyContent(FlexAlign.Center)
306e41f4b71Sopenharmony_ci        .borderRadius(10)
307e41f4b71Sopenharmony_ci        .radialGradient({
308e41f4b71Sopenharmony_ci          center: [50, 50],
309e41f4b71Sopenharmony_ci          radius: 100,
310e41f4b71Sopenharmony_ci          repeating: false, // The gradients are not repeated.
311e41f4b71Sopenharmony_ci          colors: [
312e41f4b71Sopenharmony_ci            [0xf56c6c, 0],
313e41f4b71Sopenharmony_ci            [0xffffff, 0.125],
314e41f4b71Sopenharmony_ci            [0x409EFF, 0.25]
315e41f4b71Sopenharmony_ci          ]
316e41f4b71Sopenharmony_ci        })
317e41f4b71Sopenharmony_ci      }
318e41f4b71Sopenharmony_ci    }
319e41f4b71Sopenharmony_ci    .columnsGap(10)
320e41f4b71Sopenharmony_ci    .rowsGap(10)
321e41f4b71Sopenharmony_ci    .columnsTemplate('1fr 1fr')
322e41f4b71Sopenharmony_ci    .rowsTemplate('1fr 1fr 1fr')
323e41f4b71Sopenharmony_ci    .width('100%')
324e41f4b71Sopenharmony_ci    .height('100%')
325e41f4b71Sopenharmony_ci  }
326e41f4b71Sopenharmony_ci}
327e41f4b71Sopenharmony_ci```
328e41f4b71Sopenharmony_ci
329e41f4b71Sopenharmony_ci![en-us_image_0000001592904050](figures/en-us_image_0000001592904050.png)
330