Skip to content

Commit 5d45bd1

Browse files
committed
translate all exmaples in section 05_Image into Chinese and all Chinese inline documentations
1 parent 1fbd0e1 commit 5d45bd1

File tree

6 files changed

+54
-47
lines changed

6 files changed

+54
-47
lines changed
Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,20 @@
11
/*
2-
* @name Load and Display Image
3-
* @description Images can be loaded and displayed to the screen at their
4-
* actual size or any other size.
5-
* <p><em><span class="small"> To run this example locally, you will need an
6-
* image file, and a running <a href="https://github.com/processing/p5.js/wiki/Local-server">
7-
* local server</a>.</span></em></p>
2+
* @name 加载(Load)和显示(Display)图像
3+
* @description 图像可以以原图大小或自定义大小被加载和显示。
4+
* <p><em><span class="small">要在本地运行此范例,您需要一个图像文件,并运行在<a href="https://github.com/processing/p5.js/wiki/Local-server">
5+
* 本地伺服器</a>上。</span></em></p>
86
97
*/
10-
let img; // Declare variable 'img'.
8+
let img; // 声明变量'img'
119

1210
function setup() {
1311
createCanvas(720, 400);
14-
img = loadImage('assets/moonwalk.jpg'); // Load the image
12+
img = loadImage('assets/moonwalk.jpg'); // 加载图像
1513
}
1614

1715
function draw() {
18-
// Displays the image at its actual size at point (0,0)
16+
// 在坐标(0, 0),显示原图大小的图像
1917
image(img, 0, 0);
20-
// Displays the image at point (0, height/2) at half size
18+
// 在坐标(0, 高度/2),显示一半原图大小的图像
2119
image(img, 0, height / 2, img.width / 2, img.height / 2);
2220
}

src/data/examples/zh-Hans/05_Image/01_Background_Image.js

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,16 @@
11
/*
2-
* @name Background Image
3-
* @description This example presents the fastest way to load a
4-
* background image. To load an image as the background,
5-
* it must be the same width and height as the program.
6-
* <p><em><span class="small"> To run this example locally, you will need an
7-
* image file, and a running <a href="https://github.com/processing/p5.js/wiki/Local-server">
8-
* local server</a>.</span></em></p>
2+
* @name 背景图像
3+
* @description 此范例展示了最快加载背景图像的方法。
4+
* 若需将一张图像作为背景,它必须和程序有相同的宽度和高度。
5+
* <p><em><span class="small">要在本地运行此示例,您需要一个图像文件,并运行在<a href="https://github.com/processing/p5.js/wiki/Local-server">
6+
* 本地伺服器</a>上。</span></em></p>
97
*/
108
let bg;
119
let y = 0;
1210

1311
function setup() {
14-
// The background image must be the same size as the parameters
15-
// into the createCanvas() method. In this program, the size of
16-
// the image is 720x400 pixels.
12+
// 背景图像的大小必须和createCanvas() 函数中的参数一样。
13+
// 该图像大小为720x400 像素。
1714
bg = loadImage('assets/moonwalk.jpg');
1815
createCanvas(720, 400);
1916
}
Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,23 @@
11
/*
2-
* @name Transparency
3-
* @description Move the pointer left and right across the image to change its
4-
* position. This program overlays one image over another by modifying the
5-
* alpha value of the image with the tint() function.
6-
* <p><em><span class="small"> To run this example locally, you will need an
7-
* image file, and a running <a href="https://github.com/processing/p5.js/wiki/Local-server">
8-
* local server</a>.</span></em></p>
2+
* @name 透明度
3+
* @description 左右移动指针(光标)来改变图像位置
4+
* 此程序为一张图像叠加在另一张上,通过tint() 函数来改变它的透明度值(alpha value)。
5+
* <p><em><span class="small">要在本地运行此范例,您需要一个图像文件,并运行在<a href="https://github.com/processing/p5.js/wiki/Local-server">
6+
* 本地伺服器</a>上。</span></em></p>
97
*/
108
let img;
119
let offset = 0;
1210
let easing = 0.05;
1311

1412
function setup() {
1513
createCanvas(720, 400);
16-
img = loadImage('assets/moonwalk.jpg'); // Load an image into the program
14+
img = loadImage('assets/moonwalk.jpg'); // 加载图像
1715
}
1816

1917
function draw() {
20-
image(img, 0, 0); // Display at full opacity
18+
image(img, 0, 0); // 完全不透明
2119
let dx = mouseX - img.width / 2 - offset;
2220
offset += dx * easing;
23-
tint(255, 127); // Display at half opacity
21+
tint(255, 127); // 半透明
2422
image(img, offset, 0);
2523
}

src/data/examples/zh-Hans/05_Image/03_Alpha_Mask.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
/*
22
* @name Alpha Mask
3-
* @description Loads a "mask" for an image to specify the transparency in
4-
* different parts of the image. The two images are blended together using
5-
* the mask() method of p5.Image.
6-
* <p><em><span class="small"> To run this example locally, you will need two
7-
* image files, and a running <a href="https://github.com/processing/p5.js/wiki/Local-server">
8-
* local server</a>.</span></em></p>
3+
* @description 在图像上加载一个蒙版来改变图像中不同位置的透明度。
4+
* 通过拍p5.Image 中的mask() 函数来混合两张图像(图像和蒙版)。
5+
* <p><em><span class="small">要在本地运行此范例,您需要一个图像文件,并运行在<a href="https://github.com/processing/p5.js/wiki/Local-server">
6+
* 本地伺服器</a>上。</span></em></p>
97
*/
108
let img;
119
let imgMask;
1210

1311
function preload() {
12+
// 加载图像及图像蒙版
1413
img = loadImage('assets/moonwalk.jpg');
1514
imgMask = loadImage('assets/mask.png');
1615
}
1716

1817
function setup() {
1918
createCanvas(720, 400);
19+
// maske()函数将图像蒙版覆盖在图像上
2020
img.mask(imgMask);
2121
imageMode(CENTER);
2222
}

src/data/examples/zh-Hans/05_Image/04_Create_Image.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,25 @@
11
/*
2-
* @name Create Image
3-
* @description The createImage() function provides a fresh buffer of pixels to
4-
* play with. This example creates an image gradient.
2+
* @name 创建图像
3+
* @description createImage() 函数能让我们巧妙地操控一堆像素。 此范例创建了一个渐变图像。
54
*/
6-
let img; // Declare variable 'img'.
5+
let img; // 声明变量'img'
76

87
function setup() {
98
createCanvas(720, 400);
9+
// 设置图像大小230*230 像素
1010
img = createImage(230, 230);
11+
12+
// 将显示窗口的像素资料加载到 pixels[] 数组里
13+
// 这函数必须在读写 pixels[] 之前被调用
1114
img.loadPixels();
1215
for (let x = 0; x < img.width; x++) {
1316
for (let y = 0; y < img.height; y++) {
1417
let a = map(y, 0, img.height, 255, 0);
18+
// 使用set() 设置该位置像素的颜色
1519
img.set(x, y, [0, 153, 204, a]);
1620
}
1721
}
22+
// 使用set() 后,必须调用updatePixels() 以使改变生效
1823
img.updatePixels();
1924
}
2025

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,43 @@
11
/*
2-
* @name Pointillism
3-
* @description By Dan Shiffman. Mouse horizontal location controls size of
4-
* dots. Creates a simple pointillist effect using ellipses colored according
5-
* to pixels in an image.
6-
* <p><em><span class="small"> To run this example locally, you will need an
7-
* image file, and a running <a href="https://github.com/processing/p5.js/wiki/Local-server">
8-
* local server</a>.</span></em></p>
2+
* @name 点画(Pointillism)
3+
* @description 作者:Dan Shiffman。
4+
* 鼠标水平位置控制点的大小,由左到右对应由小到大的点。
5+
* 通过带有原图像素颜色的椭圆创建出一副简单的点画。
6+
* <p><em><span class="small">要在本地运行此范例,您需要一个图像文件,并运行在<a href="https://github.com/processing/p5.js/wiki/Local-server">
7+
* 本地伺服器</a>上。</span></em></p>
98
*/
9+
// 声明变量'img', 'smallPoint', 'largePoing'
1010
let img;
1111
let smallPoint, largePoint;
1212

1313
function preload() {
14+
// 加载图像
1415
img = loadImage('assets/moonwalk.jpg');
1516
}
1617

1718
function setup() {
1819
createCanvas(720, 400);
20+
// 设置最小点宽度为4,最大点宽度为40
1921
smallPoint = 4;
2022
largePoint = 40;
2123
imageMode(CENTER);
2224
noStroke();
25+
// 设置背景颜色为白色
2326
background(255);
2427
img.loadPixels();
2528
}
2629

2730
function draw() {
31+
// map() 函数根据鼠标水平位置,
32+
// 将其在[0, 画布宽度] 的数值对应到[最小点宽度, 最大点宽度] ([4,40]) 之中,
33+
// 对应的数值即为点的大小
2834
let pointillize = map(mouseX, 0, width, smallPoint, largePoint);
35+
// 随机生成坐标(x, y)
2936
let x = floor(random(img.width));
3037
let y = floor(random(img.height));
38+
// 得到图像中坐标(x, y) 的颜色
3139
let pix = img.get(x, y);
40+
// fill(灰度值,透明度值)
3241
fill(pix, 128);
3342
ellipse(x, y, pointillize, pointillize);
3443
}

0 commit comments

Comments
 (0)