Skip to content

Commit 2e41188

Browse files
committed
done
1 parent 78aedf6 commit 2e41188

File tree

8 files changed

+137
-0
lines changed

8 files changed

+137
-0
lines changed

i18n-tracking.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ es:
179179
line 608: ' book-1-authors'
180180
line 617: ' book-2-authors'
181181
line 409: ' p5.bots'
182+
line 656: ' Image_Processing'
182183
zh-Hans:
183184
src/data/en.yml:
184185
line 480: ' notes3'
@@ -287,3 +288,4 @@ zh-Hans:
287288
line 608: ' book-1-authors'
288289
line 617: ' book-2-authors'
289290
line 409: ' p5.bots'
291+
line 656: ' Image_Processing'

src/data/en.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -653,6 +653,7 @@ examples:
653653
Arrays: "Arrays"
654654
Control: "Control"
655655
Image: "Image"
656+
Image_Processing: "Image Processing"
656657
Color: "Color"
657658
Math: "Math"
658659
Simulate: "Simulate"

src/data/es.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -654,6 +654,7 @@ examples:
654654
Arrays: "Arreglos"
655655
Control: "Control"
656656
Image: "Imagen"
657+
Image_Processing: "Procesamiento de imagen"
657658
Color: "Color"
658659
Math: "Matemática"
659660
Simulate: "Simulación"

src/data/examples/assets/sea.jpg

185 KB
Loading
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* @name Pixel Array
3+
* @description Click and drag the mouse up and down to control the signal
4+
* and press and hold any key to see the current pixel being read.
5+
* This program sequentially reads the color of every pixel of an image
6+
* and displays this color to fill the window.
7+
*/
8+
9+
let img;
10+
let direction = 1;
11+
let signal = 0;
12+
13+
function setup() {
14+
createCanvas(640, 360);
15+
noFill();
16+
stroke(255);
17+
frameRate(30);
18+
img = loadImage('assets/sea.jpg');
19+
}
20+
21+
function draw() {
22+
if (signal > img.width * img.height - 1 || signal < 0) {
23+
direction = direction * -1;
24+
}
25+
26+
if (mouseIsPressed) {
27+
let mx = constrain(mouseX, 0, img.width - 1);
28+
let my = constrain(mouseY, 0, img.height - 1);
29+
signal = my * img.width + mx;
30+
} else {
31+
signal += 0.33 * direction;
32+
}
33+
34+
let sx = int(signal) % img.width;
35+
let sy = int(signal) / img.width;
36+
if (keyIsPressed) {
37+
set(0, 0, img); // fast way to draw an image
38+
point(sx, sy);
39+
rect(sx - 5, sy - 5, 10, 10);
40+
} else {
41+
let c = img.get(sx, sy);
42+
background(c);
43+
}
44+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* @name Pixel Array
3+
* @description Click and drag the mouse up and down to control the signal
4+
* and press and hold any key to see the current pixel being read.
5+
* This program sequentially reads the color of every pixel of an image
6+
* and displays this color to fill the window.
7+
*/
8+
9+
let img;
10+
let direction = 1;
11+
let signal = 0;
12+
13+
function setup() {
14+
createCanvas(640, 360);
15+
noFill();
16+
stroke(255);
17+
frameRate(30);
18+
img = loadImage('assets/sea.jpg');
19+
}
20+
21+
function draw() {
22+
if (signal > img.width * img.height - 1 || signal < 0) {
23+
direction = direction * -1;
24+
}
25+
26+
if (mouseIsPressed) {
27+
let mx = constrain(mouseX, 0, img.width - 1);
28+
let my = constrain(mouseY, 0, img.height - 1);
29+
signal = my * img.width + mx;
30+
} else {
31+
signal += 0.33 * direction;
32+
}
33+
34+
let sx = int(signal) % img.width;
35+
let sy = int(signal) / img.width;
36+
if (keyIsPressed) {
37+
set(0, 0, img); // fast way to draw an image
38+
point(sx, sy);
39+
rect(sx - 5, sy - 5, 10, 10);
40+
} else {
41+
let c = img.get(sx, sy);
42+
background(c);
43+
}
44+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* @name Pixel Array
3+
* @description Click and drag the mouse up and down to control the signal
4+
* and press and hold any key to see the current pixel being read.
5+
* This program sequentially reads the color of every pixel of an image
6+
* and displays this color to fill the window.
7+
*/
8+
9+
let img;
10+
let direction = 1;
11+
let signal = 0;
12+
13+
function setup() {
14+
createCanvas(640, 360);
15+
noFill();
16+
stroke(255);
17+
frameRate(30);
18+
img = loadImage('assets/sea.jpg');
19+
}
20+
21+
function draw() {
22+
if (signal > img.width * img.height - 1 || signal < 0) {
23+
direction = direction * -1;
24+
}
25+
26+
if (mouseIsPressed) {
27+
let mx = constrain(mouseX, 0, img.width - 1);
28+
let my = constrain(mouseY, 0, img.height - 1);
29+
signal = my * img.width + mx;
30+
} else {
31+
signal += 0.33 * direction;
32+
}
33+
34+
let sx = int(signal) % img.width;
35+
let sy = int(signal) / img.width;
36+
if (keyIsPressed) {
37+
set(0, 0, img); // fast way to draw an image
38+
point(sx, sy);
39+
rect(sx - 5, sy - 5, 10, 10);
40+
} else {
41+
let c = img.get(sx, sy);
42+
background(c);
43+
}
44+
}

src/data/zh-Hans.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -653,6 +653,7 @@ examples:
653653
Arrays: "数组"
654654
Control: "控制"
655655
Image: "图像"
656+
Image_Processing: "图像处理"
656657
Color: "颜色"
657658
Math: "数学"
658659
Simulate: "模拟"

0 commit comments

Comments
 (0)