Skip to content

Commit 1b6a082

Browse files
authored
Merge pull request #663 from sm7515/chinese_translate
translating Interaction section
2 parents 2cf6f5e + 5732903 commit 1b6a082

File tree

11 files changed

+99
-104
lines changed

11 files changed

+99
-104
lines changed

src/data/examples/zh-Hans/10_Interaction/10_Tickle.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
/*
22
* @name Tickle
3-
* @description The word "tickle" jitters when the cursor hovers over.
4-
* Sometimes, it can be tickled off the screen.
3+
* @description "tickle" 这个单词会在光标移至它时抖动。
4+
* 有时还会抖出屏幕。
55
*/
66
let message = 'tickle',
77
font,
8-
bounds, // holds x, y, w, h of the text's bounding box
8+
bounds, // 存储文本框的 x, y, w, h
99
fontsize = 60,
1010
x,
11-
y; // x and y coordinates of the text
11+
y; // 文本的 x 和 y 坐标
1212

1313
function preload() {
1414
font = loadFont('assets/SourceSansPro-Regular.otf');
@@ -17,11 +17,11 @@ function preload() {
1717
function setup() {
1818
createCanvas(710, 400);
1919

20-
// set up the font
20+
// 设置字体
2121
textFont(font);
2222
textSize(fontsize);
2323

24-
// get the width and height of the text so we can center it initially
24+
// 获取文本的宽度和高度,以便我们可以首先将其居中
2525
bounds = font.textBounds(message, 0, 0, fontsize);
2626
x = width / 2 - bounds.w / 2;
2727
y = height / 2 - bounds.h / 2;
@@ -30,12 +30,12 @@ function setup() {
3030
function draw() {
3131
background(204, 120);
3232

33-
// write the text in black and get its bounding box
33+
// 写出黑色的文本并获取其文本框
3434
fill(0);
3535
text(message, x, y);
3636
bounds = font.textBounds(message, x, y, fontsize);
3737

38-
// check if the mouse is inside the bounding box and tickle if so
38+
// 检查鼠标是否在文本框里;如果在文本框内,抖动文本
3939
if (
4040
mouseX >= bounds.x &&
4141
mouseX <= bounds.x + bounds.w &&

src/data/examples/zh-Hans/10_Interaction/20_Follow1.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/*
2-
* @name Follow 1
2+
* @name 跟随 1
33
* @frame 710,400
4-
* @description A line segment is pushed and pulled by the cursor.
5-
* Based on code from Keith Peters.
4+
* @description 被光标拉扯的一条线段。
5+
* 基于 Keith Peters 的代码。
66
*/
77
let x = 100,
88
y = 100,

src/data/examples/zh-Hans/10_Interaction/21_Follow2.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
/*
2-
* @name Follow 2
2+
* @name 跟随 2
33
* @frame 710,400
4-
* @description A two-segmented arm follows the cursor position. The relative
5-
* angle between the segments is calculated with atan2() and the position
6-
* calculated with sin() and cos(). Based on code from Keith Peters.
4+
* @description 跟随光标移动的两段式手臂。
5+
* 两个手臂之间的相对角度是用 atan2() 计算的,位置是用 sin() 和 cos() 计算的。
6+
* 基于 Keith Peters 的代码。
77
*/
88
let x = [0, 0],
99
y = [0, 0],

src/data/examples/zh-Hans/10_Interaction/22_Follow3.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
/*
2-
* @name Follow 3
2+
* @name 跟随 3
33
* @frame 710,400
4-
* @description A segmented line follows the mouse. The relative angle from
5-
* each segment to the next is calculated with atan2() and the position of
6-
* the next is calculated with sin() and cos(). Based on code from Keith Peters.
4+
* @description 随鼠标移动的一条分段式线条。
5+
* 每段之间的相对角度是用 atan2() 计算的,位置是用 sin() 和 cos() 计算的。
6+
* 基于 Keith Peters 的代码。
77
*/
88
let x = [],
99
y = [],

src/data/examples/zh-Hans/10_Interaction/23_snake.js

Lines changed: 20 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
/*
2-
* @name Snake game
3-
* @description The famous snake game! Once you click run, click anywhere
4-
* inside the black area, and control the snake using i j k and l. Don't let
5-
* the snake hit itself or the wall!<br>
6-
* Example created by <a href='https://github.com/prashantgupta24' target='_blank'>Prashant Gupta
2+
* @name 贪吃蛇
3+
* @description 著名的贪吃蛇游戏!点击 run 后,在黑色区域里任意点击,
4+
* 使用 i j k 和 l 控制蛇。注意不要让蛇碰到自己或者墙。<br>
5+
* 由 <a href='https://github.com/prashantgupta24' target='_blank'>Prashant Gupta 创作的范例
76
*/
87

9-
// the snake is divided into small segments, which are drawn and edited on each 'draw' call
8+
// 蛇被分为几小段,在每次调用 draw() 时进行绘制和编辑
109
let numSegments = 10;
1110
let direction = 'right';
1211

13-
const xStart = 0; //starting x coordinate for snake
14-
const yStart = 250; //starting y coordinate for snake
12+
const xStart = 0; // 蛇的初始 x 坐标
13+
const yStart = 250; //蛇的初始 y 坐标
1514
const diff = 10;
1615

1716
let xCor = [];
@@ -50,15 +49,12 @@ function draw() {
5049
}
5150

5251
/*
53-
The segments are updated based on the direction of the snake.
54-
All segments from 0 to n-1 are just copied over to 1 till n, i.e. segment 0
55-
gets the value of segment 1, segment 1 gets the value of segment 2, and so on,
56-
and this results in the movement of the snake.
57-
58-
The last segment is added based on the direction in which the snake is going,
59-
if it's going left or right, the last segment's x coordinate is increased by a
60-
predefined value 'diff' than its second to last segment. And if it's going up
61-
or down, the segment's y coordinate is affected.
52+
根据蛇的方向更新每个小段。
53+
从 0 至 n-1 的所有片段都被复制到 1 至 n,也就是说,段 0 获取 段 1 的值,
54+
段 1 获取 段 2 的值,以此类推。因此,蛇就会动起来了。
55+
56+
最后一小段根据蛇运动的方向添加。如果蛇在左后移动,最后一小段的 x 坐标值将比倒数第二小段
57+
增加预定义值 "diff";如果上下移动,则更改其 y 坐标值。
6258
*/
6359
function updateSnakeCoordinates() {
6460
for (let i = 0; i < numSegments - 1; i++) {
@@ -86,9 +82,8 @@ function updateSnakeCoordinates() {
8682
}
8783

8884
/*
89-
I always check the snake's head position xCor[xCor.length - 1] and
90-
yCor[yCor.length - 1] to see if it touches the game's boundaries
91-
or if the snake hits itself.
85+
检查蛇头的位置 xCor[xCor.length - 1] 和 yCor[yCor.length - 1] 来看它是否
86+
碰到边界或者自己。
9287
*/
9388
function checkGameStatus() {
9489
if (
@@ -105,8 +100,7 @@ function checkGameStatus() {
105100
}
106101

107102
/*
108-
If the snake hits itself, that means the snake head's (x,y) coordinate
109-
has to be the same as one of its own segment's (x,y) coordinate.
103+
如果蛇碰到自己,说明蛇头的 (x,y) 坐标和它自身的小段之一的 (x,y) 坐标相同。
110104
*/
111105
function checkSnakeCollision() {
112106
const snakeHeadX = xCor[xCor.length - 1];
@@ -119,9 +113,8 @@ function checkSnakeCollision() {
119113
}
120114

121115
/*
122-
Whenever the snake consumes a fruit, I increment the number of segments,
123-
and just insert the tail segment again at the start of the array (basically
124-
I add the last segment again at the tail, thereby extending the tail)
116+
蛇每吃一个水果,小段的数量就会增加,然后将尾段插入数组的开头
117+
(将最后一个小段再次添加到尾部,从而延长了尾部)
125118
*/
126119
function checkForFruit() {
127120
point(xFruit, yFruit);
@@ -137,9 +130,8 @@ function checkForFruit() {
137130

138131
function updateFruitCoordinates() {
139132
/*
140-
The complex math logic is because I wanted the point to lie
141-
in between 100 and width-100, and be rounded off to the nearest
142-
number divisible by 10, since I move the snake in multiples of 10.
133+
这里的数学逻辑是因为我希望这个点位于 100 和 width-100 之间,并四舍五入到
134+
10 的倍数 ,因为蛇以 10 的倍数移动。
143135
*/
144136

145137
xFruit = floor(random(10, (width - 100) / 10)) * 10;
Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/*
2-
* @name Wavemaker
3-
* @description This illustrates how waves (like water waves) emerge
4-
* from particles oscillating in place. Move your mouse to direct the wave.
5-
* Contributed by Aatish Bhatia, inspired by <a href="https://beesandbombs.tumblr.com/post/45513650541/orbiters">Orbiters</a> by Dave Whyte.
2+
* @name 造波器
3+
* @description 此范例说明了波(如水波)是如何在粒子摆动中产生的。
4+
* 移动鼠标以引导波浪。
5+
* Aatish Bhatia 贡献,灵感来自 Dave Whyte 的 <a href="https://beesandbombs.tumblr.com/post/45513650541/orbiters">Orbiters</a>
66
*/
77

88
let t = 0; // time variable
@@ -14,24 +14,24 @@ function setup() {
1414
}
1515

1616
function draw() {
17-
background(10, 10); // translucent background (creates trails)
17+
background(10, 10); // 半透明背景(创建足迹)
1818

19-
// make a x and y grid of ellipses
19+
// 创建 x 和 y 网格上的椭圆
2020
for (let x = 0; x <= width; x = x + 30) {
2121
for (let y = 0; y <= height; y = y + 30) {
22-
// starting point of each circle depends on mouse position
22+
// 每个圆的初始位置取决于鼠标位置
2323
const xAngle = map(mouseX, 0, width, -4 * PI, 4 * PI, true);
2424
const yAngle = map(mouseY, 0, height, -4 * PI, 4 * PI, true);
25-
// and also varies based on the particle's location
25+
// 也根据粒子的位置变化
2626
const angle = xAngle * (x / width) + yAngle * (y / height);
2727

28-
// each particle moves in a circle
28+
// 每个粒子绕圈运动
2929
const myX = x + 20 * cos(2 * PI * t + angle);
3030
const myY = y + 20 * sin(2 * PI * t + angle);
3131

32-
ellipse(myX, myY, 10); // draw particle
32+
ellipse(myX, myY, 10); // 绘制粒子
3333
}
3434
}
3535

36-
t = t + 0.01; // update time
36+
t = t + 0.01; // 更新时间
3737
}

src/data/examples/zh-Hans/10_Interaction/25_reach1.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/*
2-
* @name Reach 1
2+
* @name 延伸 1
33
* @frame 710,400
4-
* @description The arm follows the position of the mouse by calculating the
5-
* angles with atan2(). Based on code from Keith Peters.
4+
* @description 手臂随鼠标的位置移动,使用 atan2() 计算角度。
5+
* 基于 Keith Peters 的代码。
66
*/
77
let segLength = 80,
88
x,

src/data/examples/zh-Hans/10_Interaction/26_reach2.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/*
2-
* @name Reach 2
2+
* @name 延伸 2
33
* @frame 710,400
4-
* @description The arm follows the position of the mouse by calculating the
5-
* angles with atan2(). Based on code from Keith Peters.
4+
* @description 手臂随鼠标的位置移动,使用 atan2() 计算角度。
5+
* 基于 Keith Peters 的代码。
66
*/
77
let numSegments = 10,
88
x = [],
@@ -23,8 +23,8 @@ function setup() {
2323
strokeWeight(20);
2424
stroke(255, 100);
2525

26-
x[x.length - 1] = width / 2; // Set base x-coordinate
27-
y[x.length - 1] = height; // Set base y-coordinate
26+
x[x.length - 1] = width / 2; // // 设置基础 x 坐标
27+
y[x.length - 1] = height; // 设置基础 y 坐标
2828
}
2929

3030
function draw() {

src/data/examples/zh-Hans/10_Interaction/27_reach3.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/*
2-
* @name Reach 3
2+
* @name 延伸 3
33
* @frame 710,400
4-
* @description The arm follows the position of the ball by calculating the
5-
* angles with atan2(). Based on code from Keith Peters.
4+
* @description 手臂随球的位置移动,使用 atan2() 计算角度。
5+
* 基于 Keith Peters 的代码。
66
*/
77
let numSegments = 8,
88
x = [],
@@ -28,8 +28,8 @@ function setup() {
2828
stroke(255, 100);
2929
noFill();
3030

31-
x[x.length - 1] = width / 2; // Set base x-coordinate
32-
y[x.length - 1] = height; // Set base y-coordinate
31+
x[x.length - 1] = width / 2; // 设置基础 x 坐标
32+
y[x.length - 1] = height; // 设置基础 y 坐标
3333
}
3434

3535
function draw() {
Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,34 @@
11
/*
2-
* @name Arduino sensor data via WebJack
3-
* @description WebJack is a way to read data from an Arduino (and other sources)
4-
* using audio -- it basically turns your Arduino into an audio modem.
5-
*
2+
* @name 通过 WebJack 读取 Arduino 传感器数据
3+
* @description WebJack 是使用音频从 Arduino(和其他来源)
4+
* 读取数据的方式 -- 它基本上将 Arduino 变成了音频调制解调器。
5+
*
66
* https://github.com/publiclab/webjack
7-
*
8-
* Note: WebJack and p5-webjack libraries must be added to your index.html as follows:
7+
*
8+
* 注: WebJack p5-webjack 库必须以以下方式添加到 index.html
99
* <pre><code class="language-markup">&lt;script src="https://webjack.io/dist/webjack.js">&lt;/script></code></pre>
1010
* <pre><code class="language-markup">&lt;script src="https://jywarren.github.io/p5-webjack/lib.js">&lt;/script></code></pre>
11-
*
12-
* Working example: https://editor.p5js.org/jywarren/sketches/rkztwSt8M
13-
*
14-
* Testing audio: https://www.youtube.com/watch?v=GtJW1Dlt3cg
15-
* Load this sketch onto an Arduino:
11+
*
12+
* 实例: https://editor.p5js.org/jywarren/sketches/rkztwSt8M
13+
*
14+
* 测试音频: https://www.youtube.com/watch?v=GtJW1Dlt3cg
15+
* 将此草图加载到 Arduino:
1616
* https://create.arduino.cc/editor/jywarren/023158d8-be51-4c78-99ff-36c63126b554/preview
17-
* Arduino will output audio from pin 3 + ground. Use microphone or an audio cable.
17+
* 从引脚 3 + 地引脚(GND)输出音频。请使用使用麦克风或音频线。
1818
*/
1919

20-
function setup() {
20+
function setup() {
2121
createCanvas(400, 400);
2222
noStroke();
2323
fill('#ff00aa22');
2424
receiveSensorData(handleData);
25-
}
25+
}
2626

2727
function handleData(data) {
28+
console.log(data); // 打出数据
29+
// data[0] 是第一个值, data[1] 是第二个, 以此类推.
2830

29-
console.log(data); // output the values to log
30-
// data[0] is the 1st value, data[1] 2nd, etc.
31-
32-
// draw stuff! Browse http://p5js.org/reference/
31+
// 绘制! 参考 http://p5js.org/reference/
3332
background('#ddd');
34-
ellipse(100, 200, data[0]+10, data[0]+10);
35-
33+
ellipse(100, 200, data[0] + 10, data[0] + 10);
3634
}

0 commit comments

Comments
 (0)