Skip to content

Commit a546785

Browse files
committed
Updates for 4.0 beta 2
1 parent a71d800 commit a546785

File tree

12 files changed

+56
-62
lines changed

12 files changed

+56
-62
lines changed

Basics/Math/Interpolate/Interpolate.pde

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@
44
* Move the mouse across the screen and the symbol will follow.
55
* Between drawing each frame of the animation, the ellipse moves
66
* part of the distance (0.05) from its current position toward
7-
* the cursor using the lerp() function.
8-
*
9-
* This is the same as the Easing under input only with lerp() instead.
7+
* the cursor using the lerp() function.
108
*/
119

1210
float x;
@@ -32,4 +30,4 @@ void draw() {
3230
fill(255);
3331
stroke(255);
3432
ellipse(x, y, 66, 66);
35-
}
33+
}

Basics/Math/OperatorPrecedence/OperatorPrecedence.pde

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
*
44
* If you don't direction state the order in which an
55
* expression is evaluated, it is decided by the operator
6-
* precedence. For example, in the statement "4+2*8", the
6+
* precedence. For example, in the expression 4+2*8, the
77
* 2 will first be multiplied by 8 and then the result will
88
* be added to 4. This is because multiplication has a higher
99
* precedence than addition. To avoid ambiguity in reading
1010
* the program, it is recommended to write the expression as
11-
* "4+(2*8)". The order of evaluation can be controlled through
11+
* 4+(2*8). The order of evaluation can be controlled through
1212
* adding parenthesis in the code.
1313
*/
1414

@@ -53,5 +53,3 @@ for (int i = 0; i < width; i+= 2) {
5353
line(i, 151, i, height-1);
5454
}
5555
}
56-
57-

Basics/Math/PolarToCartesian/PolarToCartesian.pde

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* by Daniel Shiffman.
44
*
55
* Convert a polar coordinate (r,theta) to cartesian (x,y).
6-
* The calculations are "x = r * cos(theta)" and "y = r * sin(theta)".
6+
* The calculations are x=r*cos(theta) and y=r*sin(theta).
77
*/
88

99
float r;
@@ -45,7 +45,3 @@ void draw() {
4545
theta += theta_vel;
4646

4747
}
48-
49-
50-
51-

Basics/Shape/DisableStyle/DisableStyle.pde

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ void draw() {
2424

2525
// Draw left bot
2626
bot.disableStyle(); // Ignore the colors in the SVG
27-
fill(0, 102, 153); // Set the SVG fill to blue
28-
stroke(255); // Set the SVG fill to white
27+
fill(0, 102, 153); // Set the SVG fill to blue
28+
stroke(255); // Set the SVG fill to white
2929
shape(bot, 20, 25, 300, 300);
3030

3131
// Draw right bot

Basics/Structure/CreateGraphics/CreateGraphics.pde

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
/**
22
* Create Graphics.
33
*
4-
* The createGraphics() function creates an object from the PGraphics class.
5-
* PGraphics is the main graphics and rendering context for Processing.
6-
* The beginDraw() method is necessary to prepare for drawing and endDraw() is
7-
* necessary to finish. Use this class if you need to draw into an off-screen
8-
* graphics buffer or to maintain two contexts with different properties.
4+
* The createGraphics() function creates an object from
5+
* the PGraphics class. PGraphics is the main graphics and
6+
* rendering context for Processing. The beginDraw() method
7+
* is necessary to prepare for drawing and endDraw() is
8+
* necessary to finish. Use this class if you need to draw
9+
* into an off-screen graphics buffer or to maintain two
10+
* drawing surfaces with different properties.
911
*/
1012

1113
PGraphics pg;

Topics/Cellular Automata/GameOfLife/GameOfLife.pde

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@
22
* Game of Life
33
* by Joan Soler-Adillon.
44
*
5-
* Press SPACE BAR to pause and change the cell's values with the mouse.
6-
* On pause, click to activate/deactivate cells.
7-
* Press R to randomly reset the cells' grid.
8-
* Press C to clear the cells' grid.
9-
*
10-
* The original Game of Life was created by John Conway in 1970.
5+
* Press SPACE BAR to pause and change the cell's values
6+
* with the mouse. On pause, click to activate/deactivate
7+
* cells. Press 'R' to randomly reset the cells' grid.
8+
* Press 'C' to clear the cells' grid. The original Game
9+
* of Life was created by John Conway in 1970.
1110
*/
1211

1312
// Size of cells
@@ -26,7 +25,8 @@ color dead = color(0);
2625

2726
// Array of cells
2827
int[][] cells;
29-
// Buffer to record the state of the cells and use this while changing the others in the interations
28+
// Buffer to record the state of the cells and use this
29+
// while changing the others in the interations
3030
int[][] cellsBuffer;
3131

3232
// Pause
@@ -57,7 +57,8 @@ void setup() {
5757
cells[x][y] = int(state); // Save state of each cell
5858
}
5959
}
60-
background(0); // Fill in black in case cells don't cover all the windows
60+
// Fill in black in case cells don't cover all the windows
61+
background(0);
6162
}
6263

6364

@@ -111,8 +112,6 @@ void draw() {
111112
}
112113
}
113114

114-
115-
116115
void iteration() { // When the clock ticks
117116
// Save cells to buffer (so we opeate with one array keeping the other intact)
118117
for (int x=0; x<width/cellSize; x++) {
@@ -179,4 +178,3 @@ void keyPressed() {
179178
}
180179
}
181180
}
182-

Topics/Cellular Automata/Wolfram/CA.pde

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
class CA {
22

3-
int[] cells; // An array of 0s and 1s
3+
int[] cells; // An array of 0s and 1s
44
int generation; // How many generations?
5-
int scl; // How many pixels wide/high is each cell?
5+
int scl; // How many pixels wide/high is each cell?
66

7-
int[] rules; // An array to store the ruleset, for example {0,1,1,0,1,1,0,1}
7+
int[] rules; // Array to store the rules, for example {0,1,1,0,1,1,0,1}
88

99
CA(int[] r) {
1010
rules = r;
@@ -30,21 +30,25 @@ class CA {
3030
for (int i = 0; i < cells.length; i++) {
3131
cells[i] = 0;
3232
}
33-
cells[cells.length/2] = 1; // We arbitrarily start with just the middle cell having a state of "1"
33+
// We arbitrarily start with just the middle
34+
// cell having a state of "1"
35+
cells[cells.length/2] = 1;
3436
generation = 0;
3537
}
3638

3739
// The process of creating the new generation
3840
void generate() {
3941
// First we create an empty array for the new values
4042
int[] nextgen = new int[cells.length];
41-
// For every spot, determine new state by examing current state, and neighbor states
43+
// For every spot, determine new state by examing current
44+
// state, and neighbor states
4245
// Ignore edges that only have one neighor
4346
for (int i = 1; i < cells.length-1; i++) {
4447
int left = cells[i-1]; // Left neighbor state
4548
int me = cells[i]; // Current state
4649
int right = cells[i+1]; // Right neighbor state
47-
nextgen[i] = executeRules(left,me,right); // Compute next generation state based on ruleset
50+
// Compute next generation state based on ruleset
51+
nextgen[i] = executeRules(left,me,right);
4852
}
4953
// Copy the array into current value
5054
for (int i = 1; i < cells.length-1; i++) {
@@ -54,7 +58,8 @@ class CA {
5458
generation++;
5559
}
5660

57-
// This is the easy part, just draw the cells, fill 255 for '1', fill 0 for '0'
61+
// This is the easy part, just draw the cells,
62+
// fill 255 for '1', fill 0 for '0'
5863
void render() {
5964
for (int i = 0; i < cells.length; i++) {
6065
if (cells[i] == 1) {
@@ -68,7 +73,8 @@ class CA {
6873
}
6974

7075
// Implementing the Wolfram rules
71-
// Could be improved and made more concise, but here we can explicitly see what is going on for each case
76+
// Could be improved and made more concise,
77+
// but here we can explicitly see what is going on for each case
7278
int executeRules (int a, int b, int c) {
7379
if (a == 1 && b == 1 && c == 1) { return rules[0]; }
7480
if (a == 1 && b == 1 && c == 0) { return rules[1]; }

Topics/Cellular Automata/Wolfram/Wolfram.pde

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,28 @@
22
* Wolfram Cellular Automata
33
* by Daniel Shiffman.
44
*
5-
* Simple demonstration of a Wolfram's 1-dimensional cellular automata.
6-
* When the system reaches bottom of the window, it restarts with a new ruleset.
5+
* Simple demonstration of a Wolfram's 1-dimensional
6+
* cellular automata. When the system reaches bottom
7+
* of the window, it restarts with a new ruleset.
78
* Mouse click restarts as well.
89
*/
910

10-
CA ca; // An instance object to describe the Wolfram basic Cellular Automata
11+
CA ca; // An instance object to the cellular automata
1112

1213
void setup() {
1314
size(640, 360);
14-
int[] ruleset = {0,1,0,1,1,0,1,0}; // An initial rule system
15-
ca = new CA(ruleset); // Initialize CA
15+
int[] ruleset = {0,1,0,1,1,0,1,0}; // An initial rule system
16+
ca = new CA(ruleset); // Initialize CA
1617
background(0);
1718
}
1819

1920
void draw() {
20-
ca.render(); // Draw the CA
21+
ca.render(); // Draw the CA
2122
ca.generate(); // Generate the next level
2223

23-
if (ca.finished()) { // If we're done, clear the screen, pick a new ruleset and restart
24+
// If we're done, clear the screen,
25+
// pick a new ruleset and restart
26+
if (ca.finished()) {
2427
background(0);
2528
ca.randomize();
2629
ca.restart();
@@ -32,6 +35,3 @@ void mousePressed() {
3235
ca.randomize();
3336
ca.restart();
3437
}
35-
36-
37-

Topics/Simulate/ForcesWithVectors/ForcesWithVectors.pde

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
/**
2-
* Forces (Gravity and Fluid Resistence) with Vectors
3-
* by Daniel Shiffman.
4-
*
5-
* Demonstration of multiple forces acting on bodies.
6-
* Bodies experience gravity continuously and fluid
2+
* Forces (Gravity and Fluid Resistence) with Vectors
3+
* by Daniel Shiffman.
4+
*
5+
* Demonstration of multiple forces acting on bodies.
6+
* Bodies experience gravity continuously and fluid
77
* resistance when in "water".
88
*/
99

@@ -60,4 +60,4 @@ void reset() {
6060
for (int i = 0; i < movers.length; i++) {
6161
movers[i] = new Mover(random(0.5, 3), 40+i*70, 0);
6262
}
63-
}
63+
}

Topics/Simulate/ForcesWithVectors/Liquid.pde

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,8 @@
77
* Bodies experience fluid resistance when in "water"
88
*/
99

10-
// Liquid class
1110
class Liquid {
1211

13-
1412
// Liquid is a rectangle
1513
float x, y, w, h;
1614
// Coefficient of drag
@@ -54,4 +52,4 @@ class Liquid {
5452
fill(127);
5553
rect(x, y, w, h);
5654
}
57-
}
55+
}

Topics/Simulate/ForcesWithVectors/Mover.pde

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
* Bodies experience fluid resistance when in "water"
88
*/
99

10-
1110
class Mover {
1211

1312
// position, velocity, and acceleration
@@ -35,7 +34,6 @@ class Mover {
3534
}
3635

3736
void update() {
38-
3937
// Velocity changes according to acceleration
4038
velocity.add(acceleration);
4139
// position changes by velocity
@@ -59,4 +57,4 @@ class Mover {
5957
position.y = height;
6058
}
6159
}
62-
}
60+
}

Topics/Vectors/VectorMath/VectorMath.pde

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Vector
33
* by Daniel Shiffman.
44
*
5-
* Demonstration some basic vector math: subtraction,
5+
* Demonstration of some basic vector math: subtraction,
66
* normalization, scaling. Normalizing a vector sets
77
* its length to 1.
88
*/

0 commit comments

Comments
 (0)