Skip to content

Commit a1da4a7

Browse files
authored
Merge pull request #648 from nyu-ossd-s20/translate
translate examples 05_Image and 07_Color into Chinese
2 parents 4fd9c1f + 94aa9a6 commit a1da4a7

14 files changed

+97
-92
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: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
/*
2-
* @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>
2+
* @name 透明度遮罩 (Alpha Mask)
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+
// mask() 函数将图像遮罩覆盖在图像上
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+
// 设置图像大小 230x230 像素
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
}

src/data/examples/zh-Hans/07_Color/00_Hue.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/*
2-
* @name Hue
3-
* @description Hue is the color reflected from or transmitted through an
4-
* object and is typically referred to as the name of the color (red, blue,
5-
* yellow, etc.) Move the cursor vertically over each bar to alter its hue.
2+
* @name 色调
3+
* @description 色调是从物件反射或透过物件传播得到的颜色,
4+
* 通常指颜色的名字(红色,蓝色,黄色等)。
5+
* 将光标在每个条形上垂直移动以更改其色调。
66
*/
77
const barWidth = 20;
88
let lastBar = -1;

src/data/examples/zh-Hans/07_Color/01_Saturation.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
/*
2-
* @name Saturation
3-
* @description Saturation is the strength or purity of the color and
4-
* represents the amount of gray in proportion to the hue. A "saturated"
5-
* color is pure and an "unsaturated" color has a large percentage of gray.
6-
* Move the cursor vertically over each bar to alter its saturation.
2+
* @name 饱和度
3+
* @description 饱和度是颜色的强度或者纯度,代表与色调成比例的灰色量。
4+
* “饱和”的颜色是纯色;“不饱和”的颜色含有很大比例的灰色。
5+
* 将光标在每个条形上垂直移动以更改其饱和度。
76
*/
87
const barWidth = 20;
98
let lastBar = -1;

src/data/examples/zh-Hans/07_Color/02_Brightness.js

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
/*
2-
* @name Brightness
3-
* @description By Dan Shiffman. This program adjusts the brightness of a part
4-
* of the image by calculating the distance of each pixel to the mouse.
5-
* <p><em><span class="small"> To run this example locally, you will need
6-
* at least an image file and a running <a href="https://github.com/processing/p5.js/wiki/Local-server">local server</a>.</span></em></p>
2+
* @name 亮度
3+
* @description 作者 Dan Shiffman。
4+
* 此程序通过计算每个像素距离光标的距离调整图像的局部亮度。
5+
* <p><em><span class="small">
6+
* 要在本地运行此范例,您需要至少一个图像文件,并运行在
7+
* <a href="https://github.com/processing/p5.js/wiki/Local-server">
8+
* 本地伺服器 </a>上。</span></em></p>
79
*/
810
let img;
911

@@ -21,19 +23,19 @@ function setup() {
2123
function draw() {
2224
for (let x = 0; x < img.width; x++) {
2325
for (let y = 0; y < img.height; y++) {
24-
// Calculate the 1D location from a 2D grid
26+
// 通过 2D 网格计算1D位置
2527
let loc = (x + y * img.width) * 4;
26-
// Get the R,G,B values from image
28+
// 从图像里获取 R,G,B 数值
2729
let r, g, b;
2830
r = img.pixels[loc];
29-
// Calculate an amount to change brightness based on proximity to the mouse
31+
// 根据距离光标的距离计算亮度改变的量
3032
let maxdist = 50;
3133
let d = dist(x, y, mouseX, mouseY);
3234
let adjustbrightness = (255 * (maxdist - d)) / maxdist;
3335
r += adjustbrightness;
34-
// Constrain RGB to make sure they are within 0-255 color range
36+
// 限制 RGB 以确保它们在 0-255 的颜色范围内
3537
r = constrain(r, 0, 255);
36-
// Make a new color and set pixel in the window
38+
// 创建一个新颜色,并在窗口里设置像素
3739
//color c = color(r, g, b);
3840
let pixloc = (y * width + x) * 4;
3941
pixels[pixloc] = r;

src/data/examples/zh-Hans/07_Color/03_Color_Variables.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
2-
* @name Color Variables
3-
* @description (Homage to Albers.) This example creates variables for colors
4-
* that may be referred to in the program by a name, rather than a number.
2+
* @name 颜色变量
3+
* @description (Albers 致敬。) 此范例为颜色们建立了变量。
4+
* 这样它们可以在程序中以名字指代,而非数字。
55
*/
66
function setup() {
77
createCanvas(710, 400);
@@ -12,8 +12,8 @@ function setup() {
1212
let middle = color(204, 153, 0);
1313
let outside = color(153, 51, 0);
1414

15-
// These statements are equivalent to the statements above.
16-
// Programmers may use the format they prefer.
15+
// 以下语句与上面的语句等效。
16+
// 程序员可以选择他们喜欢的格式。
1717
//let inside = color('#CC6600');
1818
//let middle = color('#CC9900');
1919
//let outside = color('#993300');

0 commit comments

Comments
 (0)