Skip to content

Commit 37f70cf

Browse files
committed
done with section 7
1 parent 45a1d74 commit 37f70cf

File tree

7 files changed

+70
-56
lines changed

7 files changed

+70
-56
lines changed

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: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
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

1012
function preload() {
11-
img = loadImage('assets/moonwalk.jpg');
13+
img = loadImage("assets/moonwalk.jpg");
1214
}
1315

1416
function setup() {
@@ -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');

src/data/examples/zh-Hans/07_Color/04_Relativity.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/*
2-
* @name Relativity
3-
* @description Each color is perceived in relation to other colors. The top
4-
* and bottom bars each contain the same component colors, but a different
5-
* display order causes individual colors to appear differently.
2+
* @name 相对性
3+
* @description 我们对每个颜色的感知都是相对于其他颜色而言的。
4+
* 上半部分和下半部分的条形具有相同的颜色构成,但是他们呈现每个颜色的顺序不同,
5+
* 让同一个颜色看起来也不一样。
66
*/
77
let a, b, c, d, e;
88

@@ -14,7 +14,7 @@ function setup() {
1414
c = color(42, 106, 105);
1515
d = color(165, 89, 20);
1616
e = color(146, 150, 127);
17-
noLoop(); // Draw only one time
17+
noLoop(); // 只画一次
1818
}
1919

2020
function draw() {

src/data/examples/zh-Hans/07_Color/05_Linear_Gradient.js

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
/*
2-
* @name Linear Gradient
3-
* @description The lerpColor() function is useful for interpolating between
4-
* two colors.
2+
* @name 线性渐变
3+
* @description lerpColor()函数可用于在两个颜色之间插值。
54
*/
6-
// Constants
5+
// 常量
76
const Y_AXIS = 1;
87
const X_AXIS = 2;
98
let b1, b2, c1, c2;
109

1110
function setup() {
1211
createCanvas(710, 400);
1312

14-
// Define colors
13+
// 定义颜色
1514
b1 = color(255);
1615
b2 = color(0);
1716
c1 = color(204, 102, 0);
@@ -21,10 +20,10 @@ function setup() {
2120
}
2221

2322
function draw() {
24-
// Background
23+
// 背景
2524
setGradient(0, 0, width / 2, height, b1, b2, X_AXIS);
2625
setGradient(width / 2, 0, width / 2, height, b2, b1, X_AXIS);
27-
// Foreground
26+
// 前景
2827
setGradient(50, 90, 540, 80, c1, c2, Y_AXIS);
2928
setGradient(50, 190, 540, 80, c2, c1, X_AXIS);
3029
}
@@ -33,15 +32,15 @@ function setGradient(x, y, w, h, c1, c2, axis) {
3332
noFill();
3433

3534
if (axis === Y_AXIS) {
36-
// Top to bottom gradient
35+
// 从上到下的渐变
3736
for (let i = y; i <= y + h; i++) {
3837
let inter = map(i, y, y + h, 0, 1);
3938
let c = lerpColor(c1, c2, inter);
4039
stroke(c);
4140
line(x, i, x + w, i);
4241
}
4342
} else if (axis === X_AXIS) {
44-
// Left to right gradient
43+
// 从左到右的渐变
4544
for (let i = x; i <= x + w; i++) {
4645
let inter = map(i, x, x + w, 0, 1);
4746
let c = lerpColor(c1, c2, inter);

src/data/examples/zh-Hans/07_Color/06_Radial_Gradient.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
/*
2-
* @name Radial Gradient
3-
* @description Draws a series of concentric circles to create a gradient
4-
* from one color to another.
2+
* @name 径向渐变
3+
* @description 绘制一系列同心圆,创造出从一个颜色到另一个颜色到渐变效果。
54
*/
65
let dim;
76

src/data/examples/zh-Hans/07_Color/07_Lerp_Color.js

Lines changed: 33 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
/*
22
* @name Lerp Color
3-
* @description Loop random shapes,
4-
* lerp color from red to blue.
3+
* @description 随机循环形状,颜色从红色到蓝色。
54
*/
65
function setup() {
76
createCanvas(720, 400);
@@ -18,31 +17,47 @@ function draw() {
1817
for (let i = 0; i < 15; i++) {
1918
fill(from);
2019
quad(
21-
random(-40, 220), random(height),
22-
random(-40, 220), random(height),
23-
random(-40, 220), random(height),
24-
random(-40, 220), random(height)
20+
random(-40, 220),
21+
random(height),
22+
random(-40, 220),
23+
random(height),
24+
random(-40, 220),
25+
random(height),
26+
random(-40, 220),
27+
random(height)
2528
);
2629
fill(c1);
2730
quad(
28-
random(140, 380), random(height),
29-
random(140, 380), random(height),
30-
random(140, 380), random(height),
31-
random(140, 380), random(height)
31+
random(140, 380),
32+
random(height),
33+
random(140, 380),
34+
random(height),
35+
random(140, 380),
36+
random(height),
37+
random(140, 380),
38+
random(height)
3239
);
3340
fill(c2);
3441
quad(
35-
random(320, 580), random(height),
36-
random(320, 580), random(height),
37-
random(320, 580), random(height),
38-
random(320, 580), random(height)
42+
random(320, 580),
43+
random(height),
44+
random(320, 580),
45+
random(height),
46+
random(320, 580),
47+
random(height),
48+
random(320, 580),
49+
random(height)
3950
);
4051
fill(to);
4152
quad(
42-
random(500, 760), random(height),
43-
random(500, 760), random(height),
44-
random(500, 760), random(height),
45-
random(500, 760), random(height)
53+
random(500, 760),
54+
random(height),
55+
random(500, 760),
56+
random(height),
57+
random(500, 760),
58+
random(height),
59+
random(500, 760),
60+
random(height)
4661
);
4762
}
4863
frameRate(5);

0 commit comments

Comments
 (0)