Skip to content

Commit 418d0ef

Browse files
authored
doc: translate drawing/demo3/README.md (#45)
1 parent 8361918 commit 418d0ef

File tree

1 file changed

+19
-19
lines changed

1 file changed

+19
-19
lines changed

example/drawing/demo3/README.md

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,62 +18,62 @@ struct Star: Shape {
1818
// 从矩形的中心绘制
1919
let center = CGPoint(x: rect.width / 2, y: rect.height / 2)
2020

21-
// start from directly upwards (as opposed to down or to the right)
21+
// 从直接向上开始(与向下或向右相反)
2222
var currentAngle = -CGFloat.pi / 2
2323

24-
// calculate how much we need to move with each star corner
24+
// 计算每个星形角落需要移动多少。
2525
let angleAdjustment = .pi * 2 / CGFloat(corners * 2)
2626

27-
// figure out how much we need to move X/Y for the inner points of the star
27+
// 计算星形的内部点需要在X和Y方向上移动多少。
2828
let innerX = center.x * smoothness
2929
let innerY = center.y * smoothness
3030

31-
// we're ready to start with our path now
31+
// 我们现在准备好开始绘制路径了。
3232
var path = Path()
3333

34-
// move to our initial position
34+
// 移动到我们的初始位置。
3535
path.move(to: CGPoint(x: center.x * cos(currentAngle), y: center.y * sin(currentAngle)))
3636

37-
// track the lowest point we draw to, so we can center later
37+
// 跟踪我们绘制的最低点,以便稍后进行居中处理。
3838
var bottomEdge: CGFloat = 0
3939

40-
// loop over all our points/inner points
40+
// 循环遍历所有的点/内部点。
4141
for corner in 0..<corners * 2 {
42-
// figure out the location of this point
42+
// 确定该点的位置。
4343
let sinAngle = sin(currentAngle)
4444
let cosAngle = cos(currentAngle)
4545
let bottom: CGFloat
4646

47-
// if we're a multiple of 2 we are drawing the outer edge of the star
47+
// 如果我们是2的倍数,那么我们正在绘制星形的外边缘。
4848
if corner.isMultiple(of: 2) {
49-
// store this Y position
49+
// 保存这个 Y 位置
5050
bottom = center.y * sinAngle
5151

52-
// …and add a line to there
52+
// ...并添加一条线到那里。
5353
path.addLine(to: CGPoint(x: center.x * cosAngle, y: bottom))
5454
} else {
55-
// we're not a multiple of 2, which means we're drawing an inner point
55+
// 我们不是2的倍数,这意味着我们正在绘制一个内部点。
5656

57-
// store this Y position
57+
// 保存这个 Y 位置
5858
bottom = innerY * sinAngle
5959

60-
// …and add a line to there
60+
// ...并添加一条线到那里。
6161
path.addLine(to: CGPoint(x: innerX * cosAngle, y: bottom))
6262
}
6363

64-
// if this new bottom point is our lowest, stash it away for later
64+
// 如果这个新的底部点是我们最低的点,将其保存供以后使用。
6565
if bottom > bottomEdge {
6666
bottomEdge = bottom
6767
}
6868

69-
// move on to the next corner
69+
// 继续下一个角落。
7070
currentAngle += angleAdjustment
7171
}
7272

73-
// figure out how much unused space we have at the bottom of our drawing rectangle
73+
// 计算我们绘图矩形底部剩余的未使用空间。
7474
let unusedSpace = (rect.height / 2 - bottomEdge) / 2
7575

76-
// create and apply a transform that moves our path down by that amount, centering the shape vertically
76+
// 创建并应用一个变换,将我们的路径向下移动相应的距离,垂直居中形状。
7777
let transform = CGAffineTransform(translationX: center.x, y: center.y + unusedSpace)
7878
return path.applying(transform)
7979
}
@@ -88,4 +88,4 @@ struct ContentView: View {
8888

8989
}
9090
}
91-
```
91+
```

0 commit comments

Comments
 (0)