Skip to content

Commit faea7eb

Browse files
committed
Removing a few examples for 2.0
1 parent 545e032 commit faea7eb

31 files changed

Lines changed: 313 additions & 412 deletions

File tree

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,19 @@
99

1010
float[][] distances;
1111
float maxDistance;
12-
int spacer = 10;
12+
int spacer;
1313

1414
void setup() {
1515
size(640, 360);
1616
maxDistance = dist(width/2, height/2, width, height);
1717
distances = new float[width][height];
1818
for (int y = 0; y < height; y++) {
1919
for (int x = 0; x < width; x++) {
20-
float dist = dist(width/2, height/2, x, y);
21-
distances[x][y] = dist/maxDistance * 255;
20+
float distance = dist(width/2, height/2, x, y);
21+
distances[x][y] = distance/maxDistance * 255;
2222
}
2323
}
24+
spacer = 10;
2425
noLoop(); // Run once and stop
2526
}
2627

@@ -35,3 +36,4 @@ void draw() {
3536
}
3637

3738

39+
Lines changed: 33 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,81 +1,55 @@
11
/**
22
* Simple Linear Gradient
3-
* by Ira Greenberg.
43
*
5-
* Using the convenient red(), green()
6-
* and blue() component functions,
7-
* generate some linear gradients.
4+
* The lerpColor() function is useful for interpolating
5+
* between two colors.
86
*/
97

10-
// constants
8+
// Constants
119
int Y_AXIS = 1;
1210
int X_AXIS = 2;
13-
color b1, b2, c1, c2, c3, c4, c5, c6;
11+
color b1, b2, c1, c2;
1412

15-
void setup(){
13+
void setup() {
1614
size(640, 360);
1715

18-
// create some gradients
16+
// Define colors
17+
b1 = color(255);
18+
b2 = color(0);
19+
c1 = color(204, 102, 0);
20+
c2 = color(0, 102, 153);
1921

20-
b1 = color(190, 190, 190);
21-
b2 = color(20, 20, 20);
22-
23-
24-
c1 = color(255, 120, 0);
25-
c2 = color(10, 45, 255);
26-
c3 = color(10, 255, 15);
27-
c4 = color(125, 2, 140);
28-
c5 = color(255, 255, 0);
29-
c6 = color(25, 255, 200);
3022
noLoop();
3123
}
3224

3325
void draw() {
34-
// background
35-
setGradient(0, 0, width, height, b1, b2, Y_AXIS);
36-
//center squares
37-
setGradient(25, 25, 75, 75, c1, c2, Y_AXIS);
38-
setGradient(100, 25, 75, 75, c3, c4, X_AXIS);
39-
setGradient(25, 100, 75, 75, c2, c5, X_AXIS);
40-
setGradient(100, 100, 75, 75, c4, c6, Y_AXIS);
26+
// Background
27+
setGradient(0, 0, width/2, height, b1, b2, X_AXIS);
28+
setGradient(width/2, 0, width/2, height, b2, b1, X_AXIS);
29+
// Foreground
30+
setGradient(50, 90, 540, 80, c1, c2, Y_AXIS);
31+
setGradient(50, 190, 540, 80, c2, c1, X_AXIS);
4132
}
4233

43-
void setGradient(int x, int y, float w, float h, color c1, color c2, int axis ){
44-
// calculate differences between color components
45-
float deltaR = red(c2)-red(c1);
46-
float deltaG = green(c2)-green(c1);
47-
float deltaB = blue(c2)-blue(c1);
34+
void setGradient(int x, int y, float w, float h, color c1, color c2, int axis ) {
35+
36+
noFill();
4837

49-
// choose axis
50-
if(axis == Y_AXIS){
51-
/*nested for loops set pixels
52-
in a basic table structure */
53-
// column
54-
for (int i=x; i<=(x+w); i++){
55-
// row
56-
for (int j = y; j<=(y+h); j++){
57-
color c = color(
58-
(red(c1)+(j-y)*(deltaR/h)),
59-
(green(c1)+(j-y)*(deltaG/h)),
60-
(blue(c1)+(j-y)*(deltaB/h))
61-
);
62-
set(i, j, c);
63-
}
64-
}
38+
if (axis == Y_AXIS) { // Top to bottom gradient
39+
for (int i = y; i <= y+h; i++) {
40+
float inter = map(i, y, y+h, 0, 1);
41+
color c = lerpColor(c1, c2, inter);
42+
stroke(c);
43+
line(x, i, x+w, i);
44+
}
6545
}
66-
else if(axis == X_AXIS){
67-
// column
68-
for (int i=y; i<=(y+h); i++){
69-
// row
70-
for (int j = x; j<=(x+w); j++){
71-
color c = color(
72-
(red(c1)+(j-x)*(deltaR/h)),
73-
(green(c1)+(j-x)*(deltaG/h)),
74-
(blue(c1)+(j-x)*(deltaB/h))
75-
);
76-
set(j, i, c);
77-
}
78-
}
46+
else if (axis == X_AXIS) { // Left to right gradient
47+
for (int i = x; i <= x+w; i++) {
48+
float inter = map(i, x, x+w, 0, 1);
49+
color c = lerpColor(c1, c2, inter);
50+
stroke(c);
51+
line(i, y, i, y+h);
52+
}
7953
}
8054
}
8155

Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,36 @@
11
/**
2-
* Inspired by Ira Greenberg's RadialGradient sketch,
3-
* but uses a different method for the gradients.
2+
* Radial Gradient.
3+
*
4+
* Draws are series of concentric circles to create a gradient
5+
* from one color to another.
46
*/
57

6-
int dim = 40;
8+
int dim;
79

810
void setup() {
911
size(640, 360);
12+
dim = width/2;
1013
background(0);
11-
smooth();
14+
colorMode(HSB, 360, 100, 100);
1215
noStroke();
1316
ellipseMode(RADIUS);
17+
frameRate(1);
18+
}
1419

15-
// create a simple table of gradients
16-
int rows = height / dim;
17-
int cols = width / dim;
18-
19-
for (int row = 0; row < rows; row++) {
20-
for (int col = 0; col < cols; col++) {
21-
drawGradient(col*dim + dim/2, row*dim + dim/2);
22-
}
23-
}
20+
void draw() {
21+
background(0);
22+
for (int x = 0; x <= width; x+=dim) {
23+
drawGradient(x, height/2);
24+
}
2425
}
2526

2627
void drawGradient(float x, float y) {
27-
int radius = dim/2 - 2;
28-
float r1 = random(255);
29-
float g1 = random(255);
30-
float b1 = random(255);
31-
float dr = (random(255) - r1) / radius;
32-
float dg = (random(255) - g1) / radius;
33-
float db = (random(255) - b1) / radius;
34-
28+
int radius = dim/2;
29+
float h = random(0, 360);
3530
for (int r = radius; r > 0; --r) {
36-
fill(r1, g1, b1);
31+
fill(h, 90, 90);
3732
ellipse(x, y, r, r);
38-
r1 += dr;
39-
g1 += dg;
40-
b1 += db;
33+
h = (h + 1) % 360;
4134
}
4235
}
4336

java/examples/Basics/Color/Relativity/Relativity.pde

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
11
/**
22
* Relativity.
33
*
4-
* Each color is perceived in relation to other colors.
5-
* The top and bottom bars each contain the same component colors,
6-
* but a different display order causes individual colors to appear differently.
4+
* Each color is perceived in relation to other colors. The top and bottom
5+
* bars each contain the same component colors, but a different display order
6+
* causes individual colors to appear differently.
77
*/
88

99
color a, b, c, d, e;
1010

1111
void setup() {
12-
size(200, 200);
12+
size(640, 360);
1313
noStroke();
1414
a = color(165, 167, 20);
1515
b = color(77, 86, 59);
1616
c = color(42, 106, 105);
1717
d = color(165, 89, 20);
1818
e = color(146, 150, 127);
19-
noLoop();
19+
noLoop(); // Draw only one time
2020
}
2121

2222
void draw() {
23-
drawBand(a, b, c, d, e, 0, width/50);
24-
drawBand(c, a, d, b, e, height/2, width/50);
23+
drawBand(a, b, c, d, e, 0, width/128);
24+
drawBand(c, a, d, b, e, height/2, width/128);
2525
}
2626

2727
void drawBand(color v, color w, color x, color y, color z, int ypos, int barWidth) {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ 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) {
20-
stroke(153);
20+
stroke(255);
2121
line(i, 80, i, height/2);
2222
} else {
23-
stroke(102);
23+
stroke(153);
2424
line(i, 20, i, 180);
2525
}
2626
}

java/examples/Basics/Control/LogicalOperators/LogicalOperators.pde

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Logical testerators.
2+
* Logical Operators.
33
*
44
* The logical operators for AND (&&) and OR (||) are used to
55
* combine simple relational statements into more complex expressions.
@@ -11,7 +11,7 @@ background(126);
1111

1212
boolean test = false;
1313

14-
for(int i = 5; i <= height; i += 5) {
14+
for (int i = 5; i <= height; i += 5) {
1515
// Logical AND
1616
stroke(0);
1717
if((i > 35) && (i < 100)) {
@@ -21,21 +21,21 @@ for(int i = 5; i <= height; i += 5) {
2121

2222
// Logical OR
2323
stroke(76);
24-
if((i <= 35) || (i >= 100)) {
24+
if ((i <= 35) || (i >= 100)) {
2525
line(width/2, i, width, i);
2626
test = true;
2727
}
2828

2929
// Testing if a boolean value is "true"
3030
// The expression "if(test)" is equivalent to "if(test == true)"
31-
if(test) {
31+
if (test) {
3232
stroke(0);
3333
point(width/3, i);
3434
}
3535

3636
// Testing if a boolean value is "false"
3737
// The expression "if(!test)" is equivalent to "if(test == false)"
38-
if(!test) {
38+
if (!test) {
3939
stroke(255);
4040
point(width/4, i);
4141
}

0 commit comments

Comments
 (0)