FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Examples updates for 2.0 · ranlevinstein/processing@660adf3 · GitHub

Examples updates for 2.0 · ranlevinstein/processing@660adf3 · GitHub
Skip to content

Navigation Menu

Repository navigation

Commit 660adf3

Browse files
committed
Examples updates for 2.0
1 parent 9588bb0 commit 660adf3

33 files changed

Lines changed: 302 additions & 277 deletions

File tree

‎java/examples/Basics/Arrays/Array/Array.pde‎

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,35 @@
1010
* separate ways on the screen.
1111
*/
1212

13-
size(200, 200);
1413

15-
float[] coswave = new float[width];
14+
float[] coswave;
1615

17-
for (int i = 0; i < width; i++) {
18-
float amount = map(i, 0, width, 0, PI);
19-
coswave[i] = abs(cos(amount));
16+
void setup() {
17+
size(640, 360);
18+
coswave = new float[width];
19+
for (int i = 0; i < width; i++) {
20+
float amount = map(i, 0, width, 0, PI);
21+
coswave[i] = abs(cos(amount));
22+
}
23+
noLoop();
2024
}
2125

22-
for (int i = 0; i < width; i++) {
23-
stroke(coswave[i]*255);
24-
line(i, 0, i, height/3);
25-
}
26+
void draw() {
2627

27-
for (int i = 0; i < width; i++) {
28-
stroke(coswave[i]*255 / 4);
29-
line(i, height/3, i, height/3*2);
30-
}
28+
for (int i = 0; i < width; i++) {
29+
stroke(coswave[i]*255);
30+
line(i, 0, i, height/3);
31+
}
3132

32-
for (int i = 0; i < width; i++) {
33-
stroke(255 - coswave[i]*255);
34-
line(i, height/3*2, i, height);
33+
for (int i = 0; i < width; i++) {
34+
stroke(coswave[i]*255 / 4);
35+
line(i, height/3, i, height/3*2);
36+
}
37+
38+
for (int i = 0; i < width; i++) {
39+
stroke(255 - coswave[i]*255);
40+
line(i, height/3*2, i, height);
41+
}
42+
3543
}
44+

‎java/examples/Basics/Arrays/Array2D/Array2D.pde‎

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,32 @@
66
* 2D arrays are useful for storing images. In this example, each dot
77
* is colored in relation to its distance from the center of the image.
88
*/
9-
9+
1010
float[][] distances;
1111
float maxDistance;
12+
int spacer = 10;
1213

13-
size(200, 200);
14-
background(0);
15-
maxDistance = dist(width/2, height/2, width, height);
16-
distances = new float[width][height];
17-
for(int i=0; i<height; i++) {
18-
for(int j=0; j<width; j++) {
19-
float dist = dist(width/2, height/2, j, i);
20-
distances[j][i] = dist/maxDistance * 255;
14+
void setup() {
15+
size(640, 360);
16+
maxDistance = dist(width/2, height/2, width, height);
17+
distances = new float[width][height];
18+
for (int y = 0; y < height; y++) {
19+
for (int x = 0; x < width; x++) {
20+
float dist = dist(width/2, height/2, x, y);
21+
distances[x][y] = dist/maxDistance * 255;
22+
}
2123
}
24+
noLoop(); // Run once and stop
2225
}
2326

24-
for(int i=0; i<height; i+=2) {
25-
for(int j=0; j<width; j+=2) {
26-
stroke(distances[j][i]);
27-
point(j, i);
27+
void draw() {
28+
background(0);
29+
for (int y = 0; y < height; y += spacer) {
30+
for (int x = 0; x < width; x += spacer) {
31+
stroke(distances[x][y]);
32+
point(x + spacer/2, y + spacer/2);
33+
}
2834
}
2935
}
3036

3137

32-

‎java/examples/Basics/Arrays/ArrayObjects/ArrayObjects.pde‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,11 @@ int unit = 40;
1010
int count;
1111
Module[] mods;
1212

13-
1413
void setup() {
15-
size(320, 240);
14+
size(640, 360);
1615
background(176);
1716
noStroke();
18-
17+
smooth();
1918
int wideCount = width / unit;
2019
int highCount = height / unit;
2120
count = wideCount * highCount;
@@ -24,13 +23,13 @@ void setup() {
2423
int index = 0;
2524
for (int y = 0; y < highCount; y++) {
2625
for (int x = 0; x < wideCount; x++) {
27-
mods[index++] = new Module(x*unit, y*unit, unit/2, unit/2, random(0.05, 0.8));
26+
mods[index++] = new Module(x*unit, y*unit, unit/2, unit/2, random(0.05, 0.8), unit);
2827
}
2928
}
3029
}
3130

32-
3331
void draw() {
32+
background(0);
3433
for (int i = 0; i < count; i++) {
3534
mods[i].update();
3635
mods[i].draw();
Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,39 @@
11
class Module {
2-
int mx, my;
3-
int big;
2+
int xOffset;
3+
int yOffset;
44
float x, y;
5-
int xdir = 1;
6-
int ydir = 1;
5+
int unit;
6+
int xDirection = 1;
7+
int yDirection = 1;
78
float speed;
89

9-
// Contructor (required)
10-
Module(int imx, int imy, int ix, int iy, float ispeed) {
11-
mx = imx;
12-
my = imy;
13-
x = ix;
14-
y = iy;
15-
speed = ispeed;
16-
big = unit;
10+
// Contructor
11+
Module(int xOffsetTemp, int yOffsetTemp, int xTemp, int yTemp, float speedTemp, int tempUnit) {
12+
xOffset = xOffsetTemp;
13+
yOffset = yOffsetTemp;
14+
x = xTemp;
15+
y = yTemp;
16+
speed = speedTemp;
17+
unit = tempUnit;
1718
}
1819

1920
// Custom method for updating the variables
2021
void update() {
21-
x = x + (speed * xdir);
22-
if (x >= big || x <= 0) {
23-
xdir *= -1;
24-
x = x + (1 * xdir);
25-
y = y + (1 * ydir);
22+
x = x + (speed * xDirection);
23+
if (x >= unit || x <= 0) {
24+
xDirection *= -1;
25+
x = x + (1 * xDirection);
26+
y = y + (1 * yDirection);
2627
}
27-
if (y >= big || y <= 0) {
28-
ydir *= -1;
29-
y = y + (1 * ydir);
28+
if (y >= unit || y <= 0) {
29+
yDirection *= -1;
30+
y = y + (1 * yDirection);
3031
}
3132
}
3233

3334
// Custom method for drawing the object
3435
void draw() {
35-
stroke(second() * 4);
36-
point(mx+x-1, my+y-1);
36+
fill(255);
37+
ellipse(xOffset + x, yOffset + y, 6, 6);
3738
}
3839
}

‎java/examples/Basics/Color/Hue/Hue.pde‎

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,25 @@
66
* Move the cursor vertically over each bar to alter its hue.
77
*/
88

9-
int barWidth = 5;
10-
int[] hue;
9+
int barWidth = 20;
10+
int lastBar = -1;
1111

1212
void setup()
1313
{
14-
size(200, 200);
15-
colorMode(HSB, 360, height, height);
16-
hue = new int[width/barWidth];
14+
size(640, 360);
15+
colorMode(HSB, height, height, height);
1716
noStroke();
17+
background(0);
1818
}
1919

2020
void draw()
2121
{
22-
int j = 0;
23-
for (int i=0; i<=(width-barWidth); i+=barWidth) {
24-
if ((mouseX > i) && (mouseX < i+barWidth)) {
25-
hue[j] = mouseY;
26-
}
27-
fill(hue[j], height/1.2, height/1.2);
28-
rect(i, 0, barWidth, height);
29-
j++;
22+
int whichBar = mouseX / barWidth;
23+
if (whichBar != lastBar) {
24+
int barX = whichBar * barWidth;
25+
fill(mouseY, height, height);
26+
rect(barX, 0, barWidth, height);
27+
lastBar = whichBar;
3028
}
3129
}
30+

‎java/examples/Basics/Color/Saturation/Saturation.pde‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
* Move the cursor vertically over each bar to alter its saturation.
88
*/
99

10-
int barWidth = 5;
10+
int barWidth = 20;
1111
int lastBar = -1;
1212

1313

1414
void setup() {
15-
size(200, 200);
15+
size(640, 360);
1616
colorMode(HSB, width, height, 100);
1717
noStroke();
1818
}

‎java/examples/Basics/Control/Conditionals1/Conditionals1.pde‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@
1010
* equal to zero then draw a line.
1111
*/
1212

13-
size(200, 200);
13+
size(640, 360);
1414
background(0);
1515

16-
for(int i=10; i<width; i+=10) {
16+
for(int i = 10; i < width; i += 10) {
1717
// If 'i' divides by 20 with no remainder draw the first line
1818
// else draw the second line
1919
if(i%20 == 0) {
2020
stroke(153);
21-
line(i, 40, i, height/2);
21+
line(i, 80, i, height/2);
2222
} else {
2323
stroke(102);
2424
line(i, 20, i, 180);

‎java/examples/Basics/Control/Conditionals2/Conditionals2.pde‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,20 @@
77
* action.
88
*/
99

10-
size(200, 200);
10+
size(640, 360);
1111
background(0);
1212

13-
for(int i=2; i<width-2; i+=2) {
13+
for(int i = 2; i < width-2; i += 2) {
1414
// If 'i' divides by 20 with no remainder
1515
// draw the first line else draw the second line
16-
if(i%20 == 0) {
16+
if((i % 20) == 0) {
1717
stroke(255);
18-
line(i, 40, i, height/2);
19-
} else if (i%10 == 0) {
18+
line(i, 80, i, height/2);
19+
} else if ((i % 10) == 0) {
2020
stroke(153);
2121
line(i, 20, i, 180);
22-
} else {
22+
} else {
2323
stroke(102);
24-
line(i, height/2, i, height-40);
24+
line(i, height/2, i, height-20);
2525
}
2626
}

‎java/examples/Basics/Control/EmbeddedIteration/EmbeddedIteration.pde‎

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,23 @@
22
* Embedding Iteration.
33
*
44
* Embedding "for" structures allows repetition in two dimensions.
5+
*
56
*/
6-
7-
float box_size = 11;
8-
float box_space = 12;
9-
int margin = 7;
10-
11-
size(200, 200);
7+
8+
9+
size(640, 360);
1210
background(0);
1311
noStroke();
14-
15-
// Draw gray boxes
16-
17-
for (int i = margin; i < height-margin; i += box_space){
18-
if(box_size > 0){
19-
for(int j = margin; j < width-margin; j+= box_space){
20-
fill(255-box_size*10);
21-
rect(j, i, box_size, box_size);
22-
}
23-
box_size = box_size - 0.6;
12+
13+
int gridSize = 40;
14+
15+
for (int x = gridSize; x <= width - gridSize; x += gridSize) {
16+
for (int y = gridSize; y <= height - gridSize; y += gridSize) {
17+
noStroke();
18+
fill(255);
19+
rect(x-1, y-1, 3, 3);
20+
stroke(255, 50);
21+
line(x, y, width/2, height/2);
2422
}
2523
}
2624

27-
Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,41 @@
11
/**
22
* Iteration.
33
*
4-
* Iteration with a "for" structure constructs repetitive forms.
4+
* Iteration with a "for" structure to construct repetitive forms.
55
*/
66

7-
int k;
8-
int xpos1 = 100;
9-
int xpos2 = 118;
10-
int count = 0;
11-
int timey = 0;
12-
int num = 12;
7+
int y;
8+
int num = 14;
139

14-
size(200, 200);
10+
size(640, 360);
1511
background(102);
1612
noStroke();
1713

1814
// Draw gray bars
1915
fill(255);
20-
k=60;
21-
for(int i=0; i < num/3; i++) {
22-
rect(25, k, 155, 5);
23-
k+=10;
16+
y = 60;
17+
for(int i = 0; i < num/3; i++) {
18+
rect(50, y, 475, 10);
19+
y+=20;
2420
}
2521

26-
// Black bars
22+
// Gray bars
2723
fill(51);
28-
k = 40;
29-
for(int i=0; i < num; i++) {
30-
rect(105, k, 30, 5);
31-
k += 10;
24+
y = 40;
25+
for(int i = 0; i < num; i++) {
26+
rect(405, y, 30, 10);
27+
y += 20;
3228
}
33-
k = 15;
29+
y = 50;
3430
for(int i = 0; i < num; i++) {
35-
rect(125, k, 30, 5);
36-
k +=10;
31+
rect(425, y, 30, 10);
32+
y += 20;
3733
}
3834

3935
// Thin lines
40-
k = 42;
36+
y = 45;
4137
fill(0);
42-
for(int i=0; i < num-1; i++) {
43-
rect(36, k, 20, 1);
44-
k+=10;
38+
for(int i = 0; i < num-1; i++) {
39+
rect(120, y, 40, 1);
40+
y+= 20;
4541
}

0 commit comments

Comments
 (0)

Footer

© 2026 GitHub, Inc.

Back | FazBrowse Home | New Git URL