Skip to content

Commit 4079384

Browse files
committed
done
1 parent 57a5e41 commit 4079384

File tree

10 files changed

+87
-90
lines changed

10 files changed

+87
-90
lines changed

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: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,36 @@
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.
2+
* @name 通过 WebJack 读取 Arduino 传感器数据
3+
* @description WebJack 是使用音频从 Arduino(和其他来源)
4+
* 读取数据的方式 -- 它基本上将 Arduino 变成了音频调制解调器。
55
*
66
* https://github.com/publiclab/webjack
77
*
8-
* Note: WebJack and p5-webjack libraries must be added to your index.html as follows:
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>
1111
*
12-
* Working example: https://editor.p5js.org/jywarren/sketches/rkztwSt8M
12+
* 实例: https://editor.p5js.org/jywarren/sketches/rkztwSt8M
1313
*
14-
* Testing audio: https://www.youtube.com/watch?v=GtJW1Dlt3cg
15-
* Load this sketch onto an Arduino:
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+
* Arduino will output audio from pin 3 + ground. 请使用使用麦克风或音频线。
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) {
2828

29-
console.log(data); // output the values to log
30-
// data[0] is the 1st value, data[1] 2nd, etc.
29+
console.log(data); // 打出数据
30+
// data[0] 是第一个值, data[1] 是第二个, 以此类推.
3131

32-
// draw stuff! Browse http://p5js.org/reference/
32+
// 绘制! 参见 http://p5js.org/reference/
3333
background('#ddd');
34-
ellipse(100, 200, data[0]+10, data[0]+10);
34+
ellipse(100, 200, data[0] + 10, data[0] + 10);
3535

3636
}

src/data/examples/zh-Hans/10_Interaction/29_kaleidoscope.js

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,52 @@
11
/*
2-
* @name Kaleidoscope
3-
* @description A kaleidoscope is an optical instrument with two or more reflecting surfaces tilted to each other in an angle. This example tries to replicate the behavior of a kaleidoscope. Set the number of reflections at the symmetry variable and start drawing on the screen. Adjust the brush size with the help of the slider. The clear screen as it says clears the screen. The save button will download a .jpg file of the art that you have created.
2+
* @name 万花筒
3+
* @description 万花筒是一个光学仪器,具有两个或多个互相倾斜的反射面。
4+
* 此范例尝试模仿万花筒的效果。
5+
* 通过 symmetry 变量设定反射的数量,并开始在屏幕上绘制。
6+
* 通过 slider 调整画笔的大小。
7+
* clearScreen(),顾名思义,清空屏幕。
8+
* save 按钮将你绘制的艺术品以 .jpg 的文件格式下载下来。
49
*/
5-
// Symmetry corresponding to the number of reflections. Change the number for different number of reflections
6-
let symmetry = 6;
10+
// Symmetry 指反射的次数。更改此数值以改变反射的次数。
11+
let symmetry = 6;
712

813
let angle = 360 / symmetry;
914
let saveButton, clearButton, mouseButton, keyboardButton;
1015
let slider;
1116

12-
function setup() {
17+
function setup() {
1318
createCanvas(710, 710);
1419
angleMode(DEGREES);
1520
background(127);
1621

17-
// Creating the save button for the file
22+
// 制作保存文件的按钮
1823
saveButton = createButton('save');
1924
saveButton.mousePressed(saveFile);
2025

21-
// Creating the clear screen button
26+
// 制作清空屏幕的按钮
2227
clearButton = createButton('clear');
2328
clearButton.mousePressed(clearScreen);
2429

25-
// Creating the button for Full Screen
30+
// 制作全屏按钮
2631
fullscreenButton = createButton('Full Screen');
2732
fullscreenButton.mousePressed(screenFull);
2833

29-
// Setting up the slider for the thickness of the brush
34+
// 设置 slider 以改变笔刷的粗细
3035
brushSizeSlider = createButton('Brush Size Slider');
3136
sizeSlider = createSlider(1, 32, 4, 0.1);
3237
}
3338

34-
// Save File Function
39+
// 保存文件函数
3540
function saveFile() {
3641
save('design.jpg');
3742
}
3843

39-
// Clear Screen function
44+
// 清空屏幕函数
4045
function clearScreen() {
4146
background(127);
4247
}
4348

44-
// Full Screen Function
49+
// 全屏函数
4550
function screenFull() {
4651
let fs = fullscreen();
4752
fullscreen(!fs);
@@ -55,7 +60,7 @@ function draw() {
5560
let my = mouseY - height / 2;
5661
let pmx = pmouseX - width / 2;
5762
let pmy = pmouseY - height / 2;
58-
63+
5964
if (mouseIsPressed) {
6065
for (let i = 0; i < symmetry; i++) {
6166
rotate(angle);

0 commit comments

Comments
 (0)