1# 点光源设置 (系统接口)
2
3设置点光源样式。
4
5>  **说明:**
6>
7>  从API Version 11开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。
8>
9>  只有Image、Column、Flex、Row、Stack支持设置点光源。
10
11## PointLightStyle
12
13通过设置光源和被照亮的类型实现点光源照亮周围组件的UI效果。
14
15**系统接口:** 此接口为系统接口。
16
17**系统能力:** SystemCapability.ArkUI.ArkUI.Full
18
19| 名称        | 参数类型                                                    | 必填 | 描述                                                         |
20| ----------- | ----------------------------------------------------------- | ---- | ------------------------------------------------------------ |
21| lightSource | [LightSource](#lightsource对象说明)                         | 否   | 设置光源属性,光源会影响到周围标记为可以被照亮的组件,并在组件上产生光效。<br/>默认值:无光源 |
22| illuminated | [IlluminatedType](ts-appendix-enums-sys.md#illuminatedtype) | 否   | 设置当前组件是否可以被光源照亮,以及被照亮的类型。<br/>默认值:IlluminatedType.NONE |
23| bloom       | number                                                      | 否   | 设置组件的发光强度,建议取值范围为0-1。<br/>默认值:0        |
24
25## LightSource对象说明
26
27一个组件支持添加1个光源。
28
29**系统接口:** 此接口为系统接口。
30
31**系统能力:** SystemCapability.ArkUI.ArkUI.Full
32
33| 名称                | 参数类型                                   | 必填 | 描述                                                     |
34| ------------------- | ------------------------------------------ | ---- | -------------------------------------------------------- |
35| positionX           | [Dimension](ts-types.md#dimension10)       | 是   | 光源相对于当前组件的X坐标。                              |
36| positionY           | [Dimension](ts-types.md#dimension10)       | 是   | 光源相对于当前组件的Y坐标。                              |
37| positionZ           | [Dimension](ts-types.md#dimension10)       | 是   | 光源高度。光源越高,照射范围越大。                       |
38| intensity           | number                                     | 是   | 光源强度,建议取值范围0-1。当光源强度为0时,光源不发光。 |
39| color<sup>12+</sup> | [ResourceColor](ts-types.md#resourcecolor) | 否   | 光源颜色。<br/>默认值:Color.White                       |
40
41## 示例
42
43```ts
44// xxx.ets
45@Entry
46@Component
47struct Index {
48  @State lightIntensity: number = 0;
49  @State bloomValue: number = 0;
50
51  build() {
52    Row({ space: 20 }) {
53      Flex()
54        .pointLight({ illuminated: IlluminatedType.BORDER })
55        .backgroundColor(0x307af7)
56        .size({ width: 50, height: 50 })
57        .borderRadius(25)
58
59      Flex()
60        .pointLight({
61          lightSource: { intensity: this.lightIntensity, positionX: "50%", positionY: "50%", positionZ: 80 },
62          bloom: this.bloomValue
63        })
64        .animation({ duration: 333 })
65        .backgroundColor(0x307af7)
66        .size({ width: 50, height: 50 })
67        .borderRadius(25)
68        .onTouch((event: TouchEvent) => {
69          if (event.type === TouchType.Down) {
70            this.lightIntensity = 2;
71            this.bloomValue = 1;
72          } else if (event.type === TouchType.Up || event.type === TouchType.Cancel) {
73            this.lightIntensity = 0;
74            this.bloomValue = 0;
75          }
76        })
77
78      Flex()
79        .pointLight({ illuminated: IlluminatedType.BORDER_CONTENT })
80        .backgroundColor(0x307af7)
81        .size({ width: 50, height: 50 })
82        .borderRadius(25)
83    }
84    .justifyContent(FlexAlign.Center)
85    .backgroundColor(Color.Black)
86    .size({ width: '100%', height: '100%' })
87  }
88}
89```
90