Skip to content

Commit d5a543a

Browse files
authored
Merge pull request #1288 from 0Susie0/Improve'Transfrom'Translation
Translate examples in transform module into Chinese
2 parents 3c3161a + 2216437 commit d5a543a

File tree

5 files changed

+58
-64
lines changed

5 files changed

+58
-64
lines changed

src/data/examples/zh-Hans/18_Transform/00_Translate.js

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
/*
2-
* @name Translate
3-
* @description The translate() function allows objects to be
4-
* moved to any location within the window. The first parameter
5-
* sets the x-axis offset and the second parameter sets the
6-
* y-axis offset. This example shows how transforms accumulate.
2+
* @name 平移
3+
* @description translate() 函数能够让所有的对象都能够在窗口的任意位置移动.
4+
* 第一个参数设置X轴的偏移量,第二个函数设置Y轴的偏移量. 这个例子展示了变化是如何累积的.
5+
*
76
*/
87

98
let x = 0;
@@ -17,23 +16,23 @@ function setup() {
1716

1817
function draw() {
1918
background(102);
20-
// Animate by increasing our x value
19+
// 通过增加x的值来实现动画效果.
2120
x = x + 0.8;
22-
// If the shape goes off the canvas, reset the position
21+
// 如果该形状离开了画布,就重新设置位置。
2322
if (x > width + dim) {
2423
x = -dim;
2524
}
2625

27-
// Even though our rect command draws the shape with its
28-
// center at the origin, translate moves it to the new
29-
// x and y position
26+
// 尽管我们的矩形命令是以原点为中心画出形状的,但平移会将它移动到新的位置。
27+
// 中心在原点,但平移会将其移动到新的
28+
// X和Y的位置
3029
translate(x, height / 2 - dim / 2);
3130
fill(255);
3231
rect(-dim / 2, -dim / 2, dim, dim);
3332

34-
// Transforms accumulate. Notice how this rect moves
35-
// twice as fast as the other, but it has the same
36-
// parameter for the x-axis value
33+
// 变形累积。注意这个矩形的移动速度
34+
// 的速度是另一个的两倍,但它的X轴值是相同的
35+
// X轴值的参数
3736
translate(x, dim);
3837
fill(0);
3938
rect(-dim / 2, -dim / 2, dim, dim);

src/data/examples/zh-Hans/18_Transform/01_Scale.js

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
/*
2-
* @name Scale
3-
* @description Paramenters for the scale() function are values
4-
* specified as decimal percentages. For example, the method
5-
* call scale(2.0) will increase the dimension of the shape by
6-
* 200 percent. Objects always scale from the origin. This example
7-
* shows how transforms accumulate and also how scale and translate
8-
* interact depending on their order.
2+
* @name 缩放
3+
* @description scale() 函数的参数是值
4+
* 指定为小数百分比。 例如,
5+
* 调用方法 scale(2.0) 将增加形状的尺寸
6+
* 200%。 对象总是从原点缩放。 这个例子
7+
* 显示变换如何累积以及缩放和平移如何
8+
* 根据他们的顺序进行交互。
99
*/
1010

1111
let a = 0.0;
@@ -14,31 +14,29 @@ let s = 0.0;
1414
function setup() {
1515
createCanvas(720, 400);
1616
noStroke();
17-
//Draw all rectangles from their center as opposed to
18-
// the default upper left corner
17+
//从中心点开始画所有的矩形,而不是从默认的左上角开始。
1918
rectMode(CENTER);
2019
}
2120

2221
function draw() {
2322
background(102);
2423

25-
//Slowly increase 'a' and then animate 's' with
26-
//a smooth cyclical motion by finding the cosine of 'a'
24+
//缓慢地增加'a',然后用's'做动画。
25+
//通过寻找'a'的余弦来实现平滑的循环运动
2726
a = a + 0.04;
2827
s = cos(a) * 2;
2928

30-
//Translate our rectangle from the origin to the middle of
31-
//the canvas, then scale it with 's'
29+
//将我们的矩形从原点移到画布的中间。
30+
//然后用's'缩放它。
3231
translate(width / 2, height / 2);
3332
scale(s);
3433
fill(51);
3534
rect(0, 0, 50, 50);
3635

37-
//Translate and scale are accumulating, so this translate
38-
//moves the second rectangle further right than the first
39-
//and the scale is getting doubled. Note that cosine is
40-
//making 's' both negative and positive, thus it cycles
41-
//from left to right.
36+
//translate和scale都是累加的,所以这个translate
37+
//将第二个矩形移动到比第一个矩形更右的位置
38+
//规模扩大了一倍。 注意余弦
39+
//使's'既正又负,因此图像将从左到右的循环。
4240
translate(75, 0);
4341
fill(255);
4442
scale(s);
Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
/*
2-
* @name Rotate
3-
* @description Rotating a square around the Z axis.
4-
* To get the results you expect, send the rotate function angle
5-
* parameters that are values between 0 and PI*2 (TWO_PI which is
6-
* roughly 6.28). If you prefer to think about angles as degrees
7-
* (0-360), you can use the radians() method to convert your values.
8-
* For example: scale(radians(90)) is identical to the statement
9-
* scale(PI/2). In this example, every even numbered second a jitter
10-
* is added to the rotation. During odd seconds rotation moves CW and
11-
* CCW at the speed determined by the last jitter value.
2+
* @name 旋转
3+
* @description 围绕 Z 轴旋转一个正方形。
4+
* 要获得您期望的结果,请发送角度值介于 0 和 PI*2 之间的参数
5+
* TWO_PI 是大约 6.28)给rotate()函数。
6+
* 如果您更喜欢用度数表示(0-360),
7+
* 您可以使用 radians() 方法来转换您的值。
8+
* 例如:scale(radians(90)) 等同于语句
9+
* 比例(PI/2)。 在这个例子中,每偶数秒一个抖动
10+
* 被添加到旋转中。 在奇数秒旋转移动 CW
11+
* CCW 以最后一个抖动值确定的速度。
1212
*/
1313

1414
let angle = 0.0;
@@ -18,26 +18,24 @@ function setup() {
1818
createCanvas(720, 400);
1919
noStroke();
2020
fill(255);
21-
//Draw the rectangle from the center and it will also be the
22-
//rotate around that center
21+
//从中心绘制矩形,它也将围绕那个中心旋转
2322
rectMode(CENTER);
2423
}
2524

2625
function draw() {
2726
background(51);
2827

29-
// during even-numbered seconds (0, 2, 4, 6...) add jitter to
30-
// the rotation
28+
// 在偶数秒 (0, 2, 4, 6...) 中添加抖动旋转
3129
if (second() % 2 === 0) {
3230
jitter = random(-0.1, 0.1);
3331
}
34-
//increase the angle value using the most recent jitter value
32+
//使用最近的抖动值增加角度值
3533
angle = angle + jitter;
36-
//use cosine to get a smooth CW and CCW motion when not jittering
34+
//在不抖动时使用余弦获得平滑的 CW CCW 运动
3735
let c = cos(angle);
38-
//move the shape to the center of the canvas
36+
//将形状移动到画布的中心
3937
translate(width / 2, height / 2);
40-
//apply the final rotation
38+
//应用最终旋转
4139
rotate(c);
4240
rect(0, 0, 180, 180);
4341
}

src/data/examples/zh-Hans/18_Transform/03_Arm.js

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
/*
2-
* @name Arm
3-
* @description This example uses transform matrices to create
4-
* an arm. The angle of each segment is controlled with the
5-
* mouseX and mouseY position. The transformations applied to
6-
* the first segment are also applied to the second segment
7-
* because they are inside the same push() and
8-
* pop() matrix group.
2+
* @name 手臂
3+
* @description 此示例使用变换矩阵创建
4+
* 一只手臂。 每一段的角度都由
5+
* 鼠标在画布上的位置控制。 应用于第一段变换方式
6+
* 也适用于第二段因为它们在同一个 push()和pop()
7+
* 矩阵组中。
98
*/
109

1110
let x, y;
@@ -17,31 +16,31 @@ function setup() {
1716
createCanvas(720, 400);
1817
strokeWeight(30);
1918

20-
//Stroke with a semi-transparent white
19+
//用半透明的白色划线
2120
stroke(255, 160);
2221

23-
//Position the "shoulder" of the arm in the center of the canvas
22+
//将手臂的 "肩膀 "放在画布的中心。
2423
x = width * 0.5;
2524
y = height * 0.5;
2625
}
2726

2827
function draw() {
2928
background(0);
3029

31-
//Change the angle of the segments according to the mouse positions
30+
//根据鼠标的位置来改变片段的角度
3231
angle1 = (mouseX / float(width) - 0.5) * -TWO_PI;
3332
angle2 = (mouseY / float(height) - 0.5) * PI;
3433

35-
//use push and pop to "contain" the transforms. Note that
36-
// even though we draw the segments using a custom function,
37-
// the transforms still accumulate
34+
//使用push和pop来 "包含 "这些变换。请注意
35+
// 即使我们使用一个自定义函数来画段。
36+
// 变换仍然会累积
3837
push();
3938
segment(x, y, angle1);
4039
segment(segLength, 0, angle2);
4140
pop();
4241
}
4342

44-
//a custom function for drawing segments
43+
//一个用于绘制分段的自定义函数。
4544
function segment(x, y, a) {
4645
translate(x, y);
4746
rotate(a);

src/data/zh-Hans.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -945,7 +945,7 @@ examples:
945945
Instance_Mode: 实例模式
946946
Dom: DOM
947947
Drawing: Drawing
948-
Transform: Transform
948+
Transform: 变换
949949
Typography: Typography
950950
3D: 3D
951951
Input: Input

0 commit comments

Comments
 (0)