提交 0804d89b 编写于 作者: T tianyu

update 3.1release ts-line

Signed-off-by: Ntianyu <tianyu55@h-partners.com>
上级 129253a1
...@@ -22,10 +22,10 @@ ...@@ -22,10 +22,10 @@
Circle(options?: {width?: string | number, height?: string | number}) Circle(options?: {width?: string | number, height?: string | number})
## 参数 ## 参数
| 参数名 | 参数类型 | 必填 | 默认值 | 参数描述 | | 参数名 | 参数类型 | 必填 | 默认值 | 参数描述 |
| -------- | -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- | -------- |
| width | string \| number | 否 | 0 | 宽度。 | | width | string \| number | 否 | 0 | 宽度。 |
| height | string \| number | 否 | 0 | 高度。 | | height | string \| number | 否 | 0 | 高度。 |
## 属性 ## 属性
...@@ -55,12 +55,18 @@ Circle(options?: {width?: string | number, height?: string | number}) ...@@ -55,12 +55,18 @@ Circle(options?: {width?: string | number, height?: string | number})
@Component @Component
struct CircleExample { struct CircleExample {
build() { build() {
Flex({ justifyContent: FlexAlign.SpaceAround }) { Column({ space: 10 }) {
// 绘制一个直径为150的圆 // 绘制一个直径为150的圆
Circle({ width: 150, height: 150 }) Circle({ width: 150, height: 150 })
// 绘制一个直径为150的圆 // 绘制一个直径为150、线条为红色虚线的圆环(宽高设置不一致时以短边为直径)
Circle().width(150).height(150) Circle()
}.width('100%').margin({ top: 5 }) .width(150)
.height(200)
.fillOpacity(0)
.strokeWidth(3)
.stroke(Color.Red)
.strokeDashArray([1, 2])
}.width('100%')
} }
} }
``` ```
......
...@@ -56,12 +56,17 @@ ellipse(options?: {width?: string | number, height?: string | number}) ...@@ -56,12 +56,17 @@ ellipse(options?: {width?: string | number, height?: string | number})
@Component @Component
struct EllipseExample { struct EllipseExample {
build() { build() {
Flex({ justifyContent: FlexAlign.SpaceAround }) { Column({ space: 10 }) {
// 在一个 150 * 80 的矩形框中绘制一个椭圆 // 绘制一个 150 * 80 的椭圆
Ellipse({ width: 150, height: 80 }) Ellipse({ width: 150, height: 80 })
// 在一个 150 * 70 的矩形框中绘制一个椭圆 // 绘制一个 150 * 100 、线条为蓝色的椭圆环
Ellipse().width(150).height(80) Ellipse()
}.width('100%').margin({ top: 5 }) .width(150)
.height(100)
.fillOpacity(0)
.stroke(Color.Blue)
.strokeWidth(3)
}.width('100%')
} }
} }
``` ```
......
...@@ -57,12 +57,31 @@ Line(options?: {width?: string | number, height?: string | number}) ...@@ -57,12 +57,31 @@ Line(options?: {width?: string | number, height?: string | number})
@Component @Component
struct LineExample { struct LineExample {
build() { build() {
Column() { Column({ space: 10 }) {
Line({ width: 50, height: 100 }).startPoint([0, 0]).endPoint([50, 100]) // 线条绘制的起止点坐标均是相对于Line组件本身绘制区域的坐标
Line().width(200).height(200).startPoint([50, 50]).endPoint([150, 150]) Line()
}.margin({ top: 5 }) .startPoint([0, 0])
.endPoint([50, 100])
.backgroundColor('#F5F5F5')
Line()
.width(200)
.height(200)
.startPoint([50, 50])
.endPoint([150, 150])
.strokeWidth(5)
.stroke(Color.Orange)
.strokeOpacity(0.5)
.backgroundColor('#F5F5F5')
// 当坐标点设置的值超出Line组件的宽高范围时,线条会画出组件绘制区域
Line({ width: 50, height: 50 })
.startPoint([0, 0])
.endPoint([100, 100])
.strokeWidth(3)
.strokeDashArray([1, 3])
.backgroundColor('#F5F5F5')
}
} }
} }
``` ```
![zh-cn_image_0000001219982725](figures/zh-cn_image_0000001219982725.jpg) ![zh-cn_image_0000001219982725](figures/zh-cn_image_0000001219982725.png)
...@@ -72,28 +72,75 @@ commands支持的绘制命令如下: ...@@ -72,28 +72,75 @@ commands支持的绘制命令如下:
@Component @Component
struct PathExample { struct PathExample {
build() { build() {
Column({ space: 5 }) { Column({ space: 10 }) {
Text('Straight line').fontSize(9).fontColor(0xCCCCCC).width('90%') Text('Straight line')
Path().width(300).height(10).commands('M0 0 L900 0').stroke(Color.Black).strokeWidth(3) .fontSize(11)
.fontColor(0xCCCCCC)
Text('Straight line graph').fontSize(9).fontColor(0xCCCCCC).width('90%') .width('90%')
Flex({ justifyContent: FlexAlign.SpaceAround }) { // 绘制一条长900px,宽3vp的直线
// 先后执行MoveTo(150, 0), LineTo(300, 300), LineTo(0, 300), ClosePath() Path()
Path().width(100).height(100).commands('M150 0 L300 300 L0 300 Z') .width(300)
// 先后执行MoveTo(0, 0), HorizontalLineto(300), VerticalLineto(300), HorizontalLineto(0), ClosePath() .height(10)
Path().width(100).height(100).commands('M0 0 H300 V300 H0 Z') .commands('M0 0 L900 0')
// 先后执行MoveTo(150, 0), LineTo(0, 150), LineTo(60, 300), LineTo(240, 300), LineTo(300, 150), ClosePath() .stroke(Color.Black)
Path().width(100).height(100).commands('M150 0 L0 150 L60 300 L240 300 L300 150 Z') .strokeWidth(3)
Text('Straight line graph')
.fontSize(11)
.fontColor(0xCCCCCC)
.width('90%')
// 绘制直线图形
Row({ space: 20 }) {
Path()
.width(100)
.height(100)
.commands('M150 0 L300 300 L0 300 Z')
.fillOpacity(0)
.stroke(Color.Black)
.strokeWidth(3)
Path()
.width(100)
.height(100)
.commands('M0 0 H300 V300 H0 Z')
.fillOpacity(0)
.stroke(Color.Black)
.strokeWidth(3)
Path()
.width(100)
.height(100)
.commands('M150 0 L0 150 L60 300 L240 300 L300 150 Z')
.fillOpacity(0)
.stroke(Color.Black)
.strokeWidth(3)
}.width('100%') }.width('100%')
Text('Curve graphics').fontSize(9).fontColor(0xCCCCCC).width('90%') Text('Curve graphics').fontSize(11).fontColor(0xCCCCCC).width('90%')
Flex({ justifyContent: FlexAlign.SpaceAround }) { // 绘制弧线图形
// 先后执行MoveTo(0, 300),(150, 0)(300, 300)两点之间画曲线, ClosePath() Row({ space: 20 }) {
Path().width(100).height(100).commands("M0 300 S150 0 300 300 Z") Path()
// 先后执行MoveTo(0, 150),(0, 150)(150, 0)(300, 150)三点之间依次画曲线, LineTo(150, 300),ClosePath() .width(100)
Path().width(100).height(100).commands('M0 150 C0 150 150 0 300 150 L150 300 Z') .height(100)
.commands("M0 300 S150 0 300 300 Z")
.fillOpacity(0)
.stroke(Color.Black)
.strokeWidth(3)
Path()
.width(100)
.height(100)
.commands('M0 150 C0 150 150 0 300 150 L150 300 Z')
.fillOpacity(0)
.stroke(Color.Black)
.strokeWidth(3)
Path()
.width(100)
.height(100)
.commands('M0 200 A30 20 20 0 0 250 200 Z')
.fillOpacity(0)
.stroke(Color.Black)
.strokeWidth(3)
} }
}.width('100%').margin({ top: 5 }) }.width('100%')
.margin({ top: 5 })
} }
} }
``` ```
......
...@@ -64,18 +64,25 @@ Polygon(options?: {width?: string | number, height?: string | number}) ...@@ -64,18 +64,25 @@ Polygon(options?: {width?: string | number, height?: string | number})
@Component @Component
struct PolygonExample { struct PolygonExample {
build() { build() {
Column({ space: 5 }) { Column({ space: 10 }) {
Flex({ justifyContent: FlexAlign.SpaceAround }) {
// 在 100 * 100 的矩形框中绘制一个三角形,起点(0, 0),经过(50, 100),终点(100, 0) // 在 100 * 100 的矩形框中绘制一个三角形,起点(0, 0),经过(50, 100),终点(100, 0)
Polygon({ width: 100, height: 100 }).points([[0, 0], [50, 100], [100, 0]]) Polygon({ width: 100, height: 100 })
.points([[0, 0], [50, 100], [100, 0]])
.fill(Color.Green)
// 在 100 * 100 的矩形框中绘制一个四边形,起点(0, 0),经过(0, 100)和(100, 100),终点(100, 0) // 在 100 * 100 的矩形框中绘制一个四边形,起点(0, 0),经过(0, 100)和(100, 100),终点(100, 0)
Polygon().width(100).height(100).points([[0, 0], [0, 100], [100, 100], [100, 0]]) Polygon().width(100).height(100)
.points([[0, 0], [0, 100], [100, 100], [100, 0]])
.fillOpacity(0)
.strokeWidth(5)
.stroke(Color.Blue)
// 在 100 * 100 的矩形框中绘制一个五边形,起点(50, 0),依次经过(0, 50)、(20, 100)和(80, 100),终点(100, 50) // 在 100 * 100 的矩形框中绘制一个五边形,起点(50, 0),依次经过(0, 50)、(20, 100)和(80, 100),终点(100, 50)
Polygon().width(100).height(100).points([[50, 0], [0, 50], [20, 100], [80, 100], [100, 50]]) Polygon().width(100).height(100)
}.width('100%') .points([[50, 0], [0, 50], [20, 100], [80, 100], [100, 50]])
}.margin({ top: 5 }) .fill(Color.Red)
.fillOpacity(0.6)
}.width('100%').margin({ top: 10 })
} }
} }
``` ```
![zh-cn_image_0000001174582856](figures/zh-cn_image_0000001174582856.gif) ![zh-cn_image_0000001174582856](figures/zh-cn_image_0000001174582856.png)
...@@ -65,16 +65,28 @@ Polyline(options?: {width?: string | number, height?: string | number}) ...@@ -65,16 +65,28 @@ Polyline(options?: {width?: string | number, height?: string | number})
@Component @Component
struct PolylineExample { struct PolylineExample {
build() { build() {
Column({ space: 5 }) { Column({ space: 10 }) {
Flex({ justifyContent: FlexAlign.SpaceAround }) {
// 在 100 * 100 的矩形框中绘制一段折线,起点(0, 0),经过(20,60),到达终点(100, 100) // 在 100 * 100 的矩形框中绘制一段折线,起点(0, 0),经过(20,60),到达终点(100, 100)
Polyline({ width: 100, height: 100 }).points([[0, 0], [20, 60], [100, 100]]) Polyline({ width: 100, height: 100 })
// 在 100 * 100 的矩形框中绘制一段折线,起点(0, 0),经过(0,100),到达终点(100, 100) .points([[0, 0], [20, 60], [100, 100]])
Polyline().width(100).height(100).points([[0, 0], [0, 100], [100, 100]]) .fillOpacity(0)
.stroke(Color.Blue)
.strokeWidth(3)
// 在 100 * 100 的矩形框中绘制一段折线,起点(20, 0),经过(0,100),到达终点(100, 90)
Polyline()
.width(100)
.height(100)
.fillOpacity(0)
.stroke(Color.Red)
.strokeWidth(8)
.points([[20, 0], [0, 100], [100, 90]])
// 设置折线拐角处为圆弧
.strokeLineJoin(LineJoinStyle.Round)
// 设置折线两端为半圆
.strokeLineCap(LineCapStyle.Round)
}.width('100%') }.width('100%')
}.margin({ top: 5 })
} }
} }
``` ```
![zh-cn_image_0000001219744185](figures/zh-cn_image_0000001219744185.gif) ![zh-cn_image_0000001219744185](figures/zh-cn_image_0000001219744185.png)
...@@ -63,19 +63,30 @@ Rect(options?: {width?: string | number,height?: string | number,radius?: string ...@@ -63,19 +63,30 @@ Rect(options?: {width?: string | number,height?: string | number,radius?: string
@Component @Component
struct RectExample { struct RectExample {
build() { build() {
Column({ space: 5 }) { Column({ space: 10 }) {
Text('normal').fontSize(9).fontColor(0xCCCCCC).width('90%') Text('normal').fontSize(11).fontColor(0xCCCCCC).width('90%')
// 绘制90% * 50矩形 // 绘制90% * 50矩形
Rect({ width: '90%', height: 50 }) Rect({ width: '90%', height: 50 })
// 绘制90% * 50矩形 .fill(Color.Pink)
Rect().width('90%').height(50) // 绘制90% * 50的矩形框
Rect()
Text('with rounded corners').fontSize(9).fontColor(0xCCCCCC).width('90%') .width('90%')
// 绘制90% * 50矩形, 圆角宽高20 .height(50)
Rect({ width: '90%', height: 50 }).radiusHeight(20).radiusWidth(20) .fillOpacity(0)
// 绘制90% * 50矩形, 圆角宽高20 .stroke(Color.Red)
Rect({ width: '90%', height: 50 }).radius(20) .strokeWidth(3)
}.width('100%').margin({ top: 5 })
Text('with rounded corners').fontSize(11).fontColor(0xCCCCCC).width('90%')
// 绘制90% * 80的矩形, 圆角宽高分别为40、20
Rect({ width: '90%', height: 80 })
.radiusHeight(20)
.radiusWidth(40)
.fill(Color.Pink)
// 绘制90% * 80的矩形, 圆角宽高为20
Rect({ width: '90%', height: 80 })
.radius(20)
.fill(Color.Pink)
}.width('100%').margin({ top: 10 })
} }
} }
``` ```
......
...@@ -51,70 +51,188 @@ Shape(value?: PixelMap) ...@@ -51,70 +51,188 @@ Shape(value?: PixelMap)
| antiAlias | boolean | true | 否 | 是否开启抗锯齿效果。 | | antiAlias | boolean | true | 否 | 是否开启抗锯齿效果。 |
| mesh<sup>8+</sup> | Array&lt;number&gt;,number,number | [],0,0 | 否 | 设置mesh效果。第一个参数为长度(column + 1)* (row + 1)* 2的数组,它记录了扭曲后的位图各个顶点位置,第二个参数为mesh矩阵列数column,第三个参数为mesh矩阵行数row。 | | mesh<sup>8+</sup> | Array&lt;number&gt;,number,number | [],0,0 | 否 | 设置mesh效果。第一个参数为长度(column + 1)* (row + 1)* 2的数组,它记录了扭曲后的位图各个顶点位置,第二个参数为mesh矩阵列数column,第三个参数为mesh矩阵行数row。 |
## 示例 ## 示例
### 示例1
```ts ```ts
// xxx.ets // xxx.ets
@Entry @Entry
@Component @Component
struct ShapeExample { struct ShapeExample {
build() { build() {
Column({ space: 5 }) { Column({ space: 10 }) {
Text('basic').fontSize(30).fontColor(0xCCCCCC).width(320) Text('basic').fontSize(11).fontColor(0xCCCCCC).width(320)
// 在Shape的(-2, -2)点绘制一个 300 * 50 带边框的矩形,颜色0x317Af7,边框颜色黑色,边框宽度4,边框间隙20,向左偏移10,尖端样式圆角,拐角样式圆角,抗锯齿(默认开启) // 在Shape的(-2, -2)点绘制一个 300 * 50 带边框的矩形,颜色0x317AF7,边框颜色黑色,边框宽度4,边框间隙20,向左偏移10,线条两端样式为半圆,拐角样式圆角,抗锯齿(默认开启)
// 在Shape的(-2, 58)点绘制一个 300 * 50 带边框的椭圆,颜色0x317Af7,边框颜色黑色,边框宽度4,边框间隙20,向左偏移10,尖端样式圆角,拐角样式圆角,抗锯齿(默认开启) // 在Shape的(-2, 58)点绘制一个 300 * 50 带边框的椭圆,颜色0x317AF7,边框颜色黑色,边框宽度4,边框间隙20,向左偏移10,线条两端样式为半圆,拐角样式圆角,抗锯齿(默认开启)
// 在Shape的(-2, 118)点绘制一个 300 * 10 线段,颜色0x317Af7,边框颜色黑色,宽度4,间隙20,向左偏移10,尖端样式圆角,拐角样式圆角,抗锯齿(默认开启) // 在Shape的(-2, 118)点绘制一个 300 * 10 直线路径,颜色0x317AF7,边框颜色黑色,宽度4,间隙20,向左偏移10,线条两端样式为半圆,拐角样式圆角,抗锯齿(默认开启)
Shape() { Shape() {
Rect().width(300).height(50) Rect().width(300).height(50)
Ellipse().width(300).height(50).offset({ x: 0, y: 60 }) Ellipse().width(300).height(50).offset({ x: 0, y: 60 })
Path().width(300).height(10).commands('M0 0 L900 0').offset({ x: 0, y: 120 }) Path().width(300).height(10).commands('M0 0 L900 0').offset({ x: 0, y: 120 })
} }
.viewPort({ x: -2, y: -2, width: 304, height: 130 }) .viewPort({ x: -2, y: -2, width: 304, height: 130 })
.fill(0x317Af7).stroke(Color.Black).strokeWidth(4) .fill(0x317AF7)
.strokeDashArray([20]).strokeDashOffset(10).strokeLineCap(LineCapStyle.Round) .stroke(Color.Black)
.strokeLineJoin(LineJoinStyle.Round).antiAlias(true) .strokeWidth(4)
// 在Shape的(-1, -1)点绘制一个 300 * 50 带边框的矩形,颜色0x317Af7,边框颜色黑色,边框宽度2 .strokeDashArray([20])
.strokeDashOffset(10)
.strokeLineCap(LineCapStyle.Round)
.strokeLineJoin(LineJoinStyle.Round)
.antiAlias(true)
// 分别在Shape的(0, 0)、(-5, -5)点绘制一个 300 * 50 带边框的矩形,可以看出之所以将视口的起始位置坐标设为负值是因为绘制的起点默认为线宽的中点位置,因此要让边框完全显示则需要让视口偏移半个线宽
Shape() { Shape() {
Rect().width(300).height(50) Rect().width(300).height(50)
}.viewPort({ x: -1, y: -1, width: 302, height: 52 }).fill(0x317Af7).stroke(Color.Black).strokeWidth(2) }
.viewPort({ x: 0, y: 0, width: 320, height: 70 })
.fill(0x317AF7)
.stroke(Color.Black)
.strokeWidth(10)
Text('border').fontSize(30).fontColor(0xCCCCCC).width(320).margin({top:30})
// 在Shape的(0, -5)点绘制一个 300 * 10 直线,颜色0xEE8443,边框宽度10,边框间隙20
Shape() { Shape() {
Path().width(300).height(10).commands('M0 0 L900 0') Rect().width(300).height(50)
}.viewPort({ x: 0, y: -5, width: 300, height: 20 }).stroke(0xEE8443).strokeWidth(10).strokeDashArray([20]) }
// 在Shape的(0, -5)点绘制一个 300 * 10 直线,颜色0xEE8443,边框宽度10,边框间隙20,向左偏移10 .viewPort({ x: -5, y: -5, width: 320, height: 70 })
.fill(0x317AF7)
.stroke(Color.Black)
.strokeWidth(10)
Text('path').fontSize(11).fontColor(0xCCCCCC).width(320)
// 在Shape的(0, -5)点绘制一条直线路径,颜色0xEE8443,线条宽度10,线条间隙20
Shape() { Shape() {
Path().width(300).height(10).commands('M0 0 L900 0') Path().width(300).height(10).commands('M0 0 L900 0')
} }
.viewPort({ x: 0, y: -5, width: 300, height: 20 }) .viewPort({ x: 0, y: -5, width: 300, height: 20 })
.stroke(0xEE8443).strokeWidth(10).strokeDashArray([20]).strokeDashOffset(10) .stroke(0xEE8443)
// 在Shape的(0, -5)点绘制一个 300 * 10 直线,颜色0xEE8443,边框宽度10,透明度0.5 .strokeWidth(10)
.strokeDashArray([20])
// 在Shape的(0, -5)点绘制一条直线路径,颜色0xEE8443,线条宽度10,线条间隙20,向左偏移10
Shape() { Shape() {
Path().width(300).height(10).commands('M0 0 L900 0') Path().width(300).height(10).commands('M0 0 L900 0')
}.viewPort({ x: 0, y: -5, width: 300, height: 20 }).stroke(0xEE8443).strokeWidth(10).strokeOpacity(0.5) }
// 在Shape的(0, -5)点绘制一个 300 * 10 直线,颜色0xEE8443,边框宽度10,边框间隙20,向左偏移10,尖端样式圆角 .viewPort({ x: 0, y: -5, width: 300, height: 20 })
.stroke(0xEE8443)
.strokeWidth(10)
.strokeDashArray([20])
.strokeDashOffset(10)
// 在Shape的(0, -5)点绘制一条直线路径,颜色0xEE8443,线条宽度10,透明度0.5
Shape() { Shape() {
Path().width(300).height(10).commands('M0 0 L900 0') Path().width(300).height(10).commands('M0 0 L900 0')
} }
.viewPort({ x: 0, y: -5, width: 300, height: 20 }) .viewPort({ x: 0, y: -5, width: 300, height: 20 })
.stroke(0xEE8443).strokeWidth(10).strokeDashArray([20]).strokeLineCap(LineCapStyle.Round) .stroke(0xEE8443)
// 在Shape的(-5, -5)点绘制一个 300 * 50 带边框的矩形,颜色0x317Af7,边框宽度10,边框颜色0xEE8443,拐角样式圆角 .strokeWidth(10)
.strokeOpacity(0.5)
// 在Shape的(0, -5)点绘制一条直线路径,颜色0xEE8443,线条宽度10,线条间隙20,线条两端样式为半圆
Shape() { Shape() {
Rect().width(300).height(100) Path().width(300).height(10).commands('M0 0 L900 0')
} }
.viewPort({ x: -5, y: -5, width: 310, height: 120 }) .viewPort({ x: 0, y: -5, width: 300, height: 20 })
.fill(0x317Af7).stroke(0xEE8443).strokeWidth(10).strokeLineJoin(LineJoinStyle.Round) .stroke(0xEE8443)
.strokeWidth(10)
.strokeDashArray([20])
.strokeLineCap(LineCapStyle.Round)
// 在Shape的(-80, -5)点绘制一个封闭路径,颜色0x317AF7,线条宽度10,边框颜色0xEE8443,拐角样式锐角(默认值)
Shape() { Shape() {
Path().width(300).height(60).commands('M0 0 L400 0 L400 200 Z') Path().width(200).height(60).commands('M0 0 L400 0 L400 150 Z')
} }
.viewPort({ x: -80, y: -5, width: 310, height: 100 }) .viewPort({ x: -80, y: -5, width: 310, height: 90 })
.fill(0x317Af7).stroke(0xEE8443).strokeWidth(10) .fill(0x317AF7)
.strokeLineJoin(LineJoinStyle.Miter).strokeMiterLimit(5) .stroke(0xEE8443)
.strokeWidth(10)
.strokeLineJoin(LineJoinStyle.Miter)
.strokeMiterLimit(5)
}.width('100%').margin({ top: 15 }) }.width('100%').margin({ top: 15 })
} }
} }
``` ```
![zh-cn_image_0000001184628104](figures/zh-cn_image_0000001184628104.png) ![zh-cn_image_0000001184628104](figures/zh-cn_image_0000001184628104.png)
### 示例2
```ts
// xxx.ets
@Entry
@Component
struct ShapeMeshExample {
@State columnVal: number = 0;
@State rowVal: number = 0;
@State count: number = 0;
@State verts: Array<number> = [];
@State shapeWidth: number = 600;
@State shapeHeight: number = 600;
build() {
Column() {
Shape() {
Rect()
.width('250px')
.height('250px')
.radiusWidth('10px')
.radiusHeight('10px')
.stroke('10px')
.margin({ left: '10px', top: '10px' })
.strokeWidth('10px')
.fill(Color.Blue)
Rect()
.width('250px')
.height('250px')
.radiusWidth('10px')
.radiusHeight('10px')
.stroke('10px')
.margin({ left: '270px', top: '10px' })
.strokeWidth('10px')
.fill(Color.Red)
}
.mesh(this.verts, this.columnVal, this.rowVal)
.width(this.shapeWidth + 'px')
.height(this.shapeHeight + 'px')
// 手指触摸Shape组件时会显示mesh扭曲效果
.onTouch((event: TouchEvent) => {
var touchX = event.touches[0].x * 2;
var touchY = event.touches[0].y * 2;
this.columnVal = 20;
this.rowVal = 20;
this.count = (this.columnVal + 1) * (this.rowVal + 1);
var orig = [this.count * 2];
var index = 0;
for (var i = 0; i <= this.rowVal; i++) {
var fy = this.shapeWidth * i / this.rowVal;
for (var j = 0; j <= this.columnVal; j++) {
var fx = this.shapeWidth * j / this.columnVal;
orig[index * 2 + 0] = this.verts[index * 2 + 0] = fx;
orig[index * 2 + 1] = this.verts[index * 2 + 1] = fy;
index++;
}
}
for (var k = 0; k < this.count * 2; k += 2) {
var dx = touchX - orig[k + 0];
var dy = touchY - orig[k + 1];
var dd = dx * dx + dy * dy;
var d = Math.sqrt(dd);
var pull = 80000 / (dd * d);
if (pull >= 1) {
this.verts[k + 0] = touchX;
this.verts[k + 1] = touchY;
} else {
this.verts[k + 0] = orig[k + 0] + dx * pull;
this.verts[k + 1] = orig[k + 1] + dy * pull;
}
}
})
}
.width('600px')
.height('600px')
.border({ width: 3, color: Color.Black })
}
}
```
示意图:
![zh-cn_image1_0000001184628104](figures/zh-cn_image1_0000001184628104.png)
手指触摸Shape组件时会显示mesh扭曲效果:
![zh-cn_image2_0000001184628104](figures/zh-cn_image2_0000001184628104.png)
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册