diff --git a/java/examples/Books/Getting Started/Chapter02/Ex_02_01/Ex_02_01.pde b/java/examples/Books/Getting Started/Chapter02/Ex_02_01/Ex_02_01.pde
deleted file mode 100644
index 82539334c..000000000
--- a/java/examples/Books/Getting Started/Chapter02/Ex_02_01/Ex_02_01.pde
+++ /dev/null
@@ -1,4 +0,0 @@
-// Example 02-01 from "Getting Started with Processing"
-// by Reas & Fry. O'Reilly / Make 2010
-
-ellipse(50, 50, 80, 80);
diff --git a/java/examples/Books/Getting Started/Chapter02/Ex_02_02/Ex_02_02.pde b/java/examples/Books/Getting Started/Chapter02/Ex_02_02/Ex_02_02.pde
deleted file mode 100644
index 0455e4836..000000000
--- a/java/examples/Books/Getting Started/Chapter02/Ex_02_02/Ex_02_02.pde
+++ /dev/null
@@ -1,17 +0,0 @@
-// Example 02-02 from "Getting Started with Processing"
-// by Reas & Fry. O'Reilly / Make 2010
-
-void setup() {
- size(480, 120);
- smooth();
-}
-
-void draw() {
- if (mousePressed) {
- fill(0);
- } else {
- fill(255);
- }
- ellipse(mouseX, mouseY, 80, 80);
-}
-
diff --git a/java/examples/Books/Getting Started/Chapter03/Ex_03_01/Ex_03_01.pde b/java/examples/Books/Getting Started/Chapter03/Ex_03_01/Ex_03_01.pde
deleted file mode 100644
index 2220a08fb..000000000
--- a/java/examples/Books/Getting Started/Chapter03/Ex_03_01/Ex_03_01.pde
+++ /dev/null
@@ -1,4 +0,0 @@
-// Example 03-01 from "Getting Started with Processing"
-// by Reas & Fry. O'Reilly / Make 2010
-
-size(800, 600);
diff --git a/java/examples/Books/Getting Started/Chapter03/Ex_03_02/Ex_03_02.pde b/java/examples/Books/Getting Started/Chapter03/Ex_03_02/Ex_03_02.pde
deleted file mode 100644
index abd536f2c..000000000
--- a/java/examples/Books/Getting Started/Chapter03/Ex_03_02/Ex_03_02.pde
+++ /dev/null
@@ -1,5 +0,0 @@
-// Example 03-02 from "Getting Started with Processing"
-// by Reas & Fry. O'Reilly / Make 2010
-
-size(480, 120);
-point(240, 60);
diff --git a/java/examples/Books/Getting Started/Chapter03/Ex_03_03/Ex_03_03.pde b/java/examples/Books/Getting Started/Chapter03/Ex_03_03/Ex_03_03.pde
deleted file mode 100644
index ba7ab8280..000000000
--- a/java/examples/Books/Getting Started/Chapter03/Ex_03_03/Ex_03_03.pde
+++ /dev/null
@@ -1,5 +0,0 @@
-// Example 03-03 from "Getting Started with Processing"
-// by Reas & Fry. O'Reilly / Make 2010
-
-size(480, 120);
-line(20, 50, 420, 110);
diff --git a/java/examples/Books/Getting Started/Chapter03/Ex_03_04/Ex_03_04.pde b/java/examples/Books/Getting Started/Chapter03/Ex_03_04/Ex_03_04.pde
deleted file mode 100644
index eb117b98c..000000000
--- a/java/examples/Books/Getting Started/Chapter03/Ex_03_04/Ex_03_04.pde
+++ /dev/null
@@ -1,7 +0,0 @@
-// Example 03-04 from "Getting Started with Processing"
-// by Reas & Fry. O'Reilly / Make 2010
-
-size(480, 120);
-quad(158, 55, 199, 14, 392, 66, 351, 107);
-triangle(347, 54, 392, 9, 392, 66);
-triangle(158, 55, 290, 91, 290, 112);
diff --git a/java/examples/Books/Getting Started/Chapter03/Ex_03_05/Ex_03_05.pde b/java/examples/Books/Getting Started/Chapter03/Ex_03_05/Ex_03_05.pde
deleted file mode 100644
index 9e297af1e..000000000
--- a/java/examples/Books/Getting Started/Chapter03/Ex_03_05/Ex_03_05.pde
+++ /dev/null
@@ -1,5 +0,0 @@
-// Example 03-05 from "Getting Started with Processing"
-// by Reas & Fry. O'Reilly / Make 2010
-
-size(480, 120);
-rect(180, 60, 220, 40);
diff --git a/java/examples/Books/Getting Started/Chapter03/Ex_03_06/Ex_03_06.pde b/java/examples/Books/Getting Started/Chapter03/Ex_03_06/Ex_03_06.pde
deleted file mode 100644
index d4016401c..000000000
--- a/java/examples/Books/Getting Started/Chapter03/Ex_03_06/Ex_03_06.pde
+++ /dev/null
@@ -1,7 +0,0 @@
-// Example 03-06 from "Getting Started with Processing"
-// by Reas & Fry. O'Reilly / Make 2010
-
-size(480, 120);
-ellipse(278, -100, 400, 400);
-ellipse(120, 100, 110, 110);
-ellipse(412, 60, 18, 18);
diff --git a/java/examples/Books/Getting Started/Chapter03/Ex_03_07/Ex_03_07.pde b/java/examples/Books/Getting Started/Chapter03/Ex_03_07/Ex_03_07.pde
deleted file mode 100644
index a0dc019a7..000000000
--- a/java/examples/Books/Getting Started/Chapter03/Ex_03_07/Ex_03_07.pde
+++ /dev/null
@@ -1,8 +0,0 @@
-// Example 03-07 from "Getting Started with Processing"
-// by Reas & Fry. O'Reilly / Make 2010
-
-size(480, 120);
-arc(90, 60, 80, 80, 0, HALF_PI);
-arc(190, 60, 80, 80, 0, PI+HALF_PI);
-arc(290, 60, 80, 80, PI, TWO_PI+HALF_PI);
-arc(390, 60, 80, 80, QUARTER_PI, PI+QUARTER_PI);
diff --git a/java/examples/Books/Getting Started/Chapter03/Ex_03_08/Ex_03_08.pde b/java/examples/Books/Getting Started/Chapter03/Ex_03_08/Ex_03_08.pde
deleted file mode 100644
index 75b5f4f73..000000000
--- a/java/examples/Books/Getting Started/Chapter03/Ex_03_08/Ex_03_08.pde
+++ /dev/null
@@ -1,8 +0,0 @@
-// Example 03-08 from "Getting Started with Processing"
-// by Reas & Fry. O'Reilly / Make 2010
-
-size(480, 120);
-arc(90, 60, 80, 80, 0, radians(90));
-arc(190, 60, 80, 80, 0, radians(270));
-arc(290, 60, 80, 80, radians(180), radians(450));
-arc(390, 60, 80, 80, radians(45), radians(225));
diff --git a/java/examples/Books/Getting Started/Chapter03/Ex_03_09/Ex_03_09.pde b/java/examples/Books/Getting Started/Chapter03/Ex_03_09/Ex_03_09.pde
deleted file mode 100644
index 525f1da67..000000000
--- a/java/examples/Books/Getting Started/Chapter03/Ex_03_09/Ex_03_09.pde
+++ /dev/null
@@ -1,8 +0,0 @@
-// Example 03-09 from "Getting Started with Processing"
-// by Reas & Fry. O'Reilly / Make 2010
-
-size(480, 120);
-ellipse(140, 0, 190, 190);
-// The rectangle draws on top of the ellipse
-// because it comes after in the code
-rect(160, 30, 260, 20);
diff --git a/java/examples/Books/Getting Started/Chapter03/Ex_03_10/Ex_03_10.pde b/java/examples/Books/Getting Started/Chapter03/Ex_03_10/Ex_03_10.pde
deleted file mode 100644
index b765d8fb9..000000000
--- a/java/examples/Books/Getting Started/Chapter03/Ex_03_10/Ex_03_10.pde
+++ /dev/null
@@ -1,8 +0,0 @@
-// Example 03-10 from "Getting Started with Processing"
-// by Reas & Fry. O'Reilly / Make 2010
-
-size(480, 120);
-rect(160, 30, 260, 20);
-// The ellipse draws on top of the rectangle
-// because it comes after in the code
-ellipse(140, 0, 190, 190);
diff --git a/java/examples/Books/Getting Started/Chapter03/Ex_03_11/Ex_03_11.pde b/java/examples/Books/Getting Started/Chapter03/Ex_03_11/Ex_03_11.pde
deleted file mode 100644
index d40ff08cb..000000000
--- a/java/examples/Books/Getting Started/Chapter03/Ex_03_11/Ex_03_11.pde
+++ /dev/null
@@ -1,8 +0,0 @@
-// Example 03-11 from "Getting Started with Processing"
-// by Reas & Fry. O'Reilly / Make 2010
-
-size(480, 120);
-smooth(); // Turns on smoothing
-ellipse(140, 60, 90, 90);
-noSmooth(); // Turns off smoothing
-ellipse(240, 60, 90, 90);
diff --git a/java/examples/Books/Getting Started/Chapter03/Ex_03_12/Ex_03_12.pde b/java/examples/Books/Getting Started/Chapter03/Ex_03_12/Ex_03_12.pde
deleted file mode 100644
index fdd8e9a4f..000000000
--- a/java/examples/Books/Getting Started/Chapter03/Ex_03_12/Ex_03_12.pde
+++ /dev/null
@@ -1,11 +0,0 @@
-// Example 03-12 from "Getting Started with Processing"
-// by Reas & Fry. O'Reilly / Make 2010
-
-size(480, 120);
-smooth();
-ellipse(75, 60, 90, 90);
-strokeWeight(8); // Stroke weight to 8 pixels
-ellipse(175, 60, 90, 90);
-ellipse(279, 60, 90, 90);
-strokeWeight(20); // Stroke weight to 20 pixels
-ellipse(389, 60, 90, 90);
diff --git a/java/examples/Books/Getting Started/Chapter03/Ex_03_13/Ex_03_13.pde b/java/examples/Books/Getting Started/Chapter03/Ex_03_13/Ex_03_13.pde
deleted file mode 100644
index e47332559..000000000
--- a/java/examples/Books/Getting Started/Chapter03/Ex_03_13/Ex_03_13.pde
+++ /dev/null
@@ -1,14 +0,0 @@
-// Example 03-13 from "Getting Started with Processing"
-// by Reas & Fry. O'Reilly / Make 2010
-
-size(480, 120);
-smooth();
-strokeWeight(12);
-strokeJoin(ROUND); // Round the stroke corners
-rect(40, 25, 70, 70);
-strokeJoin(BEVEL); // Bevel the stroke corners
-rect(140, 25, 70, 70);
-strokeCap(SQUARE); // Square the line endings
-line(270, 25, 340, 95);
-strokeCap(ROUND); // Round the line endings
-line(350, 25, 420, 95);
diff --git a/java/examples/Books/Getting Started/Chapter03/Ex_03_14/Ex_03_14.pde b/java/examples/Books/Getting Started/Chapter03/Ex_03_14/Ex_03_14.pde
deleted file mode 100644
index 31f7d5f93..000000000
--- a/java/examples/Books/Getting Started/Chapter03/Ex_03_14/Ex_03_14.pde
+++ /dev/null
@@ -1,12 +0,0 @@
-// Example 03-14 from "Getting Started with Processing"
-// by Reas & Fry. O'Reilly / Make 2010
-
-size(480, 120);
-smooth();
-background(0); // Black
-fill(204); // Light gray
-ellipse(132, 82, 200, 200); // Light gray circle
-fill(153); // Medium gray
-ellipse(228, -16, 200, 200); // Medium gray circle
-fill(102); // Dark gray
-ellipse(268, 118, 200, 200); // Dark gray circle
diff --git a/java/examples/Books/Getting Started/Chapter03/Ex_03_15/Ex_03_15.pde b/java/examples/Books/Getting Started/Chapter03/Ex_03_15/Ex_03_15.pde
deleted file mode 100644
index 83b5d3c44..000000000
--- a/java/examples/Books/Getting Started/Chapter03/Ex_03_15/Ex_03_15.pde
+++ /dev/null
@@ -1,11 +0,0 @@
-// Example 03-15 from "Getting Started with Processing"
-// by Reas & Fry. O'Reilly / Make 2010
-
-size(480, 120);
-smooth();
-fill(153); // Medium gray
-ellipse(132, 82, 200, 200); // Gray circle
-noFill(); // Turn off fill
-ellipse(228, -16, 200, 200); // Outline circle
-noStroke(); // Turn off stroke
-ellipse(268, 118, 200, 200); // Doesn’t draw!
diff --git a/java/examples/Books/Getting Started/Chapter03/Ex_03_16/Ex_03_16.pde b/java/examples/Books/Getting Started/Chapter03/Ex_03_16/Ex_03_16.pde
deleted file mode 100644
index 833ce14a1..000000000
--- a/java/examples/Books/Getting Started/Chapter03/Ex_03_16/Ex_03_16.pde
+++ /dev/null
@@ -1,13 +0,0 @@
-// Example 03-16 from "Getting Started with Processing"
-// by Reas & Fry. O'Reilly / Make 2010
-
-size(480, 120);
-noStroke();
-smooth();
-background(0, 26, 51); // Dark blue color
-fill(255, 0, 0); // Red color
-ellipse(132, 82, 200, 200); // Red circle
-fill(0, 255, 0); // Green color
-ellipse(228, -16, 200, 200); // Green circle
-fill(0, 0, 255); // Blue color
-ellipse(268, 118, 200, 200); // Blue circle
diff --git a/java/examples/Books/Getting Started/Chapter03/Ex_03_17/Ex_03_17.pde b/java/examples/Books/Getting Started/Chapter03/Ex_03_17/Ex_03_17.pde
deleted file mode 100644
index d7bbbd22d..000000000
--- a/java/examples/Books/Getting Started/Chapter03/Ex_03_17/Ex_03_17.pde
+++ /dev/null
@@ -1,13 +0,0 @@
-// Example 03-17 from "Getting Started with Processing"
-// by Reas & Fry. O'Reilly / Make 2010
-
-size(480, 120);
-noStroke();
-smooth();
-background(204, 226, 225); // Light blue color
-fill(255, 0, 0, 160); // Red color
-ellipse(132, 82, 200, 200); // Red circle
-fill(0, 255, 0, 160); // Green color
-ellipse(228, -16, 200, 200); // Green circle
-fill(0, 0, 255, 160); // Blue color
-ellipse(268, 118, 200, 200); // Blue circle
diff --git a/java/examples/Books/Getting Started/Chapter03/Ex_03_18/Ex_03_18.pde b/java/examples/Books/Getting Started/Chapter03/Ex_03_18/Ex_03_18.pde
deleted file mode 100644
index c19099ee0..000000000
--- a/java/examples/Books/Getting Started/Chapter03/Ex_03_18/Ex_03_18.pde
+++ /dev/null
@@ -1,13 +0,0 @@
-// Example 03-18 from "Getting Started with Processing"
-// by Reas & Fry. O'Reilly / Make 2010
-
-size(480, 120);
-beginShape();
-vertex(180, 82);
-vertex(207, 36);
-vertex(214, 63);
-vertex(407, 11);
-vertex(412, 30);
-vertex(219, 82);
-vertex(226, 109);
-endShape();
diff --git a/java/examples/Books/Getting Started/Chapter03/Ex_03_19/Ex_03_19.pde b/java/examples/Books/Getting Started/Chapter03/Ex_03_19/Ex_03_19.pde
deleted file mode 100644
index 0e1e8d785..000000000
--- a/java/examples/Books/Getting Started/Chapter03/Ex_03_19/Ex_03_19.pde
+++ /dev/null
@@ -1,13 +0,0 @@
-// Example 03-19 from "Getting Started with Processing"
-// by Reas & Fry. O'Reilly / Make 2010
-
-size(480, 120);
-beginShape();
-vertex(180, 82);
-vertex(207, 36);
-vertex(214, 63);
-vertex(407, 11);
-vertex(412, 30);
-vertex(219, 82);
-vertex(226, 109);
-endShape(CLOSE);
diff --git a/java/examples/Books/Getting Started/Chapter03/Ex_03_20/Ex_03_20.pde b/java/examples/Books/Getting Started/Chapter03/Ex_03_20/Ex_03_20.pde
deleted file mode 100644
index 76b283bfa..000000000
--- a/java/examples/Books/Getting Started/Chapter03/Ex_03_20/Ex_03_20.pde
+++ /dev/null
@@ -1,38 +0,0 @@
-// Example 03-20 from "Getting Started with Processing"
-// by Reas & Fry. O'Reilly / Make 2010
-
-size(480, 120);
-smooth();
-
-// Left creature
-beginShape();
-vertex(50, 120);
-vertex(100, 90);
-vertex(110, 60);
-vertex(80, 20);
-vertex(210, 60);
-vertex(160, 80);
-vertex(200, 90);
-vertex(140, 100);
-vertex(130, 120);
-endShape();
-fill(0);
-ellipse(155, 60, 8, 8);
-
-// Right creature
-fill(255);
-beginShape();
-vertex(370, 120);
-vertex(360, 90);
-vertex(290, 80);
-vertex(340, 70);
-vertex(280, 50);
-vertex(420, 10);
-vertex(390, 50);
-vertex(410, 90);
-vertex(460, 120);
-endShape();
-fill(0);
-ellipse(345, 50, 10, 10);
-
-
diff --git a/java/examples/Books/Getting Started/Chapter04/Ex_04_01/Ex_04_01.pde b/java/examples/Books/Getting Started/Chapter04/Ex_04_01/Ex_04_01.pde
deleted file mode 100644
index 22ab9a5e3..000000000
--- a/java/examples/Books/Getting Started/Chapter04/Ex_04_01/Ex_04_01.pde
+++ /dev/null
@@ -1,10 +0,0 @@
-// Example 04-01 from "Getting Started with Processing"
-// by Reas & Fry. O'Reilly / Make 2010
-
-size(480, 120);
-smooth();
-int y = 60;
-int d = 80;
-ellipse(75, y, d, d); // Left
-ellipse(175, y, d, d); // Middle
-ellipse(275, y, d, d); // Right
diff --git a/java/examples/Books/Getting Started/Chapter04/Ex_04_02/Ex_04_02.pde b/java/examples/Books/Getting Started/Chapter04/Ex_04_02/Ex_04_02.pde
deleted file mode 100644
index 01d3cb29a..000000000
--- a/java/examples/Books/Getting Started/Chapter04/Ex_04_02/Ex_04_02.pde
+++ /dev/null
@@ -1,10 +0,0 @@
-// Example 04-02 from "Getting Started with Processing"
-// by Reas & Fry. O'Reilly / Make 2010
-
-size(480, 120);
-smooth();
-int y = 100;
-int d = 130;
-ellipse(75, y, d, d); // Left
-ellipse(175, y, d, d); // Middle
-ellipse(275, y, d, d); // Right
diff --git a/java/examples/Books/Getting Started/Chapter04/Ex_04_03/Ex_04_03.pde b/java/examples/Books/Getting Started/Chapter04/Ex_04_03/Ex_04_03.pde
deleted file mode 100644
index b7cdec584..000000000
--- a/java/examples/Books/Getting Started/Chapter04/Ex_04_03/Ex_04_03.pde
+++ /dev/null
@@ -1,8 +0,0 @@
-// Example 04-03 from "Getting Started with Processing"
-// by Reas & Fry. O'Reilly / Make 2010
-
-size(480, 120);
-smooth();
-line(0, 0, width, height); // Line from (0,0) to (480, 120)
-line(width, 0, 0, height); // Line from (480, 0) to (0, 120)
-ellipse(width/2, height/2, 60, 60);
diff --git a/java/examples/Books/Getting Started/Chapter04/Ex_04_04/Ex_04_04.pde b/java/examples/Books/Getting Started/Chapter04/Ex_04_04/Ex_04_04.pde
deleted file mode 100644
index 294092ded..000000000
--- a/java/examples/Books/Getting Started/Chapter04/Ex_04_04/Ex_04_04.pde
+++ /dev/null
@@ -1,12 +0,0 @@
-// Example 04-04 from "Getting Started with Processing"
-// by Reas & Fry. O'Reilly / Make 2010
-
-size(480, 120);
-int x = 25;
-int h = 20;
-int y = 25;
-rect(x, y, 300, h); // Top
-x = x + 100;
-rect(x, y + h, 300, h); // Middle
-x = x - 250;
-rect(x, y + h*2, 300, h); // Bottom
diff --git a/java/examples/Books/Getting Started/Chapter04/Ex_04_05/Ex_04_05.pde b/java/examples/Books/Getting Started/Chapter04/Ex_04_05/Ex_04_05.pde
deleted file mode 100644
index beddf453e..000000000
--- a/java/examples/Books/Getting Started/Chapter04/Ex_04_05/Ex_04_05.pde
+++ /dev/null
@@ -1,13 +0,0 @@
-// Example 04-05 from "Getting Started with Processing"
-// by Reas & Fry. O'Reilly / Make 2010
-
-size(480, 120);
-smooth();
-strokeWeight(8);
-line(20, 40, 80, 80);
-line(80, 40, 140, 80);
-line(140, 40, 200, 80);
-line(200, 40, 260, 80);
-line(260, 40, 320, 80);
-line(320, 40, 380, 80);
-line(380, 40, 440, 80);
diff --git a/java/examples/Books/Getting Started/Chapter04/Ex_04_06/Ex_04_06.pde b/java/examples/Books/Getting Started/Chapter04/Ex_04_06/Ex_04_06.pde
deleted file mode 100644
index b7f5fa3f4..000000000
--- a/java/examples/Books/Getting Started/Chapter04/Ex_04_06/Ex_04_06.pde
+++ /dev/null
@@ -1,10 +0,0 @@
-// Example 04-06 from "Getting Started with Processing"
-// by Reas & Fry. O'Reilly / Make 2010
-
-size(480, 120);
-smooth();
-strokeWeight(8);
-for (int i = 20; i < 400; i += 60) {
- line(i, 40, i + 60, 80);
-}
-
diff --git a/java/examples/Books/Getting Started/Chapter04/Ex_04_07/Ex_04_07.pde b/java/examples/Books/Getting Started/Chapter04/Ex_04_07/Ex_04_07.pde
deleted file mode 100644
index 6c641d898..000000000
--- a/java/examples/Books/Getting Started/Chapter04/Ex_04_07/Ex_04_07.pde
+++ /dev/null
@@ -1,10 +0,0 @@
-// Example 04-07 from "Getting Started with Processing"
-// by Reas & Fry. O'Reilly / Make 2010
-
-size(480, 120);
-smooth();
-strokeWeight(2);
-for (int i = 20; i < 400; i += 8) {
- line(i, 40, i + 60, 80);
-}
-
diff --git a/java/examples/Books/Getting Started/Chapter04/Ex_04_08/Ex_04_08.pde b/java/examples/Books/Getting Started/Chapter04/Ex_04_08/Ex_04_08.pde
deleted file mode 100644
index 68092ced5..000000000
--- a/java/examples/Books/Getting Started/Chapter04/Ex_04_08/Ex_04_08.pde
+++ /dev/null
@@ -1,10 +0,0 @@
-// Example 04-08 from "Getting Started with Processing"
-// by Reas & Fry. O'Reilly / Make 2010
-
-size(480, 120);
-smooth();
-strokeWeight(2);
-for (int i = 20; i < 400; i += 20) {
- line(i, 0, i + i/2, 80);
-}
-
diff --git a/java/examples/Books/Getting Started/Chapter04/Ex_04_09/Ex_04_09.pde b/java/examples/Books/Getting Started/Chapter04/Ex_04_09/Ex_04_09.pde
deleted file mode 100644
index 67493fd0d..000000000
--- a/java/examples/Books/Getting Started/Chapter04/Ex_04_09/Ex_04_09.pde
+++ /dev/null
@@ -1,11 +0,0 @@
-// Example 04-09 from "Getting Started with Processing"
-// by Reas & Fry. O'Reilly / Make 2010
-
-size(480, 120);
-smooth();
-strokeWeight(2);
-for (int i = 20; i < 400; i += 20) {
- line(i, 0, i + i/2, 80);
- line(i + i/2, 80, i*1.2, 120);
-}
-
diff --git a/java/examples/Books/Getting Started/Chapter04/Ex_04_10/Ex_04_10.pde b/java/examples/Books/Getting Started/Chapter04/Ex_04_10/Ex_04_10.pde
deleted file mode 100644
index 2b6f7cb4f..000000000
--- a/java/examples/Books/Getting Started/Chapter04/Ex_04_10/Ex_04_10.pde
+++ /dev/null
@@ -1,14 +0,0 @@
-// Example 04-10 from "Getting Started with Processing"
-// by Reas & Fry. O'Reilly / Make 2010
-
-size(480, 120);
-background(0);
-smooth();
-noStroke();
-for (int y = 0; y <= height; y += 40) {
- for (int x = 0; x <= width; x += 40) {
- fill(255, 140);
- ellipse(x, y, 40, 40);
- }
-}
-
diff --git a/java/examples/Books/Getting Started/Chapter04/Ex_04_11/Ex_04_11.pde b/java/examples/Books/Getting Started/Chapter04/Ex_04_11/Ex_04_11.pde
deleted file mode 100644
index 18bf46050..000000000
--- a/java/examples/Books/Getting Started/Chapter04/Ex_04_11/Ex_04_11.pde
+++ /dev/null
@@ -1,16 +0,0 @@
-// Example 04-11 from "Getting Started with Processing"
-// by Reas & Fry. O'Reilly / Make 2010
-
-size(480, 120);
-background(0);
-smooth();
-noStroke();
-for (int y = 0; y < height+45; y += 40) {
- fill(255, 140);
- ellipse(0, y, 40, 40);
-}
-for (int x = 0; x < width+45; x += 40) {
- fill(255, 140);
- ellipse(x, 0, 40, 40);
-}
-
diff --git a/java/examples/Books/Getting Started/Chapter04/Ex_04_12/Ex_04_12.pde b/java/examples/Books/Getting Started/Chapter04/Ex_04_12/Ex_04_12.pde
deleted file mode 100644
index 565af4f4b..000000000
--- a/java/examples/Books/Getting Started/Chapter04/Ex_04_12/Ex_04_12.pde
+++ /dev/null
@@ -1,16 +0,0 @@
-// Example 04-12 from "Getting Started with Processing"
-// by Reas & Fry. O'Reilly / Make 2010
-
-size(480, 120);
-background(0);
-smooth();
-fill(255);
-stroke(102);
-for (int y = 20; y <= height-20; y += 10) {
- for (int x = 20; x <= width-20; x += 10) {
- ellipse(x, y, 4, 4);
- // Draw a line to the center of the display
- line(x, y, 240, 60);
- }
-}
-
diff --git a/java/examples/Books/Getting Started/Chapter04/Ex_04_13/Ex_04_13.pde b/java/examples/Books/Getting Started/Chapter04/Ex_04_13/Ex_04_13.pde
deleted file mode 100644
index a57dd0f97..000000000
--- a/java/examples/Books/Getting Started/Chapter04/Ex_04_13/Ex_04_13.pde
+++ /dev/null
@@ -1,12 +0,0 @@
-// Example 04-13 from "Getting Started with Processing"
-// by Reas & Fry. O'Reilly / Make 2010
-
-size(480, 120);
-background(0);
-smooth();
-for (int y = 32; y <= height; y += 8) {
- for (int x = 12; x <= width; x += 15) {
- ellipse(x + y, y, 16 - y/10.0, 16 - y/10.0);
- }
-}
-
diff --git a/java/examples/Books/Getting Started/Chapter05/Ex_05_01/Ex_05_01.pde b/java/examples/Books/Getting Started/Chapter05/Ex_05_01/Ex_05_01.pde
deleted file mode 100644
index f1359dd0e..000000000
--- a/java/examples/Books/Getting Started/Chapter05/Ex_05_01/Ex_05_01.pde
+++ /dev/null
@@ -1,9 +0,0 @@
-// Example 05-01 from "Getting Started with Processing"
-// by Reas & Fry. O'Reilly / Make 2010
-
-void draw() {
- // Displays the frame count to the Console
- println("I’m drawing");
- println(frameCount);
-}
-
diff --git a/java/examples/Books/Getting Started/Chapter05/Ex_05_02/Ex_05_02.pde b/java/examples/Books/Getting Started/Chapter05/Ex_05_02/Ex_05_02.pde
deleted file mode 100644
index 4dd7dafbb..000000000
--- a/java/examples/Books/Getting Started/Chapter05/Ex_05_02/Ex_05_02.pde
+++ /dev/null
@@ -1,11 +0,0 @@
-// Example 05-02 from "Getting Started with Processing"
-// by Reas & Fry. O'Reilly / Make 2010
-
-void setup() {
- println("I’m starting");
-}
-
-void draw() {
- println("I’m running");
-}
-
diff --git a/java/examples/Books/Getting Started/Chapter05/Ex_05_03/Ex_05_03.pde b/java/examples/Books/Getting Started/Chapter05/Ex_05_03/Ex_05_03.pde
deleted file mode 100644
index 6151ad601..000000000
--- a/java/examples/Books/Getting Started/Chapter05/Ex_05_03/Ex_05_03.pde
+++ /dev/null
@@ -1,18 +0,0 @@
-// Example 05-03 from "Getting Started with Processing"
-// by Reas & Fry. O'Reilly / Make 2010
-
-int x = 280;
-int y = -100;
-int diameter = 380;
-
-void setup() {
- size(480, 120);
- smooth();
- fill(102);
-}
-
-void draw() {
- background(204);
- ellipse(x, y, diameter, diameter);
-}
-
diff --git a/java/examples/Books/Getting Started/Chapter05/Ex_05_04/Ex_05_04.pde b/java/examples/Books/Getting Started/Chapter05/Ex_05_04/Ex_05_04.pde
deleted file mode 100644
index f5752a2e0..000000000
--- a/java/examples/Books/Getting Started/Chapter05/Ex_05_04/Ex_05_04.pde
+++ /dev/null
@@ -1,15 +0,0 @@
-// Example 05-04 from "Getting Started with Processing"
-// by Reas & Fry. O'Reilly / Make 2010
-
-void setup() {
- size(480, 120);
- fill(0, 102);
- smooth();
- noStroke();
-}
-
-void draw() {
- ellipse(mouseX, mouseY, 9, 9);
-}
-
-
diff --git a/java/examples/Books/Getting Started/Chapter05/Ex_05_05/Ex_05_05.pde b/java/examples/Books/Getting Started/Chapter05/Ex_05_05/Ex_05_05.pde
deleted file mode 100644
index fcd3daa4a..000000000
--- a/java/examples/Books/Getting Started/Chapter05/Ex_05_05/Ex_05_05.pde
+++ /dev/null
@@ -1,15 +0,0 @@
-// Example 05-05 from "Getting Started with Processing"
-// by Reas & Fry. O'Reilly / Make 2010
-
-void setup() {
- size(480, 120);
- fill(0, 102);
- smooth();
- noStroke();
-}
-
-void draw() {
- background(204);
- ellipse(mouseX, mouseY, 9, 9);
-}
-
diff --git a/java/examples/Books/Getting Started/Chapter05/Ex_05_06/Ex_05_06.pde b/java/examples/Books/Getting Started/Chapter05/Ex_05_06/Ex_05_06.pde
deleted file mode 100644
index 3346117bd..000000000
--- a/java/examples/Books/Getting Started/Chapter05/Ex_05_06/Ex_05_06.pde
+++ /dev/null
@@ -1,14 +0,0 @@
-// Example 05-06 from "Getting Started with Processing"
-// by Reas & Fry. O'Reilly / Make 2010
-
-void setup() {
- size(480, 120);
- strokeWeight(4);
- smooth();
- stroke(0, 102);
-}
-
-void draw() {
- line(mouseX, mouseY, pmouseX, pmouseY);
-}
-
diff --git a/java/examples/Books/Getting Started/Chapter05/Ex_05_07/Ex_05_07.pde b/java/examples/Books/Getting Started/Chapter05/Ex_05_07/Ex_05_07.pde
deleted file mode 100644
index 5f0415957..000000000
--- a/java/examples/Books/Getting Started/Chapter05/Ex_05_07/Ex_05_07.pde
+++ /dev/null
@@ -1,15 +0,0 @@
-// Example 05-07 from "Getting Started with Processing"
-// by Reas & Fry. O'Reilly / Make 2010
-
-void setup() {
- size(480, 120);
- smooth();
- stroke(0, 102);
-}
-
-void draw() {
- float weight = dist(mouseX, mouseY, pmouseX, pmouseY);
- strokeWeight(weight);
- line(mouseX, mouseY, pmouseX, pmouseY);
-}
-
diff --git a/java/examples/Books/Getting Started/Chapter05/Ex_05_08/Ex_05_08.pde b/java/examples/Books/Getting Started/Chapter05/Ex_05_08/Ex_05_08.pde
deleted file mode 100644
index d32f682bb..000000000
--- a/java/examples/Books/Getting Started/Chapter05/Ex_05_08/Ex_05_08.pde
+++ /dev/null
@@ -1,18 +0,0 @@
-// Example 05-08 from "Getting Started with Processing"
-// by Reas & Fry. O'Reilly / Make 2010
-
-float x;
-float easing = 0.01;
-
-void setup() {
- size(220, 120);
- smooth();
-}
-
-void draw() {
- float targetX = mouseX;
- x += (targetX - x) * easing;
- ellipse(x, 40, 12, 12);
- println(targetX + " : " + x);
-}
-
diff --git a/java/examples/Books/Getting Started/Chapter05/Ex_05_09/Ex_05_09.pde b/java/examples/Books/Getting Started/Chapter05/Ex_05_09/Ex_05_09.pde
deleted file mode 100644
index 0bca76b71..000000000
--- a/java/examples/Books/Getting Started/Chapter05/Ex_05_09/Ex_05_09.pde
+++ /dev/null
@@ -1,27 +0,0 @@
-// Example 05-09 from "Getting Started with Processing"
-// by Reas & Fry. O'Reilly / Make 2010
-
-float x;
-float y;
-float px;
-float py;
-float easing = 0.05;
-
-void setup() {
- size(480, 120);
- smooth();
- stroke(0, 102);
-}
-
-void draw() {
- float targetX = mouseX;
- x += (targetX - x) * easing;
- float targetY = mouseY;
- y += (targetY - y) * easing;
- float weight = dist(x, y, px, py);
- strokeWeight(weight);
- line(x, y, px, py);
- py = y;
- px = x;
-}
-
diff --git a/java/examples/Books/Getting Started/Chapter05/Ex_05_10/Ex_05_10.pde b/java/examples/Books/Getting Started/Chapter05/Ex_05_10/Ex_05_10.pde
deleted file mode 100644
index be0cf8ced..000000000
--- a/java/examples/Books/Getting Started/Chapter05/Ex_05_10/Ex_05_10.pde
+++ /dev/null
@@ -1,18 +0,0 @@
-// Example 05-10 from "Getting Started with Processing"
-// by Reas & Fry. O'Reilly / Make 2010
-
-void setup() {
- size(240, 120);
- strokeWeight(12);
- smooth();
-}
-
-void draw() {
- background(204);
- stroke(255);
- line(120, 60, mouseX, mouseY); // White line
- stroke(0);
- float mx = mouseX/2 + 60;
- line(120, 60, mx, mouseY); // Black line
-}
-
diff --git a/java/examples/Books/Getting Started/Chapter05/Ex_05_11/Ex_05_11.pde b/java/examples/Books/Getting Started/Chapter05/Ex_05_11/Ex_05_11.pde
deleted file mode 100644
index 0fb127237..000000000
--- a/java/examples/Books/Getting Started/Chapter05/Ex_05_11/Ex_05_11.pde
+++ /dev/null
@@ -1,18 +0,0 @@
-// Example 05-11 from "Getting Started with Processing"
-// by Reas & Fry. O'Reilly / Make 2010
-
-void setup() {
- size(240, 120);
- strokeWeight(12);
- smooth();
-}
-
-void draw() {
- background(204);
- stroke(255);
- line(120, 60, mouseX, mouseY); // White line
- stroke(0);
- float mx = map(mouseX, 0, width, 60, 180);
- line(120, 60, mx, mouseY); // Black line
-}
-
diff --git a/java/examples/Books/Getting Started/Chapter05/Ex_05_12/Ex_05_12.pde b/java/examples/Books/Getting Started/Chapter05/Ex_05_12/Ex_05_12.pde
deleted file mode 100644
index b69e2f422..000000000
--- a/java/examples/Books/Getting Started/Chapter05/Ex_05_12/Ex_05_12.pde
+++ /dev/null
@@ -1,19 +0,0 @@
-// Example 05-12 from "Getting Started with Processing"
-// by Reas & Fry. O'Reilly / Make 2010
-
-void setup() {
- size(240, 120);
- smooth();
- strokeWeight(30);
-}
-
-void draw() {
- background(204);
- stroke(102);
- line(40, 0, 70, height);
- if (mousePressed == true) {
- stroke(0);
- }
- line(0, 70, width, 50);
-}
-
diff --git a/java/examples/Books/Getting Started/Chapter05/Ex_05_13/Ex_05_13.pde b/java/examples/Books/Getting Started/Chapter05/Ex_05_13/Ex_05_13.pde
deleted file mode 100644
index a5f4cd85d..000000000
--- a/java/examples/Books/Getting Started/Chapter05/Ex_05_13/Ex_05_13.pde
+++ /dev/null
@@ -1,21 +0,0 @@
-// Example 05-13 from "Getting Started with Processing"
-// by Reas & Fry. O'Reilly / Make 2010
-
-void setup() {
- size(240, 120);
- smooth();
- strokeWeight(30);
-}
-
-void draw() {
- background(204);
- stroke(102);
- line(40, 0, 70, height);
- if (mousePressed) {
- stroke(0);
- } else {
- stroke(255);
- }
- line(0, 70, width, 50);
-}
-
diff --git a/java/examples/Books/Getting Started/Chapter05/Ex_05_14/Ex_05_14.pde b/java/examples/Books/Getting Started/Chapter05/Ex_05_14/Ex_05_14.pde
deleted file mode 100644
index a75d0a93f..000000000
--- a/java/examples/Books/Getting Started/Chapter05/Ex_05_14/Ex_05_14.pde
+++ /dev/null
@@ -1,23 +0,0 @@
-// Example 05-14 from "Getting Started with Processing"
-// by Reas & Fry. O'Reilly / Make 2010
-
-void setup() {
- size(120, 120);
- smooth();
- strokeWeight(30);
-}
-
-void draw() {
- background(204);
- stroke(102);
- line(40, 0, 70, height);
- if (mousePressed) {
- if (mouseButton == LEFT) {
- stroke(255);
- } else {
- stroke(0);
- }
- line(0, 70, width, 50);
- }
-}
-
diff --git a/java/examples/Books/Getting Started/Chapter05/Ex_05_15/Ex_05_15.pde b/java/examples/Books/Getting Started/Chapter05/Ex_05_15/Ex_05_15.pde
deleted file mode 100644
index 78a1bdae0..000000000
--- a/java/examples/Books/Getting Started/Chapter05/Ex_05_15/Ex_05_15.pde
+++ /dev/null
@@ -1,28 +0,0 @@
-// Example 05-15 from "Getting Started with Processing"
-// by Reas & Fry. O'Reilly / Make 2010
-
-float x;
-int offset = 10;
-
-void setup() {
- size(240, 120);
- smooth();
- x = width/2;
-}
-
-void draw() {
- background(204);
- if (mouseX > x) {
- x += 0.5;
- offset = -10;
- }
- if (mouseX < x) {
- x -= 0.5;
- offset = 10;
- }
- line(x, 0, x, height);
- line(mouseX, mouseY, mouseX + offset, mouseY - 10);
- line(mouseX, mouseY, mouseX + offset, mouseY + 10);
- line(mouseX, mouseY, mouseX + offset*3, mouseY);
-}
-
diff --git a/java/examples/Books/Getting Started/Chapter05/Ex_05_16/Ex_05_16.pde b/java/examples/Books/Getting Started/Chapter05/Ex_05_16/Ex_05_16.pde
deleted file mode 100644
index 7092b86ab..000000000
--- a/java/examples/Books/Getting Started/Chapter05/Ex_05_16/Ex_05_16.pde
+++ /dev/null
@@ -1,25 +0,0 @@
-// Example 05-16 from "Getting Started with Processing"
-// by Reas & Fry. O'Reilly / Make 2010
-
-int x = 120;
-int y = 60;
-int radius = 12;
-
-void setup() {
- size(240, 120);
- smooth();
- ellipseMode(RADIUS);
-}
-
-void draw() {
- background(204);
- float d = dist(mouseX, mouseY, x, y);
- if (d < radius) {
- radius++;
- fill(0);
- } else {
- fill(255);
- }
- ellipse(x, y, radius, radius);
-}
-
diff --git a/java/examples/Books/Getting Started/Chapter05/Ex_05_17/Ex_05_17.pde b/java/examples/Books/Getting Started/Chapter05/Ex_05_17/Ex_05_17.pde
deleted file mode 100644
index cf3ebe452..000000000
--- a/java/examples/Books/Getting Started/Chapter05/Ex_05_17/Ex_05_17.pde
+++ /dev/null
@@ -1,24 +0,0 @@
-// Example 05-17 from "Getting Started with Processing"
-// by Reas & Fry. O'Reilly / Make 2010
-
-int x = 80;
-int y = 30;
-int w = 80;
-int h = 60;
-
-void setup() {
- size(240, 120);
-}
-
-void draw() {
- background(204);
- if ((mouseX > x) && (mouseX < x+w) &&
- (mouseY > y) && (mouseY < y+h)) {
- fill(0);
- }
- else {
- fill(255);
- }
- rect(x, y, w, h);
-}
-
diff --git a/java/examples/Books/Getting Started/Chapter05/Ex_05_18/Ex_05_18.pde b/java/examples/Books/Getting Started/Chapter05/Ex_05_18/Ex_05_18.pde
deleted file mode 100644
index 1031bb201..000000000
--- a/java/examples/Books/Getting Started/Chapter05/Ex_05_18/Ex_05_18.pde
+++ /dev/null
@@ -1,16 +0,0 @@
-// Example 05-18 from "Getting Started with Processing"
-// by Reas & Fry. O'Reilly / Make 2010
-
-void setup() {
- size(240, 120);
- smooth();
-}
-
-void draw() {
- background(204);
- line(20, 20, 220, 100);
- if (keyPressed) {
- line(220, 20, 20, 100);
- }
-}
-
diff --git a/java/examples/Books/Getting Started/Chapter05/Ex_05_19/Ex_05_19.pde b/java/examples/Books/Getting Started/Chapter05/Ex_05_19/Ex_05_19.pde
deleted file mode 100644
index 96bb0217d..000000000
--- a/java/examples/Books/Getting Started/Chapter05/Ex_05_19/Ex_05_19.pde
+++ /dev/null
@@ -1,14 +0,0 @@
-// Example 05-19 from "Getting Started with Processing"
-// by Reas & Fry. O'Reilly / Make 2010
-
-void setup() {
- size(120, 120);
- textSize(64);
- textAlign(CENTER);
-}
-
-void draw() {
- background(0);
- text(key, 60, 80);
-}
-
diff --git a/java/examples/Books/Getting Started/Chapter05/Ex_05_20/Ex_05_20.pde b/java/examples/Books/Getting Started/Chapter05/Ex_05_20/Ex_05_20.pde
deleted file mode 100644
index df7a032eb..000000000
--- a/java/examples/Books/Getting Started/Chapter05/Ex_05_20/Ex_05_20.pde
+++ /dev/null
@@ -1,22 +0,0 @@
-// Example 05-20 from "Getting Started with Processing"
-// by Reas & Fry. O'Reilly / Make 2010
-
-void setup() {
- size(120, 120);
- smooth();
-}
-
-void draw() {
- background(204);
- if (keyPressed) {
- if ((key == 'h') || (key == 'H')) {
- line(30, 60, 90, 60);
- }
- if ((key == 'n') || (key == 'N')) {
- line(30, 20, 90, 100);
- }
- }
- line(30, 20, 30, 100);
- line(90, 20, 90, 100);
-}
-
diff --git a/java/examples/Books/Getting Started/Chapter05/Ex_05_21/Ex_05_21.pde b/java/examples/Books/Getting Started/Chapter05/Ex_05_21/Ex_05_21.pde
deleted file mode 100644
index b3e3afabe..000000000
--- a/java/examples/Books/Getting Started/Chapter05/Ex_05_21/Ex_05_21.pde
+++ /dev/null
@@ -1,21 +0,0 @@
-// Example 05-21 from "Getting Started with Processing"
-// by Reas & Fry. O'Reilly / Make 2010
-
-int x = 215;
-
-void setup() {
- size(480, 120);
-}
-
-void draw() {
- if (keyPressed && (key == CODED)) { // If it's a coded key
- if (keyCode == LEFT) { // If it's the left arrow
- x--;
- }
- else if (keyCode == RIGHT) { // If it's the right arrow
- x++;
- }
- }
- rect(x, 45, 50, 50);
-}
-
diff --git a/java/examples/Books/Getting Started/Chapter06/Ex_06_01/Ex_06_01.pde b/java/examples/Books/Getting Started/Chapter06/Ex_06_01/Ex_06_01.pde
deleted file mode 100644
index 534292bd6..000000000
--- a/java/examples/Books/Getting Started/Chapter06/Ex_06_01/Ex_06_01.pde
+++ /dev/null
@@ -1,14 +0,0 @@
-// Example 06-01 from "Getting Started with Processing"
-// by Reas & Fry. O'Reilly / Make 2010
-
-PImage img;
-
-void setup() {
- size(480, 120);
- img = loadImage("lunar.jpg");
-}
-
-void draw() {
- image(img, 0, 0);
-}
-
diff --git a/java/examples/Books/Getting Started/Chapter06/Ex_06_02/Ex_06_02.pde b/java/examples/Books/Getting Started/Chapter06/Ex_06_02/Ex_06_02.pde
deleted file mode 100644
index 38ede3e47..000000000
--- a/java/examples/Books/Getting Started/Chapter06/Ex_06_02/Ex_06_02.pde
+++ /dev/null
@@ -1,18 +0,0 @@
-// Example 06-02 from "Getting Started with Processing"
-// by Reas & Fry. O'Reilly / Make 2010
-
-PImage img1;
-PImage img2;
-
-void setup() {
- size(480, 120);
- img1 = loadImage("lunar.jpg");
- img2 = loadImage("capsule.jpg");
-}
-
-void draw() {
- image(img1, -120, 0);
- image(img1, 130, 0, 240, 120);
- image(img2, 300, 0, 240, 120);
-}
-
diff --git a/java/examples/Books/Getting Started/Chapter06/Ex_06_03/Ex_06_03.pde b/java/examples/Books/Getting Started/Chapter06/Ex_06_03/Ex_06_03.pde
deleted file mode 100644
index 11d0ce517..000000000
--- a/java/examples/Books/Getting Started/Chapter06/Ex_06_03/Ex_06_03.pde
+++ /dev/null
@@ -1,15 +0,0 @@
-// Example 06-03 from "Getting Started with Processing"
-// by Reas & Fry. O'Reilly / Make 2010
-
-PImage img;
-
-void setup() {
- size(480, 120);
- img = loadImage("lunar.jpg");
-}
-
-void draw() {
- background(0);
- image(img, 0, 0, mouseX * 2, mouseY * 2);
-}
-
diff --git a/java/examples/Books/Getting Started/Chapter06/Ex_06_04/Ex_06_04.pde b/java/examples/Books/Getting Started/Chapter06/Ex_06_04/Ex_06_04.pde
deleted file mode 100644
index a59ea353a..000000000
--- a/java/examples/Books/Getting Started/Chapter06/Ex_06_04/Ex_06_04.pde
+++ /dev/null
@@ -1,16 +0,0 @@
-// Example 06-04 from "Getting Started with Processing"
-// by Reas & Fry. O'Reilly / Make 2010
-
-PImage img;
-
-void setup() {
- size(480, 120);
- img = loadImage("clouds.gif");
-}
-
-void draw() {
- background(255);
- image(img, 0, 0);
- image(img, 0, mouseY * -1);
-}
-
diff --git a/java/examples/Books/Getting Started/Chapter06/Ex_06_04/data/clouds.gif b/java/examples/Books/Getting Started/Chapter06/Ex_06_04/data/clouds.gif
deleted file mode 100644
index ad52b85a1..000000000
Binary files a/java/examples/Books/Getting Started/Chapter06/Ex_06_04/data/clouds.gif and /dev/null differ
diff --git a/java/examples/Books/Getting Started/Chapter06/Ex_06_05/Ex_06_05.pde b/java/examples/Books/Getting Started/Chapter06/Ex_06_05/Ex_06_05.pde
deleted file mode 100644
index 0b157b55d..000000000
--- a/java/examples/Books/Getting Started/Chapter06/Ex_06_05/Ex_06_05.pde
+++ /dev/null
@@ -1,16 +0,0 @@
-// Example 06-05 from "Getting Started with Processing"
-// by Reas & Fry. O'Reilly / Make 2010
-
-PImage img;
-
-void setup() {
- size(480, 120);
- img = loadImage("clouds.png");
-}
-
-void draw() {
- background(204);
- image(img, 0, 0);
- image(img, 0, mouseY * -1);
-}
-
diff --git a/java/examples/Books/Getting Started/Chapter06/Ex_06_06/Ex_06_06.pde b/java/examples/Books/Getting Started/Chapter06/Ex_06_06/Ex_06_06.pde
deleted file mode 100644
index 1831a30bd..000000000
--- a/java/examples/Books/Getting Started/Chapter06/Ex_06_06/Ex_06_06.pde
+++ /dev/null
@@ -1,20 +0,0 @@
-// Example 06-06 from "Getting Started with Processing"
-// by Reas & Fry. O'Reilly / Make 2010
-
-PFont font;
-
-void setup() {
- size(480, 120);
- smooth();
- font = loadFont("AndaleMono-36.vlw");
- textFont(font);
-}
-
-void draw() {
- background(102);
- textSize(36);
- text("That’s one small step for man...", 25, 60);
- textSize(18);
- text("That’s one small step for man...", 27, 90);
-}
-
diff --git a/java/examples/Books/Getting Started/Chapter06/Ex_06_06/data/AndaleMono-36.vlw b/java/examples/Books/Getting Started/Chapter06/Ex_06_06/data/AndaleMono-36.vlw
deleted file mode 100644
index 34e243f0b..000000000
Binary files a/java/examples/Books/Getting Started/Chapter06/Ex_06_06/data/AndaleMono-36.vlw and /dev/null differ
diff --git a/java/examples/Books/Getting Started/Chapter06/Ex_06_07/Ex_06_07.pde b/java/examples/Books/Getting Started/Chapter06/Ex_06_07/Ex_06_07.pde
deleted file mode 100644
index b96eff645..000000000
--- a/java/examples/Books/Getting Started/Chapter06/Ex_06_07/Ex_06_07.pde
+++ /dev/null
@@ -1,18 +0,0 @@
-// Example 06-07 from "Getting Started with Processing"
-// by Reas & Fry. O'Reilly / Make 2010
-
-PFont font;
-
-void setup() {
- size(480, 120);
- font = loadFont("AndaleMono-24.vlw");
- textFont(font);
-}
-
-void draw() {
- background(102);
- text("That’s one small step for man...", 26, 30, 240, 100);
-}
-
-
-
diff --git a/java/examples/Books/Getting Started/Chapter06/Ex_06_07/data/AndaleMono-24.vlw b/java/examples/Books/Getting Started/Chapter06/Ex_06_07/data/AndaleMono-24.vlw
deleted file mode 100644
index a71ac78ac..000000000
Binary files a/java/examples/Books/Getting Started/Chapter06/Ex_06_07/data/AndaleMono-24.vlw and /dev/null differ
diff --git a/java/examples/Books/Getting Started/Chapter06/Ex_06_08/Ex_06_08.pde b/java/examples/Books/Getting Started/Chapter06/Ex_06_08/Ex_06_08.pde
deleted file mode 100644
index 25edeafb1..000000000
--- a/java/examples/Books/Getting Started/Chapter06/Ex_06_08/Ex_06_08.pde
+++ /dev/null
@@ -1,17 +0,0 @@
-// Example 06-08 from "Getting Started with Processing"
-// by Reas & Fry. O'Reilly / Make 2010
-
-PFont font;
-String quote = "That’s one small step for man...";
-
-void setup() {
- size(480, 120);
- font = loadFont("AndaleMono-24.vlw");
- textFont(font);
-}
-
-void draw() {
- background(102);
- text(quote, 26, 30, 240, 100);
-}
-
diff --git a/java/examples/Books/Getting Started/Chapter06/Ex_06_08/data/AndaleMono-24.vlw b/java/examples/Books/Getting Started/Chapter06/Ex_06_08/data/AndaleMono-24.vlw
deleted file mode 100644
index a71ac78ac..000000000
Binary files a/java/examples/Books/Getting Started/Chapter06/Ex_06_08/data/AndaleMono-24.vlw and /dev/null differ
diff --git a/java/examples/Books/Getting Started/Chapter06/Ex_06_09/Ex_06_09.pde b/java/examples/Books/Getting Started/Chapter06/Ex_06_09/Ex_06_09.pde
deleted file mode 100644
index 74c4be6a6..000000000
--- a/java/examples/Books/Getting Started/Chapter06/Ex_06_09/Ex_06_09.pde
+++ /dev/null
@@ -1,17 +0,0 @@
-// Example 06-09 from "Getting Started with Processing"
-// by Reas & Fry. O'Reilly / Make 2010
-
-PShape network;
-
-void setup() {
- size(480, 120);
- smooth();
- network = loadShape("network.svg");
-}
-
-void draw() {
- background(0);
- shape(network, 30, 10);
- shape(network, 180, 10, 280, 280);
-}
-
diff --git a/java/examples/Books/Getting Started/Chapter06/Ex_06_09/data/network.svg b/java/examples/Books/Getting Started/Chapter06/Ex_06_09/data/network.svg
deleted file mode 100644
index 5ecd8d159..000000000
--- a/java/examples/Books/Getting Started/Chapter06/Ex_06_09/data/network.svg
+++ /dev/null
@@ -1,4056 +0,0 @@
-
-
-
-
diff --git a/java/examples/Books/Getting Started/Chapter06/Ex_06_10/Ex_06_10.pde b/java/examples/Books/Getting Started/Chapter06/Ex_06_10/Ex_06_10.pde
deleted file mode 100644
index 417acc3c8..000000000
--- a/java/examples/Books/Getting Started/Chapter06/Ex_06_10/Ex_06_10.pde
+++ /dev/null
@@ -1,18 +0,0 @@
-// Example 06-10 from "Getting Started with Processing"
-// by Reas & Fry. O'Reilly / Make 2010
-
-PShape network;
-
-void setup() {
- size(240, 120);
- smooth();
- shapeMode(CENTER);
- network = loadShape("network.svg");
-}
-
-void draw() {
- background(0);
- float diameter = map(mouseX, 0, width, 10, 800);
- shape(network, 120, 60, diameter, diameter);
-}
-
diff --git a/java/examples/Books/Getting Started/Chapter06/Ex_06_10/data/network.svg b/java/examples/Books/Getting Started/Chapter06/Ex_06_10/data/network.svg
deleted file mode 100644
index 5ecd8d159..000000000
--- a/java/examples/Books/Getting Started/Chapter06/Ex_06_10/data/network.svg
+++ /dev/null
@@ -1,4056 +0,0 @@
-
-
-
-
diff --git a/java/examples/Books/Getting Started/Chapter07/Ex_07_01/Ex_07_01.pde b/java/examples/Books/Getting Started/Chapter07/Ex_07_01/Ex_07_01.pde
deleted file mode 100644
index 3db017b73..000000000
--- a/java/examples/Books/Getting Started/Chapter07/Ex_07_01/Ex_07_01.pde
+++ /dev/null
@@ -1,7 +0,0 @@
-// Example 07-01 from "Getting Started with Processing"
-// by Reas & Fry. O'Reilly / Make 2010
-
-void draw() {
- println(frameRate);
-}
-
diff --git a/java/examples/Books/Getting Started/Chapter07/Ex_07_02/Ex_07_02.pde b/java/examples/Books/Getting Started/Chapter07/Ex_07_02/Ex_07_02.pde
deleted file mode 100644
index 615aaf154..000000000
--- a/java/examples/Books/Getting Started/Chapter07/Ex_07_02/Ex_07_02.pde
+++ /dev/null
@@ -1,15 +0,0 @@
-// Example 07-02 from "Getting Started with Processing"
-// by Reas & Fry. O'Reilly / Make 2010
-
-void setup() {
- frameRate(30); // Thirty frames each second
- //frameRate(12); // Twelve frames each second
- //frameRate(2); // Two frames each second
- //frameRate(0.5); // One frame every two seconds
-}
-
-void draw() {
- println(frameRate);
-}
-
-
diff --git a/java/examples/Books/Getting Started/Chapter07/Ex_07_03/Ex_07_03.pde b/java/examples/Books/Getting Started/Chapter07/Ex_07_03/Ex_07_03.pde
deleted file mode 100644
index aafb141cc..000000000
--- a/java/examples/Books/Getting Started/Chapter07/Ex_07_03/Ex_07_03.pde
+++ /dev/null
@@ -1,19 +0,0 @@
-// Example 07-03 from "Getting Started with Processing"
-// by Reas & Fry. O'Reilly / Make 2010
-
-int radius = 40;
-float x = -radius;
-float speed = 0.5;
-
-void setup() {
- size(240, 120);
- smooth();
- ellipseMode(RADIUS);
-}
-
-void draw() {
- background(0);
- x += speed; // Increase the value of x
- arc(x, 60, radius, radius, 0.52, 5.76);
-}
-
diff --git a/java/examples/Books/Getting Started/Chapter07/Ex_07_04/Ex_07_04.pde b/java/examples/Books/Getting Started/Chapter07/Ex_07_04/Ex_07_04.pde
deleted file mode 100644
index b3c37bad9..000000000
--- a/java/examples/Books/Getting Started/Chapter07/Ex_07_04/Ex_07_04.pde
+++ /dev/null
@@ -1,22 +0,0 @@
-// Example 07-04 from "Getting Started with Processing"
-// by Reas & Fry. O'Reilly / Make 2010
-
-int radius = 40;
-float x = -radius;
-float speed = 0.5;
-
-void setup() {
- size(240, 120);
- smooth();
- ellipseMode(RADIUS);
-}
-
-void draw() {
- background(0);
- x += speed; // Increase the value of x
- if (x > width+radius) { // If the shape is off screen
- x = -radius; // move to the left edge
- }
- arc(x, 60, radius, radius, 0.52, 5.76);
-}
-
diff --git a/java/examples/Books/Getting Started/Chapter07/Ex_07_05/Ex_07_05.pde b/java/examples/Books/Getting Started/Chapter07/Ex_07_05/Ex_07_05.pde
deleted file mode 100644
index 99ac8e396..000000000
--- a/java/examples/Books/Getting Started/Chapter07/Ex_07_05/Ex_07_05.pde
+++ /dev/null
@@ -1,27 +0,0 @@
-// Example 07-05 from "Getting Started with Processing"
-// by Reas & Fry. O'Reilly / Make 2010
-
-int radius = 40;
-float x = 110;
-float speed = 0.5;
-int direction = 1;
-
-void setup() {
- size(240, 120);
- smooth();
- ellipseMode(RADIUS);
-}
-
-void draw() {
- background(0);
- x += speed * direction;
- if ((x > width-radius) || (x < radius)) {
- direction = -direction; // Flip direction
- }
- if (direction == 1) {
- arc(x, 60, radius, radius, 0.52, 5.76); // Face right
- } else {
- arc(x, 60, radius, radius, 3.67, 8.9); // Face left
- }
-}
-
diff --git a/java/examples/Books/Getting Started/Chapter07/Ex_07_06/Ex_07_06.pde b/java/examples/Books/Getting Started/Chapter07/Ex_07_06/Ex_07_06.pde
deleted file mode 100644
index c318a2fe2..000000000
--- a/java/examples/Books/Getting Started/Chapter07/Ex_07_06/Ex_07_06.pde
+++ /dev/null
@@ -1,27 +0,0 @@
-// Example 07-06 from "Getting Started with Processing"
-// by Reas & Fry. O'Reilly / Make 2010
-
-int startX = 20; // Initial x-coordinate
-int stopX = 160; // Final x-coordinate
-int startY = 30; // Initial y-coordinate
-int stopY = 80; // Final y-coordinate
-float x = startX; // Current x-coordinate
-float y = startY; // Current y-coordinate
-float step = 0.005; // Size of each step (0.0 to 1.0)
-float pct = 0.0; // Percentage traveled (0.0 to 1.0)
-
-void setup() {
- size(240, 120);
- smooth();
-}
-
-void draw() {
- background(0);
- if (pct < 1.0) {
- x = startX + ((stopX-startX) * pct);
- y = startY + ((stopY-startY) * pct);
- pct += step;
- }
- ellipse(x, y, 20, 20);
-}
-
diff --git a/java/examples/Books/Getting Started/Chapter07/Ex_07_07/Ex_07_07.pde b/java/examples/Books/Getting Started/Chapter07/Ex_07_07/Ex_07_07.pde
deleted file mode 100644
index 045de5dbc..000000000
--- a/java/examples/Books/Getting Started/Chapter07/Ex_07_07/Ex_07_07.pde
+++ /dev/null
@@ -1,8 +0,0 @@
-// Example 07-07 from "Getting Started with Processing"
-// by Reas & Fry. O'Reilly / Make 2010
-
-void draw() {
- float r = random(0, mouseX);
- println(r);
-}
-
diff --git a/java/examples/Books/Getting Started/Chapter07/Ex_07_08/Ex_07_08.pde b/java/examples/Books/Getting Started/Chapter07/Ex_07_08/Ex_07_08.pde
deleted file mode 100644
index f2d1b0ee1..000000000
--- a/java/examples/Books/Getting Started/Chapter07/Ex_07_08/Ex_07_08.pde
+++ /dev/null
@@ -1,18 +0,0 @@
-// Example 07-08 from "Getting Started with Processing"
-// by Reas & Fry. O'Reilly / Make 2010
-
-void setup() {
- size(240, 120);
- smooth();
-}
-
-void draw() {
- background(204);
- for (int x = 20; x < width; x += 20) {
- float mx = mouseX / 10;
- float offsetA = random(-mx, mx);
- float offsetB = random(-mx, mx);
- line(x + offsetA, 20, x - offsetB, 100);
- }
-}
-
diff --git a/java/examples/Books/Getting Started/Chapter07/Ex_07_09/Ex_07_09.pde b/java/examples/Books/Getting Started/Chapter07/Ex_07_09/Ex_07_09.pde
deleted file mode 100644
index 55f18fbab..000000000
--- a/java/examples/Books/Getting Started/Chapter07/Ex_07_09/Ex_07_09.pde
+++ /dev/null
@@ -1,21 +0,0 @@
-// Example 07-09 from "Getting Started with Processing"
-// by Reas & Fry. O'Reilly / Make 2010
-
-float speed = 2.5;
-int diameter = 20;
-float x;
-float y;
-
-void setup() {
- size(240, 120);
- smooth();
- x = width/2;
- y = height/2;
-}
-
-void draw() {
- x += random(-speed, speed);
- y += random(-speed, speed);
- ellipse(x, y, diameter, diameter);
-}
-
diff --git a/java/examples/Books/Getting Started/Chapter07/Ex_07_10/Ex_07_10.pde b/java/examples/Books/Getting Started/Chapter07/Ex_07_10/Ex_07_10.pde
deleted file mode 100644
index cec7c2012..000000000
--- a/java/examples/Books/Getting Started/Chapter07/Ex_07_10/Ex_07_10.pde
+++ /dev/null
@@ -1,8 +0,0 @@
-// Example 07-10 from "Getting Started with Processing"
-// by Reas & Fry. O'Reilly / Make 2010
-
-void draw() {
- int timer = millis();
- println(timer);
-}
-
diff --git a/java/examples/Books/Getting Started/Chapter07/Ex_07_11/Ex_07_11.pde b/java/examples/Books/Getting Started/Chapter07/Ex_07_11/Ex_07_11.pde
deleted file mode 100644
index 95ac8b2ab..000000000
--- a/java/examples/Books/Getting Started/Chapter07/Ex_07_11/Ex_07_11.pde
+++ /dev/null
@@ -1,23 +0,0 @@
-// Example 07-11 from "Getting Started with Processing"
-// by Reas & Fry. O'Reilly / Make 2010
-
-int time1 = 2000;
-int time2 = 4000;
-float x = 0;
-
-void setup() {
- size(480, 120);
- smooth();
-}
-
-void draw() {
- int currentTime = millis();
- background(204);
- if (currentTime > time2) {
- x -= 0.5;
- } else if (currentTime > time1) {
- x += 2;
- }
- ellipse(x, 60, 90, 90);
-}
-
diff --git a/java/examples/Books/Getting Started/Chapter07/Ex_07_12/Ex_07_12.pde b/java/examples/Books/Getting Started/Chapter07/Ex_07_12/Ex_07_12.pde
deleted file mode 100644
index 21c2f7701..000000000
--- a/java/examples/Books/Getting Started/Chapter07/Ex_07_12/Ex_07_12.pde
+++ /dev/null
@@ -1,13 +0,0 @@
-// Example 07-12 from "Getting Started with Processing"
-// by Reas & Fry. O'Reilly / Make 2010
-
-float angle = 0.0;
-
-void draw() {
- float sinval = sin(angle);
- println(sinval);
- float gray = map(sinval, -1, 1, 0, 255);
- background(gray);
- angle += 0.1;
-}
-
diff --git a/java/examples/Books/Getting Started/Chapter07/Ex_07_13/Ex_07_13.pde b/java/examples/Books/Getting Started/Chapter07/Ex_07_13/Ex_07_13.pde
deleted file mode 100644
index b6beee4f4..000000000
--- a/java/examples/Books/Getting Started/Chapter07/Ex_07_13/Ex_07_13.pde
+++ /dev/null
@@ -1,24 +0,0 @@
-// Example 07-13 from "Getting Started with Processing"
-// by Reas & Fry. O'Reilly / Make 2010
-
-float angle = 0.0;
-float offset = 60;
-float scalar = 40;
-float speed = 0.05;
-
-void setup() {
- size(240, 120);
- smooth();
-}
-
-void draw() {
- background(0);
- float y1 = offset + sin(angle) * scalar;
- float y2 = offset + sin(angle + 0.4) * scalar;
- float y3 = offset + sin(angle + 0.8) * scalar;
- ellipse( 80, y1, 40, 40);
- ellipse(120, y2, 40, 40);
- ellipse(160, y3, 40, 40);
- angle += speed;
-}
-
diff --git a/java/examples/Books/Getting Started/Chapter07/Ex_07_14/Ex_07_14.pde b/java/examples/Books/Getting Started/Chapter07/Ex_07_14/Ex_07_14.pde
deleted file mode 100644
index 55bf6952d..000000000
--- a/java/examples/Books/Getting Started/Chapter07/Ex_07_14/Ex_07_14.pde
+++ /dev/null
@@ -1,20 +0,0 @@
-// Example 07-14 from "Getting Started with Processing"
-// by Reas & Fry. O'Reilly / Make 2010
-
-float angle = 0.0;
-float offset = 60;
-float scalar = 30;
-float speed = 0.05;
-
-void setup() {
- size(120, 120);
- smooth();
-}
-
-void draw() {
- float x = offset + cos(angle) * scalar;
- float y = offset + sin(angle) * scalar;
- ellipse( x, y, 40, 40);
- angle += speed;
-}
-
diff --git a/java/examples/Books/Getting Started/Chapter07/Ex_07_15/Ex_07_15.pde b/java/examples/Books/Getting Started/Chapter07/Ex_07_15/Ex_07_15.pde
deleted file mode 100644
index 85a550f76..000000000
--- a/java/examples/Books/Getting Started/Chapter07/Ex_07_15/Ex_07_15.pde
+++ /dev/null
@@ -1,22 +0,0 @@
-// Example 07-15 from "Getting Started with Processing"
-// by Reas & Fry. O'Reilly / Make 2010
-
-float angle = 0.0;
-float offset = 60;
-float scalar = 2;
-float speed = 0.05;
-
-void setup() {
- size(120, 120);
- fill(0);
- smooth();
-}
-
-void draw() {
- float x = offset + cos(angle) * scalar;
- float y = offset + sin(angle) * scalar;
- ellipse( x, y, 2, 2);
- angle += speed;
- scalar += speed;
-}
-
diff --git a/java/examples/Books/Getting Started/Chapter07/Ex_07_16/Ex_07_16.pde b/java/examples/Books/Getting Started/Chapter07/Ex_07_16/Ex_07_16.pde
deleted file mode 100644
index 981566038..000000000
--- a/java/examples/Books/Getting Started/Chapter07/Ex_07_16/Ex_07_16.pde
+++ /dev/null
@@ -1,12 +0,0 @@
-// Example 07-16 from "Getting Started with Processing"
-// by Reas & Fry. O'Reilly / Make 2010
-
-void setup() {
- size(120, 120);
-}
-
-void draw() {
- translate(mouseX, mouseY);
- rect(0, 0, 30, 30);
-}
-
diff --git a/java/examples/Books/Getting Started/Chapter07/Ex_07_17/Ex_07_17.pde b/java/examples/Books/Getting Started/Chapter07/Ex_07_17/Ex_07_17.pde
deleted file mode 100644
index c25f2919c..000000000
--- a/java/examples/Books/Getting Started/Chapter07/Ex_07_17/Ex_07_17.pde
+++ /dev/null
@@ -1,14 +0,0 @@
-// Example 07-17 from "Getting Started with Processing"
-// by Reas & Fry. O'Reilly / Make 2010
-
-void setup() {
- size(120, 120);
-}
-
-void draw() {
- translate(mouseX, mouseY);
- rect(0, 0, 30, 30);
- translate(35, 10);
- rect(0, 0, 15, 15);
-}
-
diff --git a/java/examples/Books/Getting Started/Chapter07/Ex_07_18/Ex_07_18.pde b/java/examples/Books/Getting Started/Chapter07/Ex_07_18/Ex_07_18.pde
deleted file mode 100644
index 62530d982..000000000
--- a/java/examples/Books/Getting Started/Chapter07/Ex_07_18/Ex_07_18.pde
+++ /dev/null
@@ -1,16 +0,0 @@
-// Example 07-18 from "Getting Started with Processing"
-// by Reas & Fry. O'Reilly / Make 2010
-
-void setup() {
- size(120, 120);
-}
-
-void draw() {
- pushMatrix();
- translate(mouseX, mouseY);
- rect(0, 0, 30, 30);
- popMatrix();
- translate(35, 10);
- rect(0, 0, 15, 15);
-}
-
diff --git a/java/examples/Books/Getting Started/Chapter07/Ex_07_19/Ex_07_19.pde b/java/examples/Books/Getting Started/Chapter07/Ex_07_19/Ex_07_19.pde
deleted file mode 100644
index 3b8f61554..000000000
--- a/java/examples/Books/Getting Started/Chapter07/Ex_07_19/Ex_07_19.pde
+++ /dev/null
@@ -1,17 +0,0 @@
-// Example 07-19 from "Getting Started with Processing"
-// by Reas & Fry. O'Reilly / Make 2010
-
-float angle = 0.0;
-
-void setup() {
- size(120, 120);
- smooth();
-}
-
-void draw() {
- translate(mouseX, mouseY);
- rotate(angle);
- rect(-15, -15, 30, 30);
- angle += 0.1;
-}
-
diff --git a/java/examples/Books/Getting Started/Chapter07/Ex_07_20/Ex_07_20.pde b/java/examples/Books/Getting Started/Chapter07/Ex_07_20/Ex_07_20.pde
deleted file mode 100644
index 599b07389..000000000
--- a/java/examples/Books/Getting Started/Chapter07/Ex_07_20/Ex_07_20.pde
+++ /dev/null
@@ -1,17 +0,0 @@
-// Example 07-20 from "Getting Started with Processing"
-// by Reas & Fry. O'Reilly / Make 2010
-
-float angle = 0.0;
-
-void setup() {
- size(120, 120);
- smooth();
-}
-
-void draw() {
- rotate(angle);
- translate(mouseX, mouseY);
- rect(-15, -15, 30, 30);
- angle += 0.1;
-}
-
diff --git a/java/examples/Books/Getting Started/Chapter07/Ex_07_21/Ex_07_21.pde b/java/examples/Books/Getting Started/Chapter07/Ex_07_21/Ex_07_21.pde
deleted file mode 100644
index 323ed422d..000000000
--- a/java/examples/Books/Getting Started/Chapter07/Ex_07_21/Ex_07_21.pde
+++ /dev/null
@@ -1,17 +0,0 @@
-// Example 07-21 from "Getting Started with Processing"
-// by Reas & Fry. O'Reilly / Make 2010
-
-float angle = 0.0;
-
-void setup() {
- size(120, 120);
- smooth();
-}
-
-void draw() {
- translate(mouseX, mouseY);
- scale(sin(angle) + 2);
- rect(-15, -15, 30, 30);
- angle += 0.1;
-}
-
diff --git a/java/examples/Books/Getting Started/Chapter07/Ex_07_22/Ex_07_22.pde b/java/examples/Books/Getting Started/Chapter07/Ex_07_22/Ex_07_22.pde
deleted file mode 100644
index 4eaf3f2b3..000000000
--- a/java/examples/Books/Getting Started/Chapter07/Ex_07_22/Ex_07_22.pde
+++ /dev/null
@@ -1,19 +0,0 @@
-// Example 07-22 from "Getting Started with Processing"
-// by Reas & Fry. O'Reilly / Make 2010
-
-float angle = 0.0;
-
-void setup() {
- size(120, 120);
- smooth();
-}
-
-void draw() {
- translate(mouseX, mouseY);
- float scalar = sin(angle) + 2;
- scale(scalar);
- strokeWeight(1.0 / scalar);
- rect(-15, -15, 30, 30);
- angle += 0.1;
-}
-
diff --git a/java/examples/Books/Getting Started/Chapter07/Ex_07_23/Ex_07_23.pde b/java/examples/Books/Getting Started/Chapter07/Ex_07_23/Ex_07_23.pde
deleted file mode 100644
index 0c42b9fbc..000000000
--- a/java/examples/Books/Getting Started/Chapter07/Ex_07_23/Ex_07_23.pde
+++ /dev/null
@@ -1,33 +0,0 @@
-// Example 07-23 from "Getting Started with Processing"
-// by Reas & Fry. O'Reilly / Make 2010
-
-float angle = 0.0;
-float angleDirection = 1;
-float speed = 0.005;
-
-void setup() {
- size(120, 120);
- smooth();
-}
-
-void draw() {
- background(204);
- translate(20, 25); // Move to start position
- rotate(angle);
- strokeWeight(12);
- line(0, 0, 40, 0);
- translate(40, 0); // Move to next joint
- rotate(angle * 2.0);
- strokeWeight(6);
- line(0, 0, 30, 0);
- translate(30, 0); // Move the next joint
- rotate(angle * 2.5);
- strokeWeight(3);
- line(0, 0, 20, 0);
-
- angle += speed * angleDirection;
- if ((angle > QUARTER_PI) || (angle < 0)) {
- angleDirection *= -1;
- }
-}
-
diff --git a/java/examples/Books/Getting Started/Chapter08/Ex_08_01/Ex_08_01.pde b/java/examples/Books/Getting Started/Chapter08/Ex_08_01/Ex_08_01.pde
deleted file mode 100644
index 4ca134af5..000000000
--- a/java/examples/Books/Getting Started/Chapter08/Ex_08_01/Ex_08_01.pde
+++ /dev/null
@@ -1,16 +0,0 @@
-// Example 08-01 from "Getting Started with Processing"
-// by Reas & Fry. O'Reilly / Make 2010
-
-void setup() {
- println("Ready to roll!");
- rollDice(20);
- rollDice(20);
- rollDice(6);
- println("Finished.");
-}
-
-void rollDice(int numSides) {
- int d = 1 + int(random(numSides));
- println("Rolling... " + d);
-}
-
diff --git a/java/examples/Books/Getting Started/Chapter08/Ex_08_02/Ex_08_02.pde b/java/examples/Books/Getting Started/Chapter08/Ex_08_02/Ex_08_02.pde
deleted file mode 100644
index a4516b752..000000000
--- a/java/examples/Books/Getting Started/Chapter08/Ex_08_02/Ex_08_02.pde
+++ /dev/null
@@ -1,14 +0,0 @@
-// Example 08-02 from "Getting Started with Processing"
-// by Reas & Fry. O'Reilly / Make 2010
-
-void setup() {
- println("Ready to roll!");
- int d1 = 1 + int(random(20));
- println("Rolling... " + d1);
- int d2 = 1 + int(random(20));
- println("Rolling... " + d2);
- int d3 = 1 + int(random(6));
- println("Rolling... " + d3);
- println("Finished.");
-}
-
diff --git a/java/examples/Books/Getting Started/Chapter08/Ex_08_03/Ex_08_03.pde b/java/examples/Books/Getting Started/Chapter08/Ex_08_03/Ex_08_03.pde
deleted file mode 100644
index 9f17ec89f..000000000
--- a/java/examples/Books/Getting Started/Chapter08/Ex_08_03/Ex_08_03.pde
+++ /dev/null
@@ -1,25 +0,0 @@
-// Example 08-03 from "Getting Started with Processing"
-// by Reas & Fry. O'Reilly / Make 2010
-
-void setup() {
- size(480, 120);
- smooth();
-}
-
-void draw() {
- background(204);
- translate(110, 110);
- stroke(0);
- strokeWeight(70);
- line(0, -35, 0, -65); // Body
- noStroke();
- fill(255);
- ellipse(-17.5, -65, 35, 35); // Left eye dome
- ellipse(17.5, -65, 35, 35); // Right eye dome
- arc(0, -65, 70, 70, 0, PI); // Chin
- fill(0);
- ellipse(-14, -65, 8, 8); // Left eye
- ellipse(14, -65, 8, 8); // Right eye
- quad(0, -58, 4, -51, 0, -44, -4, -51); // Beak
-}
-
diff --git a/java/examples/Books/Getting Started/Chapter08/Ex_08_04/Ex_08_04.pde b/java/examples/Books/Getting Started/Chapter08/Ex_08_04/Ex_08_04.pde
deleted file mode 100644
index 2a9eba4a0..000000000
--- a/java/examples/Books/Getting Started/Chapter08/Ex_08_04/Ex_08_04.pde
+++ /dev/null
@@ -1,42 +0,0 @@
-// Example 08-04 from "Getting Started with Processing"
-// by Reas & Fry. O'Reilly / Make 2010
-
-void setup() {
- size(480, 120);
- smooth();
-}
-
-void draw() {
- background(204);
-
- // Left owl
- translate(110, 110);
- stroke(0);
- strokeWeight(70);
- line(0, -35, 0, -65); // Body
- noStroke();
- fill(255);
- ellipse(-17.5, -65, 35, 35); // Left eye dome
- ellipse(17.5, -65, 35, 35); // Right eye dome
- arc(0, -65, 70, 70, 0, PI); // Chin
- fill(0);
- ellipse(-14, -65, 8, 8); // Left eye
- ellipse(14, -65, 8, 8); // Right eye
- quad(0, -58, 4, -51, 0, -44, -4, -51); // Beak
-
- // Right owl
- translate(70, 0);
- stroke(0);
- strokeWeight(70);
- line(0, -35, 0, -65); // Body
- noStroke();
- fill(255);
- ellipse(-17.5, -65, 35, 35); // Left eye dome
- ellipse(17.5, -65, 35, 35); // Right eye dome
- arc(0, -65, 70, 70, 0, PI); // Chin
- fill(0);
- ellipse(-14, -65, 8, 8); // Left eye
- ellipse(14, -65, 8, 8); // Right eye
- quad(0, -58, 4, -51, 0, -44, -4, -51); // Beak
-}
-
diff --git a/java/examples/Books/Getting Started/Chapter08/Ex_08_05/Ex_08_05.pde b/java/examples/Books/Getting Started/Chapter08/Ex_08_05/Ex_08_05.pde
deleted file mode 100644
index b477a30d5..000000000
--- a/java/examples/Books/Getting Started/Chapter08/Ex_08_05/Ex_08_05.pde
+++ /dev/null
@@ -1,32 +0,0 @@
-// Example 08-05 from "Getting Started with Processing"
-// by Reas & Fry. O'Reilly / Make 2010
-
-void setup() {
- size(480, 120);
- smooth();
-}
-
-void draw() {
- background(204);
- owl(110, 110);
- owl(180, 110);
-}
-
-void owl(int x, int y) {
- pushMatrix();
- translate(x, y);
- stroke(0);
- strokeWeight(70);
- line(0, -35, 0, -65); // Body
- noStroke();
- fill(255);
- ellipse(-17.5, -65, 35, 35); // Left eye dome
- ellipse(17.5, -65, 35, 35); // Right eye dome
- arc(0, -65, 70, 70, 0, PI); // Chin
- fill(0);
- ellipse(-14, -65, 8, 8); // Left eye
- ellipse(14, -65, 8, 8); // Right eye
- quad(0, -58, 4, -51, 0, -44, -4, -51); // Beak
- popMatrix();
-}
-
diff --git a/java/examples/Books/Getting Started/Chapter08/Ex_08_06/Ex_08_06.pde b/java/examples/Books/Getting Started/Chapter08/Ex_08_06/Ex_08_06.pde
deleted file mode 100644
index df886744c..000000000
--- a/java/examples/Books/Getting Started/Chapter08/Ex_08_06/Ex_08_06.pde
+++ /dev/null
@@ -1,33 +0,0 @@
-// Example 08-06 from "Getting Started with Processing"
-// by Reas & Fry. O'Reilly / Make 2010
-
-void setup() {
- size(480, 120);
- smooth();
-}
-
-void draw() {
- background(204);
- for (int x = 35; x < width + 70; x += 70) {
- owl(x, 110);
- }
-}
-
-void owl(int x, int y) {
- pushMatrix();
- translate(x, y);
- stroke(0);
- strokeWeight(70);
- line(0, -35, 0, -65); // Body
- noStroke();
- fill(255);
- ellipse(-17.5, -65, 35, 35); // Left eye dome
- ellipse(17.5, -65, 35, 35); // Right eye dome
- arc(0, -65, 70, 70, 0, PI); // Chin
- fill(0);
- ellipse(-14, -65, 8, 8); // Left eye
- ellipse(14, -65, 8, 8); // Right eye
- quad(0, -58, 4, -51, 0, -44, -4, -51); // Beak
- popMatrix();
-}
-
diff --git a/java/examples/Books/Getting Started/Chapter08/Ex_08_07/Ex_08_07.pde b/java/examples/Books/Getting Started/Chapter08/Ex_08_07/Ex_08_07.pde
deleted file mode 100644
index 51f496c9b..000000000
--- a/java/examples/Books/Getting Started/Chapter08/Ex_08_07/Ex_08_07.pde
+++ /dev/null
@@ -1,37 +0,0 @@
-// Example 08-07 from "Getting Started with Processing"
-// by Reas & Fry. O'Reilly / Make 2010
-
-void setup() {
- size(480, 120);
- smooth();
-}
-
-void draw() {
- background(204);
- randomSeed(0);
- for (int i = 35; i < width + 40; i += 40) {
- int gray = int(random(0, 102));
- float scalar = random(0.25, 1.0);
- owl(i, 110, gray, scalar);
- }
-}
-
-void owl(int x, int y, int g, float s) {
- pushMatrix();
- translate(x, y);
- scale(s); // Set the size
- stroke(g); // Set the gray value
- strokeWeight(70);
- line(0, -35, 0, -65); // Body
- noStroke();
- fill(255-g);
- ellipse(-17.5, -65, 35, 35); // Left eye dome
- ellipse(17.5, -65, 35, 35); // Right eye dome
- arc(0, -65, 70, 70, 0, PI); // Chin
- fill(g);
- ellipse(-14, -65, 8, 8); // Left eye
- ellipse(14, -65, 8, 8); // Right eye
- quad(0, -58, 4, -51, 0, -44, -4, -51); // Beak
- popMatrix();
-}
-
diff --git a/java/examples/Books/Getting Started/Chapter08/Ex_08_08/Ex_08_08.pde b/java/examples/Books/Getting Started/Chapter08/Ex_08_08/Ex_08_08.pde
deleted file mode 100644
index 04450188b..000000000
--- a/java/examples/Books/Getting Started/Chapter08/Ex_08_08/Ex_08_08.pde
+++ /dev/null
@@ -1,14 +0,0 @@
-// Example 08-08 from "Getting Started with Processing"
-// by Reas & Fry. O'Reilly / Make 2010
-
-void setup() {
- float yourWeight = 132;
- float marsWeight = calculateMars(yourWeight);
- println(marsWeight);
-}
-
-float calculateMars(float w) {
- float newWeight = w * 0.38;
- return newWeight;
-}
-
diff --git a/java/examples/Books/Getting Started/Chapter09/Ex_09_01/Ex_09_01.pde b/java/examples/Books/Getting Started/Chapter09/Ex_09_01/Ex_09_01.pde
deleted file mode 100644
index 3ba66c8a6..000000000
--- a/java/examples/Books/Getting Started/Chapter09/Ex_09_01/Ex_09_01.pde
+++ /dev/null
@@ -1,40 +0,0 @@
-// Example 09-01 from "Getting Started with Processing"
-// by Reas & Fry. O'Reilly / Make 2010
-
-JitterBug bug; // Declare object
-
-void setup() {
- size(480, 120);
- smooth();
- // Create object and pass in parameters
- bug = new JitterBug(width/2, height/2, 20);
-}
-
-void draw() {
- bug.move();
- bug.display();
-}
-
-class JitterBug {
- float x;
- float y;
- int diameter;
- float speed = 2.5;
-
- JitterBug(float tempX, float tempY, int tempDiameter) {
- x = tempX;
- y = tempY;
- diameter = tempDiameter;
- }
-
- void move() {
- x += random(-speed, speed);
- y += random(-speed, speed);
- }
-
- void display() {
- ellipse(x, y, diameter, diameter);
- }
-}
-
-
diff --git a/java/examples/Books/Getting Started/Chapter09/Ex_09_02/Ex_09_02.pde b/java/examples/Books/Getting Started/Chapter09/Ex_09_02/Ex_09_02.pde
deleted file mode 100644
index 3b229def1..000000000
--- a/java/examples/Books/Getting Started/Chapter09/Ex_09_02/Ex_09_02.pde
+++ /dev/null
@@ -1,45 +0,0 @@
-// Example 09-02 from "Getting Started with Processing"
-// by Reas & Fry. O'Reilly / Make 2010
-
-JitterBug jit;
-JitterBug bug;
-
-void setup() {
- size(480, 120);
- smooth();
- jit = new JitterBug(width * 0.33, height/2, 50);
- bug = new JitterBug(width * 0.66, height/2, 10);
-}
-
-void draw() {
- jit.move();
- jit.display();
- bug.move();
- bug.display();
-}
-
-class JitterBug {
-
- float x;
- float y;
- int diameter;
- float speed = 2.5;
-
- JitterBug(float tempX, float tempY, int tempDiameter) {
- x = tempX;
- y = tempY;
- diameter = tempDiameter;
- }
-
- void move() {
- x += random(-speed, speed);
- y += random(-speed, speed);
- }
-
- void display() {
- ellipse(x, y, diameter, diameter);
- }
-}
-
-
-
diff --git a/java/examples/Books/Getting Started/Chapter10/Ex_10_01/Ex_10_01.pde b/java/examples/Books/Getting Started/Chapter10/Ex_10_01/Ex_10_01.pde
deleted file mode 100644
index e2936c92e..000000000
--- a/java/examples/Books/Getting Started/Chapter10/Ex_10_01/Ex_10_01.pde
+++ /dev/null
@@ -1,20 +0,0 @@
-// Example 10-01 from "Getting Started with Processing"
-// by Reas & Fry. O'Reilly / Make 2010
-
-float x1 = -20;
-float x2 = 20;
-
-void setup() {
- size(240, 120);
- smooth();
- noStroke();
-}
-
-void draw() {
- background(0);
- x1 += 0.5;
- x2 += 0.5;
- arc(x1, 30, 40, 40, 0.52, 5.76);
- arc(x2, 90, 40, 40, 0.52, 5.76);
-}
-
diff --git a/java/examples/Books/Getting Started/Chapter10/Ex_10_02/Ex_10_02.pde b/java/examples/Books/Getting Started/Chapter10/Ex_10_02/Ex_10_02.pde
deleted file mode 100644
index ae04cde1c..000000000
--- a/java/examples/Books/Getting Started/Chapter10/Ex_10_02/Ex_10_02.pde
+++ /dev/null
@@ -1,29 +0,0 @@
-// Example 10-02 from "Getting Started with Processing"
-// by Reas & Fry. O'Reilly / Make 2010
-
-float x1 = -10;
-float x2 = 10;
-float x3 = 35;
-float x4 = 18;
-float x5 = 30;
-
-void setup() {
- size(240, 120);
- smooth();
- noStroke();
-}
-
-void draw() {
- background(0);
- x1 += 0.5;
- x2 += 0.5;
- x3 += 0.5;
- x4 += 0.5;
- x5 += 0.5;
- arc(x1, 20, 20, 20, 0.52, 5.76);
- arc(x2, 40, 20, 20, 0.52, 5.76);
- arc(x3, 60, 20, 20, 0.52, 5.76);
- arc(x4, 80, 20, 20, 0.52, 5.76);
- arc(x5, 100, 20, 20, 0.52, 5.76);
-}
-
diff --git a/java/examples/Books/Getting Started/Chapter10/Ex_10_03/Ex_10_03.pde b/java/examples/Books/Getting Started/Chapter10/Ex_10_03/Ex_10_03.pde
deleted file mode 100644
index 7902c2895..000000000
--- a/java/examples/Books/Getting Started/Chapter10/Ex_10_03/Ex_10_03.pde
+++ /dev/null
@@ -1,24 +0,0 @@
-// Example 10-03 from "Getting Started with Processing"
-// by Reas & Fry. O'Reilly / Make 2010
-
-float[] x = new float[3000];
-
-void setup() {
- size(240, 120);
- smooth();
- noStroke();
- fill(255, 200);
- for (int i = 0; i < x.length; i++) {
- x[i] = random(-1000, 200);
- }
-}
-
-void draw() {
- background(0);
- for (int i = 0; i < x.length; i++) {
- x[i] += 0.5;
- float y = i * 0.4;
- arc(x[i], y, 12, 12, 0.52, 5.76);
- }
-}
-
diff --git a/java/examples/Books/Getting Started/Chapter10/Ex_10_04/Ex_10_04.pde b/java/examples/Books/Getting Started/Chapter10/Ex_10_04/Ex_10_04.pde
deleted file mode 100644
index 3b6830679..000000000
--- a/java/examples/Books/Getting Started/Chapter10/Ex_10_04/Ex_10_04.pde
+++ /dev/null
@@ -1,12 +0,0 @@
-// Example 10-04 from "Getting Started with Processing"
-// by Reas & Fry. O'Reilly / Make 2010
-
-int[] x; // Declare the array
-
-void setup() {
- size(200, 200);
- x = new int[2]; // Create the array
- x[0] = 12; // Assign the first value
- x[1] = 2; // Assign the second value
-}
-
diff --git a/java/examples/Books/Getting Started/Chapter10/Ex_10_05/Ex_10_05.pde b/java/examples/Books/Getting Started/Chapter10/Ex_10_05/Ex_10_05.pde
deleted file mode 100644
index 53408bc04..000000000
--- a/java/examples/Books/Getting Started/Chapter10/Ex_10_05/Ex_10_05.pde
+++ /dev/null
@@ -1,11 +0,0 @@
-// Example 10-05 from "Getting Started with Processing"
-// by Reas & Fry. O'Reilly / Make 2010
-
-int[] x = new int[2]; // Declare and create the array
-
-void setup() {
- size(200, 200);
- x[0] = 12; // Assign the first value
- x[1] = 2; // Assign the second value
-}
-
diff --git a/java/examples/Books/Getting Started/Chapter10/Ex_10_06/Ex_10_06.pde b/java/examples/Books/Getting Started/Chapter10/Ex_10_06/Ex_10_06.pde
deleted file mode 100644
index a3b551a7a..000000000
--- a/java/examples/Books/Getting Started/Chapter10/Ex_10_06/Ex_10_06.pde
+++ /dev/null
@@ -1,9 +0,0 @@
-// Example 10-06 from "Getting Started with Processing"
-// by Reas & Fry. O'Reilly / Make 2010
-
-int[] x = { 12, 2 }; // Declare, create, and assign
-
-void setup() {
- size(200, 200);
-}
-
diff --git a/java/examples/Books/Getting Started/Chapter10/Ex_10_07/Ex_10_07.pde b/java/examples/Books/Getting Started/Chapter10/Ex_10_07/Ex_10_07.pde
deleted file mode 100644
index 581c46a2c..000000000
--- a/java/examples/Books/Getting Started/Chapter10/Ex_10_07/Ex_10_07.pde
+++ /dev/null
@@ -1,19 +0,0 @@
-// Example 10-07 from "Getting Started with Processing"
-// by Reas & Fry. O'Reilly / Make 2010
-
-float[] x = {-20, 20};
-
-void setup() {
- size(240, 120);
- smooth();
- noStroke();
-}
-
-void draw() {
- background(0);
- x[0] += 0.5; // Increase the first element
- x[1] += 0.5; // Increase the second element
- arc(x[0], 30, 40, 40, 0.52, 5.76);
- arc(x[1], 90, 40, 40, 0.52, 5.76);
-}
-
diff --git a/java/examples/Books/Getting Started/Chapter10/Ex_10_08/Ex_10_08.pde b/java/examples/Books/Getting Started/Chapter10/Ex_10_08/Ex_10_08.pde
deleted file mode 100644
index a1738f00e..000000000
--- a/java/examples/Books/Getting Started/Chapter10/Ex_10_08/Ex_10_08.pde
+++ /dev/null
@@ -1,20 +0,0 @@
-// Example 10-08 from "Getting Started with Processing"
-// by Reas & Fry. O'Reilly / Make 2010
-
-float[] gray;
-
-void setup() {
- size(240, 120);
- gray = new float[width];
- for (int i = 0; i < gray.length; i++) {
- gray[i] = random(0, 255);
- }
-}
-
-void draw() {
- for (int i = 0; i < gray.length; i++) {
- stroke(gray[i]);
- line(i, 0, i, height);
- }
-}
-
diff --git a/java/examples/Books/Getting Started/Chapter10/Ex_10_09/Ex_10_09.pde b/java/examples/Books/Getting Started/Chapter10/Ex_10_09/Ex_10_09.pde
deleted file mode 100644
index 74246b2b2..000000000
--- a/java/examples/Books/Getting Started/Chapter10/Ex_10_09/Ex_10_09.pde
+++ /dev/null
@@ -1,28 +0,0 @@
-// Example 10-09 from "Getting Started with Processing"
-// by Reas & Fry. O'Reilly / Make 2010
-
-int num = 60;
-int[] x = new int[num];
-int[] y = new int[num];
-
-void setup() {
- size(240, 120);
- smooth();
- noStroke();
-}
-
-void draw() {
- background(0);
- // Copy array values from back to front
- for (int i = x.length-1; i > 0; i--) {
- x[i] = x[i-1];
- y[i] = y[i-1];
- }
- x[0] = mouseX; // Set the first element
- y[0] = mouseY; // Set the first element
- for (int i = 0; i < x.length; i++) {
- fill(i * 4);
- ellipse(x[i], y[i], 40, 40);
- }
-}
-
diff --git a/java/examples/Books/Getting Started/Chapter10/Ex_10_10/Ex_10_10.pde b/java/examples/Books/Getting Started/Chapter10/Ex_10_10/Ex_10_10.pde
deleted file mode 100644
index 6e1734e20..000000000
--- a/java/examples/Books/Getting Started/Chapter10/Ex_10_10/Ex_10_10.pde
+++ /dev/null
@@ -1,47 +0,0 @@
-// Example 10-10 from "Getting Started with Processing"
-// by Reas & Fry. O'Reilly / Make 2010
-
-JitterBug[] bugs = new JitterBug[33];
-
-void setup() {
- size(240, 120);
- smooth();
- for (int i = 0; i < bugs.length; i++) {
- float x = random(width);
- float y = random(height);
- int r = i + 2;
- bugs[i] = new JitterBug(x, y, r);
- }
-}
-
-void draw() {
- for (int i = 0; i < bugs.length; i++) {
- bugs[i].move();
- bugs[i].display();
- }
-}
-
-class JitterBug {
-
- float x;
- float y;
- int diameter;
- float speed = 2.5;
-
- JitterBug(float tempX, float tempY, int tempDiameter) {
- x = tempX;
- y = tempY;
- diameter = tempDiameter;
- }
-
- void move() {
- x += random(-speed, speed);
- y += random(-speed, speed);
- }
-
- void display() {
- ellipse(x, y, diameter, diameter);
- }
-
-}
-
diff --git a/java/examples/Books/Getting Started/Chapter10/Ex_10_11/Ex_10_11.pde b/java/examples/Books/Getting Started/Chapter10/Ex_10_11/Ex_10_11.pde
deleted file mode 100644
index 8bac9402a..000000000
--- a/java/examples/Books/Getting Started/Chapter10/Ex_10_11/Ex_10_11.pde
+++ /dev/null
@@ -1,24 +0,0 @@
-// Example 10-11 from "Getting Started with Processing"
-// by Reas & Fry. O'Reilly / Make 2010
-
-int numFrames = 12; // The number of frames
-PImage[] images = new PImage[numFrames]; // Make the array
-int currentFrame = 1;
-
-void setup() {
- size(240, 120);
- for (int i = 1; i < images.length; i++) {
- String imageName = "frame-" + nf(i, 4) + ".png";
- images[i] = loadImage(imageName); // Load each image
- }
- frameRate(24);
-}
-
-void draw() {
- image(images[currentFrame], 0, 0);
- currentFrame++; // Next frame
- if (currentFrame >= images.length) {
- currentFrame = 1; // Return to first frame
- }
-}
-
diff --git a/java/examples/Books/Getting Started/Chapter11/Ex_11_01/Ex_11_01.pde b/java/examples/Books/Getting Started/Chapter11/Ex_11_01/Ex_11_01.pde
deleted file mode 100644
index 189a80672..000000000
--- a/java/examples/Books/Getting Started/Chapter11/Ex_11_01/Ex_11_01.pde
+++ /dev/null
@@ -1,29 +0,0 @@
-// Example 11-01 from "Getting Started with Processing"
-// by Reas & Fry. O'Reilly / Make 2010
-
-import processing.opengl.*;
-
-void setup() {
- size(440, 220, OPENGL);
- noStroke();
- fill(255, 190);
-}
-
-void draw() {
- background(0);
- translate(width/2, height/2, 0);
- rotateX(mouseX / 200.0);
- rotateY(mouseY / 100.0);
- int dim = 18;
- for (int i = -height/2; i < height/2; i += dim*1.2) {
- for (int j = -height/2; j < height/2; j += dim*1.2) {
- beginShape();
- vertex(i, j, 0);
- vertex(i+dim, j, 0);
- vertex(i+dim, j+dim, -dim);
- vertex(i, j+dim, -dim);
- endShape();
- }
- }
-}
-
diff --git a/java/examples/Books/Getting Started/Chapter11/Ex_11_02/Ex_11_02.pde b/java/examples/Books/Getting Started/Chapter11/Ex_11_02/Ex_11_02.pde
deleted file mode 100644
index a0585cb85..000000000
--- a/java/examples/Books/Getting Started/Chapter11/Ex_11_02/Ex_11_02.pde
+++ /dev/null
@@ -1,36 +0,0 @@
-// Example 11-02 from "Getting Started with Processing"
-// by Reas & Fry. O'Reilly / Make 2010
-
-import processing.opengl.*;
-
-void setup() {
- size(420, 220, OPENGL);
- noStroke();
- fill(255);
-}
-
-void draw() {
- lights();
- //ambientLight(102, 102, 102);
- //directionalLight(255, 255, 255, // Color
- // -1, 0, 0); // Direction XYZ
- //pointLight(255, 255, 255, // Color
- // mouseX, 110, 50); // Position
- //spotLight(255, 255, 255, // Color
- // mouseX, 0, 200, // Position
- // 0, 0, -1, // Direction XYZ
- // PI, 2); // Concentration
- rotateY(PI/24);
- background(0);
- translate(width/2, height/2, -20);
- int dim = 18;
- for (int i = -height/2; i < height/2; i += dim*1.4) {
- for (int j = -height/2; j < height/2; j += dim*1.4) {
- pushMatrix();
- translate(i, j, -j);
- box(dim, dim, dim);
- popMatrix();
- }
- }
-}
-
diff --git a/java/examples/Books/Getting Started/Chapter11/Ex_11_03/Ex_11_03.pde b/java/examples/Books/Getting Started/Chapter11/Ex_11_03/Ex_11_03.pde
deleted file mode 100644
index 7c0c0871d..000000000
--- a/java/examples/Books/Getting Started/Chapter11/Ex_11_03/Ex_11_03.pde
+++ /dev/null
@@ -1,29 +0,0 @@
-// Example 11-03 from "Getting Started with Processing"
-// by Reas & Fry. O'Reilly / Make 2010
-
-import processing.opengl.*;
-
-void setup() {
- size(420, 220, OPENGL);
- noStroke();
-}
-
-void draw() {
- lights();
- background(0);
- float camZ = (height/2.0) / tan(PI*60.0 / 360.0);
- camera(mouseX, mouseY, camZ, // Camera location
- width/2.0, height/2.0, 0, // Camera target
- 0, 1, 0); // Camera orientation
- translate(width/2, height/2, -20);
- int dim = 18;
- for (int i = -height/2; i < height/2; i += dim*1.4) {
- for (int j = -height/2; j < height/2; j += dim*1.4) {
- pushMatrix();
- translate(i, j, -j);
- box(dim, dim, dim);
- popMatrix();
- }
- }
-}
-
diff --git a/java/examples/Books/Getting Started/Chapter11/Ex_11_04/Ex_11_04.pde b/java/examples/Books/Getting Started/Chapter11/Ex_11_04/Ex_11_04.pde
deleted file mode 100644
index fa63b0dd5..000000000
--- a/java/examples/Books/Getting Started/Chapter11/Ex_11_04/Ex_11_04.pde
+++ /dev/null
@@ -1,27 +0,0 @@
-// Example 11-04 from "Getting Started with Processing"
-// by Reas & Fry. O'Reilly / Make 2010
-
-float x = 0;
-
-void setup() {
- size(720, 480);
- smooth();
- noFill();
- strokeCap(SQUARE);
- frameRate(30);
-}
-
-void draw() {
- background(204);
- translate(x, 0);
- for (int y = 40; y < 280; y += 20) {
- line(-260, y, 0, y + 200);
- line(0, y + 200, 260, y);
- }
- if (frameCount < 60) {
- saveFrame("frames/SaveExample-####.tif");
- } else {
- exit();
- }
- x += 2.5;
-}
diff --git a/java/examples/Books/Getting Started/Chapter11/Ex_11_05/Ex_11_05.pde b/java/examples/Books/Getting Started/Chapter11/Ex_11_05/Ex_11_05.pde
deleted file mode 100644
index 104c28c73..000000000
--- a/java/examples/Books/Getting Started/Chapter11/Ex_11_05/Ex_11_05.pde
+++ /dev/null
@@ -1,25 +0,0 @@
-// Example 11-05 from "Getting Started with Processing"
-// by Reas & Fry. O'Reilly / Make 2010
-
-import processing.pdf.*;
-
-void setup() {
- size(600, 800, PDF, "Ex-11-5.pdf");
- noFill();
- strokeCap(SQUARE);
-}
-
-void draw() {
- background(255);
- for (int y = 100; y < height - 300; y+=20) {
- float r = random(0, 102);
- strokeWeight(r / 10);
- beginShape();
- vertex(100, y);
- vertex(width/2, y + 200);
- vertex(width-100, y);
- endShape();
- }
- exit();
-}
-
diff --git a/java/examples/Books/Getting Started/Chapter11/Ex_11_06/Ex_11_06.pde b/java/examples/Books/Getting Started/Chapter11/Ex_11_06/Ex_11_06.pde
deleted file mode 100644
index 70db3c766..000000000
--- a/java/examples/Books/Getting Started/Chapter11/Ex_11_06/Ex_11_06.pde
+++ /dev/null
@@ -1,17 +0,0 @@
-// Example 11-06 from "Getting Started with Processing"
-// by Reas & Fry. O'Reilly / Make 2010
-
-// Note: This is code for an Arduino board, not Processing
-
-int sensorPin = 0; // Select input pin
-int val = 0;
-
-void setup() {
- Serial.begin(9600); // Open serial port
-}
-
-void loop() {
- val = analogRead(sensorPin) / 4; // Read value from sensor
- Serial.print(val, BYTE); // Print variable to serial port
- delay(100); // Wait 100 milliseconds
-}
diff --git a/java/examples/Books/Getting Started/Chapter11/Ex_11_07/Ex_11_07.pde b/java/examples/Books/Getting Started/Chapter11/Ex_11_07/Ex_11_07.pde
deleted file mode 100644
index 8965855a7..000000000
--- a/java/examples/Books/Getting Started/Chapter11/Ex_11_07/Ex_11_07.pde
+++ /dev/null
@@ -1,30 +0,0 @@
-// Example 11-07 from "Getting Started with Processing"
-// by Reas & Fry. O'Reilly / Make 2010
-
-import processing.serial.*;
-
-Serial port; // Create object from Serial class
-float val; // Data received from the serial port
-
-void setup() {
- size(440, 220);
- // IMPORTANT NOTE:
- // The first serial port retrieved by Serial.list()
- // should be your Arduino. If not, uncomment the next
- // line by deleting the // before it. Run the sketch
- // again to see a list of serial ports. Then, change
- // the 0 in between [ and ] to the number of the port
- // that your Arduino is connected to.
- //println(Serial.list());
- String arduinoPort = Serial.list()[0];
- port = new Serial(this, arduinoPort, 9600);
-}
-
-void draw() {
- if (port.available() > 0) { // If data is available,
- val = port.read(); // read it and store it in val
- val = map(val, 0, 255, 0, height); // Convert the value
- }
- rect(40, val-10, 360, 20);
-}
-
diff --git a/java/examples/Books/Getting Started/Chapter11/Ex_11_08/Ex_11_08.pde b/java/examples/Books/Getting Started/Chapter11/Ex_11_08/Ex_11_08.pde
deleted file mode 100644
index 444e8c692..000000000
--- a/java/examples/Books/Getting Started/Chapter11/Ex_11_08/Ex_11_08.pde
+++ /dev/null
@@ -1,44 +0,0 @@
-// Example 11-08 from "Getting Started with Processing"
-// by Reas & Fry. O'Reilly / Make 2010
-
-import processing.serial.*;
-
-Serial port; // Create object from Serial class
-float val; // Data received from the serial port
-int x;
-float easing = 0.05;
-float easedVal;
-
-void setup() {
- size(440, 440);
- frameRate(30);
- smooth();
- String arduinoPort = Serial.list()[0];
- port = new Serial(this, arduinoPort, 9600);
- background(0);
-}
-
-void draw() {
- if ( port.available() > 0) { // If data is available,
- val = port.read(); // read it and store it in val
- val = map(val, 0, 255, 0, height); // Convert the values
- }
-
- float targetVal = val;
- easedVal += (targetVal - easedVal) * easing;
-
- stroke(0);
- line(x, 0, x, height); // Black line
- stroke(255);
- line(x+1, 0, x+1, height); // White line
- line(x, 220, x, val); // Raw value
- line(x, 440, x, easedVal + 220); // Averaged value
-
- x++;
- if (x > width) {
- x = 0;
- }
-}
-
-
-
diff --git a/java/examples/Books/Getting Started/Chapter11/Ex_11_09/Ex_11_09.pde b/java/examples/Books/Getting Started/Chapter11/Ex_11_09/Ex_11_09.pde
deleted file mode 100644
index ed28e4622..000000000
--- a/java/examples/Books/Getting Started/Chapter11/Ex_11_09/Ex_11_09.pde
+++ /dev/null
@@ -1,41 +0,0 @@
-// Example 11-09 from "Getting Started with Processing"
-// by Reas & Fry. O'Reilly / Make 2010
-
-import processing.serial.*;
-
-Serial port; // Create object from Serial class
-float val; // Data received from the serial port
-float angle;
-float radius;
-
-void setup() {
- size(440, 440);
- frameRate(30);
- strokeWeight(2);
- smooth();
- String arduinoPort = Serial.list()[0];
- port = new Serial(this, arduinoPort, 9600);
- background(0);
-}
-
-void draw() {
- if ( port.available() > 0) { // If data is available,
- val = port.read(); // read it and store it in val
- // Convert the values to set the radius
- radius = map(val, 0, 255, 0, height * 0.45);
- }
-
- int middleX = width/2;
- int middleY = height/2;
- float x = middleX + cos(angle) * height/2;
- float y = middleY + sin(angle) * height/2;
- stroke(0);
- line(middleX, middleY, x, y);
-
- x = middleX + cos(angle) * radius;
- y = middleY + sin(angle) * radius;
- stroke(255);
- line(middleX, middleY, x, y);
-
- angle += 0.01;
-}
diff --git a/java/examples/Books/Getting Started/Robots/Robot1_Draw/Robot1_Draw.pde b/java/examples/Books/Getting Started/Robots/Robot1_Draw/Robot1_Draw.pde
deleted file mode 100644
index 60b197205..000000000
--- a/java/examples/Books/Getting Started/Robots/Robot1_Draw/Robot1_Draw.pde
+++ /dev/null
@@ -1,41 +0,0 @@
-// Robot 1: Draw from "Getting Started with Processing"
-// by Reas & Fry. O'Reilly / Make 2010
-
-size(720, 480);
-smooth();
-strokeWeight(2);
-background(204);
-ellipseMode(RADIUS);
-
-// Neck
-stroke(102); // Set stroke to gray
-line(266, 257, 266, 162); // Left
-line(276, 257, 276, 162); // Middle
-line(286, 257, 286, 162); // Right
-
-// Antennae
-line(276, 155, 246, 112); // Small
-line(276, 155, 306, 56); // Tall
-line(276, 155, 342, 170); // Medium
-
-// Body
-noStroke(); // Disable stroke
-fill(102); // Set fill to gray
-ellipse(264, 377, 33, 33); // Antigravity orb
-fill(0); // Set fill to black
-rect(219, 257, 90, 120); // Main body
-fill(102); // Set fill to gray
-rect(219, 274, 90, 6); // Gray stripe
-
-// Head
-fill(0); // Set fill to black
-ellipse(276, 155, 45, 45); // Head
-fill(255); // Set fill to white
-ellipse(288, 150, 14, 14); // Large eye
-fill(0); // Set fill to black
-ellipse(288, 150, 3, 3); // Pupil
-fill(153); // Set fill to light gray
-ellipse(263, 148, 5, 5); // Small eye 1
-ellipse(296, 130, 4, 4); // Small eye 2
-ellipse(305, 162, 3, 3); // Small eye 3
-
diff --git a/java/examples/Books/Getting Started/Robots/Robot2_Variables/Robot2_Variables.pde b/java/examples/Books/Getting Started/Robots/Robot2_Variables/Robot2_Variables.pde
deleted file mode 100644
index a20816e2c..000000000
--- a/java/examples/Books/Getting Started/Robots/Robot2_Variables/Robot2_Variables.pde
+++ /dev/null
@@ -1,54 +0,0 @@
-// Robot 2: Variables from "Getting Started with Processing"
-// by Reas & Fry. O'Reilly / Make 2010
-
-int x = 60; // X-coordinate
-int y = 420; // Y-coordinate
-int bodyHeight = 110; // Body Height
-int neckHeight = 140; // Neck Height
-int radius = 45;
-int ny = y - bodyHeight - neckHeight - radius; // Neck Y
-
-size(170, 480);
-smooth();
-strokeWeight(2);
-background(204);
-ellipseMode(RADIUS);
-
-// Neck
-stroke(102);
-line(x+2, y-bodyHeight, x+2, ny);
-line(x+12, y-bodyHeight, x+12, ny);
-line(x+22, y-bodyHeight, x+22, ny);
-
-// Antennae
-line(x+12, ny, x-18, ny-43);
-line(x+12, ny, x+42, ny-99);
-line(x+12, ny, x+78, ny+15);
-
-// Body
-noStroke();
-fill(102);
-ellipse(x, y-33, 33, 33);
-fill(0);
-rect(x-45, y-bodyHeight, 90, bodyHeight-33);
-fill(102);
-rect(x-45, y-bodyHeight+17, 90, 6);
-
-// Head
-fill(0);
-ellipse(x+12, ny, radius, radius);
-fill(255);
-ellipse(x+24, ny-6, 14, 14);
-fill(0);
-ellipse(x+24, ny-6, 3, 3);
-fill(153);
-ellipse(x, ny-8, 5, 5);
-ellipse(x+30, ny-26, 4, 4);
-ellipse(x+41, ny+6, 3, 3);
-
-
-
-
-
-
-
diff --git a/java/examples/Books/Getting Started/Robots/Robot3_Response/Robot3_Response.pde b/java/examples/Books/Getting Started/Robots/Robot3_Response/Robot3_Response.pde
deleted file mode 100644
index dea4634d9..000000000
--- a/java/examples/Books/Getting Started/Robots/Robot3_Response/Robot3_Response.pde
+++ /dev/null
@@ -1,59 +0,0 @@
-// Robot 3: Response from "Getting Started with Processing"
-// by Reas & Fry. O'Reilly / Make 2010
-
-float x = 60; // X-coordinate
-float y = 440; // Y-coordinate
-int radius = 45; // Head Radius
-int bodyHeight = 160; // Body Height
-int neckHeight = 70; // Neck Height
-
-float easing = 0.02;
-
-void setup() {
- size(360, 480);
- smooth();
- strokeWeight(2);
- ellipseMode(RADIUS);
-}
-
-void draw() {
-
- int targetX = mouseX;
- x += (targetX - x) * easing;
-
- if (mousePressed) {
- neckHeight = 16;
- bodyHeight = 90;
- } else {
- neckHeight = 70;
- bodyHeight = 160;
- }
-
- float ny = y - bodyHeight - neckHeight - radius;
-
- background(204);
-
- // Neck
- stroke(102);
- line(x+12, y-bodyHeight, x+12, ny);
-
- // Antennae
- line(x+12, ny, x-18, ny-43);
- line(x+12, ny, x+42, ny-99);
- line(x+12, ny, x+78, ny+15);
-
- // Body
- noStroke();
- fill(102);
- ellipse(x, y-33, 33, 33);
- fill(0);
- rect(x-45, y-bodyHeight, 90, bodyHeight-33);
-
- // Head
- fill(0);
- ellipse(x+12, ny, radius, radius);
- fill(255);
- ellipse(x+24, ny-6, 14, 14);
- fill(0);
- ellipse(x+24, ny-6, 3, 3);
-}
diff --git a/java/examples/Books/Getting Started/Robots/Robot4_Media/Robot4_Media.pde b/java/examples/Books/Getting Started/Robots/Robot4_Media/Robot4_Media.pde
deleted file mode 100644
index 1945fa3d4..000000000
--- a/java/examples/Books/Getting Started/Robots/Robot4_Media/Robot4_Media.pde
+++ /dev/null
@@ -1,43 +0,0 @@
-// Robot 4: Media from "Getting Started with Processing"
-// by Reas & Fry. O'Reilly / Make 2010
-
-
-PShape bot1;
-PShape bot2;
-PShape bot3;
-PImage landscape;
-
-float easing = 0.05;
-float offset = 0;
-
-void setup() {
- size(720, 480);
- bot1 = loadShape("robot1.svg");
- bot2 = loadShape("robot2.svg");
- bot3 = loadShape("robot3.svg");
- landscape = loadImage("alpine.png");
- smooth();
-}
-
-void draw() {
- // Set the background to the "landscape" image, this image
- // must be the same width and height as the program
- background(landscape);
-
- // Set the left/right offset and apply easing to make
- // the transition smooth
- float targetOffset = map(mouseY, 0, height, -40, 40);
- offset += (targetOffset - offset) * easing;
-
- // Draw the left robot
- shape(bot1, 85 + offset, 65);
-
- // Draw the right robot smaller and give it a smaller offset
- float smallerOffset = offset * 0.7;
- shape(bot2, 510 + smallerOffset, 140, 78, 248);
-
- // Draw the smallest robot, give it a smaller offset
- smallerOffset *= -0.5;
- shape(bot3, 410 + smallerOffset, 225, 39, 124);
-}
-
diff --git a/java/examples/Books/Getting Started/Robots/Robot4_Media/data/robot1.svg b/java/examples/Books/Getting Started/Robots/Robot4_Media/data/robot1.svg
deleted file mode 100644
index e44805f1c..000000000
--- a/java/examples/Books/Getting Started/Robots/Robot4_Media/data/robot1.svg
+++ /dev/null
@@ -1,1033 +0,0 @@
-
-
-
-
diff --git a/java/examples/Books/Getting Started/Robots/Robot4_Media/data/robot2.svg b/java/examples/Books/Getting Started/Robots/Robot4_Media/data/robot2.svg
deleted file mode 100644
index bda32e6a1..000000000
--- a/java/examples/Books/Getting Started/Robots/Robot4_Media/data/robot2.svg
+++ /dev/null
@@ -1,92 +0,0 @@
-
-
-
-
diff --git a/java/examples/Books/Getting Started/Robots/Robot4_Media/data/robot3.svg b/java/examples/Books/Getting Started/Robots/Robot4_Media/data/robot3.svg
deleted file mode 100644
index 436456609..000000000
--- a/java/examples/Books/Getting Started/Robots/Robot4_Media/data/robot3.svg
+++ /dev/null
@@ -1,78 +0,0 @@
-
-
-
-
diff --git a/java/examples/Books/Getting Started/Robots/Robot5_Motion/Robot5_Motion.pde b/java/examples/Books/Getting Started/Robots/Robot5_Motion/Robot5_Motion.pde
deleted file mode 100644
index 70c0a2eff..000000000
--- a/java/examples/Books/Getting Started/Robots/Robot5_Motion/Robot5_Motion.pde
+++ /dev/null
@@ -1,57 +0,0 @@
-// Robot 5: Motion from "Getting Started with Processing"
-// by Reas & Fry. O'Reilly / Make 2010
-
-float x = 180; // X-coordinate
-float y = 400; // Y-coordinate
-float bodyHeight = 153; // Body Height
-float neckHeight = 56; // Neck Height
-float radius = 45; // Head Radius
-float angle = 0.0; // Angle for motion
-
-void setup() {
- size(360, 480);
- smooth();
- ellipseMode(RADIUS);
-}
-
-void draw() {
- // Change position by a small random amount
- x += random(-4, 4);
- y += random(-1, 1);
-
- // Change height of neck
- neckHeight = 80 + sin(angle) * 30;
- angle += 0.05;
-
- // Adjust the height of the head
- float ny = y - bodyHeight - neckHeight - radius;
-
- // Neck
- stroke(102);
- line(x+2, y-bodyHeight, x+2, ny);
- line(x+12, y-bodyHeight, x+12, ny);
- line(x+22, y-bodyHeight, x+22, ny);
-
- // Antennae
- line(x+12, ny, x-18, ny-43);
- line(x+12, ny, x+42, ny-99);
- line(x+12, ny, x+78, ny+15);
-
- // Body
- noStroke();
- fill(102);
- ellipse(x, y-33, 33, 33);
- fill(0);
- rect(x-45, y-bodyHeight, 90, bodyHeight-33);
- fill(102);
- rect(x-45, y-bodyHeight+17, 90, 6);
-
- // Head
- fill(0);
- ellipse(x+12, ny, radius, radius);
- fill(255);
- ellipse(x+24, ny-6, 14, 14);
- fill(0);
- ellipse(x+24, ny-6, 3, 3);
-}
-
diff --git a/java/examples/Books/Getting Started/Robots/Robot6_Functions/Robot6_Functions.pde b/java/examples/Books/Getting Started/Robots/Robot6_Functions/Robot6_Functions.pde
deleted file mode 100644
index 9d1878b54..000000000
--- a/java/examples/Books/Getting Started/Robots/Robot6_Functions/Robot6_Functions.pde
+++ /dev/null
@@ -1,63 +0,0 @@
-// Robot 6: Functions from "Getting Started with Processing"
-// by Reas & Fry. O'Reilly / Make 2010
-
-
-void setup() {
- size(720, 480);
- smooth();
- strokeWeight(2);
- ellipseMode(RADIUS);
-}
-
-void draw() {
- background(204);
- drawRobot(120, 420, 110, 140);
- drawRobot(270, 460, 260, 95);
- drawRobot(420, 310, 80, 10);
- drawRobot(570, 390, 180, 40);
-}
-
-void drawRobot(int x, int y, int bodyHeight, int neckHeight) {
-
- int radius = 45;
- int ny = y - bodyHeight - neckHeight - radius; // neckHeight Y
-
- // Neck
- stroke(102);
- line(x+2, y-bodyHeight, x+2, ny);
- line(x+12, y-bodyHeight, x+12, ny);
- line(x+22, y-bodyHeight, x+22, ny);
-
- // Antennae
- line(x+12, ny, x-18, ny-43);
- line(x+12, ny, x+42, ny-99);
- line(x+12, ny, x+78, ny+15);
-
- // Body
- noStroke();
- fill(102);
- ellipse(x, y-33, 33, 33);
- fill(0);
- rect(x-45, y-bodyHeight, 90, bodyHeight-33);
- fill(102);
- rect(x-45, y-bodyHeight+17, 90, 6);
-
- // Head
- fill(0);
- ellipse(x+12, ny, radius, radius);
- fill(255);
- ellipse(x+24, ny-6, 14, 14);
- fill(0);
- ellipse(x+24, ny-6, 3, 3);
- fill(153);
- ellipse(x, ny-8, 5, 5);
- ellipse(x+30, ny-26, 4, 4);
- ellipse(x+41, ny+6, 3, 3);
-}
-
-
-
-
-
-
-
diff --git a/java/examples/Books/Getting Started/Robots/Robot7_Objects/Robot7_Objects.pde b/java/examples/Books/Getting Started/Robots/Robot7_Objects/Robot7_Objects.pde
deleted file mode 100644
index 5f0da699f..000000000
--- a/java/examples/Books/Getting Started/Robots/Robot7_Objects/Robot7_Objects.pde
+++ /dev/null
@@ -1,53 +0,0 @@
-// Robot 7: Objects from "Getting Started with Processing"
-// by Reas & Fry. O'Reilly / Make 2010
-
-Robot bot1;
-Robot bot2;
-
-void setup() {
- size(720, 480);
- bot1 = new Robot("robot1.svg", 90, 80);
- bot2 = new Robot("robot2.svg", 440, 30);
- smooth();
-}
-
-void draw() {
- background(204);
-
- // Update and display first robot
- bot1.update();
- bot1.display();
-
- // Update and display second robot
- bot2.update();
- bot2.display();
-}
-
-class Robot {
- float xpos;
- float ypos;
- float angle;
- PShape botShape;
- float yoffset = 0.0;
-
- // Set initial values in constructor
- Robot(String svgName, float tempX, float tempY) {
- botShape = loadShape(svgName);
- xpos = tempX;
- ypos = tempY;
- angle = random(0, TWO_PI);
- }
-
- // Update the fields
- void update() {
- angle += 0.05;
- yoffset = sin(angle) * 20;
- }
-
- // Draw the robot to the screen
- void display() {
- shape(botShape, xpos, ypos + yoffset);
- }
-
-}
-
diff --git a/java/examples/Books/Getting Started/Robots/Robot7_Objects/data/robot1.svg b/java/examples/Books/Getting Started/Robots/Robot7_Objects/data/robot1.svg
deleted file mode 100644
index e44805f1c..000000000
--- a/java/examples/Books/Getting Started/Robots/Robot7_Objects/data/robot1.svg
+++ /dev/null
@@ -1,1033 +0,0 @@
-
-
-
-
diff --git a/java/examples/Books/Getting Started/Robots/Robot7_Objects/data/robot2.svg b/java/examples/Books/Getting Started/Robots/Robot7_Objects/data/robot2.svg
deleted file mode 100644
index bda32e6a1..000000000
--- a/java/examples/Books/Getting Started/Robots/Robot7_Objects/data/robot2.svg
+++ /dev/null
@@ -1,92 +0,0 @@
-
-
-
-
diff --git a/java/examples/Books/Getting Started/Robots/Robot8_Arrays/Robot8_Arrays.pde b/java/examples/Books/Getting Started/Robots/Robot8_Arrays/Robot8_Arrays.pde
deleted file mode 100644
index 396a5d6c5..000000000
--- a/java/examples/Books/Getting Started/Robots/Robot8_Arrays/Robot8_Arrays.pde
+++ /dev/null
@@ -1,58 +0,0 @@
-// Robot 8: Arrays from "Getting Started with Processing"
-// by Reas & Fry. O'Reilly / Make 2010
-
-Robot[] bots; // Declare array of Robot objects
-
-void setup() {
- size(720, 480);
- PShape robotShape = loadShape("robot1.svg");
- // Create the array of Robot objects
- bots = new Robot[20];
- // Create each object
- for (int i = 0; i < bots.length; i++) {
- // Create a random x-coordinate
- float x = random(-40, width-40);
- // Assign the y-coordinate based on the order
- float y = map(i, 0, bots.length, -100, height-200);
- bots[i] = new Robot(robotShape, x, y);
- }
- smooth();
-}
-
-void draw() {
- background(204);
- // Update and display each bot in the array
- for (int i = 0; i < bots.length; i++) {
- bots[i].update();
- bots[i].display();
- }
-}
-
-class Robot {
- float xpos;
- float ypos;
- float angle;
- PShape botShape;
- float yoffset = 0.0;
-
- // Set initial values in constructor
- Robot(PShape shape, float tempX, float tempY) {
- botShape = shape;
- xpos = tempX;
- ypos = tempY;
- angle = random(0, TWO_PI);
- }
-
- // Update the fields
- void update() {
- angle += 0.05;
- yoffset = sin(angle) * 20;
- }
-
- // Draw the robot to the screen
- void display() {
- shape(botShape, xpos, ypos + yoffset);
- }
-
-}
-
diff --git a/java/examples/Books/Getting Started/Robots/Robot8_Arrays/data/robot1.svg b/java/examples/Books/Getting Started/Robots/Robot8_Arrays/data/robot1.svg
deleted file mode 100644
index e44805f1c..000000000
--- a/java/examples/Books/Getting Started/Robots/Robot8_Arrays/data/robot1.svg
+++ /dev/null
@@ -1,1033 +0,0 @@
-
-
-
-
diff --git a/java/examples/Books/Getting Started/media/AndaleMono-24.vlw b/java/examples/Books/Getting Started/media/AndaleMono-24.vlw
deleted file mode 100644
index a71ac78ac..000000000
Binary files a/java/examples/Books/Getting Started/media/AndaleMono-24.vlw and /dev/null differ
diff --git a/java/examples/Books/Getting Started/media/AndaleMono-36.vlw b/java/examples/Books/Getting Started/media/AndaleMono-36.vlw
deleted file mode 100644
index 34e243f0b..000000000
Binary files a/java/examples/Books/Getting Started/media/AndaleMono-36.vlw and /dev/null differ
diff --git a/java/examples/Books/Getting Started/media/clouds.gif b/java/examples/Books/Getting Started/media/clouds.gif
deleted file mode 100644
index ad52b85a1..000000000
Binary files a/java/examples/Books/Getting Started/media/clouds.gif and /dev/null differ
diff --git a/java/examples/Books/Getting Started/media/network.svg b/java/examples/Books/Getting Started/media/network.svg
deleted file mode 100644
index 5ecd8d159..000000000
--- a/java/examples/Books/Getting Started/media/network.svg
+++ /dev/null
@@ -1,4056 +0,0 @@
-
-
-
-
diff --git a/java/examples/Books/Getting Started/media/robot1.svg b/java/examples/Books/Getting Started/media/robot1.svg
deleted file mode 100644
index e44805f1c..000000000
--- a/java/examples/Books/Getting Started/media/robot1.svg
+++ /dev/null
@@ -1,1033 +0,0 @@
-
-
-
-
diff --git a/java/examples/Books/Getting Started/media/robot2.svg b/java/examples/Books/Getting Started/media/robot2.svg
deleted file mode 100644
index e44805f1c..000000000
--- a/java/examples/Books/Getting Started/media/robot2.svg
+++ /dev/null
@@ -1,1033 +0,0 @@
-
-
-
-
diff --git a/java/examples/Books/Nature of Code/chp10_nn/Exercise_10_5_LayeredNetworkAnimation/Connection.pde b/java/examples/Books/Nature of Code/chp10_nn/Exercise_10_5_LayeredNetworkAnimation/Connection.pde
deleted file mode 100644
index 0dcfe7a67..000000000
--- a/java/examples/Books/Nature of Code/chp10_nn/Exercise_10_5_LayeredNetworkAnimation/Connection.pde
+++ /dev/null
@@ -1,65 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// An animated drawing of a Neural Network
-
-class Connection {
- // Connection is from Neuron A to B
- Neuron a;
- Neuron b;
-
- // Connection has a weight
- float weight;
-
- // Variables to track the animation
- boolean sending = false;
- PVector sender;
-
- // Need to store the output for when its time to pass along
- float output = 0;
-
- Connection(Neuron from, Neuron to, float w) {
- weight = w;
- a = from;
- b = to;
- }
-
-
- // The Connection is active
- void feedforward(float val) {
- output = val*weight; // Compute output
- sender = a.location.get(); // Start animation at Neuron A
- sending = true; // Turn on sending
- }
-
- // Update traveling sender
- void update() {
- if (sending) {
- // Use a simple interpolation
- sender.x = lerp(sender.x, b.location.x, 0.1);
- sender.y = lerp(sender.y, b.location.y, 0.1);
- float d = PVector.dist(sender, b.location);
- // If we've reached the end
- if (d < 1) {
- // Pass along the output!
- b.feedforward(output);
- sending = false;
- }
- }
- }
-
- // Draw line and traveling circle
- void display() {
- stroke(0);
- strokeWeight(1+weight*4);
- line(a.location.x, a.location.y, b.location.x, b.location.y);
-
- if (sending) {
- fill(0);
- strokeWeight(1);
- ellipse(sender.x, sender.y, 16, 16);
- }
- }
-}
-
diff --git a/java/examples/Books/Nature of Code/chp10_nn/Exercise_10_5_LayeredNetworkAnimation/Exercise_10_5_LayeredNetworkAnimation.pde b/java/examples/Books/Nature of Code/chp10_nn/Exercise_10_5_LayeredNetworkAnimation/Exercise_10_5_LayeredNetworkAnimation.pde
deleted file mode 100644
index 87958e675..000000000
--- a/java/examples/Books/Nature of Code/chp10_nn/Exercise_10_5_LayeredNetworkAnimation/Exercise_10_5_LayeredNetworkAnimation.pde
+++ /dev/null
@@ -1,49 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// An animated drawing of a Neural Network
-
-Network network;
-
-void setup() {
- size(640,360);
- // Create the Network object
- network = new Network(width/2, height/2);
-
- int layers = 3;
- int inputs = 2;
-
- Neuron output = new Neuron(250, 0);
- for (int i = 0; i < layers; i++) {
- for (int j = 0; j < inputs; j++) {
- float x = map(i, 0, layers, -250, 300);
- float y = map(j, 0, inputs-1, -75, 75);
- Neuron n = new Neuron(x, y);
- if (i > 0) {
- for (int k = 0; k < inputs; k++) {
- Neuron prev = network.neurons.get(network.neurons.size()-inputs+k-j);
- network.connect(prev, n, random(1));
- }
- }
- if (i == layers-1) {
- network.connect(n, output, random(1));
- }
- network.addNeuron(n);
- }
- }
- network.addNeuron(output);
-}
-
-void draw() {
- background(255);
- // Update and display the Network
- network.update();
- network.display();
-
- // Every 30 frames feed in an input
- if (frameCount % 30 == 0) {
- network.feedforward(random(1),random(1));
- }
-}
-
diff --git a/java/examples/Books/Nature of Code/chp10_nn/Exercise_10_5_LayeredNetworkAnimation/Network.pde b/java/examples/Books/Nature of Code/chp10_nn/Exercise_10_5_LayeredNetworkAnimation/Network.pde
deleted file mode 100644
index 68a9f597f..000000000
--- a/java/examples/Books/Nature of Code/chp10_nn/Exercise_10_5_LayeredNetworkAnimation/Network.pde
+++ /dev/null
@@ -1,68 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// An animated drawing of a Neural Network
-
-class Network {
-
- // The Network has a list of neurons
- ArrayList neurons;
-
- // The Network now keeps a duplicate list of all Connection objects.
- // This makes it easier to draw everything in this class
- ArrayList connections;
- PVector location;
-
- Network(float x, float y) {
- location = new PVector(x, y);
- neurons = new ArrayList();
- connections = new ArrayList();
- }
-
- // We can add a Neuron
- void addNeuron(Neuron n) {
- neurons.add(n);
- }
-
- // We can connection two Neurons
- void connect(Neuron a, Neuron b, float weight) {
- Connection c = new Connection(a, b, weight);
- a.addConnection(c);
- // Also add the Connection here
- connections.add(c);
- }
-
- // Sending an input to the first Neuron
- // We should do something better to track multiple inputs
- void feedforward(float input1, float input2) {
- Neuron n1 = neurons.get(0);
- n1.feedforward(input1);
-
- Neuron n2 = neurons.get(1);
- n2.feedforward(input2);
-
- }
-
- // Update the animation
- void update() {
- for (Connection c : connections) {
- c.update();
- }
- }
-
- // Draw everything
- void display() {
- pushMatrix();
- translate(location.x, location.y);
- for (Neuron n : neurons) {
- n.display();
- }
-
- for (Connection c : connections) {
- c.display();
- }
- popMatrix();
- }
-}
-
diff --git a/java/examples/Books/Nature of Code/chp10_nn/Exercise_10_5_LayeredNetworkAnimation/Neuron.pde b/java/examples/Books/Nature of Code/chp10_nn/Exercise_10_5_LayeredNetworkAnimation/Neuron.pde
deleted file mode 100644
index 819fe6750..000000000
--- a/java/examples/Books/Nature of Code/chp10_nn/Exercise_10_5_LayeredNetworkAnimation/Neuron.pde
+++ /dev/null
@@ -1,64 +0,0 @@
-// Daniel Shiffman
-// The Nature of Code
-// http://natureofcode.com
-
-// An animated drawing of a Neural Network
-
-class Neuron {
- // Neuron has a location
- PVector location;
-
- // Neuron has a list of connections
- ArrayList connections;
-
- // We now track the inputs and sum them
- float sum = 0;
-
- // The Neuron's size can be animated
- float r = 32;
-
- Neuron(float x, float y) {
- location = new PVector(x, y);
- connections = new ArrayList();
- }
-
- // Add a Connection
- void addConnection(Connection c) {
- connections.add(c);
- }
-
- // Receive an input
- void feedforward(float input) {
- // Accumulate it
- sum += input;
- // Activate it?
- if (sum > 1) {
- fire();
- sum = 0; // Reset the sum to 0 if it fires
- }
- }
-
- // The Neuron fires
- void fire() {
- r = 64; // It suddenly is bigger
-
- // We send the output through all connections
- for (Connection c : connections) {
- c.feedforward(sum);
- }
- }
-
- // Draw it as a circle
- void display() {
- stroke(0);
- strokeWeight(1);
- // Brightness is mapped to sum
- float b = map(sum,0,1,255,0);
- fill(b);
- ellipse(location.x, location.y, r, r);
-
- // Size shrinks down back to original dimensions
- r = lerp(r,32,0.1);
- }
-}
-
diff --git a/java/examples/Books/Nature of Code/chp10_nn/LayeredNetworkViz/Connection.pde b/java/examples/Books/Nature of Code/chp10_nn/LayeredNetworkViz/Connection.pde
deleted file mode 100644
index 4d3c6d365..000000000
--- a/java/examples/Books/Nature of Code/chp10_nn/LayeredNetworkViz/Connection.pde
+++ /dev/null
@@ -1,24 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-class Connection {
- float weight;
- Neuron a;
- Neuron b;
-
- Connection(Neuron from, Neuron to,float w) {
- weight = w;
- a = from;
- b = to;
- }
-
- void display() {
- stroke(0);
- strokeWeight(weight*4);
- line(a.location.x, a.location.y, b.location.x, b.location.y);
- }
-}
-
-
-
diff --git a/java/examples/Books/Nature of Code/chp10_nn/LayeredNetworkViz/LayeredNetworkViz.pde b/java/examples/Books/Nature of Code/chp10_nn/LayeredNetworkViz/LayeredNetworkViz.pde
deleted file mode 100644
index e9a8f2de2..000000000
--- a/java/examples/Books/Nature of Code/chp10_nn/LayeredNetworkViz/LayeredNetworkViz.pde
+++ /dev/null
@@ -1,16 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-Network network;
-
-void setup() {
- size(640, 360);
- network = new Network(4,3,1);
-}
-
-void draw() {
- background(255);
- network.display();
-}
-
diff --git a/java/examples/Books/Nature of Code/chp10_nn/LayeredNetworkViz/Network.pde b/java/examples/Books/Nature of Code/chp10_nn/LayeredNetworkViz/Network.pde
deleted file mode 100644
index ec87c6e37..000000000
--- a/java/examples/Books/Nature of Code/chp10_nn/LayeredNetworkViz/Network.pde
+++ /dev/null
@@ -1,47 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-class Network {
- ArrayList neurons;
- PVector location;
- Network(int layers, int inputs, int outputs) {
- location = new PVector(width/2, height/2);
-
- neurons = new ArrayList();
-
- Neuron output = new Neuron(250, 0);
- for (int i = 0; i < layers; i++) {
- for (int j = 0; j < inputs; j++) {
- float x = map(i, 0, layers, -200, 200);
- float y = map(j, 0, inputs-1, -100, 100);
- println(j + " " + y);
- Neuron n = new Neuron(x, y);
-
- if (i > 0) {
- for (int k = 0; k < inputs; k++) {
- Neuron prev = neurons.get(neurons.size()-inputs+k-j);
- prev.connect(n);
- }
- }
-
- if (i == layers-1) {
- n.connect(output);
- }
- neurons.add(n);
- }
- }
- neurons.add(output);
- }
-
-
- void display() {
- pushMatrix();
- translate(location.x, location.y);
- for (Neuron n : neurons) {
- n.display();
- }
- popMatrix();
- }
-}
-
diff --git a/java/examples/Books/Nature of Code/chp10_nn/LayeredNetworkViz/Neuron.pde b/java/examples/Books/Nature of Code/chp10_nn/LayeredNetworkViz/Neuron.pde
deleted file mode 100644
index e500dcb2b..000000000
--- a/java/examples/Books/Nature of Code/chp10_nn/LayeredNetworkViz/Neuron.pde
+++ /dev/null
@@ -1,31 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-class Neuron {
- PVector location;
-
- ArrayList connections;
-
- Neuron(float x, float y) {
- location = new PVector(x, y);
- connections = new ArrayList();
- }
-
- void connect(Neuron n) {
- Connection c = new Connection(this, n, random(1));
- connections.add(c);
- }
-
- void display() {
- stroke(0);
- strokeWeight(1);
- fill(0);
- ellipse(location.x, location.y, 16, 16);
-
- for (Connection c : connections) {
- c.display();
- }
- }
-}
-
diff --git a/java/examples/Books/Nature of Code/chp10_nn/NOC_10_01_SimplePerceptron/NOC_10_01_SimplePerceptron.pde b/java/examples/Books/Nature of Code/chp10_nn/NOC_10_01_SimplePerceptron/NOC_10_01_SimplePerceptron.pde
deleted file mode 100644
index 93148cea1..000000000
--- a/java/examples/Books/Nature of Code/chp10_nn/NOC_10_01_SimplePerceptron/NOC_10_01_SimplePerceptron.pde
+++ /dev/null
@@ -1,90 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Simple Perceptron Example
-// See: http://en.wikipedia.org/wiki/Perceptron
-
-// Code based on text "Artificial Intelligence", George Luger
-
-// A list of points we will use to "train" the perceptron
-Trainer[] training = new Trainer[2000];
-// A Perceptron object
-Perceptron ptron;
-
-// We will train the perceptron with one "Point" object at a time
-int count = 0;
-
-// Coordinate space
-float xmin = -400;
-float ymin = -100;
-float xmax = 400;
-float ymax = 100;
-
-// The function to describe a line
-float f(float x) {
- return 0.4*x+1;
-}
-
-void setup() {
- size(640, 360);
-
- // The perceptron has 3 inputs -- x, y, and bias
- // Second value is "Learning Constant"
- ptron = new Perceptron(3, 0.00001); // Learning Constant is low just b/c it's fun to watch, this is not necessarily optimal
-
- // Create a random set of training points and calculate the "known" answer
- for (int i = 0; i < training.length; i++) {
- float x = random(xmin, xmax);
- float y = random(ymin, ymax);
- int answer = 1;
- if (y < f(x)) answer = -1;
- training[i] = new Trainer(x, y, answer);
- }
- smooth();
-}
-
-
-void draw() {
- background(255);
- translate(width/2,height/2);
-
- // Draw the line
- strokeWeight(4);
- stroke(127);
- float x1 = xmin;
- float y1 = f(x1);
- float x2 = xmax;
- float y2 = f(x2);
- line(x1,y1,x2,y2);
-
- // Draw the line based on the current weights
- // Formula is weights[0]*x + weights[1]*y + weights[2] = 0
- stroke(0);
- strokeWeight(1);
- float[] weights = ptron.getWeights();
- x1 = xmin;
- y1 = (-weights[2] - weights[0]*x1)/weights[1];
- x2 = xmax;
- y2 = (-weights[2] - weights[0]*x2)/weights[1];
- line(x1,y1,x2,y2);
-
-
-
- // Train the Perceptron with one "training" point at a time
- ptron.train(training[count].inputs, training[count].answer);
- count = (count + 1) % training.length;
-
- // Draw all the points based on what the Perceptron would "guess"
- // Does not use the "known" correct answer
- for (int i = 0; i < count; i++) {
- stroke(0);
- strokeWeight(1);
- fill(0);
- int guess = ptron.feedforward(training[i].inputs);
- if (guess > 0) noFill();
-
- ellipse(training[i].inputs[0], training[i].inputs[1], 8, 8);
- }
-}
-
diff --git a/java/examples/Books/Nature of Code/chp10_nn/NOC_10_01_SimplePerceptron/Perceptron.pde b/java/examples/Books/Nature of Code/chp10_nn/NOC_10_01_SimplePerceptron/Perceptron.pde
deleted file mode 100644
index 0eec0da5b..000000000
--- a/java/examples/Books/Nature of Code/chp10_nn/NOC_10_01_SimplePerceptron/Perceptron.pde
+++ /dev/null
@@ -1,60 +0,0 @@
-// Daniel Shiffman
-// The Nature of Code
-// http://natureofcode.com
-
-// Simple Perceptron Example
-// See: http://en.wikipedia.org/wiki/Perceptron
-
-// Perceptron Class
-
-class Perceptron {
- float[] weights; // Array of weights for inputs
- float c; // learning constant
-
- // Perceptron is created with n weights and learning constant
- Perceptron(int n, float c_) {
- weights = new float[n];
- // Start with random weights
- for (int i = 0; i < weights.length; i++) {
- weights[i] = random(-1,1);
- }
- c = c_;
- }
-
- // Function to train the Perceptron
- // Weights are adjusted based on "desired" answer
- void train(float[] inputs, int desired) {
- // Guess the result
- int guess = feedforward(inputs);
- // Compute the factor for changing the weight based on the error
- // Error = desired output - guessed output
- // Note this can only be 0, -2, or 2
- // Multiply by learning constant
- float error = desired - guess;
- // Adjust weights based on weightChange * input
- for (int i = 0; i < weights.length; i++) {
- weights[i] += c * error * inputs[i];
- }
- }
-
- // Guess -1 or 1 based on input values
- int feedforward(float[] inputs) {
- // Sum all values
- float sum = 0;
- for (int i = 0; i < weights.length; i++) {
- sum += inputs[i]*weights[i];
- }
- // Result is sign of the sum, -1 or 1
- return activate(sum);
- }
-
- int activate(float sum) {
- if (sum > 0) return 1;
- else return -1;
- }
-
- // Return weights
- float[] getWeights() {
- return weights;
- }
-}
diff --git a/java/examples/Books/Nature of Code/chp10_nn/NOC_10_01_SimplePerceptron/Trainer.pde b/java/examples/Books/Nature of Code/chp10_nn/NOC_10_01_SimplePerceptron/Trainer.pde
deleted file mode 100644
index 69db5371c..000000000
--- a/java/examples/Books/Nature of Code/chp10_nn/NOC_10_01_SimplePerceptron/Trainer.pde
+++ /dev/null
@@ -1,24 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Simple Perceptron Example
-// See: http://en.wikipedia.org/wiki/Perceptron
-
-// A class to describe a training point
-// Has an x and y, a "bias" (1) and known output
-// Could also add a variable for "guess" but not required here
-
-class Trainer {
-
- float[] inputs;
- int answer;
-
- Trainer(float x, float y, int a) {
- inputs = new float[3];
- inputs[0] = x;
- inputs[1] = y;
- inputs[2] = 1;
- answer = a;
- }
-}
diff --git a/java/examples/Books/Nature of Code/chp10_nn/NOC_10_02_SeekingNeural/NOC_10_02_SeekingNeural.pde b/java/examples/Books/Nature of Code/chp10_nn/NOC_10_02_SeekingNeural/NOC_10_02_SeekingNeural.pde
deleted file mode 100644
index de91587f1..000000000
--- a/java/examples/Books/Nature of Code/chp10_nn/NOC_10_02_SeekingNeural/NOC_10_02_SeekingNeural.pde
+++ /dev/null
@@ -1,63 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// A Vehicle controlled by a Perceptron
-
-Vehicle v;
-
-PVector desired;
-
-ArrayList targets;
-
-void setup() {
- size(640, 360);
- // The Vehicle's desired location
- desired = new PVector(width/2,height/2);
-
-
- // Create a list of targets
- makeTargets();
-
- // Create the Vehicle (it has to know about the number of targets
- // in order to configure its brain)
- v = new Vehicle(targets.size(), random(width), random(height));
-}
-
-// Make a random ArrayList of targets to steer towards
-void makeTargets() {
- targets = new ArrayList();
- for (int i = 0; i < 8; i++) {
- targets.add(new PVector(random(width), random(height)));
- }
-}
-
-void draw() {
- background(255);
-
- // Draw a circle to show the Vehicle's goal
- stroke(0);
- strokeWeight(2);
- fill(0, 100);
- ellipse(desired.x, desired.y, 36, 36);
-
- // Draw the targets
- for (PVector target : targets) {
- noFill();
- stroke(0);
- strokeWeight(2);
- ellipse(target.x, target.y, 16, 16);
- line(target.x,target.y-16,target.x,target.y+16);
- line(target.x-16,target.y,target.x+16,target.y);
- }
-
- // Update the Vehicle
- v.steer(targets);
- v.update();
- v.display();
-}
-
-void mousePressed() {
- makeTargets();
-}
-
diff --git a/java/examples/Books/Nature of Code/chp10_nn/NOC_10_02_SeekingNeural/Perceptron.pde b/java/examples/Books/Nature of Code/chp10_nn/NOC_10_02_SeekingNeural/Perceptron.pde
deleted file mode 100644
index f52c726b3..000000000
--- a/java/examples/Books/Nature of Code/chp10_nn/NOC_10_02_SeekingNeural/Perceptron.pde
+++ /dev/null
@@ -1,45 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Simple Perceptron Example
-// See: http://en.wikipedia.org/wiki/Perceptron
-
-// Perceptron Class
-
-class Perceptron {
- float[] weights; // Array of weights for inputs
- float c; // learning constant
-
- // Perceptron is created with n weights and learning constant
- Perceptron(int n, float c_) {
- weights = new float[n];
- c = c_;
- // Start with random weights
- for (int i = 0; i < weights.length; i++) {
- weights[i] = random(0, 1);
- }
- }
-
- // Function to train the Perceptron
- // Weights are adjusted based on vehicle's error
- void train(PVector[] forces, PVector error) {
- for (int i = 0; i < weights.length; i++) {
- weights[i] += c*error.x*forces[i].x;
- weights[i] += c*error.y*forces[i].y;
- weights[i] = constrain(weights[i], 0, 1);
- }
- }
-
- // Give me a steering result
- PVector feedforward(PVector[] forces) {
- // Sum all values
- PVector sum = new PVector();
- for (int i = 0; i < weights.length; i++) {
- forces[i].mult(weights[i]);
- sum.add(forces[i]);
- }
- return sum;
- }
-}
-
diff --git a/java/examples/Books/Nature of Code/chp10_nn/NOC_10_02_SeekingNeural/Vehicle.pde b/java/examples/Books/Nature of Code/chp10_nn/NOC_10_02_SeekingNeural/Vehicle.pde
deleted file mode 100644
index efd9bf287..000000000
--- a/java/examples/Books/Nature of Code/chp10_nn/NOC_10_02_SeekingNeural/Vehicle.pde
+++ /dev/null
@@ -1,102 +0,0 @@
-// Seek
-// Daniel Shiffman
-
-// The "Vehicle" class
-
-class Vehicle {
-
- // Vehicle now has a brain!
- Perceptron brain;
-
- PVector location;
- PVector velocity;
- PVector acceleration;
- float r;
- float maxforce; // Maximum steering force
- float maxspeed; // Maximum speed
-
- Vehicle(int n, float x, float y) {
- brain = new Perceptron(n,0.001);
- acceleration = new PVector(0,0);
- velocity = new PVector(0,0);
- location = new PVector(x,y);
- r = 3.0;
- maxspeed = 4;
- maxforce = 0.1;
- }
-
- // Method to update location
- void update() {
- // Update velocity
- velocity.add(acceleration);
- // Limit speed
- velocity.limit(maxspeed);
- location.add(velocity);
- // Reset accelerationelertion to 0 each cycle
- acceleration.mult(0);
-
- location.x = constrain(location.x,0,width);
- location.y = constrain(location.y,0,height);
- }
-
- void applyForce(PVector force) {
- // We could add mass here if we want A = F / M
- acceleration.add(force);
- }
-
- // Here is where the brain processes everything
- void steer(ArrayList targets) {
- // Make an array of forces
- PVector[] forces = new PVector[targets.size()];
-
- // Steer towards all targets
- for (int i = 0; i < forces.length; i++) {
- forces[i] = seek(targets.get(i));
- }
-
- // That array of forces is the input to the brain
- PVector result = brain.feedforward(forces);
-
- // Use the result to steer the vehicle
- applyForce(result);
-
- // Train the brain according to the error
- PVector error = PVector.sub(desired, location);
- brain.train(forces,error);
-
- }
-
- // A method that calculates a steering force towards a target
- // STEER = DESIRED MINUS VELOCITY
- PVector seek(PVector target) {
- PVector desired = PVector.sub(target,location); // A vector pointing from the location to the target
-
- // Normalize desired and scale to maximum speed
- desired.normalize();
- desired.mult(maxspeed);
- // Steering = Desired minus velocity
- PVector steer = PVector.sub(desired,velocity);
- steer.limit(maxforce); // Limit to maximum steering force
-
- return steer;
- }
-
- void display() {
-
- // Draw a triangle rotated in the direction of velocity
- float theta = velocity.heading2D() + PI/2;
- fill(175);
- stroke(0);
- strokeWeight(1);
- pushMatrix();
- translate(location.x,location.y);
- rotate(theta);
- beginShape();
- vertex(0, -r*2);
- vertex(-r, r*2);
- vertex(r, r*2);
- endShape(CLOSE);
- popMatrix();
- }
-}
-
diff --git a/java/examples/Books/Nature of Code/chp10_nn/NOC_10_03_NetworkViz/Connection.pde b/java/examples/Books/Nature of Code/chp10_nn/NOC_10_03_NetworkViz/Connection.pde
deleted file mode 100644
index 5e183e58f..000000000
--- a/java/examples/Books/Nature of Code/chp10_nn/NOC_10_03_NetworkViz/Connection.pde
+++ /dev/null
@@ -1,31 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// A static drawing of a Neural Network
-
-class Connection {
-
- // Connection is from Neuron A to B
- Neuron a;
- Neuron b;
-
- // Connection has a weight
- float weight;
-
- Connection(Neuron from, Neuron to,float w) {
- weight = w;
- a = from;
- b = to;
- }
-
- // Drawn as a line
- void display() {
- stroke(0);
- strokeWeight(weight*4);
- line(a.location.x, a.location.y, b.location.x, b.location.y);
- }
-}
-
-
-
diff --git a/java/examples/Books/Nature of Code/chp10_nn/NOC_10_03_NetworkViz/NOC_10_03_NetworkViz.pde b/java/examples/Books/Nature of Code/chp10_nn/NOC_10_03_NetworkViz/NOC_10_03_NetworkViz.pde
deleted file mode 100644
index c368b9966..000000000
--- a/java/examples/Books/Nature of Code/chp10_nn/NOC_10_03_NetworkViz/NOC_10_03_NetworkViz.pde
+++ /dev/null
@@ -1,39 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// A static drawing of a Neural Network
-
-Network network;
-
-void setup() {
- size(640, 360);
- // Create the Network object
- network = new Network(width/2,height/2);
-
- // Create a bunch of Neurons
- Neuron a = new Neuron(-200,0);
- Neuron b = new Neuron(0,75);
- Neuron c = new Neuron(0,-75);
- Neuron d = new Neuron(200,0);
-
- // Connect them
- network.connect(a,b);
- network.connect(a,c);
- network.connect(b,d);
- network.connect(c,d);
-
- // Add them to the Network
- network.addNeuron(a);
- network.addNeuron(b);
- network.addNeuron(c);
- network.addNeuron(d);
-}
-
-void draw() {
- background(255);
- // Draw the Network
- network.display();
- noLoop();
-}
-
diff --git a/java/examples/Books/Nature of Code/chp10_nn/NOC_10_03_NetworkViz/Network.pde b/java/examples/Books/Nature of Code/chp10_nn/NOC_10_03_NetworkViz/Network.pde
deleted file mode 100644
index 44b94a80f..000000000
--- a/java/examples/Books/Nature of Code/chp10_nn/NOC_10_03_NetworkViz/Network.pde
+++ /dev/null
@@ -1,39 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// A static drawing of a Neural Network
-
-class Network {
-
- // The Network has a list of neurons
- ArrayList neurons;
- PVector location;
-
- Network(float x, float y) {
- location = new PVector(x,y);
- neurons = new ArrayList();
- }
-
- // We can add a Neuron
- void addNeuron(Neuron n) {
- neurons.add(n);
- }
-
- // We can connection two Neurons
- void connect(Neuron a, Neuron b) {
- Connection c = new Connection(a, b, random(1));
- a.addConnection(c);
- }
-
- // We can draw the network
- void display() {
- pushMatrix();
- translate(location.x, location.y);
- for (Neuron n : neurons) {
- n.display();
- }
- popMatrix();
- }
-}
-
diff --git a/java/examples/Books/Nature of Code/chp10_nn/NOC_10_03_NetworkViz/Neuron.pde b/java/examples/Books/Nature of Code/chp10_nn/NOC_10_03_NetworkViz/Neuron.pde
deleted file mode 100644
index d14ed2a5e..000000000
--- a/java/examples/Books/Nature of Code/chp10_nn/NOC_10_03_NetworkViz/Neuron.pde
+++ /dev/null
@@ -1,38 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// A static drawing of a Neural Network
-
-class Neuron {
-
- // Neuron has a location
- PVector location;
-
- // Neuron has a list of connections
- ArrayList connections;
-
- Neuron(float x, float y) {
- location = new PVector(x, y);
- connections = new ArrayList();
- }
-
- // Add a Connection
- void addConnection(Connection c) {
- connections.add(c);
- }
-
- // Draw Neuron as a circle
- void display() {
- stroke(0);
- strokeWeight(1);
- fill(0);
- ellipse(location.x, location.y, 16, 16);
-
- // Draw all its connections
- for (Connection c : connections) {
- c.display();
- }
- }
-}
-
diff --git a/java/examples/Books/Nature of Code/chp10_nn/NOC_10_04_NetworkAnimation/Connection.pde b/java/examples/Books/Nature of Code/chp10_nn/NOC_10_04_NetworkAnimation/Connection.pde
deleted file mode 100644
index 0dcfe7a67..000000000
--- a/java/examples/Books/Nature of Code/chp10_nn/NOC_10_04_NetworkAnimation/Connection.pde
+++ /dev/null
@@ -1,65 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// An animated drawing of a Neural Network
-
-class Connection {
- // Connection is from Neuron A to B
- Neuron a;
- Neuron b;
-
- // Connection has a weight
- float weight;
-
- // Variables to track the animation
- boolean sending = false;
- PVector sender;
-
- // Need to store the output for when its time to pass along
- float output = 0;
-
- Connection(Neuron from, Neuron to, float w) {
- weight = w;
- a = from;
- b = to;
- }
-
-
- // The Connection is active
- void feedforward(float val) {
- output = val*weight; // Compute output
- sender = a.location.get(); // Start animation at Neuron A
- sending = true; // Turn on sending
- }
-
- // Update traveling sender
- void update() {
- if (sending) {
- // Use a simple interpolation
- sender.x = lerp(sender.x, b.location.x, 0.1);
- sender.y = lerp(sender.y, b.location.y, 0.1);
- float d = PVector.dist(sender, b.location);
- // If we've reached the end
- if (d < 1) {
- // Pass along the output!
- b.feedforward(output);
- sending = false;
- }
- }
- }
-
- // Draw line and traveling circle
- void display() {
- stroke(0);
- strokeWeight(1+weight*4);
- line(a.location.x, a.location.y, b.location.x, b.location.y);
-
- if (sending) {
- fill(0);
- strokeWeight(1);
- ellipse(sender.x, sender.y, 16, 16);
- }
- }
-}
-
diff --git a/java/examples/Books/Nature of Code/chp10_nn/NOC_10_04_NetworkAnimation/NOC_10_04_NetworkAnimation.pde b/java/examples/Books/Nature of Code/chp10_nn/NOC_10_04_NetworkAnimation/NOC_10_04_NetworkAnimation.pde
deleted file mode 100644
index 4c2d2ed6c..000000000
--- a/java/examples/Books/Nature of Code/chp10_nn/NOC_10_04_NetworkAnimation/NOC_10_04_NetworkAnimation.pde
+++ /dev/null
@@ -1,50 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// An animated drawing of a Neural Network
-
-Network network;
-
-void setup() {
- size(640, 360);
- // Create the Network object
- network = new Network(width/2, height/2);
-
- // Create a bunch of Neurons
- Neuron a = new Neuron(-275, 0);
- Neuron b = new Neuron(-150, 0);
- Neuron c = new Neuron(0, 75);
- Neuron d = new Neuron(0, -75);
- Neuron e = new Neuron(150, 0);
- Neuron f = new Neuron(275, 0);
-
- // Connect them
- network.connect(a, b,1);
- network.connect(b, c,random(1));
- network.connect(b, d,random(1));
- network.connect(c, e,random(1));
- network.connect(d, e,random(1));
- network.connect(e, f,1);
-
- // Add them to the Network
- network.addNeuron(a);
- network.addNeuron(b);
- network.addNeuron(c);
- network.addNeuron(d);
- network.addNeuron(e);
- network.addNeuron(f);
-}
-
-void draw() {
- background(255);
- // Update and display the Network
- network.update();
- network.display();
-
- // Every 30 frames feed in an input
- if (frameCount % 30 == 0) {
- network.feedforward(random(1));
- }
-}
-
diff --git a/java/examples/Books/Nature of Code/chp10_nn/NOC_10_04_NetworkAnimation/Network.pde b/java/examples/Books/Nature of Code/chp10_nn/NOC_10_04_NetworkAnimation/Network.pde
deleted file mode 100644
index 5506414c9..000000000
--- a/java/examples/Books/Nature of Code/chp10_nn/NOC_10_04_NetworkAnimation/Network.pde
+++ /dev/null
@@ -1,64 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// An animated drawing of a Neural Network
-
-class Network {
-
- // The Network has a list of neurons
- ArrayList neurons;
-
- // The Network now keeps a duplicate list of all Connection objects.
- // This makes it easier to draw everything in this class
- ArrayList connections;
- PVector location;
-
- Network(float x, float y) {
- location = new PVector(x, y);
- neurons = new ArrayList();
- connections = new ArrayList();
- }
-
- // We can add a Neuron
- void addNeuron(Neuron n) {
- neurons.add(n);
- }
-
- // We can connection two Neurons
- void connect(Neuron a, Neuron b, float weight) {
- Connection c = new Connection(a, b, weight);
- a.addConnection(c);
- // Also add the Connection here
- connections.add(c);
- }
-
- // Sending an input to the first Neuron
- // We should do something better to track multiple inputs
- void feedforward(float input) {
- Neuron start = neurons.get(0);
- start.feedforward(input);
- }
-
- // Update the animation
- void update() {
- for (Connection c : connections) {
- c.update();
- }
- }
-
- // Draw everything
- void display() {
- pushMatrix();
- translate(location.x, location.y);
- for (Neuron n : neurons) {
- n.display();
- }
-
- for (Connection c : connections) {
- c.display();
- }
- popMatrix();
- }
-}
-
diff --git a/java/examples/Books/Nature of Code/chp10_nn/NOC_10_04_NetworkAnimation/Neuron.pde b/java/examples/Books/Nature of Code/chp10_nn/NOC_10_04_NetworkAnimation/Neuron.pde
deleted file mode 100644
index 89bc6c822..000000000
--- a/java/examples/Books/Nature of Code/chp10_nn/NOC_10_04_NetworkAnimation/Neuron.pde
+++ /dev/null
@@ -1,64 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// An animated drawing of a Neural Network
-
-class Neuron {
- // Neuron has a location
- PVector location;
-
- // Neuron has a list of connections
- ArrayList connections;
-
- // We now track the inputs and sum them
- float sum = 0;
-
- // The Neuron's size can be animated
- float r = 32;
-
- Neuron(float x, float y) {
- location = new PVector(x, y);
- connections = new ArrayList();
- }
-
- // Add a Connection
- void addConnection(Connection c) {
- connections.add(c);
- }
-
- // Receive an input
- void feedforward(float input) {
- // Accumulate it
- sum += input;
- // Activate it?
- if (sum > 1) {
- fire();
- sum = 0; // Reset the sum to 0 if it fires
- }
- }
-
- // The Neuron fires
- void fire() {
- r = 64; // It suddenly is bigger
-
- // We send the output through all connections
- for (Connection c : connections) {
- c.feedforward(sum);
- }
- }
-
- // Draw it as a circle
- void display() {
- stroke(0);
- strokeWeight(1);
- // Brightness is mapped to sum
- float b = map(sum,0,1,255,0);
- fill(b);
- ellipse(location.x, location.y, r, r);
-
- // Size shrinks down back to original dimensions
- r = lerp(r,32,0.1);
- }
-}
-
diff --git a/java/examples/Books/Nature of Code/chp10_nn/xor/Landscape.pde b/java/examples/Books/Nature of Code/chp10_nn/xor/Landscape.pde
deleted file mode 100755
index 07bc45c54..000000000
--- a/java/examples/Books/Nature of Code/chp10_nn/xor/Landscape.pde
+++ /dev/null
@@ -1,75 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// "Landscape" example
-
-class Landscape {
-
- int scl; // size of each cell
- int w,h; // width and height of thingie
- int rows, cols; // number of rows and columns
- float zoff = 0.0; // perlin noise argument
- float[][] z; // using an array to store all the height values
-
- Landscape(int scl_, int w_, int h_) {
- scl = scl_;
- w = w_;
- h = h_;
- cols = w/scl;
- rows = h/scl;
- z = new float[cols][rows];
- }
-
-
- // Calculate height values (based off a neural netork)
- void calculate(Network nn) {
- float x = 0;
- float dx = (float) 1.0 / cols;
- for (int i = 0; i < cols; i++)
- {
- float y = 0;
- float dy = (float) 1.0 / rows;
- for (int j = 0; j < rows; j++)
- {
- float[] input = new float[2];
- input[0] = x;
- input[1] = y;
- float result = nn.feedForward(input);
- z[i][j] = z[i][j]*0.95 + 0.05*(float)(result*280.0f-140.0);
- y += dy;
- }
- x += dx;
- }
-
- }
-
- // Render landscape as grid of quads
- void render() {
- // Every cell is an individual quad
- // (could use quad_strip here, but produces funny results, investigate this)
- for (int x = 0; x < z.length-1; x++)
- {
- for (int y = 0; y < z[x].length-1; y++)
- {
- // one quad at a time
- // each quad's color is determined by the height value at each vertex
- // (clean this part up)
- noStroke();
- pushMatrix();
- beginShape(QUADS);
- translate(x*scl-w/2,y*scl-h/2,0);
- fill(z[x][y]+127,220);
- vertex(0,0,z[x][y]);
- fill(z[x+1][y]+127,220);
- vertex(scl,0,z[x+1][y]);
- fill(z[x+1][y+1]+127,220);
- vertex(scl,scl,z[x+1][y+1]);
- fill(z[x][y+1]+127,220);
- vertex(0,scl,z[x][y+1]);
- endShape();
- popMatrix();
- }
- }
- }
-}
diff --git a/java/examples/Books/Nature of Code/chp10_nn/xor/code/src/Connection.java b/java/examples/Books/Nature of Code/chp10_nn/xor/code/src/Connection.java
deleted file mode 100644
index d8415d2a6..000000000
--- a/java/examples/Books/Nature of Code/chp10_nn/xor/code/src/Connection.java
+++ /dev/null
@@ -1,47 +0,0 @@
-// Daniel Shiffman
-// The Nature of Code, Fall 2006
-// Neural Network
-
-// Class to describe a connection between two neurons
-
-package nn;
-
-public class Connection {
-
- private Neuron from; // Connection goes from. . .
- private Neuron to; // To. . .
- private float weight; // Weight of the connection. . .
-
- // Constructor builds a connection with a random weight
- public Connection(Neuron a_, Neuron b_) {
- from = a_;
- to = b_;
- weight = (float) Math.random()*2-1;
- }
-
- // In case I want to set the weights manually, using this for testing
- public Connection(Neuron a_, Neuron b_, float w) {
- from = a_;
- to = b_;
- weight = w;
- }
-
- public Neuron getFrom() {
- return from;
- }
-
- public Neuron getTo() {
- return to;
- }
-
- public float getWeight() {
- return weight;
- }
-
- // Changing the weight of the connection
- public void adjustWeight(float deltaWeight) {
- weight += deltaWeight;
- }
-
-
-}
diff --git a/java/examples/Books/Nature of Code/chp10_nn/xor/code/src/HiddenNeuron.java b/java/examples/Books/Nature of Code/chp10_nn/xor/code/src/HiddenNeuron.java
deleted file mode 100644
index 3c8d7945d..000000000
--- a/java/examples/Books/Nature of Code/chp10_nn/xor/code/src/HiddenNeuron.java
+++ /dev/null
@@ -1,20 +0,0 @@
-//Daniel Shiffman
-//The Nature of Code, Fall 2006
-//Neural Network
-
-// Hidden Neuron Class
-// So far not necessary to differentiate these
-
-package nn;
-
-public class HiddenNeuron extends Neuron {
-
- public HiddenNeuron() {
- super();
- }
-
- public HiddenNeuron(int i) {
- super(i);
- }
-
-}
diff --git a/java/examples/Books/Nature of Code/chp10_nn/xor/code/src/InputNeuron.java b/java/examples/Books/Nature of Code/chp10_nn/xor/code/src/InputNeuron.java
deleted file mode 100644
index a2191632f..000000000
--- a/java/examples/Books/Nature of Code/chp10_nn/xor/code/src/InputNeuron.java
+++ /dev/null
@@ -1,23 +0,0 @@
-//Daniel Shiffman
-//The Nature of Code, Fall 2006
-//Neural Network
-
-// Input Neuron Class
-// Has additional functionality to receive beginning input
-
-package nn;
-
-public class InputNeuron extends Neuron {
- public InputNeuron() {
- super();
- }
-
- public InputNeuron(int i) {
- super(i);
- }
-
- public void input(float d) {
- output = d;
- }
-
-}
diff --git a/java/examples/Books/Nature of Code/chp10_nn/xor/code/src/Network.java b/java/examples/Books/Nature of Code/chp10_nn/xor/code/src/Network.java
deleted file mode 100644
index c0854712d..000000000
--- a/java/examples/Books/Nature of Code/chp10_nn/xor/code/src/Network.java
+++ /dev/null
@@ -1,143 +0,0 @@
-// Daniel Shiffman
-// The Nature of Code, Fall 2006
-// Neural Network
-
-// Class to describe the entire network
-// Arrays for input neurons, hidden neurons, and output neuron
-
-// Need to update this so that it would work with an array out outputs
-// Rather silly that I didn't do this initially
-
-// Also need to build in a "Layer" class so that there can easily
-// be more than one hidden layer
-
-package nn;
-
-import java.util.ArrayList;
-
-public class Network {
-
- // Layers
- InputNeuron[] input;
- HiddenNeuron[] hidden;
- OutputNeuron output;
-
- public static final float LEARNING_CONSTANT = 0.5f;
-
- // Only One output now to start!!! (i can do better, really. . .)
- // Constructor makes the entire network based on number of inputs & number of neurons in hidden layer
- // Only One hidden layer!!! (fix this dood)
-
- public Network(int inputs, int hiddentotal) {
-
- input = new InputNeuron[inputs+1]; // Got to add a bias input
- hidden = new HiddenNeuron[hiddentotal+1];
-
- // Make input neurons
- for (int i = 0; i < input.length-1; i++) {
- input[i] = new InputNeuron();
- }
-
- // Make hidden neurons
- for (int i = 0; i < hidden.length-1; i++) {
- hidden[i] = new HiddenNeuron();
- }
-
- // Make bias neurons
- input[input.length-1] = new InputNeuron(1);
- hidden[hidden.length-1] = new HiddenNeuron(1);
-
- // Make output neuron
- output = new OutputNeuron();
-
- // Connect input layer to hidden layer
- for (int i = 0; i < input.length; i++) {
- for (int j = 0; j < hidden.length-1; j++) {
- // Create the connection object and put it in both neurons
- Connection c = new Connection(input[i],hidden[j]);
- input[i].addConnection(c);
- hidden[j].addConnection(c);
- }
- }
-
- // Connect the hidden layer to the output neuron
- for (int i = 0; i < hidden.length; i++) {
- Connection c = new Connection(hidden[i],output);
- hidden[i].addConnection(c);
- output.addConnection(c);
- }
-
- }
-
-
- public float feedForward(float[] inputVals) {
-
- // Feed the input with an array of inputs
- for (int i = 0; i < inputVals.length; i++) {
- input[i].input(inputVals[i]);
- }
-
- // Have the hidden layer calculate its output
- for (int i = 0; i < hidden.length-1; i++) {
- hidden[i].calcOutput();
- }
-
- // Calculate the output of the output neuron
- output.calcOutput();
-
- // Return output
- return output.getOutput();
- }
-
- public float train(float[] inputs, float answer) {
- float result = feedForward(inputs);
-
-
- // This is where the error correction all starts
- // Derivative of sigmoid output function * diff between known and guess
- float deltaOutput = result*(1-result) * (answer-result);
-
-
- // BACKPROPOGATION
- // This is easier b/c we just have one output
- // Apply Delta to connections between hidden and output
- ArrayList connections = output.getConnections();
- for (int i = 0; i < connections.size(); i++) {
- Connection c = (Connection) connections.get(i);
- Neuron neuron = c.getFrom();
- float output = neuron.getOutput();
- float deltaWeight = output*deltaOutput;
- c.adjustWeight(LEARNING_CONSTANT*deltaWeight);
- }
-
- // ADJUST HIDDEN WEIGHTS
- for (int i = 0; i < hidden.length; i++) {
- connections = hidden[i].getConnections();
- float sum = 0;
- // Sum output delta * hidden layer connections (just one output)
- for (int j = 0; j < connections.size(); j++) {
- Connection c = (Connection) connections.get(j);
- // Is this a connection from hidden layer to next layer (output)?
- if (c.getFrom() == hidden[i]) {
- sum += c.getWeight()*deltaOutput;
- }
- }
- // Then adjust the weights coming in based:
- // Above sum * derivative of sigmoid output function for hidden neurons
- for (int j = 0; j < connections.size(); j++) {
- Connection c = (Connection) connections.get(j);
- // Is this a connection from previous layer (input) to hidden layer?
- if (c.getTo() == hidden[i]) {
- float output = hidden[i].getOutput();
- float deltaHidden = output * (1 - output); // Derivative of sigmoid(x)
- deltaHidden *= sum; // Would sum for all outputs if more than one output
- Neuron neuron = c.getFrom();
- float deltaWeight = neuron.getOutput()*deltaHidden;
- c.adjustWeight(LEARNING_CONSTANT*deltaWeight);
- }
- }
- }
-
- return result;
- }
-}
diff --git a/java/examples/Books/Nature of Code/chp10_nn/xor/code/src/Neuron.java b/java/examples/Books/Nature of Code/chp10_nn/xor/code/src/Neuron.java
deleted file mode 100644
index 234780016..000000000
--- a/java/examples/Books/Nature of Code/chp10_nn/xor/code/src/Neuron.java
+++ /dev/null
@@ -1,81 +0,0 @@
-//Daniel Shiffman
-//The Nature of Code, Fall 2006
-//Neural Network
-
-//Generic Neuron Class
-//Can be a bias neuron (true or false)
-
-package nn;
-
-import java.util.ArrayList;
-
-public class Neuron {
-
- protected float output;
- protected ArrayList connections;
- protected boolean bias = false;
-
- // A regular Neuron
- public Neuron() {
- output = 0;
- // Using an arraylist to store list of connections to other neurons
- connections = new ArrayList();
- bias = false;
- }
-
- // Constructor for a bias neuron
- public Neuron(int i) {
- output = i;
- connections = new ArrayList();
- bias = true;
- }
-
- // Function to calculate output of this neuron
- // Output is sum of all inputs*weight of connections
- public void calcOutput() {
- if (bias) {
- // do nothing
- } else {
- float sum = 0;
- float bias = 0;
- //System.out.println("Looking through " + connections.size() + " connections");
- for (int i = 0; i < connections.size(); i++) {
- Connection c = (Connection) connections.get(i);
- Neuron from = c.getFrom();
- Neuron to = c.getTo();
- // Is this connection moving forward to us
- // Ignore connections that we send our output to
- if (to == this) {
- // This isn't really necessary
- // But I am treating the bias individually in case I need to at some point
- if (from.bias) {
- bias = from.getOutput()*c.getWeight();
- } else {
- sum += from.getOutput()*c.getWeight();
- }
- }
- }
- // Output is result of sigmoid function
- output = f(bias+sum);
- }
- }
-
- void addConnection(Connection c) {
- connections.add(c);
- }
-
- float getOutput() {
- return output;
- }
-
- // Sigmoid function
- public static float f(float x) {
- return 1.0f / (1.0f + (float) Math.exp(-x));
- }
-
- public ArrayList getConnections() {
- return connections;
- }
-
-
-}
diff --git a/java/examples/Books/Nature of Code/chp10_nn/xor/code/src/OutputNeuron.java b/java/examples/Books/Nature of Code/chp10_nn/xor/code/src/OutputNeuron.java
deleted file mode 100644
index abe8daee4..000000000
--- a/java/examples/Books/Nature of Code/chp10_nn/xor/code/src/OutputNeuron.java
+++ /dev/null
@@ -1,7 +0,0 @@
-package nn;
-
-public class OutputNeuron extends Neuron {
- public OutputNeuron() {
- super();
- }
-}
diff --git a/java/examples/Books/Nature of Code/chp10_nn/xor/xor.pde b/java/examples/Books/Nature of Code/chp10_nn/xor/xor.pde
deleted file mode 100644
index dd73eef29..000000000
--- a/java/examples/Books/Nature of Code/chp10_nn/xor/xor.pde
+++ /dev/null
@@ -1,112 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// XOR Multi-Layered Neural Network Example
-// Neural network code is all in the "code" folder
-
-import nn.*;
-
-ArrayList inputs; // List of training input values
-Network nn; // Neural Network Object
-int count; // Total training interations
-Landscape land; // Solution space
-float theta = 0.0; // Angle of rotation
-PFont f; // Font
-
-
-void setup() {
-
- size(400,400,P3D);
-
- // Create a landscape object
- land = new Landscape(20,300,300);
-
- f = createFont("Courier",12,true);
-
- nn = new Network(2,4);
-
- // Create a list of 4 training inputs
- inputs = new ArrayList();
- float[] input = new float[2];
- input[0] = 1;
- input[1] = 0;
- inputs.add((float []) input.clone());
- input[0] = 0;
- input[1] = 1;
- inputs.add((float []) input.clone());
- input[0] = 1;
- input[1] = 1;
- inputs.add((float []) input.clone());
- input[0] = 0;
- input[1] = 0;
- inputs.add((float []) input.clone());
-}
-
-void draw() {
-
- int trainingIterationsPerFrame = 5;
-
- for (int i = 0; i < trainingIterationsPerFrame; i++) {
- // Pick a random training input
- int pick = int(random(inputs.size()));
- // Grab that input
- float[] inp = (float[]) inputs.get(pick);
- // Compute XOR
- float known = 1;
- if ((inp[0] == 1.0 && inp[1] == 1.0) || (inp[0] == 0 && inp[1] == 0)) known = 0;
- // Train that sucker!
- float result = nn.train(inp,known);
- count++;
- }
-
- // Ok, visualize the solution space
- background(175);
- pushMatrix();
- translate(width/2,height/2+20,-160);
- rotateX(PI/3);
- rotateZ(theta);
-
- // Put a little BOX on screen
- pushMatrix();
- stroke(50);
- noFill();
- translate(-10,-10,0);
- box(280);
-
- // Draw the landscape
- popMatrix();
- land.calculate(nn);
- land.render();
- theta += 0.0025;
- popMatrix();
-
- // Display overal neural net stats
- networkStatus();
-
-}
-
-
-void networkStatus() {
- float mse = 0.0;
-
- textFont(f);
- fill(0);
- text("Your friendly neighborhood neural network solving XOR.",10,20);
- text("Total iterations: " + count,10,40);
-
- for (int i = 0; i < inputs.size(); i++) {
- float[] inp = (float[]) inputs.get(i);
- float known = 1;
- if ((inp[0] == 1.0 && inp[1] == 1.0) || (inp[0] == 0 && inp[1] == 0)) known = 0;
- float result = nn.feedForward(inp);
- //System.out.println("For: " + inp[0] + " " + inp[1] + ": " + result);
- mse += (result - known)*(result - known);
- }
-
- float rmse = sqrt(mse/4.0);
- text("Root mean squared error: " + nf(rmse,1,5), 10,60);
-
-}
-
-
diff --git a/java/examples/Books/Nature of Code/chp1_vectors/NOC_1_10_motion101_acceleration/Mover.pde b/java/examples/Books/Nature of Code/chp1_vectors/NOC_1_10_motion101_acceleration/Mover.pde
deleted file mode 100644
index 44b00fefe..000000000
--- a/java/examples/Books/Nature of Code/chp1_vectors/NOC_1_10_motion101_acceleration/Mover.pde
+++ /dev/null
@@ -1,49 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-class Mover {
-
- // The Mover tracks location, velocity, and acceleration
- PVector location;
- PVector velocity;
- PVector acceleration;
- // The Mover's maximum speed
- float topspeed;
-
- Mover() {
- // Start in the center
- location = new PVector(width/2,height/2);
- velocity = new PVector(0,0);
- topspeed = 5;
- }
-
- void update() {
-
- // Compute a vector that points from location to mouse
- PVector mouse = new PVector(mouseX,mouseY);
- PVector acceleration = PVector.sub(mouse,location);
- // Set magnitude of acceleration
- //acceleration.setMag(0.2);
- acceleration.normalize();
- acceleration.mult(0.2);
-
- // Velocity changes according to acceleration
- velocity.add(acceleration);
- // Limit the velocity by topspeed
- velocity.limit(topspeed);
- // Location changes by velocity
- location.add(velocity);
- }
-
- void display() {
- stroke(0);
- strokeWeight(2);
- fill(127);
- ellipse(location.x,location.y,48,48);
- }
-
-}
-
-
-
diff --git a/java/examples/Books/Nature of Code/chp1_vectors/NOC_1_10_motion101_acceleration/NOC_1_10_motion101_acceleration.pde b/java/examples/Books/Nature of Code/chp1_vectors/NOC_1_10_motion101_acceleration/NOC_1_10_motion101_acceleration.pde
deleted file mode 100644
index baf4b6522..000000000
--- a/java/examples/Books/Nature of Code/chp1_vectors/NOC_1_10_motion101_acceleration/NOC_1_10_motion101_acceleration.pde
+++ /dev/null
@@ -1,21 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// A Mover object
-Mover mover;
-
-void setup() {
- size(800,200);
- mover = new Mover();
-}
-
-void draw() {
- background(255);
-
- // Update the location
- mover.update();
- // Display the Mover
- mover.display();
-}
-
diff --git a/java/examples/Books/Nature of Code/chp1_vectors/NOC_1_11_motion101_acceleration_array/Mover.pde b/java/examples/Books/Nature of Code/chp1_vectors/NOC_1_11_motion101_acceleration_array/Mover.pde
deleted file mode 100644
index b0713e6ed..000000000
--- a/java/examples/Books/Nature of Code/chp1_vectors/NOC_1_11_motion101_acceleration_array/Mover.pde
+++ /dev/null
@@ -1,48 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-class Mover {
-
- // The Mover tracks location, velocity, and acceleration
- PVector location;
- PVector velocity;
- PVector acceleration;
- // The Mover's maximum speed
- float topspeed;
-
- Mover() {
- // Start in the center
- location = new PVector(random(width),random(height));
- velocity = new PVector(0,0);
- topspeed = 5;
- }
-
- void update() {
-
- // Compute a vector that points from location to mouse
- PVector mouse = new PVector(mouseX,mouseY);
- PVector acceleration = PVector.sub(mouse,location);
- // Set magnitude of acceleration
- //acceleration.setMag(0.2);
- acceleration.normalize();
- acceleration.mult(0.2);
-
- // Velocity changes according to acceleration
- velocity.add(acceleration);
- // Limit the velocity by topspeed
- velocity.limit(topspeed);
- // Location changes by velocity
- location.add(velocity);
- }
-
- void display() {
- stroke(0);
- strokeWeight(2);
- fill(127,200);
- ellipse(location.x,location.y,48,48);
- }
-
-}
-
-
diff --git a/java/examples/Books/Nature of Code/chp1_vectors/NOC_1_11_motion101_acceleration_array/NOC_1_11_motion101_acceleration_array.pde b/java/examples/Books/Nature of Code/chp1_vectors/NOC_1_11_motion101_acceleration_array/NOC_1_11_motion101_acceleration_array.pde
deleted file mode 100644
index 40e9b48d6..000000000
--- a/java/examples/Books/Nature of Code/chp1_vectors/NOC_1_11_motion101_acceleration_array/NOC_1_11_motion101_acceleration_array.pde
+++ /dev/null
@@ -1,28 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Demonstration of the basics of motion with vector.
-// A "Mover" object stores location, velocity, and acceleration as vectors
-// The motion is controlled by affecting the acceleration (in this case towards the mouse)
-
-Mover[] movers = new Mover[20];
-
-void setup() {
- size(800,200);
- for (int i = 0; i < movers.length; i++) {
- movers[i] = new Mover();
- }
-}
-
-void draw() {
-
- background(255);
-
- for (int i = 0; i < movers.length; i++) {
- movers[i].update();
- movers[i].display();
- }
-}
-
-
diff --git a/java/examples/Books/Nature of Code/chp1_vectors/NOC_1_1_bouncingball_novectors/NOC_1_1_bouncingball_novectors.pde b/java/examples/Books/Nature of Code/chp1_vectors/NOC_1_1_bouncingball_novectors/NOC_1_1_bouncingball_novectors.pde
deleted file mode 100644
index 09b4224a8..000000000
--- a/java/examples/Books/Nature of Code/chp1_vectors/NOC_1_1_bouncingball_novectors/NOC_1_1_bouncingball_novectors.pde
+++ /dev/null
@@ -1,38 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Example 1-1: Bouncing Ball, no vectors
-float x = 100;
-float y = 100;
-float xspeed = 2.5;
-float yspeed = 2;
-
-void setup() {
- size(800, 200);
- smooth();
-}
-
-void draw() {
- background(255);
-
-
- // Add the current speed to the location.
- x = x + xspeed;
- y = y + yspeed;
-
- if ((x > width) || (x < 0)) {
- xspeed = xspeed * -1;
- }
- if ((y > height) || (y < 0)) {
- yspeed = yspeed * -1;
- }
-
-
- // Display circle at x location
- stroke(0);
- strokeWeight(2);
- fill(127);
- ellipse(x, y, 48, 48);
-}
-
diff --git a/java/examples/Books/Nature of Code/chp1_vectors/NOC_1_2_bouncingball_vectors/NOC_1_2_bouncingball_vectors.pde b/java/examples/Books/Nature of Code/chp1_vectors/NOC_1_2_bouncingball_vectors/NOC_1_2_bouncingball_vectors.pde
deleted file mode 100644
index 232de4c48..000000000
--- a/java/examples/Books/Nature of Code/chp1_vectors/NOC_1_2_bouncingball_vectors/NOC_1_2_bouncingball_vectors.pde
+++ /dev/null
@@ -1,37 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Example 1-2: Bouncing Ball, with PVector!
-PVector location;
-PVector velocity;
-
-void setup() {
- size(200,200);
- background(255);
- location = new PVector(100,100);
- velocity = new PVector(2.5,5);
-}
-
-void draw() {
- noStroke();
- fill(255,10);
- rect(0,0,width,height);
-
- // Add the current speed to the location.
- location.add(velocity);
-
- if ((location.x > width) || (location.x < 0)) {
- velocity.x = velocity.x * -1;
- }
- if ((location.y > height) || (location.y < 0)) {
- velocity.y = velocity.y * -1;
- }
-
- // Display circle at x location
- stroke(0);
- fill(175);
- ellipse(location.x,location.y,16,16);
-}
-
-
diff --git a/java/examples/Books/Nature of Code/chp1_vectors/NOC_1_3_vector_subtraction/NOC_1_3_vector_subtraction.pde b/java/examples/Books/Nature of Code/chp1_vectors/NOC_1_3_vector_subtraction/NOC_1_3_vector_subtraction.pde
deleted file mode 100644
index a9659a409..000000000
--- a/java/examples/Books/Nature of Code/chp1_vectors/NOC_1_3_vector_subtraction/NOC_1_3_vector_subtraction.pde
+++ /dev/null
@@ -1,26 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Example 1-3: Vector subtraction
-
-void setup() {
- size(800,200);
- smooth();
-}
-
-void draw() {
- background(255);
-
- PVector mouse = new PVector(mouseX,mouseY);
- PVector center = new PVector(width/2,height/2);
- mouse.sub(center);
-
- translate(width/2,height/2);
- strokeWeight(2);
- stroke(0);
- line(0,0,mouse.x,mouse.y);
-
-}
-
-
diff --git a/java/examples/Books/Nature of Code/chp1_vectors/NOC_1_4_vector_multiplication/NOC_1_4_vector_multiplication.pde b/java/examples/Books/Nature of Code/chp1_vectors/NOC_1_4_vector_multiplication/NOC_1_4_vector_multiplication.pde
deleted file mode 100644
index 3f7f76b3f..000000000
--- a/java/examples/Books/Nature of Code/chp1_vectors/NOC_1_4_vector_multiplication/NOC_1_4_vector_multiplication.pde
+++ /dev/null
@@ -1,28 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Example 1-4: Vector multiplication
-
-void setup() {
- size(800,200);
- smooth();
-}
-
-void draw() {
- background(255);
-
- PVector mouse = new PVector(mouseX,mouseY);
- PVector center = new PVector(width/2,height/2);
- mouse.sub(center);
-
- // Multiplying a vector! The vector is now half its original size (multiplied by 0.5).
- mouse.mult(0.5);
-
- translate(width/2,height/2);
- strokeWeight(2);
- stroke(0);
- line(0,0,mouse.x,mouse.y);
-}
-
-
diff --git a/java/examples/Books/Nature of Code/chp1_vectors/NOC_1_5_vector_magnitude/NOC_1_5_vector_magnitude.pde b/java/examples/Books/Nature of Code/chp1_vectors/NOC_1_5_vector_magnitude/NOC_1_5_vector_magnitude.pde
deleted file mode 100644
index 53d0b99a1..000000000
--- a/java/examples/Books/Nature of Code/chp1_vectors/NOC_1_5_vector_magnitude/NOC_1_5_vector_magnitude.pde
+++ /dev/null
@@ -1,31 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Example 1-5: Vector magnitude
-
-void setup() {
- size(800,200);
- smooth();
-}
-
-void draw() {
- background(255);
-
- PVector mouse = new PVector(mouseX,mouseY);
- PVector center = new PVector(width/2,height/2);
- mouse.sub(center);
-
- float m = mouse.mag();
- fill(0);
- noStroke();
- rect(0,0,m,10);
-
- translate(width/2,height/2);
- stroke(0);
- strokeWeight(2);
- line(0,0,mouse.x,mouse.y);
-
-}
-
-
diff --git a/java/examples/Books/Nature of Code/chp1_vectors/NOC_1_6_vector_normalize/NOC_1_6_vector_normalize.pde b/java/examples/Books/Nature of Code/chp1_vectors/NOC_1_6_vector_normalize/NOC_1_6_vector_normalize.pde
deleted file mode 100644
index 659d8a512..000000000
--- a/java/examples/Books/Nature of Code/chp1_vectors/NOC_1_6_vector_normalize/NOC_1_6_vector_normalize.pde
+++ /dev/null
@@ -1,37 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Demonstration of normalizing a vector.
-// Normalizing a vector sets its length to 1.
-
-void setup() {
- size(800,200);
- smooth();
-}
-
-void draw() {
- background(255);
-
- // A vector that points to the mouse location
- PVector mouse = new PVector(mouseX,mouseY);
- // A vector that points to the center of the window
- PVector center = new PVector(width/2,height/2);
- // Subtract center from mouse which results in a vector that points from center to mouse
- mouse.sub(center);
-
- // Normalize the vector
- mouse.normalize();
-
- // Multiply its length by 50
- mouse.mult(150);
-
- translate(width/2,height/2);
- // Draw the resulting vector
- stroke(0);
- strokeWeight(2);
- line(0,0,mouse.x,mouse.y);
-
-}
-
-
diff --git a/java/examples/Books/Nature of Code/chp1_vectors/NOC_1_7_motion101/Mover.pde b/java/examples/Books/Nature of Code/chp1_vectors/NOC_1_7_motion101/Mover.pde
deleted file mode 100644
index 8d7abe902..000000000
--- a/java/examples/Books/Nature of Code/chp1_vectors/NOC_1_7_motion101/Mover.pde
+++ /dev/null
@@ -1,43 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-class Mover {
-
- PVector location;
- PVector velocity;
-
- Mover() {
- location = new PVector(random(width), random(height));
- velocity = new PVector(random(-2, 2), random(-2, 2));
- }
-
- void update() {
- location.add(velocity);
- }
-
- void display() {
- stroke(0);
- strokeWeight(2);
- fill(127);
- ellipse(location.x, location.y, 48, 48);
- }
-
- void checkEdges() {
-
- if (location.x > width) {
- location.x = 0;
- }
- else if (location.x < 0) {
- location.x = width;
- }
-
- if (location.y > height) {
- location.y = 0;
- }
- else if (location.y < 0) {
- location.y = height;
- }
- }
-}
-
diff --git a/java/examples/Books/Nature of Code/chp1_vectors/NOC_1_7_motion101/NOC_1_7_motion101.pde b/java/examples/Books/Nature of Code/chp1_vectors/NOC_1_7_motion101/NOC_1_7_motion101.pde
deleted file mode 100644
index 9f968a254..000000000
--- a/java/examples/Books/Nature of Code/chp1_vectors/NOC_1_7_motion101/NOC_1_7_motion101.pde
+++ /dev/null
@@ -1,19 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-Mover mover;
-
-void setup() {
- size(800,200);
- mover = new Mover();
-}
-
-void draw() {
- background(255);
-
- mover.update();
- mover.checkEdges();
- mover.display();
-}
-
diff --git a/java/examples/Books/Nature of Code/chp1_vectors/NOC_1_8_motion101_acceleration/Mover.pde b/java/examples/Books/Nature of Code/chp1_vectors/NOC_1_8_motion101_acceleration/Mover.pde
deleted file mode 100644
index fdf9f5093..000000000
--- a/java/examples/Books/Nature of Code/chp1_vectors/NOC_1_8_motion101_acceleration/Mover.pde
+++ /dev/null
@@ -1,49 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-class Mover {
-
- PVector location;
- PVector velocity;
- PVector acceleration;
- float topspeed;
-
- Mover() {
- location = new PVector(width/2, height/2);
- velocity = new PVector(0, 0);
- acceleration = new PVector(-0.001, 0.01);
- topspeed = 10;
- }
-
- void update() {
- velocity.add(acceleration);
- velocity.limit(topspeed);
- location.add(velocity);
- }
-
- void display() {
- stroke(0);
- strokeWeight(2);
- fill(127);
- ellipse(location.x, location.y, 48, 48);
- }
-
- void checkEdges() {
-
- if (location.x > width) {
- location.x = 0;
- }
- else if (location.x < 0) {
- location.x = width;
- }
-
- if (location.y > height) {
- location.y = 0;
- }
- else if (location.y < 0) {
- location.y = height;
- }
- }
-}
-
diff --git a/java/examples/Books/Nature of Code/chp1_vectors/NOC_1_8_motion101_acceleration/NOC_1_8_motion101_acceleration.pde b/java/examples/Books/Nature of Code/chp1_vectors/NOC_1_8_motion101_acceleration/NOC_1_8_motion101_acceleration.pde
deleted file mode 100644
index 3d1668104..000000000
--- a/java/examples/Books/Nature of Code/chp1_vectors/NOC_1_8_motion101_acceleration/NOC_1_8_motion101_acceleration.pde
+++ /dev/null
@@ -1,20 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-Mover mover;
-
-void setup() {
- size(800,200);
- mover = new Mover();
-}
-
-void draw() {
- background(255);
-
- mover.update();
- mover.checkEdges();
- mover.display();
-}
-
-
diff --git a/java/examples/Books/Nature of Code/chp1_vectors/NOC_1_9_motion101_acceleration/Mover.pde b/java/examples/Books/Nature of Code/chp1_vectors/NOC_1_9_motion101_acceleration/Mover.pde
deleted file mode 100644
index d5644bff2..000000000
--- a/java/examples/Books/Nature of Code/chp1_vectors/NOC_1_9_motion101_acceleration/Mover.pde
+++ /dev/null
@@ -1,52 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-class Mover {
-
- PVector location;
- PVector velocity;
- PVector acceleration;
- float topspeed;
-
- Mover() {
- location = new PVector(width/2, height/2);
- velocity = new PVector(0, 0);
- topspeed = 6;
- }
-
- void update() {
-
- acceleration = PVector.random2D();
- acceleration.mult(random(2));
-
- velocity.add(acceleration);
- velocity.limit(topspeed);
- location.add(velocity);
- }
-
- void display() {
- stroke(0);
- strokeWeight(2);
- fill(127);
- ellipse(location.x, location.y, 48, 48);
- }
-
- void checkEdges() {
-
- if (location.x > width) {
- location.x = 0;
- }
- else if (location.x < 0) {
- location.x = width;
- }
-
- if (location.y > height) {
- location.y = 0;
- }
- else if (location.y < 0) {
- location.y = height;
- }
- }
-}
-
diff --git a/java/examples/Books/Nature of Code/chp1_vectors/NOC_1_9_motion101_acceleration/NOC_1_9_motion101_acceleration.pde b/java/examples/Books/Nature of Code/chp1_vectors/NOC_1_9_motion101_acceleration/NOC_1_9_motion101_acceleration.pde
deleted file mode 100644
index 30e22723f..000000000
--- a/java/examples/Books/Nature of Code/chp1_vectors/NOC_1_9_motion101_acceleration/NOC_1_9_motion101_acceleration.pde
+++ /dev/null
@@ -1,18 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-Mover mover;
-
-void setup() {
- size(800,200);
- mover = new Mover();
-}
-
-void draw() {
- background(255);
- mover.update();
- mover.checkEdges();
- mover.display();
-}
-
diff --git a/java/examples/Books/Nature of Code/chp2_forces/Exercise_2_10_attractrepel/Attractor.pde b/java/examples/Books/Nature of Code/chp2_forces/Exercise_2_10_attractrepel/Attractor.pde
deleted file mode 100644
index bff0c1f5c..000000000
--- a/java/examples/Books/Nature of Code/chp2_forces/Exercise_2_10_attractrepel/Attractor.pde
+++ /dev/null
@@ -1,75 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// A class for a draggable attractive body in our world
-
-class Attractor {
- float mass; // Mass, tied to size
- PVector location; // Location
- boolean dragging = false; // Is the object being dragged?
- boolean rollover = false; // Is the mouse over the ellipse?
- PVector drag; // holds the offset for when object is clicked on
-
- Attractor() {
- location = new PVector(width/2,height/2);
- mass = 10;
- drag = new PVector(0.0,0.0);
- }
-
- PVector attract(Mover m) {
- PVector force = PVector.sub(location,m.location); // Calculate direction of force
- float d = force.mag(); // Distance between objects
- d = constrain(d,5.0,25.0); // Limiting the distance to eliminate "extreme" results for very close or very far objects
- force.normalize(); // Normalize vector (distance doesn't matter here, we just want this vector for direction)
- float strength = (g * mass * m.mass) / (d * d); // Calculate gravitional force magnitude
- force.mult(strength); // Get force vector --> magnitude * direction
- return force;
- }
-
- // Method to display
- void display() {
- ellipseMode(CENTER);
- stroke(0);
- if (dragging) fill (50);
- else if (rollover) fill(100);
- else fill(0);
- ellipse(location.x,location.y,mass*6,mass*6);
- }
-
- // The methods below are for mouse interaction
- void clicked(int mx, int my) {
- float d = dist(mx,my,location.x,location.y);
- if (d < mass) {
- dragging = true;
- drag.x = location.x-mx;
- drag.y = location.y-my;
- }
- }
-
- void rollover(int mx, int my) {
- float d = dist(mx,my,location.x,location.y);
- if (d < mass) {
- rollover = true;
- }
- else {
- rollover = false;
- }
- }
-
- void stopDragging() {
- dragging = false;
- }
-
-
-
- void drag() {
- if (dragging) {
- location.x = mouseX + drag.x;
- location.y = mouseY + drag.y;
- }
- }
-
-}
-
-
diff --git a/java/examples/Books/Nature of Code/chp2_forces/Exercise_2_10_attractrepel/Exercise_2_10_attractrepel.pde b/java/examples/Books/Nature of Code/chp2_forces/Exercise_2_10_attractrepel/Exercise_2_10_attractrepel.pde
deleted file mode 100644
index 03eefdbc6..000000000
--- a/java/examples/Books/Nature of Code/chp2_forces/Exercise_2_10_attractrepel/Exercise_2_10_attractrepel.pde
+++ /dev/null
@@ -1,55 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-Mover[] movers = new Mover[20];
-
-Attractor a;
-
-float g = 1;
-
-void setup() {
- size(800,200);
- a = new Attractor();
- for (int i = 0; i < movers.length; i++) {
- movers[i] = new Mover(random(4,12),random(width),random(height));
- }
-}
-
-void draw() {
- background(255);
-
- a.display();
-
-
- for (int i = 0; i < movers.length; i++) {
- for (int j = 0; j < movers.length; j++) {
- if (i != j) {
- PVector force = movers[j].repel(movers[i]);
- movers[i].applyForce(force);
- }
- }
-
- PVector force = a.attract(movers[i]);
- movers[i].applyForce(force);
- movers[i].update();
- movers[i].display();
- }
-
-
-
-}
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/java/examples/Books/Nature of Code/chp2_forces/Exercise_2_10_attractrepel/Mover.pde b/java/examples/Books/Nature of Code/chp2_forces/Exercise_2_10_attractrepel/Mover.pde
deleted file mode 100644
index 0725db4c9..000000000
--- a/java/examples/Books/Nature of Code/chp2_forces/Exercise_2_10_attractrepel/Mover.pde
+++ /dev/null
@@ -1,73 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-class Mover {
-
- PVector location;
- PVector velocity;
- PVector acceleration;
- float mass;
-
- Mover(float m, float x , float y) {
- mass = m;
- location = new PVector(x,y);
- velocity = new PVector(0,0);
- acceleration = new PVector(0,0);
- }
-
- void applyForce(PVector force) {
- PVector f = PVector.div(force,mass);
- acceleration.add(f);
- }
-
- void update() {
- velocity.add(acceleration);
- location.add(velocity);
- acceleration.mult(0);
- }
-
- void display() {
- stroke(0);
- fill(175,200);
- ellipse(location.x,location.y,mass*2,mass*2);
- }
-
- PVector repel(Mover m) {
- PVector force = PVector.sub(location,m.location); // Calculate direction of force
- float distance = force.mag(); // Distance between objects
- distance = constrain(distance,1.0,10000.0); // Limiting the distance to eliminate "extreme" results for very close or very far objects
- force.normalize(); // Normalize vector (distance doesn't matter here, we just want this vector for direction
-
- float strength = (g * mass * m.mass) / (distance * distance); // Calculate gravitional force magnitude
- force.mult(-1*strength); // Get force vector --> magnitude * direction
- return force;
- }
-
- void checkEdges() {
-
- if (location.x > width) {
- location.x = width;
- velocity.x *= -1;
- }
- else if (location.x < 0) {
- location.x = 0;
- velocity.x *= -1;
- }
-
- if (location.y > height) {
- location.y = height;
- velocity.y *= -1;
- }
- else if (location.y < 0) {
- location.y = 0;
- velocity.y *= -1;
- }
-
- }
-
-}
-
-
-
-
diff --git a/java/examples/Books/Nature of Code/chp2_forces/Extra_instantforce/Extra_instantforce.pde b/java/examples/Books/Nature of Code/chp2_forces/Extra_instantforce/Extra_instantforce.pde
deleted file mode 100644
index ac2636abd..000000000
--- a/java/examples/Books/Nature of Code/chp2_forces/Extra_instantforce/Extra_instantforce.pde
+++ /dev/null
@@ -1,57 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-Mover m;
-
-float t = 0.0;
-
-void setup() {
- size(640, 360);
- m = new Mover();
-}
-
-void draw() {
- background(255);
-
- // Perlin noise wind
- float wx = map(noise(t),0,1,-1,1);
- PVector wind = new PVector(wx, 0);
- t += 0.01;
- line(width/2,height/2,width/2+wind.x*100,height/2+wind.y*100);
- m.applyForce(wind);
-
- // Gravity
- PVector gravity = new PVector(0, 0.1);
- //m.applyForce(gravity);
-
- // Shake force
- //m.shake();
-
- // Boundary force
- if (m.location.x > width - 50) {
- PVector boundary = new PVector(-1,0);
- m.applyForce(boundary);
- } else if (m.location.x < 50) {
- PVector boundary = new PVector(1,0);
- m.applyForce(boundary);
- }
-
-
-
-
- m.update();
- m.display();
- //m.checkEdges();
-}
-
-// Instant Force
-void mousePressed() {
- PVector cannon = PVector.random2D();
- cannon.mult(5);
- m.applyForce(cannon);
-}
-
-
-
-
diff --git a/java/examples/Books/Nature of Code/chp2_forces/Extra_instantforce/Mover.pde b/java/examples/Books/Nature of Code/chp2_forces/Extra_instantforce/Mover.pde
deleted file mode 100644
index 681cfed16..000000000
--- a/java/examples/Books/Nature of Code/chp2_forces/Extra_instantforce/Mover.pde
+++ /dev/null
@@ -1,69 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-class Mover {
-
- PVector location;
- PVector velocity;
- PVector acceleration;
- float mass;
-
- Mover() {
- location = new PVector(width/2,height/2);
- velocity = new PVector(0,0);
- acceleration = new PVector(0,0);
- mass = 1;
- }
-
- void shake() {
- PVector force = PVector.random2D();
- force.mult(0.7);
- applyForce(force);
-
-
- }
-
- void applyForce(PVector force) {
- PVector f = PVector.div(force,mass);
- acceleration.add(f);
- }
-
- void update() {
- velocity.add(acceleration);
- location.add(velocity);
- acceleration.mult(0);
-
- // Simple friction
- velocity.mult(0.95);
-
- }
-
- void display() {
- stroke(0);
- strokeWeight(2);
- fill(127);
- ellipse(location.x,location.y,48,48);
- }
-
- void checkEdges() {
-
- if (location.x > width) {
- location.x = width;
- velocity.x *= -1;
- } else if (location.x < 0) {
- velocity.x *= -1;
- location.x = 0;
- }
-
- if (location.y > height) {
- velocity.y *= -1;
- location.y = height;
- }
-
- }
-
-}
-
-
-
diff --git a/java/examples/Books/Nature of Code/chp2_forces/NOC_02forces_many_attraction_3D/Attractor.pde b/java/examples/Books/Nature of Code/chp2_forces/NOC_02forces_many_attraction_3D/Attractor.pde
deleted file mode 100644
index a242a2ef2..000000000
--- a/java/examples/Books/Nature of Code/chp2_forces/NOC_02forces_many_attraction_3D/Attractor.pde
+++ /dev/null
@@ -1,42 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Attraction
-
-// A class for a draggable attractive body in our world
-
-class Attractor {
- float mass; // Mass, tied to size
- PVector location; // Location
- float g;
-
- Attractor() {
- location = new PVector(0,0);
- mass = 20;
- g = 0.4;
- }
-
-
- PVector attract(Mover m) {
- PVector force = PVector.sub(location,m.location); // Calculate direction of force
- float distance = force.mag(); // Distance between objects
- distance = constrain(distance,5.0,25.0); // Limiting the distance to eliminate "extreme" results for very close or very far objects
- force.normalize(); // Normalize vector (distance doesn't matter here, we just want this vector for direction)
- float strength = (g * mass * m.mass) / (distance * distance); // Calculate gravitional force magnitude
- force.mult(strength); // Get force vector --> magnitude * direction
- return force;
- }
-
- // Method to display
- void display() {
- stroke(255);
- noFill();
- pushMatrix();
- translate(location.x,location.y,location.z);
- sphere(mass*2);
- popMatrix();
- }
-}
-
-
diff --git a/java/examples/Books/Nature of Code/chp2_forces/NOC_02forces_many_attraction_3D/Mover.pde b/java/examples/Books/Nature of Code/chp2_forces/NOC_02forces_many_attraction_3D/Mover.pde
deleted file mode 100644
index 5a5b3dcdf..000000000
--- a/java/examples/Books/Nature of Code/chp2_forces/NOC_02forces_many_attraction_3D/Mover.pde
+++ /dev/null
@@ -1,55 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-class Mover {
-
- PVector location;
- PVector velocity;
- PVector acceleration;
- float mass;
-
- Mover(float m, float x, float y, float z) {
- mass = m;
- location = new PVector(x,y,z);
- velocity = new PVector(1,0);
- acceleration = new PVector(0,0);
- }
-
- void applyForce(PVector force) {
- PVector f = PVector.div(force,mass);
- acceleration.add(f);
- }
-
- void update() {
- velocity.add(acceleration);
- location.add(velocity);
- acceleration.mult(0);
- }
-
- void display() {
- noStroke();
- fill(255);
- pushMatrix();
- translate(location.x,location.y,location.z);
- sphere(mass*8);
- popMatrix();
- }
-
- void checkEdges() {
-
- if (location.x > width) {
- location.x = 0;
- }
- else if (location.x < 0) {
- location.x = width;
- }
-
- if (location.y > height) {
- velocity.y *= -1;
- location.y = height;
- }
- }
-}
-
-
diff --git a/java/examples/Books/Nature of Code/chp2_forces/NOC_02forces_many_attraction_3D/NOC_02forces_many_attraction_3D.pde b/java/examples/Books/Nature of Code/chp2_forces/NOC_02forces_many_attraction_3D/NOC_02forces_many_attraction_3D.pde
deleted file mode 100644
index 5faf4dca0..000000000
--- a/java/examples/Books/Nature of Code/chp2_forces/NOC_02forces_many_attraction_3D/NOC_02forces_many_attraction_3D.pde
+++ /dev/null
@@ -1,53 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-import processing.opengl.*;
-
-Mover[] movers = new Mover[10];
-
-Attractor a;
-
-float angle = 0;
-
-void setup() {
- size(800,200,OPENGL);
- background(255);
- for (int i = 0; i < movers.length; i++) {
- movers[i] = new Mover(random(0.1,2),random(-width/2,width/2),random(-height/2,height/2),random(-100,100));
- }
- a = new Attractor();
-}
-
-void draw() {
- background(0);
- sphereDetail(8);
- lights();
- translate(width/2,height/2);
- rotateY(angle);
-
-
- a.display();
-
- for (int i = 0; i < movers.length; i++) {
- PVector force = a.attract(movers[i]);
- movers[i].applyForce(force);
-
- movers[i].update();
- movers[i].display();
- }
-
- angle += 0.003;
-
-}
-
-
-
-
-
-
-
-
-
-
-
diff --git a/java/examples/Books/Nature of Code/chp2_forces/NOC_02forces_many_mutual_boundaries/Mover.pde b/java/examples/Books/Nature of Code/chp2_forces/NOC_02forces_many_mutual_boundaries/Mover.pde
deleted file mode 100644
index ed666c5f0..000000000
--- a/java/examples/Books/Nature of Code/chp2_forces/NOC_02forces_many_mutual_boundaries/Mover.pde
+++ /dev/null
@@ -1,74 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-class Mover {
-
- PVector location;
- PVector velocity;
- PVector acceleration;
- float mass;
-
- Mover(float m, float x, float y) {
- mass = m;
- location = new PVector(x, y);
- velocity = new PVector(0, 0);
- acceleration = new PVector(0, 0);
- }
-
- void applyForce(PVector force) {
- PVector f = PVector.div(force, mass);
- acceleration.add(f);
- }
-
- void update() {
- velocity.add(acceleration);
- location.add(velocity);
- acceleration.mult(0);
- }
-
- void display() {
- stroke(0);
- fill(175, 200);
- ellipse(location.x, location.y, mass*16, mass*16);
- }
-
- PVector attract(Mover m) {
- PVector force = PVector.sub(location, m.location); // Calculate direction of force
- float distance = force.mag(); // Distance between objects
- distance = constrain(distance, 5.0, 25.0); // Limiting the distance to eliminate "extreme" results for very close or very far objects
- force.normalize(); // Normalize vector (distance doesn't matter here, we just want this vector for direction
-
- float strength = (g * mass * m.mass) / (distance * distance); // Calculate gravitional force magnitude
- force.mult(strength); // Get force vector --> magnitude * direction
- return force;
- }
-
- void boundaries() {
-
- float d = 50;
-
- PVector force = new PVector(0, 0);
-
- if (location.x < d) {
- force.x = 1;
- }
- else if (location.x > width -d) {
- force.x = -1;
- }
-
- if (location.y < d) {
- force.y = 1;
- }
- else if (location.y > height-d) {
- force.y = -1;
- }
-
- force.normalize();
- force.mult(0.1);
-
- applyForce(force);
- }
-}
-
-
diff --git a/java/examples/Books/Nature of Code/chp2_forces/NOC_02forces_many_mutual_boundaries/NOC_02forces_many_mutual_boundaries.pde b/java/examples/Books/Nature of Code/chp2_forces/NOC_02forces_many_mutual_boundaries/NOC_02forces_many_mutual_boundaries.pde
deleted file mode 100644
index caf6d8b63..000000000
--- a/java/examples/Books/Nature of Code/chp2_forces/NOC_02forces_many_mutual_boundaries/NOC_02forces_many_mutual_boundaries.pde
+++ /dev/null
@@ -1,47 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-Mover[] movers = new Mover[20];
-
-float g = 0.4;
-
-void setup() {
- size(800,200);
- for (int i = 0; i < movers.length; i++) {
- movers[i] = new Mover(random(1,2),random(width),random(height));
- }
-}
-
-void draw() {
- background(255);
-
-
- for (int i = 0; i < movers.length; i++) {
- for (int j = 0; j < movers.length; j++) {
- if (i != j) {
- PVector force = movers[j].attract(movers[i]);
- movers[i].applyForce(force);
- }
- }
-
- movers[i].boundaries();
-
- movers[i].update();
- movers[i].display();
- }
-
-}
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/java/examples/Books/Nature of Code/chp2_forces/NOC_2_1_forces/Mover.pde b/java/examples/Books/Nature of Code/chp2_forces/NOC_2_1_forces/Mover.pde
deleted file mode 100644
index 839b1afdc..000000000
--- a/java/examples/Books/Nature of Code/chp2_forces/NOC_2_1_forces/Mover.pde
+++ /dev/null
@@ -1,57 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-class Mover {
-
- PVector location;
- PVector velocity;
- PVector acceleration;
- float mass;
-
- Mover() {
- location = new PVector(30,30);
- velocity = new PVector(0,0);
- acceleration = new PVector(0,0);
- mass = 1;
- }
-
- void applyForce(PVector force) {
- PVector f = PVector.div(force,mass);
- acceleration.add(f);
- }
-
- void update() {
- velocity.add(acceleration);
- location.add(velocity);
- acceleration.mult(0);
- }
-
- void display() {
- stroke(0);
- strokeWeight(2);
- fill(127);
- ellipse(location.x,location.y,48,48);
- }
-
- void checkEdges() {
-
- if (location.x > width) {
- location.x = width;
- velocity.x *= -1;
- } else if (location.x < 0) {
- velocity.x *= -1;
- location.x = 0;
- }
-
- if (location.y > height) {
- velocity.y *= -1;
- location.y = height;
- }
-
- }
-
-}
-
-
-
diff --git a/java/examples/Books/Nature of Code/chp2_forces/NOC_2_1_forces/NOC_2_1_forces.pde b/java/examples/Books/Nature of Code/chp2_forces/NOC_2_1_forces/NOC_2_1_forces.pde
deleted file mode 100644
index 92713efaa..000000000
--- a/java/examples/Books/Nature of Code/chp2_forces/NOC_2_1_forces/NOC_2_1_forces.pde
+++ /dev/null
@@ -1,30 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-Mover m;
-
-void setup() {
- size(640,360);
- m = new Mover();
-}
-
-void draw() {
- background(255);
-
- PVector wind = new PVector(0.01,0);
- PVector gravity = new PVector(0,0.1);
- m.applyForce(wind);
- m.applyForce(gravity);
-
-
- m.update();
- m.display();
- m.checkEdges();
-
-}
-
-
-
-
-
diff --git a/java/examples/Books/Nature of Code/chp2_forces/NOC_2_2_forces_many/Mover.pde b/java/examples/Books/Nature of Code/chp2_forces/NOC_2_2_forces_many/Mover.pde
deleted file mode 100644
index 6b008918c..000000000
--- a/java/examples/Books/Nature of Code/chp2_forces/NOC_2_2_forces_many/Mover.pde
+++ /dev/null
@@ -1,57 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-class Mover {
-
- PVector location;
- PVector velocity;
- PVector acceleration;
- float mass;
-
- Mover(float m, float x , float y) {
- mass = m;
- location = new PVector(x,y);
- velocity = new PVector(0,0);
- acceleration = new PVector(0,0);
- }
-
- void applyForce(PVector force) {
- PVector f = PVector.div(force,mass);
- acceleration.add(f);
- }
-
- void update() {
- velocity.add(acceleration);
- location.add(velocity);
- acceleration.mult(0);
- }
-
- void display() {
- stroke(0);
- strokeWeight(2);
- fill(0,127);
- ellipse(location.x,location.y,mass*16,mass*16);
- }
-
- void checkEdges() {
-
- if (location.x > width) {
- location.x = width;
- velocity.x *= -1;
- } else if (location.x < 0) {
- velocity.x *= -1;
- location.x = 0;
- }
-
- if (location.y > height) {
- velocity.y *= -1;
- location.y = height;
- }
-
- }
-
-}
-
-
-
diff --git a/java/examples/Books/Nature of Code/chp2_forces/NOC_2_2_forces_many/NOC_2_2_forces_many.pde b/java/examples/Books/Nature of Code/chp2_forces/NOC_2_2_forces_many/NOC_2_2_forces_many.pde
deleted file mode 100644
index db74a7634..000000000
--- a/java/examples/Books/Nature of Code/chp2_forces/NOC_2_2_forces_many/NOC_2_2_forces_many.pde
+++ /dev/null
@@ -1,39 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-Mover[] movers = new Mover[20];
-
-void setup() {
- size(800,200);
- for (int i = 0; i < movers.length; i++) {
- movers[i] = new Mover(random(0.1,4),0,0);
- }
-}
-
-void draw() {
- background(255);
-
- for (int i = 0; i < movers.length; i++) {
-
- PVector wind = new PVector(0.01,0);
- PVector gravity = new PVector(0,0.1);
-
- movers[i].applyForce(wind);
- movers[i].applyForce(gravity);
-
- movers[i].update();
- movers[i].display();
- movers[i].checkEdges();
- }
-
-}
-
-
-
-
-
-
-
-
-
diff --git a/java/examples/Books/Nature of Code/chp2_forces/NOC_2_3_forces_many_realgravity/Mover.pde b/java/examples/Books/Nature of Code/chp2_forces/NOC_2_3_forces_many_realgravity/Mover.pde
deleted file mode 100644
index 6b008918c..000000000
--- a/java/examples/Books/Nature of Code/chp2_forces/NOC_2_3_forces_many_realgravity/Mover.pde
+++ /dev/null
@@ -1,57 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-class Mover {
-
- PVector location;
- PVector velocity;
- PVector acceleration;
- float mass;
-
- Mover(float m, float x , float y) {
- mass = m;
- location = new PVector(x,y);
- velocity = new PVector(0,0);
- acceleration = new PVector(0,0);
- }
-
- void applyForce(PVector force) {
- PVector f = PVector.div(force,mass);
- acceleration.add(f);
- }
-
- void update() {
- velocity.add(acceleration);
- location.add(velocity);
- acceleration.mult(0);
- }
-
- void display() {
- stroke(0);
- strokeWeight(2);
- fill(0,127);
- ellipse(location.x,location.y,mass*16,mass*16);
- }
-
- void checkEdges() {
-
- if (location.x > width) {
- location.x = width;
- velocity.x *= -1;
- } else if (location.x < 0) {
- velocity.x *= -1;
- location.x = 0;
- }
-
- if (location.y > height) {
- velocity.y *= -1;
- location.y = height;
- }
-
- }
-
-}
-
-
-
diff --git a/java/examples/Books/Nature of Code/chp2_forces/NOC_2_3_forces_many_realgravity/NOC_2_3_forces_many_realgravity.pde b/java/examples/Books/Nature of Code/chp2_forces/NOC_2_3_forces_many_realgravity/NOC_2_3_forces_many_realgravity.pde
deleted file mode 100644
index c3ecd8488..000000000
--- a/java/examples/Books/Nature of Code/chp2_forces/NOC_2_3_forces_many_realgravity/NOC_2_3_forces_many_realgravity.pde
+++ /dev/null
@@ -1,37 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-Mover[] movers = new Mover[20];
-
-void setup() {
- size(800, 200);
- for (int i = 0; i < movers.length; i++) {
- movers[i] = new Mover(random(1, 4), 0, 0);
- }
-}
-
-void draw() {
- background(255);
-
- for (int i = 0; i < movers.length; i++) {
-
- PVector wind = new PVector(0.01, 0);
- PVector gravity = new PVector(0, 0.1*movers[i].mass);
-
- movers[i].applyForce(wind);
- movers[i].applyForce(gravity);
-
- movers[i].update();
- movers[i].display();
- movers[i].checkEdges();
- }
-}
-
-
-
-
-
-
-
-
diff --git a/java/examples/Books/Nature of Code/chp2_forces/NOC_2_4_forces_friction/Mover.pde b/java/examples/Books/Nature of Code/chp2_forces/NOC_2_4_forces_friction/Mover.pde
deleted file mode 100644
index 263724c51..000000000
--- a/java/examples/Books/Nature of Code/chp2_forces/NOC_2_4_forces_friction/Mover.pde
+++ /dev/null
@@ -1,57 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-class Mover {
-
- PVector location;
- PVector velocity;
- PVector acceleration;
- float mass;
-
- Mover(float m, float x , float y) {
- mass = m;
- location = new PVector(x,y);
- velocity = new PVector(0,0);
- acceleration = new PVector(0,0);
- }
-
- void applyForce(PVector force) {
- PVector f = PVector.div(force,mass);
- acceleration.add(f);
- }
-
- void update() {
- velocity.add(acceleration);
- location.add(velocity);
- acceleration.mult(0);
- }
-
- void display() {
- stroke(0);
- strokeWeight(2);
- fill(0,127);
- ellipse(location.x,location.y,mass*16,mass*16);
- }
-
- void checkEdges() {
-
- if (location.x > width) {
- location.x = width;
- velocity.x *= -1;
- } else if (location.x < 0) {
- location.x = 0;
- velocity.x *= -1;
- }
-
- if (location.y > height) {
- velocity.y *= -1;
- location.y = height;
- }
-
- }
-
-}
-
-
-
diff --git a/java/examples/Books/Nature of Code/chp2_forces/NOC_2_4_forces_friction/NOC_2_4_forces_friction.pde b/java/examples/Books/Nature of Code/chp2_forces/NOC_2_4_forces_friction/NOC_2_4_forces_friction.pde
deleted file mode 100644
index 02c417066..000000000
--- a/java/examples/Books/Nature of Code/chp2_forces/NOC_2_4_forces_friction/NOC_2_4_forces_friction.pde
+++ /dev/null
@@ -1,45 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-Mover[] movers = new Mover[5];
-
-void setup() {
- size(383, 200);
- randomSeed(1);
- for (int i = 0; i < movers.length; i++) {
- movers[i] = new Mover(random(1, 4), random(width), 0);
- }
-}
-
-void draw() {
- background(255);
-
- for (int i = 0; i < movers.length; i++) {
-
- PVector wind = new PVector(0.01, 0);
- PVector gravity = new PVector(0, 0.1*movers[i].mass);
-
- float c = 0.05;
- PVector friction = movers[i].velocity.get();
- friction.mult(-1);
- friction.normalize();
- friction.mult(c);
-
- movers[i].applyForce(friction);
- movers[i].applyForce(wind);
- movers[i].applyForce(gravity);
-
- movers[i].update();
- movers[i].display();
- movers[i].checkEdges();
- }
-}
-
-
-
-
-
-
-
-
diff --git a/java/examples/Books/Nature of Code/chp2_forces/NOC_2_4_forces_nofriction/Mover.pde b/java/examples/Books/Nature of Code/chp2_forces/NOC_2_4_forces_nofriction/Mover.pde
deleted file mode 100644
index 263724c51..000000000
--- a/java/examples/Books/Nature of Code/chp2_forces/NOC_2_4_forces_nofriction/Mover.pde
+++ /dev/null
@@ -1,57 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-class Mover {
-
- PVector location;
- PVector velocity;
- PVector acceleration;
- float mass;
-
- Mover(float m, float x , float y) {
- mass = m;
- location = new PVector(x,y);
- velocity = new PVector(0,0);
- acceleration = new PVector(0,0);
- }
-
- void applyForce(PVector force) {
- PVector f = PVector.div(force,mass);
- acceleration.add(f);
- }
-
- void update() {
- velocity.add(acceleration);
- location.add(velocity);
- acceleration.mult(0);
- }
-
- void display() {
- stroke(0);
- strokeWeight(2);
- fill(0,127);
- ellipse(location.x,location.y,mass*16,mass*16);
- }
-
- void checkEdges() {
-
- if (location.x > width) {
- location.x = width;
- velocity.x *= -1;
- } else if (location.x < 0) {
- location.x = 0;
- velocity.x *= -1;
- }
-
- if (location.y > height) {
- velocity.y *= -1;
- location.y = height;
- }
-
- }
-
-}
-
-
-
diff --git a/java/examples/Books/Nature of Code/chp2_forces/NOC_2_4_forces_nofriction/NOC_2_4_forces_nofriction.pde b/java/examples/Books/Nature of Code/chp2_forces/NOC_2_4_forces_nofriction/NOC_2_4_forces_nofriction.pde
deleted file mode 100644
index 029236deb..000000000
--- a/java/examples/Books/Nature of Code/chp2_forces/NOC_2_4_forces_nofriction/NOC_2_4_forces_nofriction.pde
+++ /dev/null
@@ -1,45 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-Mover[] movers = new Mover[5];
-
-void setup() {
- size(383, 200);
- randomSeed(1);
- for (int i = 0; i < movers.length; i++) {
- movers[i] = new Mover(random(1, 4), random(width), 0);
- }
-}
-
-void draw() {
- background(255);
-
- for (int i = 0; i < movers.length; i++) {
-
- PVector wind = new PVector(0.01, 0);
- PVector gravity = new PVector(0, 0.1*movers[i].mass);
-
- float c = 0.05;
- PVector friction = movers[i].velocity.get();
- friction.mult(-1);
- friction.normalize();
- friction.mult(c);
-
- //movers[i].applyForce(friction);
- movers[i].applyForce(wind);
- movers[i].applyForce(gravity);
-
- movers[i].update();
- movers[i].display();
- movers[i].checkEdges();
- }
-}
-
-
-
-
-
-
-
-
diff --git a/java/examples/Books/Nature of Code/chp2_forces/NOC_2_5_fluidresistance/Liquid.pde b/java/examples/Books/Nature of Code/chp2_forces/NOC_2_5_fluidresistance/Liquid.pde
deleted file mode 100644
index b0ea9b736..000000000
--- a/java/examples/Books/Nature of Code/chp2_forces/NOC_2_5_fluidresistance/Liquid.pde
+++ /dev/null
@@ -1,57 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
- // Liquid class
- class Liquid {
-
-
- // Liquid is a rectangle
- float x,y,w,h;
- // Coefficient of drag
- float c;
-
- Liquid(float x_, float y_, float w_, float h_, float c_) {
- x = x_;
- y = y_;
- w = w_;
- h = h_;
- c = c_;
- }
-
- // Is the Mover in the Liquid?
- boolean contains(Mover m) {
- PVector l = m.location;
- if (l.x > x && l.x < x + w && l.y > y && l.y < y + h) {
- return true;
- }
- else {
- return false;
- }
- }
-
- // Calculate drag force
- PVector drag(Mover m) {
- // Magnitude is coefficient * speed squared
- float speed = m.velocity.mag();
- float dragMagnitude = c * speed * speed;
-
- // Direction is inverse of velocity
- PVector dragForce = m.velocity.get();
- dragForce.mult(-1);
-
- // Scale according to magnitude
- // dragForce.setMag(dragMagnitude);
- dragForce.normalize();
- dragForce.mult(dragMagnitude);
- return dragForce;
- }
-
- void display() {
- noStroke();
- fill(50);
- rect(x,y,w,h);
- }
-
-}
-
diff --git a/java/examples/Books/Nature of Code/chp2_forces/NOC_2_5_fluidresistance/Mover.pde b/java/examples/Books/Nature of Code/chp2_forces/NOC_2_5_fluidresistance/Mover.pde
deleted file mode 100644
index 791e90954..000000000
--- a/java/examples/Books/Nature of Code/chp2_forces/NOC_2_5_fluidresistance/Mover.pde
+++ /dev/null
@@ -1,58 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-class Mover {
-
- // location, velocity, and acceleration
- PVector location;
- PVector velocity;
- PVector acceleration;
-
- // Mass is tied to size
- float mass;
-
- Mover(float m, float x, float y) {
- mass = m;
- location = new PVector(x, y);
- velocity = new PVector(0, 0);
- acceleration = new PVector(0, 0);
- }
-
- // Newton's 2nd law: F = M * A
- // or A = F / M
- void applyForce(PVector force) {
- // Divide by mass
- PVector f = PVector.div(force, mass);
- // Accumulate all forces in acceleration
- acceleration.add(f);
- }
-
- void update() {
-
- // Velocity changes according to acceleration
- velocity.add(acceleration);
- // Location changes by velocity
- location.add(velocity);
- // We must clear acceleration each frame
- acceleration.mult(0);
- }
-
- // Draw Mover
- void display() {
- stroke(0);
- strokeWeight(2);
- fill(127, 200);
- ellipse(location.x, location.y, mass*16, mass*16);
- }
-
- // Bounce off bottom of window
- void checkEdges() {
- if (location.y > height) {
- velocity.y *= -0.9; // A little dampening when hitting the bottom
- location.y = height;
- }
- }
-}
-
-
diff --git a/java/examples/Books/Nature of Code/chp2_forces/NOC_2_5_fluidresistance/NOC_2_5_fluidresistance.pde b/java/examples/Books/Nature of Code/chp2_forces/NOC_2_5_fluidresistance/NOC_2_5_fluidresistance.pde
deleted file mode 100644
index ff9573d6d..000000000
--- a/java/examples/Books/Nature of Code/chp2_forces/NOC_2_5_fluidresistance/NOC_2_5_fluidresistance.pde
+++ /dev/null
@@ -1,72 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Forces (Gravity and Fluid Resistence) with Vectors
-
-// Demonstration of multiple force acting on bodies (Mover class)
-// Bodies experience gravity continuously
-// Bodies experience fluid resistance when in "water"
-
-// Five moving bodies
-Mover[] movers = new Mover[11];
-
-// Liquid
-Liquid liquid;
-
-void setup() {
- size(800, 200);
- reset();
- // Create liquid object
- liquid = new Liquid(0, height/2, width, height/2, 0.1);
-}
-
-void draw() {
- background(255);
-
- // Draw water
- liquid.display();
-
- for (int i = 0; i < movers.length; i++) {
-
- // Is the Mover in the liquid?
- if (liquid.contains(movers[i])) {
- // Calculate drag force
- PVector dragForce = liquid.drag(movers[i]);
- // Apply drag force to Mover
- movers[i].applyForce(dragForce);
- }
-
- // Gravity is scaled by mass here!
- PVector gravity = new PVector(0, 0.1*movers[i].mass);
- // Apply gravity
- movers[i].applyForce(gravity);
-
- // Update and display
- movers[i].update();
- movers[i].display();
- movers[i].checkEdges();
- }
-
- fill(0);
- text("click mouse to reset",10,30);
-
-}
-
-void mousePressed() {
- reset();
-}
-
-// Restart all the Mover objects randomly
-void reset() {
- for (int i = 0; i < movers.length; i++) {
- movers[i] = new Mover(random(0.5, 3), 40+i*70, 0);
- }
-}
-
-
-
-
-
-
-
diff --git a/java/examples/Books/Nature of Code/chp2_forces/NOC_2_5_fluidresistance_sequence/Liquid.pde b/java/examples/Books/Nature of Code/chp2_forces/NOC_2_5_fluidresistance_sequence/Liquid.pde
deleted file mode 100644
index bce05cc7c..000000000
--- a/java/examples/Books/Nature of Code/chp2_forces/NOC_2_5_fluidresistance_sequence/Liquid.pde
+++ /dev/null
@@ -1,57 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
- // Liquid class
- class Liquid {
-
-
- // Liquid is a rectangle
- float x,y,w,h;
- // Coefficient of drag
- float c;
-
- Liquid(float x_, float y_, float w_, float h_, float c_) {
- x = x_;
- y = y_;
- w = w_;
- h = h_;
- c = c_;
- }
-
- // Is the Mover in the Liquid?
- boolean contains(Mover m) {
- PVector l = m.location;
- if (l.x > x && l.x < x + w && l.y > y && l.y < y + h) {
- return true;
- }
- else {
- return false;
- }
- }
-
- // Calculate drag force
- PVector drag(Mover m) {
- // Magnitude is coefficient * speed squared
- float speed = m.velocity.mag();
- float dragMagnitude = c * speed * speed;
-
- // Direction is inverse of velocity
- PVector dragForce = m.velocity.get();
- dragForce.mult(-1);
-
- // Scale according to magnitude
- // dragForce.setMag(dragMagnitude);
- dragForce.normalize();
- dragForce.mult(dragMagnitude);
- return dragForce;
- }
-
- void display() {
- noStroke();
- fill(50);
- rect(x,y,w,h);
- }
-
-}
-
diff --git a/java/examples/Books/Nature of Code/chp2_forces/NOC_2_5_fluidresistance_sequence/Mover.pde b/java/examples/Books/Nature of Code/chp2_forces/NOC_2_5_fluidresistance_sequence/Mover.pde
deleted file mode 100644
index d45e3b664..000000000
--- a/java/examples/Books/Nature of Code/chp2_forces/NOC_2_5_fluidresistance_sequence/Mover.pde
+++ /dev/null
@@ -1,58 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-class Mover {
-
- // location, velocity, and acceleration
- PVector location;
- PVector velocity;
- PVector acceleration;
-
- // Mass is tied to size
- float mass;
-
- Mover(float m, float x, float y) {
- mass = m;
- location = new PVector(x, y);
- velocity = new PVector(0, 0);
- acceleration = new PVector(0, 0);
- }
-
- // Newton's 2nd law: F = M * A
- // or A = F / M
- void applyForce(PVector force) {
- // Divide by mass
- PVector f = PVector.div(force, mass);
- // Accumulate all forces in acceleration
- acceleration.add(f);
- }
-
- void update() {
-
- // Velocity changes according to acceleration
- velocity.add(acceleration);
- // Location changes by velocity
- location.add(velocity);
- // We must clear acceleration each frame
- acceleration.mult(0);
- }
-
- // Draw Mover
- void display() {
- stroke(0);
- strokeWeight(2*2.25);
- fill(127,200);
- ellipse(location.x, location.y, mass*16, mass*16);
- }
-
- // Bounce off bottom of window
- void checkEdges() {
- if (location.y > height) {
- velocity.y *= -0.9; // A little dampening when hitting the bottom
- location.y = height;
- }
- }
-}
-
-
diff --git a/java/examples/Books/Nature of Code/chp2_forces/NOC_2_5_fluidresistance_sequence/NOC_2_5_fluidresistance_sequence.pde b/java/examples/Books/Nature of Code/chp2_forces/NOC_2_5_fluidresistance_sequence/NOC_2_5_fluidresistance_sequence.pde
deleted file mode 100644
index 99d47915b..000000000
--- a/java/examples/Books/Nature of Code/chp2_forces/NOC_2_5_fluidresistance_sequence/NOC_2_5_fluidresistance_sequence.pde
+++ /dev/null
@@ -1,74 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Forces (Gravity and Fluid Resistence) with Vectors
-
-// Demonstration of multiple force acting on bodies (Mover class)
-// Bodies experience gravity continuously
-// Bodies experience fluid resistance when in "water"
-
-// Five moving bodies
-Mover[] movers = new Mover[5];
-
-// Liquid
-Liquid liquid;
-
-void setup() {
- size(450, 450);
- randomSeed(1);
- reset();
- // Create liquid object
- liquid = new Liquid(0, height/2, width, height/2, 0.1);
-}
-
-void draw() {
- background(255);
-
- // Draw water
- liquid.display();
-
- for (int i = 0; i < movers.length; i++) {
-
- // Is the Mover in the liquid?
- if (liquid.contains(movers[i])) {
- // Calculate drag force
- PVector dragForce = liquid.drag(movers[i]);
- // Apply drag force to Mover
- movers[i].applyForce(dragForce);
- }
-
- // Gravity is scaled by mass here!
- PVector gravity = new PVector(0, 0.1*movers[i].mass);
- // Apply gravity
- movers[i].applyForce(gravity);
-
- // Update and display
- movers[i].update();
- movers[i].display();
- movers[i].checkEdges();
- }
-
- fill(255);
- //text("click mouse to reset",10,30);
-
- if (frameCount % 20 == 0) saveFrame("ch2_05_####.png");
-}
-
-void mousePressed() {
- reset();
-}
-
-// Restart all the Mover objects randomly
-void reset() {
- for (int i = 0; i < movers.length; i++) {
- movers[i] = new Mover(random(0.5*2.25,3*2.25), 20*2.25+i*40*2.25, 0);
- }
-}
-
-
-
-
-
-
-
diff --git a/java/examples/Books/Nature of Code/chp2_forces/NOC_2_6_attraction/Attractor.pde b/java/examples/Books/Nature of Code/chp2_forces/NOC_2_6_attraction/Attractor.pde
deleted file mode 100644
index 556605cb7..000000000
--- a/java/examples/Books/Nature of Code/chp2_forces/NOC_2_6_attraction/Attractor.pde
+++ /dev/null
@@ -1,78 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// A class for a draggable attractive body in our world
-
-class Attractor {
- float mass; // Mass, tied to size
- float G; // Gravitational Constant
- PVector location; // Location
- boolean dragging = false; // Is the object being dragged?
- boolean rollover = false; // Is the mouse over the ellipse?
- PVector dragOffset; // holds the offset for when object is clicked on
-
- Attractor() {
- location = new PVector(width/2,height/2);
- mass = 20;
- G = 1;
- dragOffset = new PVector(0.0,0.0);
- }
-
- PVector attract(Mover m) {
- PVector force = PVector.sub(location,m.location); // Calculate direction of force
- float d = force.mag(); // Distance between objects
- d = constrain(d,5.0,25.0); // Limiting the distance to eliminate "extreme" results for very close or very far objects
- force.normalize(); // Normalize vector (distance doesn't matter here, we just want this vector for direction)
- float strength = (G * mass * m.mass) / (d * d); // Calculate gravitional force magnitude
- force.mult(strength); // Get force vector --> magnitude * direction
- return force;
- }
-
- // Method to display
- void display() {
- ellipseMode(CENTER);
- strokeWeight(4);
- stroke(0);
- if (dragging) fill (50);
- else if (rollover) fill(100);
- else fill(175,200);
- ellipse(location.x,location.y,mass*2,mass*2);
- }
-
- // The methods below are for mouse interaction
- void clicked(int mx, int my) {
- float d = dist(mx,my,location.x,location.y);
- if (d < mass) {
- dragging = true;
- dragOffset.x = location.x-mx;
- dragOffset.y = location.y-my;
- }
- }
-
- void hover(int mx, int my) {
- float d = dist(mx,my,location.x,location.y);
- if (d < mass) {
- rollover = true;
- }
- else {
- rollover = false;
- }
- }
-
- void stopDragging() {
- dragging = false;
- }
-
-
-
- void drag() {
- if (dragging) {
- location.x = mouseX + dragOffset.x;
- location.y = mouseY + dragOffset.y;
- }
- }
-
-}
-
-
diff --git a/java/examples/Books/Nature of Code/chp2_forces/NOC_2_6_attraction/Mover.pde b/java/examples/Books/Nature of Code/chp2_forces/NOC_2_6_attraction/Mover.pde
deleted file mode 100644
index 7c35ead44..000000000
--- a/java/examples/Books/Nature of Code/chp2_forces/NOC_2_6_attraction/Mover.pde
+++ /dev/null
@@ -1,55 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-class Mover {
-
- PVector location;
- PVector velocity;
- PVector acceleration;
- float mass;
-
- Mover() {
- location = new PVector(400,50);
- velocity = new PVector(1,0);
- acceleration = new PVector(0,0);
- mass = 1;
- }
-
- void applyForce(PVector force) {
- PVector f = PVector.div(force,mass);
- acceleration.add(f);
- }
-
- void update() {
- velocity.add(acceleration);
- location.add(velocity);
- acceleration.mult(0);
- }
-
- void display() {
- stroke(0);
- strokeWeight(2);
- fill(127);
- ellipse(location.x,location.y,16,16);
- }
-
- void checkEdges() {
-
- if (location.x > width) {
- location.x = 0;
- } else if (location.x < 0) {
- location.x = width;
- }
-
- if (location.y > height) {
- velocity.y *= -1;
- location.y = height;
- }
-
- }
-
-}
-
-
-
diff --git a/java/examples/Books/Nature of Code/chp2_forces/NOC_2_6_attraction/NOC_2_6_attraction.pde b/java/examples/Books/Nature of Code/chp2_forces/NOC_2_6_attraction/NOC_2_6_attraction.pde
deleted file mode 100644
index d2ab1284a..000000000
--- a/java/examples/Books/Nature of Code/chp2_forces/NOC_2_6_attraction/NOC_2_6_attraction.pde
+++ /dev/null
@@ -1,39 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-Mover m;
-Attractor a;
-
-void setup() {
- size(640,360);
- m = new Mover();
- a = new Attractor();
-}
-
-void draw() {
- background(255);
-
- PVector force = a.attract(m);
- m.applyForce(force);
- m.update();
-
- a.drag();
- a.hover(mouseX,mouseY);
-
- a.display();
- m.display();
-}
-
-void mousePressed() {
- a.clicked(mouseX,mouseY);
-}
-
-void mouseReleased() {
- a.stopDragging();
-}
-
-
-
-
-
diff --git a/java/examples/Books/Nature of Code/chp2_forces/NOC_2_7_attraction_many/Attractor.pde b/java/examples/Books/Nature of Code/chp2_forces/NOC_2_7_attraction_many/Attractor.pde
deleted file mode 100644
index 556605cb7..000000000
--- a/java/examples/Books/Nature of Code/chp2_forces/NOC_2_7_attraction_many/Attractor.pde
+++ /dev/null
@@ -1,78 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// A class for a draggable attractive body in our world
-
-class Attractor {
- float mass; // Mass, tied to size
- float G; // Gravitational Constant
- PVector location; // Location
- boolean dragging = false; // Is the object being dragged?
- boolean rollover = false; // Is the mouse over the ellipse?
- PVector dragOffset; // holds the offset for when object is clicked on
-
- Attractor() {
- location = new PVector(width/2,height/2);
- mass = 20;
- G = 1;
- dragOffset = new PVector(0.0,0.0);
- }
-
- PVector attract(Mover m) {
- PVector force = PVector.sub(location,m.location); // Calculate direction of force
- float d = force.mag(); // Distance between objects
- d = constrain(d,5.0,25.0); // Limiting the distance to eliminate "extreme" results for very close or very far objects
- force.normalize(); // Normalize vector (distance doesn't matter here, we just want this vector for direction)
- float strength = (G * mass * m.mass) / (d * d); // Calculate gravitional force magnitude
- force.mult(strength); // Get force vector --> magnitude * direction
- return force;
- }
-
- // Method to display
- void display() {
- ellipseMode(CENTER);
- strokeWeight(4);
- stroke(0);
- if (dragging) fill (50);
- else if (rollover) fill(100);
- else fill(175,200);
- ellipse(location.x,location.y,mass*2,mass*2);
- }
-
- // The methods below are for mouse interaction
- void clicked(int mx, int my) {
- float d = dist(mx,my,location.x,location.y);
- if (d < mass) {
- dragging = true;
- dragOffset.x = location.x-mx;
- dragOffset.y = location.y-my;
- }
- }
-
- void hover(int mx, int my) {
- float d = dist(mx,my,location.x,location.y);
- if (d < mass) {
- rollover = true;
- }
- else {
- rollover = false;
- }
- }
-
- void stopDragging() {
- dragging = false;
- }
-
-
-
- void drag() {
- if (dragging) {
- location.x = mouseX + dragOffset.x;
- location.y = mouseY + dragOffset.y;
- }
- }
-
-}
-
-
diff --git a/java/examples/Books/Nature of Code/chp2_forces/NOC_2_7_attraction_many/Mover.pde b/java/examples/Books/Nature of Code/chp2_forces/NOC_2_7_attraction_many/Mover.pde
deleted file mode 100644
index 245dd0c3e..000000000
--- a/java/examples/Books/Nature of Code/chp2_forces/NOC_2_7_attraction_many/Mover.pde
+++ /dev/null
@@ -1,37 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-class Mover {
-
- PVector location;
- PVector velocity;
- PVector acceleration;
- float mass;
-
- Mover(float m, float x, float y) {
- mass = m;
- location = new PVector(x, y);
- velocity = new PVector(1, 0);
- acceleration = new PVector(0, 0);
- }
-
- void applyForce(PVector force) {
- PVector f = PVector.div(force, mass);
- acceleration.add(f);
- }
-
- void update() {
- velocity.add(acceleration);
- location.add(velocity);
- acceleration.mult(0);
- }
-
- void display() {
- stroke(0);
- strokeWeight(2);
- fill(0,100);
- ellipse(location.x, location.y, mass*25, mass*25);
- }
-}
-
diff --git a/java/examples/Books/Nature of Code/chp2_forces/NOC_2_7_attraction_many/NOC_2_7_attraction_many.pde b/java/examples/Books/Nature of Code/chp2_forces/NOC_2_7_attraction_many/NOC_2_7_attraction_many.pde
deleted file mode 100644
index e7f5b1c5b..000000000
--- a/java/examples/Books/Nature of Code/chp2_forces/NOC_2_7_attraction_many/NOC_2_7_attraction_many.pde
+++ /dev/null
@@ -1,49 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-Mover[] movers = new Mover[10];
-
-Attractor a;
-
-void setup() {
- size(800, 200);
- for (int i = 0; i < movers.length; i++) {
- movers[i] = new Mover(random(0.1, 2), random(width), random(height));
- }
- a = new Attractor();
- }
-
-void draw() {
- background(255);
-
- a.display();
- a.drag();
- a.hover(mouseX, mouseY);
-
- for (int i = 0; i < movers.length; i++) {
- PVector force = a.attract(movers[i]);
- movers[i].applyForce(force);
-
- movers[i].update();
- movers[i].display();
- }
-}
-
-void mousePressed() {
- a.clicked(mouseX, mouseY);
-}
-
-void mouseReleased() {
- a.stopDragging();
-}
-
-
-
-
-
-
-
-
-
-
diff --git a/java/examples/Books/Nature of Code/chp2_forces/NOC_2_8_mutual_attraction/Mover.pde b/java/examples/Books/Nature of Code/chp2_forces/NOC_2_8_mutual_attraction/Mover.pde
deleted file mode 100644
index 63b9dbc67..000000000
--- a/java/examples/Books/Nature of Code/chp2_forces/NOC_2_8_mutual_attraction/Mover.pde
+++ /dev/null
@@ -1,52 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-class Mover {
-
- PVector location;
- PVector velocity;
- PVector acceleration;
- float mass;
-
- Mover(float m, float x, float y) {
- mass = m;
- location = new PVector(x, y);
- velocity = new PVector(0, 0);
- acceleration = new PVector(0, 0);
- }
-
- void applyForce(PVector force) {
- PVector f = PVector.div(force, mass);
- acceleration.add(f);
- }
-
- void update() {
- velocity.add(acceleration);
- location.add(velocity);
- acceleration.mult(0);
- }
-
- void display() {
- stroke(0);
- strokeWeight(2);
- fill(0, 100);
- ellipse(location.x, location.y, mass*24, mass*24);
- }
-
- PVector attract(Mover m) {
- PVector force = PVector.sub(location, m.location); // Calculate direction of force
- float distance = force.mag(); // Distance between objects
- distance = constrain(distance, 5.0, 25.0); // Limiting the distance to eliminate "extreme" results for very close or very far objects
- force.normalize(); // Normalize vector (distance doesn't matter here, we just want this vector for direction
-
- float strength = (g * mass * m.mass) / (distance * distance); // Calculate gravitional force magnitude
- force.mult(strength); // Get force vector --> magnitude * direction
- return force;
- }
-
-
-}
-
-
-
diff --git a/java/examples/Books/Nature of Code/chp2_forces/NOC_2_8_mutual_attraction/NOC_2_8_mutual_attraction.pde b/java/examples/Books/Nature of Code/chp2_forces/NOC_2_8_mutual_attraction/NOC_2_8_mutual_attraction.pde
deleted file mode 100644
index 3a6ef45a8..000000000
--- a/java/examples/Books/Nature of Code/chp2_forces/NOC_2_8_mutual_attraction/NOC_2_8_mutual_attraction.pde
+++ /dev/null
@@ -1,45 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-Mover[] movers = new Mover[20];
-
-float g = 0.4;
-
-void setup() {
- size(800,200);
- for (int i = 0; i < movers.length; i++) {
- movers[i] = new Mover(random(0.1,2),random(width),random(height));
- }
-}
-
-void draw() {
- background(255);
-
-
- for (int i = 0; i < movers.length; i++) {
- for (int j = 0; j < movers.length; j++) {
- if (i != j) {
- PVector force = movers[j].attract(movers[i]);
- movers[i].applyForce(force);
- }
- }
-
- movers[i].update();
- movers[i].display();
- }
-
-}
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/java/examples/Books/Nature of Code/chp3_oscillation/AdditiveWave/AdditiveWave.pde b/java/examples/Books/Nature of Code/chp3_oscillation/AdditiveWave/AdditiveWave.pde
deleted file mode 100644
index 2636374b8..000000000
--- a/java/examples/Books/Nature of Code/chp3_oscillation/AdditiveWave/AdditiveWave.pde
+++ /dev/null
@@ -1,69 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Additive Wave
-// Create a more complex wave by adding two waves together.
-
-// Maybe better for this answer to be OOP???
-
-int xspacing = 8; // How far apart should each horizontal location be spaced
-int w; // Width of entire wave
-int maxwaves = 5; // total # of waves to add together
-
-float theta = 0.0;
-float[] amplitude = new float[maxwaves]; // Height of wave
-float[] dx = new float[maxwaves]; // Value for incrementing X, to be calculated as a function of period and xspacing
-float[] yvalues; // Using an array to store height values for the wave (not entirely necessary)
-
-void setup() {
- size(640,360);
- colorMode(RGB, 255, 255, 255, 100);
- w = width + 16;
-
- for (int i = 0; i < maxwaves; i++) {
- amplitude[i] = random(10,30);
- float period = random(100,300); // How many pixels before the wave repeats
- dx[i] = (TWO_PI / period) * xspacing;
- }
-
- yvalues = new float[w/xspacing];
-}
-
-void draw() {
- background(0);
- calcWave();
- renderWave();
-}
-
-void calcWave() {
- // Increment theta (try different values for 'angular velocity' here
- theta += 0.02;
-
- // Set all height values to zero
- for (int i = 0; i < yvalues.length; i++) {
- yvalues[i] = 0;
- }
-
- // Accumulate wave height values
- for (int j = 0; j < maxwaves; j++) {
- float x = theta;
- for (int i = 0; i < yvalues.length; i++) {
- // Every other wave is cosine instead of sine
- if (j % 2 == 0) yvalues[i] += sin(x)*amplitude[j];
- else yvalues[i] += cos(x)*amplitude[j];
- x+=dx[j];
- }
- }
-}
-
-void renderWave() {
- // A simple way to draw the wave with an ellipse at each location
- noStroke();
- fill(255,50);
- ellipseMode(CENTER);
- for (int x = 0; x < yvalues.length; x++) {
- ellipse(x*xspacing,height/2+yvalues[x],16,16);
- }
-}
-
diff --git a/java/examples/Books/Nature of Code/chp3_oscillation/AttractionArrayWithOscillation/AttractionArrayWithOscillation.pde b/java/examples/Books/Nature of Code/chp3_oscillation/AttractionArrayWithOscillation/AttractionArrayWithOscillation.pde
deleted file mode 100644
index 8f58c9712..000000000
--- a/java/examples/Books/Nature of Code/chp3_oscillation/AttractionArrayWithOscillation/AttractionArrayWithOscillation.pde
+++ /dev/null
@@ -1,46 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Attraction Array with Oscillating objects around each Crawler
-
-// Click and drag attractive body to move throughout space
-
-Crawler[] crawlers = new Crawler[6];
-Attractor a;
-
-void setup() {
- size(640,360);
- // Some random bodies
- for (int i = 0; i < crawlers.length; i++) {
- crawlers[i] = new Crawler();
- }
- // Create an attractive body
- a = new Attractor(new PVector(width/2,height/2),20,0.4);
-}
-
-void draw() {
- background(255);
- a.rollover(mouseX,mouseY);
- a.go();
-
- for (int i = 0; i < crawlers.length; i++) {
- // Calculate a force exerted by "attractor" on "Crawler"
- PVector f = a.attract(crawlers[i]);
- // Apply that force to the Crawler
- crawlers[i].applyForce(f);
- // Update and render
- crawlers[i].update();
- crawlers[i].display();
- }
-
-
-}
-
-void mousePressed() {
- a.clicked(mouseX,mouseY);
-}
-
-void mouseReleased() {
- a.stopDragging();
-}
diff --git a/java/examples/Books/Nature of Code/chp3_oscillation/AttractionArrayWithOscillation/Attractor.pde b/java/examples/Books/Nature of Code/chp3_oscillation/AttractionArrayWithOscillation/Attractor.pde
deleted file mode 100644
index 4e97f0cab..000000000
--- a/java/examples/Books/Nature of Code/chp3_oscillation/AttractionArrayWithOscillation/Attractor.pde
+++ /dev/null
@@ -1,82 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Attraction
-
-// A class for a draggable attractive body in our world
-
-class Attractor {
- float mass; // Mass, tied to size
- float G; // Gravitational Constant
- PVector loc; // Location
- boolean dragging = false; // Is the object being dragged?
- boolean rollover = false; // Is the mouse over the ellipse?
- PVector drag; // holds the offset for when object is clicked on
-
- Attractor(PVector l_,float m_, float g_) {
- loc = l_.get();
- mass = m_;
- G = g_;
- drag = new PVector(0.0,0.0);
- }
-
- void go() {
- render();
- drag();
- }
-
- PVector attract(Crawler c) {
- PVector dir = PVector.sub(loc,c.loc); // Calculate direction of force
- float d = dir.mag(); // Distance between objects
- d = constrain(d,5.0,25.0); // Limiting the distance to eliminate "extreme" results for very close or very far objects
- dir.normalize(); // Normalize vector (distance doesn't matter here, we just want this vector for direction)
- float force = (G * mass * c.mass) / (d * d); // Calculate gravitional force magnitude
- dir.mult(force); // Get force vector --> magnitude * direction
- return dir;
- }
-
- // Method to display
- void render() {
- ellipseMode(CENTER);
- stroke(0,100);
- if (dragging) fill (50);
- else if (rollover) fill(100);
- else fill(175,50);
- ellipse(loc.x,loc.y,mass*2,mass*2);
- }
-
- // The methods below are for mouse interaction
- void clicked(int mx, int my) {
- float d = dist(mx,my,loc.x,loc.y);
- if (d < mass) {
- dragging = true;
- drag.x = loc.x-mx;
- drag.y = loc.y-my;
- }
- }
-
- void rollover(int mx, int my) {
- float d = dist(mx,my,loc.x,loc.y);
- if (d < mass) {
- rollover = true;
- } else {
- rollover = false;
- }
- }
-
- void stopDragging() {
- dragging = false;
- }
-
-
-
- void drag() {
- if (dragging) {
- loc.x = mouseX + drag.x;
- loc.y = mouseY + drag.y;
- }
- }
-
-}
-
diff --git a/java/examples/Books/Nature of Code/chp3_oscillation/AttractionArrayWithOscillation/Crawler.pde b/java/examples/Books/Nature of Code/chp3_oscillation/AttractionArrayWithOscillation/Crawler.pde
deleted file mode 100644
index 7c03641ee..000000000
--- a/java/examples/Books/Nature of Code/chp3_oscillation/AttractionArrayWithOscillation/Crawler.pde
+++ /dev/null
@@ -1,58 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Attraction
-
-// A class to describe a thing in our world, has vectors for location, velocity, and acceleration
-// Also includes scalar values for mass, maximum velocity, and elasticity
-
-class Crawler {
- PVector loc;
- PVector vel;
- PVector acc;
- float mass;
-
- Oscillator osc;
-
- Crawler() {
- acc = new PVector();
- vel = new PVector(random(-1,1),random(-1,1));
- loc = new PVector(random(width),random(height));
- mass = random(8,16);
- osc = new Oscillator(mass*2);
- }
-
- void applyForce(PVector force) {
- PVector f = force.get();
- f.div(mass);
- acc.add(f);
- }
-
- // Method to update location
- void update() {
- vel.add(acc);
- loc.add(vel);
- // Multiplying by 0 sets the all the components to 0
- acc.mult(0);
-
- osc.update(vel.mag()/10);
- }
-
- // Method to display
- void display() {
- float angle = vel.heading2D();
- pushMatrix();
- translate(loc.x,loc.y);
- rotate(angle);
- ellipseMode(CENTER);
- stroke(0);
- fill(175,100);
- ellipse(0,0,mass*2,mass*2);
-
- osc.display(loc);
- popMatrix();
-
- }
-}
-
diff --git a/java/examples/Books/Nature of Code/chp3_oscillation/AttractionArrayWithOscillation/Oscillator.pde b/java/examples/Books/Nature of Code/chp3_oscillation/AttractionArrayWithOscillation/Oscillator.pde
deleted file mode 100644
index 2f4d4506d..000000000
--- a/java/examples/Books/Nature of Code/chp3_oscillation/AttractionArrayWithOscillation/Oscillator.pde
+++ /dev/null
@@ -1,37 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Attraction Array with Oscillating objects around each thing
-
-class Oscillator {
-
- // Because we are going to oscillate along the x and y axis we can use PVector for two angles, amplitudes, etc.!
- float theta;
- float amplitude;
-
- Oscillator(float r) {
-
- // Initialize randomly
- theta = 0;
- amplitude = r;
-
- }
-
- // Update theta and offset
- void update(float thetaVel) {
- theta += thetaVel;
- }
-
- // Display based on a location
- void display(PVector loc) {
- float x = map(cos(theta),-1,1,0,amplitude);
-
- stroke(0);
- fill(50);
- line(0,0,x,0);
- ellipse(x,0,8,8);
- }
-}
-
-
diff --git a/java/examples/Books/Nature of Code/chp3_oscillation/Exercise_3_01_exercise_baton/Exercise_3_01_exercise_baton.pde b/java/examples/Books/Nature of Code/chp3_oscillation/Exercise_3_01_exercise_baton/Exercise_3_01_exercise_baton.pde
deleted file mode 100644
index 590ea83ab..000000000
--- a/java/examples/Books/Nature of Code/chp3_oscillation/Exercise_3_01_exercise_baton/Exercise_3_01_exercise_baton.pde
+++ /dev/null
@@ -1,28 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-float angle = 0;
-
-void setup() {
- size(750, 150);
- smooth();
-}
-
-void draw() {
- background(255);
-
- fill(127);
- stroke(0);
- rectMode(CENTER);
- translate(width/2, height/2);
- rotate(angle);
- line(-50, 0, 50, 0);
- stroke(0);
- strokeWeight(2);
- fill(127);
- ellipse(50, 0, 16, 16);
- ellipse(-50, 0, 16, 16);
- angle += 0.05;
-}
-
diff --git a/java/examples/Books/Nature of Code/chp3_oscillation/Exercise_3_03_cannon/CannonBall.pde b/java/examples/Books/Nature of Code/chp3_oscillation/Exercise_3_03_cannon/CannonBall.pde
deleted file mode 100644
index 80a9ca8ba..000000000
--- a/java/examples/Books/Nature of Code/chp3_oscillation/Exercise_3_03_cannon/CannonBall.pde
+++ /dev/null
@@ -1,44 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-class CannonBall {
- // All of our regular motion stuff
- PVector location;
- PVector velocity;
- PVector acceleration;
-
- // Size
- float r = 8;
-
- float topspeed = 10;
-
- CannonBall(float x, float y) {
- location = new PVector(x,y);
- velocity = new PVector();
- acceleration = new PVector();
- }
-
- // Standard Euler integration
- void update() {
- velocity.add(acceleration);
- velocity.limit(topspeed);
- location.add(velocity);
- acceleration.mult(0);
- }
-
- void applyForce(PVector force) {
- acceleration.add(force);
- }
-
-
- void display() {
- stroke(0);
- strokeWeight(2);
- pushMatrix();
- translate(location.x,location.y);
- ellipse(0,0,r*2,r*2);
- popMatrix();
- }
-}
-
diff --git a/java/examples/Books/Nature of Code/chp3_oscillation/Exercise_3_03_cannon/Exercise_3_03_cannon.pde b/java/examples/Books/Nature of Code/chp3_oscillation/Exercise_3_03_cannon/Exercise_3_03_cannon.pde
deleted file mode 100644
index 72313eaa9..000000000
--- a/java/examples/Books/Nature of Code/chp3_oscillation/Exercise_3_03_cannon/Exercise_3_03_cannon.pde
+++ /dev/null
@@ -1,54 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-
-// All of this stuff should go into a Cannon class
-float angle = -PI/4;
-PVector location = new PVector(50, 300);
-boolean shot = false;
-
-CannonBall ball;
-
-void setup() {
- size(640, 360);
- ball = new CannonBall(location.x, location.y);
-}
-
-void draw() {
- background(255);
-
- pushMatrix();
- translate(location.x, location.y);
- rotate(angle);
- rect(0, -5, 50, 10);
- popMatrix();
-
- if (shot) {
- PVector gravity = new PVector(0, 0.2);
- ball.applyForce(gravity);
- ball.update();
- }
- ball.display();
-
- if (ball.location.y > height) {
- ball = new CannonBall(location.x, location.y);
- shot = false;
- }
-}
-
-void keyPressed() {
- if (key == CODED && keyCode == RIGHT) {
- angle += 0.1;
- }
- else if (key == CODED && keyCode == LEFT) {
- angle -= 0.1;
- }
- else if (key == ' ') {
- shot = true;
- PVector force = PVector.fromAngle(angle);
- force.mult(10);
- ball.applyForce(force);
- }
-}
-
diff --git a/java/examples/Books/Nature of Code/chp3_oscillation/Exercise_3_04_spiral/Exercise_3_04_spiral.pde b/java/examples/Books/Nature of Code/chp3_oscillation/Exercise_3_04_spiral/Exercise_3_04_spiral.pde
deleted file mode 100644
index 90b7fea95..000000000
--- a/java/examples/Books/Nature of Code/chp3_oscillation/Exercise_3_04_spiral/Exercise_3_04_spiral.pde
+++ /dev/null
@@ -1,30 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// A Polar coordinate, radius now starts at 0 to spiral outwards
-float r = 0;
-float theta = 0;
-
-void setup() {
- size(750,200);
- background(255);
- smooth();
-}
-
-void draw() {
- // Polar to Cartesian conversion
- float x = r * cos(theta);
- float y = r * sin(theta);
-
- // Draw an ellipse at x,y
- noStroke();
- fill(0);
- // Adjust for center of window
- ellipse(x+width/2, y+height/2, 16, 16);
-
- // Increment the angle
- theta += 0.01;
- // Increment the radius
- r += 0.05;
-}
diff --git a/java/examples/Books/Nature of Code/chp3_oscillation/Exercise_3_05_asteroids/Exercise_3_05_asteroids.pde b/java/examples/Books/Nature of Code/chp3_oscillation/Exercise_3_05_asteroids/Exercise_3_05_asteroids.pde
deleted file mode 100644
index d0340916f..000000000
--- a/java/examples/Books/Nature of Code/chp3_oscillation/Exercise_3_05_asteroids/Exercise_3_05_asteroids.pde
+++ /dev/null
@@ -1,41 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Chapter 3: Asteroids exercise
-
-// Mover object
-Spaceship ship;
-
-void setup() {
- size(640, 360);
- ship = new Spaceship();
-}
-
-void draw() {
- background(255);
-
- // Update location
- ship.update();
- // Wrape edges
- ship.wrapEdges();
- // Draw ship
- ship.display();
-
-
- fill(0);
- //text("left right arrows to turn, z to thrust",10,height-5);
-
- // Turn or thrust the ship depending on what key is pressed
- if (keyPressed) {
- if (key == CODED && keyCode == LEFT) {
- ship.turn(-0.03);
- } else if (key == CODED && keyCode == RIGHT) {
- ship.turn(0.03);
- } else if (key == 'z' || key == 'Z') {
- ship.thrust();
- }
- }
-}
-
-
diff --git a/java/examples/Books/Nature of Code/chp3_oscillation/Exercise_3_05_asteroids/Spaceship.pde b/java/examples/Books/Nature of Code/chp3_oscillation/Exercise_3_05_asteroids/Spaceship.pde
deleted file mode 100644
index 3a8682da7..000000000
--- a/java/examples/Books/Nature of Code/chp3_oscillation/Exercise_3_05_asteroids/Spaceship.pde
+++ /dev/null
@@ -1,99 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Chapter 3: Asteroids
-
-class Spaceship {
- // All of our regular motion stuff
- PVector location;
- PVector velocity;
- PVector acceleration;
-
- // Arbitrary damping to slow down ship
- float damping = 0.995;
- float topspeed = 6;
-
- // Variable for heading!
- float heading = 0;
-
- // Size
- float r = 16;
-
- // Are we thrusting (to color boosters)
- boolean thrusting = false;
-
- Spaceship() {
- location = new PVector(width/2,height/2);
- velocity = new PVector();
- acceleration = new PVector();
- }
-
- // Standard Euler integration
- void update() {
- velocity.add(acceleration);
- velocity.mult(damping);
- velocity.limit(topspeed);
- location.add(velocity);
- acceleration.mult(0);
- }
-
- // Newton's law: F = M * A
- void applyForce(PVector force) {
- PVector f = force.get();
- //f.div(mass); // ignoring mass right now
- acceleration.add(f);
- }
-
- // Turn changes angle
- void turn(float a) {
- heading += a;
- }
-
- // Apply a thrust force
- void thrust() {
- // Offset the angle since we drew the ship vertically
- float angle = heading - PI/2;
- // Polar to cartesian for force vector!
- PVector force = new PVector(cos(angle),sin(angle));
- force.mult(0.1);
- applyForce(force);
- // To draw booster
- thrusting = true;
- }
-
- void wrapEdges() {
- float buffer = r*2;
- if (location.x > width + buffer) location.x = -buffer;
- else if (location.x < -buffer) location.x = width+buffer;
- if (location.y > height + buffer) location.y = -buffer;
- else if (location.y < -buffer) location.y = height+buffer;
- }
-
-
- // Draw the ship
- void display() {
- stroke(0);
- strokeWeight(2);
- pushMatrix();
- translate(location.x,location.y+r);
- rotate(heading);
- fill(175);
- if (thrusting) fill(255,0,0);
- // Booster rockets
- rect(-r/2,r,r/3,r/2);
- rect(r/2,r,r/3,r/2);
- fill(175);
- // A triangle
- beginShape();
- vertex(-r,r);
- vertex(0,-r);
- vertex(r,r);
- endShape(CLOSE);
- rectMode(CENTER);
- popMatrix();
-
- thrusting = false;
- }
-}
-
diff --git a/java/examples/Books/Nature of Code/chp3_oscillation/Exercise_3_10_OOPWave/Exercise_3_10_OOPWave.pde b/java/examples/Books/Nature of Code/chp3_oscillation/Exercise_3_10_OOPWave/Exercise_3_10_OOPWave.pde
deleted file mode 100644
index f8b759970..000000000
--- a/java/examples/Books/Nature of Code/chp3_oscillation/Exercise_3_10_OOPWave/Exercise_3_10_OOPWave.pde
+++ /dev/null
@@ -1,32 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Sine Wave
-
-// Two wave objects
-Wave wave0;
-Wave wave1;
-
-void setup() {
- size(750,200);
- // Initialize a wave with starting point, width, amplitude, and period
- wave0 = new Wave(new PVector(50,75),100,20,500);
- wave1 = new Wave(new PVector(300,100),300,40,220);
-
-}
-
-void draw() {
- background(255);
-
- // Update and display waves
- wave0.calculate();
- wave0.display();
-
- wave1.calculate();
- wave1.display();
-
-
-}
-
-
diff --git a/java/examples/Books/Nature of Code/chp3_oscillation/Exercise_3_10_OOPWave/Wave.pde b/java/examples/Books/Nature of Code/chp3_oscillation/Exercise_3_10_OOPWave/Wave.pde
deleted file mode 100644
index df88f7cd0..000000000
--- a/java/examples/Books/Nature of Code/chp3_oscillation/Exercise_3_10_OOPWave/Wave.pde
+++ /dev/null
@@ -1,49 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-class Wave {
-
- int xspacing = 8; // How far apart should each horizontal location be spaced
- int w; // Width of entire wave
-
- PVector origin; // Where does the wave's first point start
- float theta = 0.0; // Start angle at 0
- float amplitude; // Height of wave
- float period; // How many pixels before the wave repeats
- float dx; // Value for incrementing X, to be calculated as a function of period and xspacing
- float[] yvalues; // Using an array to store height values for the wave (not entirely necessary)
-
- Wave(PVector o, int w_, float a, float p) {
- origin = o.get();
- w = w_;
- period = p;
- amplitude = a;
- dx = (TWO_PI / period) * xspacing;
- yvalues = new float[w/xspacing];
- }
-
-
- void calculate() {
- // Increment theta (try different values for 'angular velocity' here
- theta += 0.02;
-
- // For every x value, calculate a y value with sine function
- float x = theta;
- for (int i = 0; i < yvalues.length; i++) {
- yvalues[i] = sin(x)*amplitude;
- x+=dx;
- }
- }
-
- void display() {
- // A simple way to draw the wave with an ellipse at each location
- for (int x = 0; x < yvalues.length; x++) {
- stroke(0);
- fill(0,50);
- ellipseMode(CENTER);
- ellipse(origin.x+x*xspacing,origin.y+yvalues[x],48,48);
- }
- }
-}
-
diff --git a/java/examples/Books/Nature of Code/chp3_oscillation/Exercise_3_11_AdditiveWave/Exercise_3_11_AdditiveWave.pde b/java/examples/Books/Nature of Code/chp3_oscillation/Exercise_3_11_AdditiveWave/Exercise_3_11_AdditiveWave.pde
deleted file mode 100644
index ccf0975a3..000000000
--- a/java/examples/Books/Nature of Code/chp3_oscillation/Exercise_3_11_AdditiveWave/Exercise_3_11_AdditiveWave.pde
+++ /dev/null
@@ -1,66 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Additive Wave
-// Create a more complex wave by adding two waves together.
-
-int xspacing = 8; // How far apart should each horizontal location be spaced
-int w; // Width of entire wave
-int maxwaves = 5; // total # of waves to add together
-
-float theta = 0.0;
-float[] amplitude = new float[maxwaves]; // Height of wave
-float[] dx = new float[maxwaves]; // Value for incrementing X, to be calculated as a function of period and xspacing
-float[] yvalues; // Using an array to store height values for the wave (not entirely necessary)
-
-void setup() {
- size(750,200);
- w = width + 16;
-
- for (int i = 0; i < maxwaves; i++) {
- amplitude[i] = random(10,30);
- float period = random(100,300); // How many pixels before the wave repeats
- dx[i] = (TWO_PI / period) * xspacing;
- }
-
- yvalues = new float[w/xspacing];
-}
-
-void draw() {
- background(255);
- calcWave();
- renderWave();
-}
-
-void calcWave() {
- // Increment theta (try different values for 'angular velocity' here
- theta += 0.02;
-
- // Set all height values to zero
- for (int i = 0; i < yvalues.length; i++) {
- yvalues[i] = 0;
- }
-
- // Accumulate wave height values
- for (int j = 0; j < maxwaves; j++) {
- float x = theta;
- for (int i = 0; i < yvalues.length; i++) {
- // Every other wave is cosine instead of sine
- if (j % 2 == 0) yvalues[i] += sin(x)*amplitude[j];
- else yvalues[i] += cos(x)*amplitude[j];
- x+=dx[j];
- }
- }
-}
-
-void renderWave() {
- // A simple way to draw the wave with an ellipse at each location
- stroke(0);
- fill(127,50);
- ellipseMode(CENTER);
- for (int x = 0; x < yvalues.length; x++) {
- ellipse(x*xspacing,height/2+yvalues[x],48,48);
- }
-}
-
diff --git a/java/examples/Books/Nature of Code/chp3_oscillation/Exercise_3_16_springs/Exercise_3_16_springs.pde b/java/examples/Books/Nature of Code/chp3_oscillation/Exercise_3_16_springs/Exercise_3_16_springs.pde
deleted file mode 100644
index 9f0d74795..000000000
--- a/java/examples/Books/Nature of Code/chp3_oscillation/Exercise_3_16_springs/Exercise_3_16_springs.pde
+++ /dev/null
@@ -1,57 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Mover object
-Bob b1;
-Bob b2;
-Bob b3;
-
-Spring s1;
-Spring s2;
-Spring s3;
-
-void setup() {
- size(640, 360);
- // Create objects at starting location
- // Note third argument in Spring constructor is "rest length"
- b1 = new Bob(width/2, 100);
- b2 = new Bob(width/2, 200);
- b3 = new Bob(width/2, 300);
-
- s1 = new Spring(b1,b2,100);
- s2 = new Spring(b2,b3,100);
- s3 = new Spring(b1,b3,100);
-}
-
-void draw() {
- background(255);
-
- s1.update();
- s2.update();
- s3.update();
-
- s1.display();
- s2.display();
- s3.display();
-
- b1.update();
- b1.display();
- b2.update();
- b2.display();
- b3.update();
- b3.display();
-
- b1.drag(mouseX, mouseY);
-}
-
-
-
-void mousePressed() {
- b1.clicked(mouseX, mouseY);
-}
-
-void mouseReleased() {
- b1.stopDragging();
-}
-
diff --git a/java/examples/Books/Nature of Code/chp3_oscillation/Exercise_3_16_springs/Mover.pde b/java/examples/Books/Nature of Code/chp3_oscillation/Exercise_3_16_springs/Mover.pde
deleted file mode 100644
index 368aa20d2..000000000
--- a/java/examples/Books/Nature of Code/chp3_oscillation/Exercise_3_16_springs/Mover.pde
+++ /dev/null
@@ -1,78 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Bob class, just like our regular Mover (location, velocity, acceleration, mass)
-
-class Bob {
- PVector location;
- PVector velocity;
- PVector acceleration;
- float mass = 12;
-
- // Arbitrary damping to simulate friction / drag
- float damping = 0.95;
-
- // For mouse interaction
- PVector dragOffset;
- boolean dragging = false;
-
- // Constructor
- Bob(float x, float y) {
- location = new PVector(x,y);
- velocity = new PVector();
- acceleration = new PVector();
- dragOffset = new PVector();
- }
-
- // Standard Euler integration
- void update() {
- velocity.add(acceleration);
- velocity.mult(damping);
- location.add(velocity);
- acceleration.mult(0);
- }
-
- // Newton's law: F = M * A
- void applyForce(PVector force) {
- PVector f = force.get();
- f.div(mass);
- acceleration.add(f);
- }
-
-
- // Draw the bob
- void display() {
- stroke(0);
- strokeWeight(2);
- fill(175);
- if (dragging) {
- fill(50);
- }
- ellipse(location.x,location.y,mass*2,mass*2);
- }
-
- // The methods below are for mouse interaction
-
- // This checks to see if we clicked on the mover
- void clicked(int mx, int my) {
- float d = dist(mx,my,location.x,location.y);
- if (d < mass) {
- dragging = true;
- dragOffset.x = location.x-mx;
- dragOffset.y = location.y-my;
- }
- }
-
- void stopDragging() {
- dragging = false;
- }
-
- void drag(int mx, int my) {
- if (dragging) {
- location.x = mx + dragOffset.x;
- location.y = my + dragOffset.y;
- }
- }
-}
-
diff --git a/java/examples/Books/Nature of Code/chp3_oscillation/Exercise_3_16_springs/Spring.pde b/java/examples/Books/Nature of Code/chp3_oscillation/Exercise_3_16_springs/Spring.pde
deleted file mode 100644
index 0f4060e13..000000000
--- a/java/examples/Books/Nature of Code/chp3_oscillation/Exercise_3_16_springs/Spring.pde
+++ /dev/null
@@ -1,52 +0,0 @@
-// Nature of Code 2011
-// Daniel Shiffman
-// Chapter 3: Oscillation
-
-// Class to describe an anchor point that can connect to "Bob" objects via a spring
-// Thank you: http://www.myphysicslab.com/spring2d.html
-
-class Spring {
-
- // Location
- PVector anchor;
-
- // Rest length and spring constant
- float len;
- float k = 0.2;
-
- Bob a;
- Bob b;
-
- // Constructor
- Spring(Bob a_, Bob b_, int l) {
- a = a_;
- b = b_;
- len = l;
- }
-
- // Calculate spring force
- void update() {
- // Vector pointing from anchor to bob location
- PVector force = PVector.sub(a.location, b.location);
- // What is distance
- float d = force.mag();
- // Stretch is difference between current distance and rest length
- float stretch = d - len;
-
- // Calculate force according to Hooke's Law
- // F = k * stretch
- force.normalize();
- force.mult(-1 * k * stretch);
- a.applyForce(force);
- force.mult(-1);
- b.applyForce(force);
- }
-
-
- void display() {
- strokeWeight(2);
- stroke(0);
- line(a.location.x, a.location.y, b.location.x, b.location.y);
- }
-}
-
diff --git a/java/examples/Books/Nature of Code/chp3_oscillation/Exercise_3_16_springs_array/Exercise_3_16_springs_array.pde b/java/examples/Books/Nature of Code/chp3_oscillation/Exercise_3_16_springs_array/Exercise_3_16_springs_array.pde
deleted file mode 100644
index 01a0bcad4..000000000
--- a/java/examples/Books/Nature of Code/chp3_oscillation/Exercise_3_16_springs_array/Exercise_3_16_springs_array.pde
+++ /dev/null
@@ -1,50 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Mover object
-Bob[] bobs = new Bob[5];
-
-Spring[] springs = new Spring[4];
-
-void setup() {
- size(640, 360);
- // Create objects at starting location
- // Note third argument in Spring constructor is "rest length"
- for (int i = 0; i < bobs.length; i++) {
- bobs[i] = new Bob(width/2, i*40);
- }
- for (int i = 0; i < springs.length; i++) {
- springs[i] = new Spring(bobs[i], bobs[i+1],40);
- }
-}
-
-void draw() {
- background(255);
-
- for (Spring s : springs) {
- s.update();
- s.display();
- }
-
- for (Bob b : bobs) {
- b.update();
- b.display();
- b.drag(mouseX, mouseY);
- }
-}
-
-
-
-void mousePressed() {
- for (Bob b : bobs) {
- b.clicked(mouseX, mouseY);
- }
-}
-
-void mouseReleased() {
- for (Bob b : bobs) {
- b.stopDragging();
- }
-}
-
diff --git a/java/examples/Books/Nature of Code/chp3_oscillation/Exercise_3_16_springs_array/Mover.pde b/java/examples/Books/Nature of Code/chp3_oscillation/Exercise_3_16_springs_array/Mover.pde
deleted file mode 100644
index 7f5e0fcc5..000000000
--- a/java/examples/Books/Nature of Code/chp3_oscillation/Exercise_3_16_springs_array/Mover.pde
+++ /dev/null
@@ -1,78 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Bob class, just like our regular Mover (location, velocity, acceleration, mass)
-
-class Bob {
- PVector location;
- PVector velocity;
- PVector acceleration;
- float mass = 8;
-
- // Arbitrary damping to simulate friction / drag
- float damping = 0.95;
-
- // For mouse interaction
- PVector dragOffset;
- boolean dragging = false;
-
- // Constructor
- Bob(float x, float y) {
- location = new PVector(x,y);
- velocity = new PVector();
- acceleration = new PVector();
- dragOffset = new PVector();
- }
-
- // Standard Euler integration
- void update() {
- velocity.add(acceleration);
- velocity.mult(damping);
- location.add(velocity);
- acceleration.mult(0);
- }
-
- // Newton's law: F = M * A
- void applyForce(PVector force) {
- PVector f = force.get();
- f.div(mass);
- acceleration.add(f);
- }
-
-
- // Draw the bob
- void display() {
- stroke(0);
- strokeWeight(2);
- fill(175,120);
- if (dragging) {
- fill(50);
- }
- ellipse(location.x,location.y,mass*2,mass*2);
- }
-
- // The methods below are for mouse interaction
-
- // This checks to see if we clicked on the mover
- void clicked(int mx, int my) {
- float d = dist(mx,my,location.x,location.y);
- if (d < mass) {
- dragging = true;
- dragOffset.x = location.x-mx;
- dragOffset.y = location.y-my;
- }
- }
-
- void stopDragging() {
- dragging = false;
- }
-
- void drag(int mx, int my) {
- if (dragging) {
- location.x = mx + dragOffset.x;
- location.y = my + dragOffset.y;
- }
- }
-}
-
diff --git a/java/examples/Books/Nature of Code/chp3_oscillation/Exercise_3_16_springs_array/Spring.pde b/java/examples/Books/Nature of Code/chp3_oscillation/Exercise_3_16_springs_array/Spring.pde
deleted file mode 100644
index 0f4060e13..000000000
--- a/java/examples/Books/Nature of Code/chp3_oscillation/Exercise_3_16_springs_array/Spring.pde
+++ /dev/null
@@ -1,52 +0,0 @@
-// Nature of Code 2011
-// Daniel Shiffman
-// Chapter 3: Oscillation
-
-// Class to describe an anchor point that can connect to "Bob" objects via a spring
-// Thank you: http://www.myphysicslab.com/spring2d.html
-
-class Spring {
-
- // Location
- PVector anchor;
-
- // Rest length and spring constant
- float len;
- float k = 0.2;
-
- Bob a;
- Bob b;
-
- // Constructor
- Spring(Bob a_, Bob b_, int l) {
- a = a_;
- b = b_;
- len = l;
- }
-
- // Calculate spring force
- void update() {
- // Vector pointing from anchor to bob location
- PVector force = PVector.sub(a.location, b.location);
- // What is distance
- float d = force.mag();
- // Stretch is difference between current distance and rest length
- float stretch = d - len;
-
- // Calculate force according to Hooke's Law
- // F = k * stretch
- force.normalize();
- force.mult(-1 * k * stretch);
- a.applyForce(force);
- force.mult(-1);
- b.applyForce(force);
- }
-
-
- void display() {
- strokeWeight(2);
- stroke(0);
- line(a.location.x, a.location.y, b.location.x, b.location.y);
- }
-}
-
diff --git a/java/examples/Books/Nature of Code/chp3_oscillation/ExtraOscillatingBody/Attractor.pde b/java/examples/Books/Nature of Code/chp3_oscillation/ExtraOscillatingBody/Attractor.pde
deleted file mode 100644
index 556605cb7..000000000
--- a/java/examples/Books/Nature of Code/chp3_oscillation/ExtraOscillatingBody/Attractor.pde
+++ /dev/null
@@ -1,78 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// A class for a draggable attractive body in our world
-
-class Attractor {
- float mass; // Mass, tied to size
- float G; // Gravitational Constant
- PVector location; // Location
- boolean dragging = false; // Is the object being dragged?
- boolean rollover = false; // Is the mouse over the ellipse?
- PVector dragOffset; // holds the offset for when object is clicked on
-
- Attractor() {
- location = new PVector(width/2,height/2);
- mass = 20;
- G = 1;
- dragOffset = new PVector(0.0,0.0);
- }
-
- PVector attract(Mover m) {
- PVector force = PVector.sub(location,m.location); // Calculate direction of force
- float d = force.mag(); // Distance between objects
- d = constrain(d,5.0,25.0); // Limiting the distance to eliminate "extreme" results for very close or very far objects
- force.normalize(); // Normalize vector (distance doesn't matter here, we just want this vector for direction)
- float strength = (G * mass * m.mass) / (d * d); // Calculate gravitional force magnitude
- force.mult(strength); // Get force vector --> magnitude * direction
- return force;
- }
-
- // Method to display
- void display() {
- ellipseMode(CENTER);
- strokeWeight(4);
- stroke(0);
- if (dragging) fill (50);
- else if (rollover) fill(100);
- else fill(175,200);
- ellipse(location.x,location.y,mass*2,mass*2);
- }
-
- // The methods below are for mouse interaction
- void clicked(int mx, int my) {
- float d = dist(mx,my,location.x,location.y);
- if (d < mass) {
- dragging = true;
- dragOffset.x = location.x-mx;
- dragOffset.y = location.y-my;
- }
- }
-
- void hover(int mx, int my) {
- float d = dist(mx,my,location.x,location.y);
- if (d < mass) {
- rollover = true;
- }
- else {
- rollover = false;
- }
- }
-
- void stopDragging() {
- dragging = false;
- }
-
-
-
- void drag() {
- if (dragging) {
- location.x = mouseX + dragOffset.x;
- location.y = mouseY + dragOffset.y;
- }
- }
-
-}
-
-
diff --git a/java/examples/Books/Nature of Code/chp3_oscillation/ExtraOscillatingBody/ExtraOscillatingBody.pde b/java/examples/Books/Nature of Code/chp3_oscillation/ExtraOscillatingBody/ExtraOscillatingBody.pde
deleted file mode 100644
index 25f1b1ca5..000000000
--- a/java/examples/Books/Nature of Code/chp3_oscillation/ExtraOscillatingBody/ExtraOscillatingBody.pde
+++ /dev/null
@@ -1,40 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-Mover m;
-Attractor a;
-
-void setup() {
- size(640,360);
- m = new Mover();
- a = new Attractor();
-}
-
-void draw() {
- background(255);
-
- PVector force = a.attract(m);
- m.applyForce(force);
- m.update();
-
- a.drag();
- a.hover(mouseX,mouseY);
-
- a.display();
- m.display();
-
-}
-
-void mousePressed() {
- a.clicked(mouseX,mouseY);
-}
-
-void mouseReleased() {
- a.stopDragging();
-}
-
-
-
-
-
diff --git a/java/examples/Books/Nature of Code/chp3_oscillation/ExtraOscillatingBody/Mover.pde b/java/examples/Books/Nature of Code/chp3_oscillation/ExtraOscillatingBody/Mover.pde
deleted file mode 100644
index 00850bc1c..000000000
--- a/java/examples/Books/Nature of Code/chp3_oscillation/ExtraOscillatingBody/Mover.pde
+++ /dev/null
@@ -1,64 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-class Mover {
-
- PVector location;
- PVector velocity;
- PVector acceleration;
- float mass;
-
- Mover() {
- location = new PVector(400,50);
- velocity = new PVector(1,0);
- acceleration = new PVector(0,0);
- mass = 1;
- }
-
- void applyForce(PVector force) {
- PVector f = PVector.div(force,mass);
- acceleration.add(f);
- }
-
- void update() {
- velocity.add(acceleration);
- location.add(velocity);
- acceleration.mult(0);
- }
-
- void display() {
- stroke(0);
- strokeWeight(2);
- fill(127);
- pushMatrix();
- translate(location.x,location.y);
- float heading = velocity.heading();
- rotate(heading);
- ellipse(0,0,16,16);
- rectMode(CENTER);
- // "20" should be a variable that is oscillating
- // with sine function
- rect(20,0,10,10);
- popMatrix();
- }
-
- void checkEdges() {
-
- if (location.x > width) {
- location.x = 0;
- } else if (location.x < 0) {
- location.x = width;
- }
-
- if (location.y > height) {
- velocity.y *= -1;
- location.y = height;
- }
-
- }
-
-}
-
-
-
diff --git a/java/examples/Books/Nature of Code/chp3_oscillation/ExtraOscillatingUpAndDown/ExtraOscillatingUpAndDown.pde b/java/examples/Books/Nature of Code/chp3_oscillation/ExtraOscillatingUpAndDown/ExtraOscillatingUpAndDown.pde
deleted file mode 100644
index 68b1b2074..000000000
--- a/java/examples/Books/Nature of Code/chp3_oscillation/ExtraOscillatingUpAndDown/ExtraOscillatingUpAndDown.pde
+++ /dev/null
@@ -1,15 +0,0 @@
-float angle = 0;
-void setup() {
- size(400,400);
-}
-
-void draw() {
- background(255);
- float y = 100*sin(angle);
- angle += 0.02;
-
- fill(127);
- translate(width/2,height/2);
- line(0,0,0,y);
- ellipse(0,y,16,16);
-}
diff --git a/java/examples/Books/Nature of Code/chp3_oscillation/MultipleOscillations/MultipleOscillations.pde b/java/examples/Books/Nature of Code/chp3_oscillation/MultipleOscillations/MultipleOscillations.pde
deleted file mode 100644
index 4a53d917f..000000000
--- a/java/examples/Books/Nature of Code/chp3_oscillation/MultipleOscillations/MultipleOscillations.pde
+++ /dev/null
@@ -1,34 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-float angle1 = 0;
-float aVelocity1 = 0.01;
-float amplitude1 = 300;
-
-float angle2 = 0;
-float aVelocity2 = 0.3;
-float amplitude2 = 10;
-
-
-void setup() {
- size(640,360);
-}
-
-void draw() {
- background(255);
-
- float x = 0;
- x += amplitude1 * cos(angle1);
- x += amplitude2 * sin(angle2);
-
- angle1 += aVelocity1;
- angle2 += aVelocity2;
-
- ellipseMode(CENTER);
- stroke(0);
- fill(175);
- translate(width/2,height/2);
- line(0,0,x,0);
- ellipse(x,0,20,20);
-}
diff --git a/java/examples/Books/Nature of Code/chp3_oscillation/NOC_03spring_exercise_sine/NOC_03spring_exercise_sine.pde b/java/examples/Books/Nature of Code/chp3_oscillation/NOC_03spring_exercise_sine/NOC_03spring_exercise_sine.pde
deleted file mode 100644
index 4645efce7..000000000
--- a/java/examples/Books/Nature of Code/chp3_oscillation/NOC_03spring_exercise_sine/NOC_03spring_exercise_sine.pde
+++ /dev/null
@@ -1,25 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-float angle = 0;
-float aVelocity = 0.05;
-
-void setup() {
- size(640,360);
- smooth();
-}
-
-void draw() {
- background(255);
-
- float x = width/2;
- float y = map(sin(angle),-1,1,50,250);
- angle += aVelocity;
-
- ellipseMode(CENTER);
- stroke(0);
- fill(175);
- line(x,0,x,y);
- ellipse(x,y,20,20);
-}
diff --git a/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_01_angular_motion/NOC_3_01_angular_motion.pde b/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_01_angular_motion/NOC_3_01_angular_motion.pde
deleted file mode 100644
index e36c11dd8..000000000
--- a/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_01_angular_motion/NOC_3_01_angular_motion.pde
+++ /dev/null
@@ -1,34 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-float angle = 0;
-float aVelocity = 0;
-float aAcceleration = 0.0001;
-
-void setup() {
- size(800, 200);
- smooth();
-}
-
-void draw() {
- background(255);
-
-
- fill(127);
- stroke(0);
-
- translate(width/2, height/2);
- rectMode(CENTER);
- rotate(angle);
- stroke(0);
- strokeWeight(2);
- fill(127);
- line(-60, 0, 60, 0);
- ellipse(60, 0, 16, 16);
- ellipse(-60, 0, 16, 16);
-
- angle += aVelocity;
- aVelocity += aAcceleration;
-}
-
diff --git a/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_02_forces_angular_motion/Attractor.pde b/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_02_forces_angular_motion/Attractor.pde
deleted file mode 100644
index c7c457db7..000000000
--- a/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_02_forces_angular_motion/Attractor.pde
+++ /dev/null
@@ -1,39 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Attraction
-
-// A class for a draggable attractive body in our world
-
-class Attractor {
- float mass; // Mass, tied to size
- PVector location; // Location
- float g;
-
- Attractor() {
- location = new PVector(width/2, height/2);
- mass = 20;
- g = 0.4;
- }
-
-
- PVector attract(Mover m) {
- PVector force = PVector.sub(location, m.location); // Calculate direction of force
- float distance = force.mag(); // Distance between objects
- distance = constrain(distance, 5.0, 25.0); // Limiting the distance to eliminate "extreme" results for very close or very far objects
- force.normalize(); // Normalize vector (distance doesn't matter here, we just want this vector for direction)
- float strength = (g * mass * m.mass) / (distance * distance); // Calculate gravitional force magnitude
- force.mult(strength); // Get force vector --> magnitude * direction
- return force;
- }
-
- // Method to display
- void display() {
- stroke(0);
- strokeWeight(2);
- fill(127);
- ellipse(location.x, location.y, 48, 48);
- }
-}
-
diff --git a/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_02_forces_angular_motion/Mover.pde b/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_02_forces_angular_motion/Mover.pde
deleted file mode 100644
index be9646c09..000000000
--- a/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_02_forces_angular_motion/Mover.pde
+++ /dev/null
@@ -1,53 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-class Mover {
-
- PVector location;
- PVector velocity;
- PVector acceleration;
- float mass;
-
- float angle = 0;
- float aVelocity = 0;
- float aAcceleration = 0;
-
- Mover(float m, float x, float y) {
- mass = m;
- location = new PVector(x,y);
- velocity = new PVector(random(-1,1),random(-1,1));
- acceleration = new PVector(0,0);
- }
-
- void applyForce(PVector force) {
- PVector f = PVector.div(force,mass);
- acceleration.add(f);
- }
-
- void update() {
-
- velocity.add(acceleration);
- location.add(velocity);
-
- aAcceleration = acceleration.x / 10.0;
- aVelocity += aAcceleration;
- aVelocity = constrain(aVelocity,-0.1,0.1);
- angle += aVelocity;
-
- acceleration.mult(0);
- }
-
- void display() {
- stroke(0);
- fill(175,200);
- rectMode(CENTER);
- pushMatrix();
- translate(location.x,location.y);
- rotate(angle);
- rect(0,0,mass*16,mass*16);
- popMatrix();
- }
-
-}
-
diff --git a/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_02_forces_angular_motion/NOC_3_02_forces_angular_motion.pde b/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_02_forces_angular_motion/NOC_3_02_forces_angular_motion.pde
deleted file mode 100644
index 4d4302aff..000000000
--- a/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_02_forces_angular_motion/NOC_3_02_forces_angular_motion.pde
+++ /dev/null
@@ -1,42 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-Mover[] movers = new Mover[20];
-
-Attractor a;
-
-void setup() {
- size(800,200);
- background(255);
- for (int i = 0; i < movers.length; i++) {
- movers[i] = new Mover(random(0.1,2),random(width),random(height));
- }
- a = new Attractor();
-}
-
-void draw() {
- background(255);
-
- a.display();
-
- for (int i = 0; i < movers.length; i++) {
- PVector force = a.attract(movers[i]);
- movers[i].applyForce(force);
-
- movers[i].update();
- movers[i].display();
- }
-
-}
-
-
-
-
-
-
-
-
-
-
-
diff --git a/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_03_pointing_velocity/Mover.pde b/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_03_pointing_velocity/Mover.pde
deleted file mode 100644
index 399d93a4d..000000000
--- a/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_03_pointing_velocity/Mover.pde
+++ /dev/null
@@ -1,69 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-class Mover {
-
- PVector location;
- PVector velocity;
- PVector acceleration;
- float topspeed;
-
- float xoff, yoff;
-
- float r = 16;
-
- Mover() {
- location = new PVector(width/2, height/2);
- velocity = new PVector(0, 0);
- topspeed = 4;
- xoff = 1000;
- yoff = 0;
- }
-
- void update() {
-
- PVector mouse = new PVector(mouseX, mouseY);
- PVector dir = PVector.sub(mouse, location);
- dir.normalize();
- dir.mult(0.5);
- acceleration = dir;
-
- velocity.add(acceleration);
- velocity.limit(topspeed);
- location.add(velocity);
- }
-
- void display() {
- float theta = velocity.heading2D();
-
- stroke(0);
- strokeWeight(2);
- fill(127);
- pushMatrix();
- rectMode(CENTER);
- translate(location.x, location.y);
- rotate(theta);
- rect(0, 0, 30, 10);
- popMatrix();
- }
-
- void checkEdges() {
-
- if (location.x > width) {
- location.x = 0;
- }
- else if (location.x < 0) {
- location.x = width;
- }
-
- if (location.y > height) {
- location.y = 0;
- }
- else if (location.y < 0) {
- location.y = height;
- }
- }
-}
-
-
diff --git a/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_03_pointing_velocity/NOC_3_03_pointing_velocity.pde b/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_03_pointing_velocity/NOC_3_03_pointing_velocity.pde
deleted file mode 100644
index df09af915..000000000
--- a/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_03_pointing_velocity/NOC_3_03_pointing_velocity.pde
+++ /dev/null
@@ -1,20 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-Mover mover;
-
-void setup() {
- size(800,200);
- mover = new Mover();
-}
-
-void draw() {
- background(255);
-
- mover.update();
- mover.checkEdges();
- mover.display();
-}
-
-
diff --git a/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_04_PolarToCartesian/NOC_3_04_PolarToCartesian.pde b/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_04_PolarToCartesian/NOC_3_04_PolarToCartesian.pde
deleted file mode 100644
index 8be1f3bd1..000000000
--- a/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_04_PolarToCartesian/NOC_3_04_PolarToCartesian.pde
+++ /dev/null
@@ -1,48 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// PolarToCartesian
-// Convert a polar coordinate (r,theta) to cartesian (x,y):
-// x = r * cos(theta)
-// y = r * sin(theta)
-
-float r;
-float theta;
-
-
-void setup() {
- size(800, 200);
- // Initialize all values
- r = height * 0.45;
- theta = 0;
-}
-
-void draw() {
-
- background(255);
-
- // Translate the origin point to the center of the screen
- translate(width/2, height/2);
-
- // Convert polar to cartesian
- float x = r * cos(theta);
- float y = r * sin(theta);
-
- // Draw the ellipse at the cartesian coordinate
- ellipseMode(CENTER);
- fill(127);
- stroke(0);
- strokeWeight(2);
- line(0,0,x,y);
- ellipse(x, y, 48, 48);
-
- // Increase the angle over time
- theta += 0.02;
-
-
-}
-
-
-
-
diff --git a/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_04_PolarToCartesian_trail/NOC_3_04_PolarToCartesian_trail.pde b/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_04_PolarToCartesian_trail/NOC_3_04_PolarToCartesian_trail.pde
deleted file mode 100644
index 928afe73a..000000000
--- a/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_04_PolarToCartesian_trail/NOC_3_04_PolarToCartesian_trail.pde
+++ /dev/null
@@ -1,52 +0,0 @@
-/**
- * PolarToCartesian
- * by Daniel Shiffman.
- *
- * Convert a polar coordinate (r,theta) to cartesian (x,y):
- * x = r * cos(theta)
- * y = r * sin(theta)
- */
-
-float r;
-float theta;
-
-
-void setup() {
- size(800, 200);
- background(255);
- // Initialize all values
- r = height * 0.45;
- theta = 0;
-}
-
-void draw() {
-
- //background(255);
- noStroke();
- fill(255,5);
- rect(0,0,width,height);
-
- // Translate the origin point to the center of the screen
- translate(width/2, height/2);
-
- // Convert polar to cartesian
- float x = r * cos(theta);
- float y = r * sin(theta);
-
- // Draw the ellipse at the cartesian coordinate
- ellipseMode(CENTER);
- fill(127);
- stroke(0);
- strokeWeight(2);
- line(0,0,x,y);
- ellipse(x, y, 48, 48);
-
- // Increase the angle over time
- theta += 0.02;
-
-
-}
-
-
-
-
diff --git a/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_05_simple_harmonic_motion/NOC_3_05_simple_harmonic_motion.pde b/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_05_simple_harmonic_motion/NOC_3_05_simple_harmonic_motion.pde
deleted file mode 100644
index e2830e6ca..000000000
--- a/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_05_simple_harmonic_motion/NOC_3_05_simple_harmonic_motion.pde
+++ /dev/null
@@ -1,22 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-void setup() {
- size(800,200);
-}
-
-void draw() {
- background(255);
-
- float period = 120;
- float amplitude = 300;
- // Calculating horizontal location according to formula for simple harmonic motion
- float x = amplitude * cos(TWO_PI * frameCount / period);
- stroke(0);
- strokeWeight(2);
- fill(127);
- translate(width/2,height/2);
- line(0,0,x,0);
- ellipse(x,0,48,48);
-}
diff --git a/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_06_simple_harmonic_motion/NOC_3_06_simple_harmonic_motion.pde b/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_06_simple_harmonic_motion/NOC_3_06_simple_harmonic_motion.pde
deleted file mode 100644
index 4ab3782c0..000000000
--- a/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_06_simple_harmonic_motion/NOC_3_06_simple_harmonic_motion.pde
+++ /dev/null
@@ -1,27 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-float angle = 0;
-float aVelocity = 0.03;
-
-void setup() {
- size(640,360);
-
- smooth();
-}
-
-void draw() {
- background(255);
-
- float amplitude = 300;
- float x = amplitude * cos(angle);
- angle += aVelocity;
-
- ellipseMode(CENTER);
- stroke(0);
- fill(175);
- translate(width/2,height/2);
- line(0,0,x,0);
- ellipse(x,0,20,20);
-}
diff --git a/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_07_oscillating_objects/NOC_3_07_oscillating_objects.pde b/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_07_oscillating_objects/NOC_3_07_oscillating_objects.pde
deleted file mode 100644
index 20af612ed..000000000
--- a/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_07_oscillating_objects/NOC_3_07_oscillating_objects.pde
+++ /dev/null
@@ -1,29 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// An array of objects
-Oscillator[] oscillators = new Oscillator[10];
-
-void setup() {
- size(800,200);
- smooth();
- // Initialize all objects
- for (int i = 0; i < oscillators.length; i++) {
- oscillators[i] = new Oscillator();
- }
- background(255);
-}
-
-void draw() {
- background(255);
- // Run all objects
- for (int i = 0; i < oscillators.length; i++) {
- oscillators[i].oscillate();
- oscillators[i].display();
- }
-}
-
-
-
-
diff --git a/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_07_oscillating_objects/Oscillator.pde b/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_07_oscillating_objects/Oscillator.pde
deleted file mode 100644
index da9a7d6ca..000000000
--- a/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_07_oscillating_objects/Oscillator.pde
+++ /dev/null
@@ -1,37 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-class Oscillator {
-
- PVector angle;
- PVector velocity;
- PVector amplitude;
-
- Oscillator() {
- angle = new PVector();
- velocity = new PVector(random(-0.05, 0.05), random(-0.05, 0.05));
- amplitude = new PVector(random(20,width/2), random(20,height/2));
- }
-
- void oscillate() {
- angle.add(velocity);
- }
-
- void display() {
-
- float x = sin(angle.x)*amplitude.x;
- float y = sin(angle.y)*amplitude.y;
-
- pushMatrix();
- translate(width/2, height/2);
- stroke(0);
- strokeWeight(2);
- fill(127,127);
- line(0, 0, x, y);
- ellipse(x, y, 32, 32);
- popMatrix();
- }
-}
-
-
diff --git a/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_08_static_wave_lines/NOC_3_08_static_wave_lines.pde b/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_08_static_wave_lines/NOC_3_08_static_wave_lines.pde
deleted file mode 100644
index 1149e065d..000000000
--- a/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_08_static_wave_lines/NOC_3_08_static_wave_lines.pde
+++ /dev/null
@@ -1,21 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-float angle = 0;
-float angleVel = 0.1;
-
-size(800,200);
-background(255);
-stroke(0);
-strokeWeight(2);
-noFill();
-
-beginShape();
-for (int x = 0; x <= width; x += 5) {
- float y = map(sin(angle),-1,1,0,height);
- vertex(x,y);
- angle +=angleVel;
-}
-endShape();
-
diff --git a/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_09_exercise_additive_wave/NOC_3_09_exercise_additive_wave.pde b/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_09_exercise_additive_wave/NOC_3_09_exercise_additive_wave.pde
deleted file mode 100644
index fd7f4bc7b..000000000
--- a/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_09_exercise_additive_wave/NOC_3_09_exercise_additive_wave.pde
+++ /dev/null
@@ -1,69 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Additive Wave
-// Create a more complex wave by adding two waves together.
-
-// Maybe better for this answer to be OOP???
-
-int xspacing = 8; // How far apart should each horizontal location be spaced
-int w; // Width of entire wave
-int maxwaves = 5; // total # of waves to add together
-
-float theta = 0.0;
-float[] amplitude = new float[maxwaves]; // Height of wave
-float[] dx = new float[maxwaves]; // Value for incrementing X, to be calculated as a function of period and xspacing
-float[] yvalues; // Using an array to store height values for the wave (not entirely necessary)
-
-void setup() {
- size(640,360);
- colorMode(RGB, 255, 255, 255, 100);
- w = width + 16;
-
- for (int i = 0; i < maxwaves; i++) {
- amplitude[i] = random(10,30);
- float period = random(100,300); // How many pixels before the wave repeats
- dx[i] = (TWO_PI / period) * xspacing;
- }
-
- yvalues = new float[w/xspacing];
-}
-
-void draw() {
- background(0);
- calcWave();
- renderWave();
-}
-
-void calcWave() {
- // Increment theta (try different values for 'angular velocity' here
- theta += 0.02;
-
- // Set all height values to zero
- for (int i = 0; i < yvalues.length; i++) {
- yvalues[i] = 0;
- }
-
- // Accumulate wave height values
- for (int j = 0; j < maxwaves; j++) {
- float x = theta;
- for (int i = 0; i < yvalues.length; i++) {
- // Every other wave is cosine instead of sine
- if (j % 2 == 0) yvalues[i] += sin(x)*amplitude[j];
- else yvalues[i] += cos(x)*amplitude[j];
- x+=dx[j];
- }
- }
-}
-
-void renderWave() {
- // A simple way to draw the wave with an ellipse at each location
- noStroke();
- fill(255,50);
- ellipseMode(CENTER);
- for (int x = 0; x < yvalues.length; x++) {
- ellipse(x*xspacing,height/2+yvalues[x],16,16);
- }
-}
-
diff --git a/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_09_wave/NOC_3_09_wave.pde b/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_09_wave/NOC_3_09_wave.pde
deleted file mode 100644
index 5eb61b28b..000000000
--- a/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_09_wave/NOC_3_09_wave.pde
+++ /dev/null
@@ -1,28 +0,0 @@
-
-float startAngle = 0;
-float angleVel = 0.23;
-
-void setup() {
- size(800,200);
- smooth();
-}
-
-void draw() {
- background(255);
-
- startAngle += 0.015;
- float angle = startAngle;
-
- for (int x = 0; x <= width; x += 24) {
- float y = map(sin(angle),-1,1,0,height);
- stroke(0);
- fill(0,50);
- strokeWeight(2);
- ellipse(x,y,48,48);
- angle += angleVel;
- }
-
-}
-
-
-
diff --git a/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_09_wave_a/NOC_3_09_wave_a.pde b/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_09_wave_a/NOC_3_09_wave_a.pde
deleted file mode 100644
index 95c824eb5..000000000
--- a/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_09_wave_a/NOC_3_09_wave_a.pde
+++ /dev/null
@@ -1,31 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-float startAngle = 0;
-float angleVel = 0.05;
-
-void setup() {
- size(250,200);
- smooth();
-}
-
-void draw() {
- background(255);
-
- startAngle += 0.015;
- float angle = startAngle;
-
- for (int x = 0; x <= width; x += 24) {
- float y = map(sin(angle),-1,1,0,height);
- stroke(0);
- fill(0,50);
- strokeWeight(2);
- ellipse(x,y,48,48);
- angle += angleVel;
- }
-
-}
-
-
-
diff --git a/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_09_wave_b/NOC_3_09_wave_b.pde b/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_09_wave_b/NOC_3_09_wave_b.pde
deleted file mode 100644
index 9749647db..000000000
--- a/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_09_wave_b/NOC_3_09_wave_b.pde
+++ /dev/null
@@ -1,28 +0,0 @@
-
-float startAngle = 0;
-float angleVel = 0.2;
-
-void setup() {
- size(250,200);
- smooth();
-}
-
-void draw() {
- background(255);
-
- startAngle += 0.015;
- float angle = startAngle;
-
- for (int x = 0; x <= width; x += 24) {
- float y = map(sin(angle),-1,1,0,height);
- stroke(0);
- fill(0,50);
- strokeWeight(2);
- ellipse(x,y,48,48);
- angle += angleVel;
- }
-
-}
-
-
-
diff --git a/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_09_wave_c/NOC_3_09_wave_c.pde b/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_09_wave_c/NOC_3_09_wave_c.pde
deleted file mode 100644
index 88a1e396d..000000000
--- a/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_09_wave_c/NOC_3_09_wave_c.pde
+++ /dev/null
@@ -1,31 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-float startAngle = 0;
-float angleVel = 0.4;
-
-void setup() {
- size(250,200);
- smooth();
-}
-
-void draw() {
- background(255);
-
- startAngle += 0.015;
- float angle = startAngle;
-
- for (int x = 0; x <= width; x += 24) {
- float y = map(sin(angle),-1,1,0,height);
- stroke(0);
- fill(0,50);
- strokeWeight(2);
- ellipse(x,y,48,48);
- angle += angleVel;
- }
-
-}
-
-
-
diff --git a/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_10_PendulumExample/NOC_3_10_PendulumExample.pde b/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_10_PendulumExample/NOC_3_10_PendulumExample.pde
deleted file mode 100644
index 80fe915bb..000000000
--- a/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_10_PendulumExample/NOC_3_10_PendulumExample.pde
+++ /dev/null
@@ -1,44 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Pendulum
-
-// A simple pendulum simulation
-// Given a pendulum with an angle theta (0 being the pendulum at rest) and a radius r
-// we can use sine to calculate the angular component of the gravitational force.
-
-// Gravity Force = Mass * Gravitational Constant;
-// Pendulum Force = Gravity Force * sine(theta)
-// Angular Acceleration = Pendulum Force / Mass = gravitational acceleration * sine(theta);
-
-// Note this is an ideal world scenario with no tension in the
-// pendulum arm, a more realistic formula might be:
-// Angular Acceleration = (g / R) * sine(theta)
-
-// For a more substantial explanation, visit:
-// http://www.myphysicslab.com/pendulum1.html
-
-Pendulum p;
-
-void setup() {
- size(800,200);
- // Make a new Pendulum with an origin location and armlength
- p = new Pendulum(new PVector(width/2,0),175);
-
-}
-
-void draw() {
-
- background(255);
- p.go();
-}
-
-void mousePressed() {
- p.clicked(mouseX,mouseY);
-}
-
-void mouseReleased() {
- p.stopDragging();
-}
-
diff --git a/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_10_PendulumExample/Pendulum.pde b/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_10_PendulumExample/Pendulum.pde
deleted file mode 100644
index 02d400155..000000000
--- a/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_10_PendulumExample/Pendulum.pde
+++ /dev/null
@@ -1,98 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Pendulum
-
-// A Simple Pendulum Class
-// Includes functionality for user can click and drag the pendulum
-
-class Pendulum {
-
- PVector location; // Location of pendulum ball
- PVector origin; // Location of arm origin
- float r; // Length of arm
- float angle; // Pendulum arm angle
- float aVelocity; // Angle velocity
- float aAcceleration; // Angle acceleration
-
- float ballr; // Ball radius
- float damping; // Arbitary damping amount
-
- boolean dragging = false;
-
- // This constructor could be improved to allow a greater variety of pendulums
- Pendulum(PVector origin_, float r_) {
- // Fill all variables
- origin = origin_.get();
- location = new PVector();
- r = r_;
- angle = PI/4;
-
- aVelocity = 0.0;
- aAcceleration = 0.0;
- damping = 0.995; // Arbitrary damping
- ballr = 48.0; // Arbitrary ball radius
- }
-
- void go() {
- update();
- drag(); //for user interaction
- display();
- }
-
- // Function to update location
- void update() {
- // As long as we aren't dragging the pendulum, let it swing!
- if (!dragging) {
- float gravity = 0.4; // Arbitrary constant
- aAcceleration = (-1 * gravity / r) * sin(angle); // Calculate acceleration (see: http://www.myphysicslab.com/pendulum1.html)
- aVelocity += aAcceleration; // Increment velocity
- aVelocity *= damping; // Arbitrary damping
- angle += aVelocity; // Increment angle
- }
- }
-
- void display() {
- location.set(r*sin(angle), r*cos(angle), 0); // Polar to cartesian conversion
- location.add(origin); // Make sure the location is relative to the pendulum's origin
-
- stroke(0);
- strokeWeight(2);
- // Draw the arm
- line(origin.x, origin.y, location.x, location.y);
- ellipseMode(CENTER);
- fill(175);
- if (dragging) fill(0);
- // Draw the ball
- ellipse(location.x, location.y, ballr, ballr);
- }
-
-
- // The methods below are for mouse interaction
-
- // This checks to see if we clicked on the pendulum ball
- void clicked(int mx, int my) {
- float d = dist(mx, my, location.x, location.y);
- if (d < ballr) {
- dragging = true;
- }
- }
-
- // This tells us we are not longer clicking on the ball
- void stopDragging() {
- aVelocity = 0; // No velocity once you let go
- dragging = false;
- }
-
- void drag() {
- // If we are draging the ball, we calculate the angle between the
- // pendulum origin and mouse location
- // we assign that angle to the pendulum
- if (dragging) {
- PVector diff = PVector.sub(origin, new PVector(mouseX, mouseY)); // Difference between 2 points
- angle = atan2(-1*diff.y, diff.x) - radians(90); // Angle relative to vertical axis
- }
- }
-}
-
diff --git a/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_10_PendulumExampleSimplified/NOC_3_10_PendulumExampleSimplified.pde b/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_10_PendulumExampleSimplified/NOC_3_10_PendulumExampleSimplified.pde
deleted file mode 100644
index 07c09ed46..000000000
--- a/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_10_PendulumExampleSimplified/NOC_3_10_PendulumExampleSimplified.pde
+++ /dev/null
@@ -1,35 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Pendulum
-
-// A simple pendulum simulation
-// Given a pendulum with an angle theta (0 being the pendulum at rest) and a radius r
-// we can use sine to calculate the angular component of the gravitational force.
-
-// Gravity Force = Mass * Gravitational Constant;
-// Pendulum Force = Gravity Force * sine(theta)
-// Angular Acceleration = Pendulum Force / Mass = Gravitational Constant * sine(theta);
-
-// Note this is an ideal world scenario with no tension in the
-// pendulum arm, a more realistic formula might be:
-// Angular Acceleration = (G / R) * sine(theta)
-
-// For a more substantial explanation, visit:
-// http://www.myphysicslab.com/pendulum1.html
-
-Pendulum p;
-
-void setup() {
- size(800,200);
- // Make a new Pendulum with an origin location and armlength
- p = new Pendulum(new PVector(width/2,0),175);
-
-}
-
-void draw() {
- background(255);
- p.go();
-}
-
diff --git a/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_10_PendulumExampleSimplified/Pendulum.pde b/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_10_PendulumExampleSimplified/Pendulum.pde
deleted file mode 100644
index 1b63fd3cc..000000000
--- a/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_10_PendulumExampleSimplified/Pendulum.pde
+++ /dev/null
@@ -1,64 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Pendulum
-
-// A Simple Pendulum Class
-// Includes functionality for user can click and drag the pendulum
-
-class Pendulum {
-
- PVector location; // Location of pendulum ball
- PVector origin; // Location of arm origin
- float r; // Length of arm
- float angle; // Pendulum arm angle
- float aVelocity; // Angle velocity
- float aAcceleration; // Angle acceleration
- float damping; // Arbitary damping amount
-
- // This constructor could be improved to allow a greater variety of pendulums
- Pendulum(PVector origin_, float r_) {
- // Fill all variables
- origin = origin_.get();
- location = new PVector();
- r = r_;
- angle = PI/4;
-
- aVelocity = 0.0;
- aAcceleration = 0.0;
- damping = 0.995; // Arbitrary damping
- }
-
- void go() {
- update();
- display();
- }
-
- // Function to update location
- void update() {
- float gravity = 0.4; // Arbitrary constant
- aAcceleration = (-1 * gravity / r) * sin(angle); // Calculate acceleration (see: http://www.myphysicslab.com/pendulum1.html)
- aVelocity += aAcceleration; // Increment velocity
- aVelocity *= damping; // Arbitrary damping
- angle += aVelocity; // Increment angle
- }
-
- void display() {
- location.set(r*sin(angle), r*cos(angle), 0); // Polar to cartesian conversion
- location.add(origin); // Make sure the location is relative to the pendulum's origin
-
- stroke(0);
- strokeWeight(2);
- // Draw the arm
- line(origin.x, origin.y, location.x, location.y);
- ellipseMode(CENTER);
- fill(175);
- // Draw the ball
- ellipse(location.x, location.y, 48, 48);
- }
-
-}
-
-
-
diff --git a/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_11_spring/Mover.pde b/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_11_spring/Mover.pde
deleted file mode 100644
index 4545f5cd1..000000000
--- a/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_11_spring/Mover.pde
+++ /dev/null
@@ -1,78 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Bob class, just like our regular Mover (location, velocity, acceleration, mass)
-
-class Bob {
- PVector location;
- PVector velocity;
- PVector acceleration;
- float mass = 24;
-
- // Arbitrary damping to simulate friction / drag
- float damping = 0.98;
-
- // For mouse interaction
- PVector dragOffset;
- boolean dragging = false;
-
- // Constructor
- Bob(float x, float y) {
- location = new PVector(x,y);
- velocity = new PVector();
- acceleration = new PVector();
- dragOffset = new PVector();
- }
-
- // Standard Euler integration
- void update() {
- velocity.add(acceleration);
- velocity.mult(damping);
- location.add(velocity);
- acceleration.mult(0);
- }
-
- // Newton's law: F = M * A
- void applyForce(PVector force) {
- PVector f = force.get();
- f.div(mass);
- acceleration.add(f);
- }
-
-
- // Draw the bob
- void display() {
- stroke(0);
- strokeWeight(2);
- fill(175);
- if (dragging) {
- fill(50);
- }
- ellipse(location.x,location.y,mass*2,mass*2);
- }
-
- // The methods below are for mouse interaction
-
- // This checks to see if we clicked on the mover
- void clicked(int mx, int my) {
- float d = dist(mx,my,location.x,location.y);
- if (d < mass) {
- dragging = true;
- dragOffset.x = location.x-mx;
- dragOffset.y = location.y-my;
- }
- }
-
- void stopDragging() {
- dragging = false;
- }
-
- void drag(int mx, int my) {
- if (dragging) {
- location.x = mx + dragOffset.x;
- location.y = my + dragOffset.y;
- }
- }
-}
-
diff --git a/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_11_spring/NOC_3_11_spring.pde b/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_11_spring/NOC_3_11_spring.pde
deleted file mode 100644
index ff09a0a9a..000000000
--- a/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_11_spring/NOC_3_11_spring.pde
+++ /dev/null
@@ -1,56 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Mover object
-Bob bob;
-
-// Spring object
-Spring spring;
-
-void setup() {
- size(640,360);
- // Create objects at starting location
- // Note third argument in Spring constructor is "rest length"
- spring = new Spring(width/2,10,100);
- bob = new Bob(width/2,100);
-
-}
-
-void draw() {
- background(255);
- // Apply a gravity force to the bob
- PVector gravity = new PVector(0,2);
- bob.applyForce(gravity);
-
- // Connect the bob to the spring (this calculates the force)
- spring.connect(bob);
- // Constrain spring distance between min and max
- spring.constrainLength(bob,30,200);
-
- // Update bob
- bob.update();
- // If it's being dragged
- bob.drag(mouseX,mouseY);
-
- // Draw everything
- spring.displayLine(bob); // Draw a line between spring and bob
- bob.display();
- spring.display();
-
- fill(0);
- text("click on bob to drag",10,height-5);
-}
-
-
-// For mouse interaction with bob
-
-void mousePressed() {
- bob.clicked(mouseX,mouseY);
-}
-
-void mouseReleased() {
- bob.stopDragging();
-}
-
-
diff --git a/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_11_spring/Spring.pde b/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_11_spring/Spring.pde
deleted file mode 100644
index 565fbb307..000000000
--- a/java/examples/Books/Nature of Code/chp3_oscillation/NOC_3_11_spring/Spring.pde
+++ /dev/null
@@ -1,75 +0,0 @@
-// Nature of Code 2011
-// Daniel Shiffman
-// Chapter 3: Oscillation
-
-// Class to describe an anchor point that can connect to "Bob" objects via a spring
-// Thank you: http://www.myphysicslab.com/spring2d.html
-
-class Spring {
-
- // Location
- PVector anchor;
-
- // Rest length and spring constant
- float len;
- float k = 0.2;
-
- // Constructor
- Spring(float x, float y, int l) {
- anchor = new PVector(x, y);
- len = l;
- }
-
- // Calculate spring force
- void connect(Bob b) {
- // Vector pointing from anchor to bob location
- PVector force = PVector.sub(b.location, anchor);
- // What is distance
- float d = force.mag();
- // Stretch is difference between current distance and rest length
- float stretch = d - len;
-
- // Calculate force according to Hooke's Law
- // F = k * stretch
- force.normalize();
- force.mult(-1 * k * stretch);
- b.applyForce(force);
- }
-
- // Constrain the distance between bob and anchor between min and max
- void constrainLength(Bob b, float minlen, float maxlen) {
- PVector dir = PVector.sub(b.location, anchor);
- float d = dir.mag();
- // Is it too short?
- if (d < minlen) {
- dir.normalize();
- dir.mult(minlen);
- // Reset location and stop from moving (not realistic physics)
- b.location = PVector.add(anchor, dir);
- b.velocity.mult(0);
- // Is it too long?
- }
- else if (d > maxlen) {
- dir.normalize();
- dir.mult(maxlen);
- // Reset location and stop from moving (not realistic physics)
- b.location = PVector.add(anchor, dir);
- b.velocity.mult(0);
- }
- }
-
- void display() {
- stroke(0);
- fill(175);
- strokeWeight(2);
- rectMode(CENTER);
- rect(anchor.x, anchor.y, 10, 10);
- }
-
- void displayLine(Bob b) {
- strokeWeight(2);
- stroke(0);
- line(b.location.x, b.location.y, anchor.x, anchor.y);
- }
-}
-
diff --git a/java/examples/Books/Nature of Code/chp3_oscillation/OOPWaveParticles/OOPWaveParticles.pde b/java/examples/Books/Nature of Code/chp3_oscillation/OOPWaveParticles/OOPWaveParticles.pde
deleted file mode 100644
index 423afa435..000000000
--- a/java/examples/Books/Nature of Code/chp3_oscillation/OOPWaveParticles/OOPWaveParticles.pde
+++ /dev/null
@@ -1,32 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Sine Wave
-
-// Two wave objects
-Wave wave0;
-Wave wave1;
-
-void setup() {
- size(640,360);
- // Initialize a wave with starting point, width, amplitude, and period
- wave0 = new Wave(new PVector(200,75),100,20,500);
- wave1 = new Wave(new PVector(150,250),300,40,220);
-
-}
-
-void draw() {
- background(255);
-
- // Update and display waves
- wave0.calculate();
- wave0.display();
-
- wave1.calculate();
- wave1.display();
-
-
-}
-
-
diff --git a/java/examples/Books/Nature of Code/chp3_oscillation/OOPWaveParticles/Particle.pde b/java/examples/Books/Nature of Code/chp3_oscillation/OOPWaveParticles/Particle.pde
deleted file mode 100644
index d04daea97..000000000
--- a/java/examples/Books/Nature of Code/chp3_oscillation/OOPWaveParticles/Particle.pde
+++ /dev/null
@@ -1,23 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-class Particle {
- PVector location;
-
- Particle() {
- location = new PVector();
- }
-
- void setLocation(float x, float y) {
- location.x = x;
- location.y = y;
- }
-
- void display() {
- fill(random(255));
- ellipse(location.x,location.y,16,16);
- }
-
-
-}
diff --git a/java/examples/Books/Nature of Code/chp3_oscillation/OOPWaveParticles/Wave.pde b/java/examples/Books/Nature of Code/chp3_oscillation/OOPWaveParticles/Wave.pde
deleted file mode 100644
index 9763ba892..000000000
--- a/java/examples/Books/Nature of Code/chp3_oscillation/OOPWaveParticles/Wave.pde
+++ /dev/null
@@ -1,56 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-class Wave {
-
- int xspacing = 8; // How far apart should each horizontal location be spaced
- int w; // Width of entire wave
-
- PVector origin; // Where does the wave's first point start
- float theta = 0.0; // Start angle at 0
- float amplitude; // Height of wave
- float period; // How many pixels before the wave repeats
- float dx; // Value for incrementing X, to be calculated as a function of period and xspacing
- //float[] yvalues; // Using an array to store height values for the wave (not entirely necessary)
- Particle[] particles;
-
- Wave(PVector o, int w_, float a, float p) {
- origin = o.get();
- w = w_;
- period = p;
- amplitude = a;
- dx = (TWO_PI / period) * xspacing;
- particles = new Particle[w/xspacing];
- for (int i = 0; i < particles.length; i++) {
- particles[i] = new Particle();
- }
- }
-
-
- void calculate() {
- // Increment theta (try different values for 'angular velocity' here
- theta += 0.02;
-
- // For every x value, calculate a y value with sine function
- float x = theta;
- for (int i = 0; i < particles.length; i++) {
- particles[i].setLocation(origin.x+i*xspacing,origin.y+sin(x)*amplitude);
- x+=dx;
- }
- }
-
- void manipulate() {
- // Loop through the array of particles and check stuff regarding the mouse
-
- }
-
- void display() {
-
- // A simple way to draw the wave with an ellipse at each location
- for (int i = 0; i < particles.length; i++) {
- particles[i].display();
- }
- }
-}
-
diff --git a/java/examples/Books/Nature of Code/chp4_systems/CircleVsBlob/CircleVsBlob.pde b/java/examples/Books/Nature of Code/chp4_systems/CircleVsBlob/CircleVsBlob.pde
deleted file mode 100644
index a81a4ed84..000000000
--- a/java/examples/Books/Nature of Code/chp4_systems/CircleVsBlob/CircleVsBlob.pde
+++ /dev/null
@@ -1,24 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-void setup() {
- size(200,200);
- PImage img = loadImage("texture.png");
- background(0);
- image(img,0,0,width,height);
- save("blob.tif");
-
- background(0);
- fill(255);
- noStroke();
- ellipse(100,100,width,height);
- save("circle.tif");
-}
-
-void draw() {
-
-
-}
-
-
diff --git a/java/examples/Books/Nature of Code/chp4_systems/CircleVsBlob/blob.tif b/java/examples/Books/Nature of Code/chp4_systems/CircleVsBlob/blob.tif
deleted file mode 100644
index 62b3058e4..000000000
Binary files a/java/examples/Books/Nature of Code/chp4_systems/CircleVsBlob/blob.tif and /dev/null differ
diff --git a/java/examples/Books/Nature of Code/chp4_systems/CircleVsBlob/circle.tif b/java/examples/Books/Nature of Code/chp4_systems/CircleVsBlob/circle.tif
deleted file mode 100644
index 101ae8775..000000000
Binary files a/java/examples/Books/Nature of Code/chp4_systems/CircleVsBlob/circle.tif and /dev/null differ
diff --git a/java/examples/Books/Nature of Code/chp4_systems/CircleVsBlob/data/texture.gif b/java/examples/Books/Nature of Code/chp4_systems/CircleVsBlob/data/texture.gif
deleted file mode 100644
index 17e84e806..000000000
Binary files a/java/examples/Books/Nature of Code/chp4_systems/CircleVsBlob/data/texture.gif and /dev/null differ
diff --git a/java/examples/Books/Nature of Code/chp4_systems/CircleVsBlob/data/texture.psd b/java/examples/Books/Nature of Code/chp4_systems/CircleVsBlob/data/texture.psd
deleted file mode 100644
index 8208feb02..000000000
Binary files a/java/examples/Books/Nature of Code/chp4_systems/CircleVsBlob/data/texture.psd and /dev/null differ
diff --git a/java/examples/Books/Nature of Code/chp4_systems/Exercise_4_03_MovingParticleSystem/Exercise_4_03_MovingParticleSystem.pde b/java/examples/Books/Nature of Code/chp4_systems/Exercise_4_03_MovingParticleSystem/Exercise_4_03_MovingParticleSystem.pde
deleted file mode 100644
index 3e26041b4..000000000
--- a/java/examples/Books/Nature of Code/chp4_systems/Exercise_4_03_MovingParticleSystem/Exercise_4_03_MovingParticleSystem.pde
+++ /dev/null
@@ -1,26 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-ParticleSystem ps;
-
-void setup() {
- size(640,360);
- ps = new ParticleSystem(new PVector(width/2,50));
-}
-
-void draw() {
- background(255);
-
- // Option #1 (move the Particle System origin)
- ps.origin.set(mouseX,mouseY,0);
-
- ps.addParticle();
- ps.run();
-
- // Option #2 (move the Particle System origin)
- // ps.addParticle(mouseX,mouseY);
-
-
-
-}
diff --git a/java/examples/Books/Nature of Code/chp4_systems/Exercise_4_03_MovingParticleSystem/Particle.pde b/java/examples/Books/Nature of Code/chp4_systems/Exercise_4_03_MovingParticleSystem/Particle.pde
deleted file mode 100644
index 12d1ef02a..000000000
--- a/java/examples/Books/Nature of Code/chp4_systems/Exercise_4_03_MovingParticleSystem/Particle.pde
+++ /dev/null
@@ -1,50 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Simple Particle System
-
-class Particle {
- PVector location;
- PVector velocity;
- PVector acceleration;
- float lifespan;
-
- Particle(PVector l) {
- acceleration = new PVector(0,0.05);
- velocity = new PVector(random(-1,1),random(-2,0));
- location = l.get();
- lifespan = 255.0;
- }
-
- void run() {
- update();
- display();
- }
-
- // Method to update location
- void update() {
- velocity.add(acceleration);
- location.add(velocity);
- lifespan -= 2.0;
- }
-
- // Method to display
- void display() {
- stroke(0,lifespan);
- strokeWeight(2);
- fill(127,lifespan);
- ellipse(location.x,location.y,12,12);
- }
-
- // Is the particle still useful?
- boolean isDead() {
- if (lifespan < 0.0) {
- return true;
- } else {
- return false;
- }
- }
-}
-
-
diff --git a/java/examples/Books/Nature of Code/chp4_systems/Exercise_4_03_MovingParticleSystem/ParticleSystem.pde b/java/examples/Books/Nature of Code/chp4_systems/Exercise_4_03_MovingParticleSystem/ParticleSystem.pde
deleted file mode 100644
index 264df8539..000000000
--- a/java/examples/Books/Nature of Code/chp4_systems/Exercise_4_03_MovingParticleSystem/ParticleSystem.pde
+++ /dev/null
@@ -1,36 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Using Generics now! comment and annotate, etc.
-
-class ParticleSystem {
- ArrayList particles;
- PVector origin;
-
- ParticleSystem(PVector location) {
- origin = location.get();
- particles = new ArrayList();
- }
-
- void addParticle() {
- particles.add(new Particle(origin));
- }
-
- void addParticle(float x, float y) {
- particles.add(new Particle(new PVector(x, y)));
- }
-
- void run() {
- for (int i = particles.size()-1; i >= 0; i--) {
- Particle p = particles.get(i);
- p.run();
- if (p.isDead()) {
- particles.remove(i);
- }
- }
- }
-}
-
-
-
diff --git a/java/examples/Books/Nature of Code/chp4_systems/Exercise_4_04_asteroids/Exercise_4_04_asteroids.pde b/java/examples/Books/Nature of Code/chp4_systems/Exercise_4_04_asteroids/Exercise_4_04_asteroids.pde
deleted file mode 100644
index d0340916f..000000000
--- a/java/examples/Books/Nature of Code/chp4_systems/Exercise_4_04_asteroids/Exercise_4_04_asteroids.pde
+++ /dev/null
@@ -1,41 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Chapter 3: Asteroids exercise
-
-// Mover object
-Spaceship ship;
-
-void setup() {
- size(640, 360);
- ship = new Spaceship();
-}
-
-void draw() {
- background(255);
-
- // Update location
- ship.update();
- // Wrape edges
- ship.wrapEdges();
- // Draw ship
- ship.display();
-
-
- fill(0);
- //text("left right arrows to turn, z to thrust",10,height-5);
-
- // Turn or thrust the ship depending on what key is pressed
- if (keyPressed) {
- if (key == CODED && keyCode == LEFT) {
- ship.turn(-0.03);
- } else if (key == CODED && keyCode == RIGHT) {
- ship.turn(0.03);
- } else if (key == 'z' || key == 'Z') {
- ship.thrust();
- }
- }
-}
-
-
diff --git a/java/examples/Books/Nature of Code/chp4_systems/Exercise_4_04_asteroids/Particle.pde b/java/examples/Books/Nature of Code/chp4_systems/Exercise_4_04_asteroids/Particle.pde
deleted file mode 100644
index e6736696e..000000000
--- a/java/examples/Books/Nature of Code/chp4_systems/Exercise_4_04_asteroids/Particle.pde
+++ /dev/null
@@ -1,49 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Simple Particle System
-
-class Particle {
- PVector location;
- PVector velocity;
- PVector acceleration;
- float lifespan;
-
- Particle(PVector l,PVector dir) {
- acceleration = dir.get();
- velocity = PVector.random2D();
- location = l.get();
- lifespan = 255.0;
- }
-
- void run() {
- update();
- display();
- }
-
- // Method to update location
- void update() {
- velocity.add(acceleration);
- location.add(velocity);
- lifespan -= 2.0;
- }
-
- // Method to display
- void display() {
- noStroke();
- fill(127,0,0,lifespan);
- ellipse(location.x,location.y,12,12);
- }
-
- // Is the particle still useful?
- boolean isDead() {
- if (lifespan < 0.0) {
- return true;
- } else {
- return false;
- }
- }
-}
-
-
diff --git a/java/examples/Books/Nature of Code/chp4_systems/Exercise_4_04_asteroids/ParticleSystem.pde b/java/examples/Books/Nature of Code/chp4_systems/Exercise_4_04_asteroids/ParticleSystem.pde
deleted file mode 100644
index 0b83fa96a..000000000
--- a/java/examples/Books/Nature of Code/chp4_systems/Exercise_4_04_asteroids/ParticleSystem.pde
+++ /dev/null
@@ -1,30 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Using Generics now! comment and annotate, etc.
-
-class ParticleSystem {
- ArrayList particles;
-
- ParticleSystem() {
- particles = new ArrayList();
- }
-
- void addParticle(float x, float y, PVector force) {
- particles.add(new Particle(new PVector(x, y),force));
- }
-
- void run() {
- for (int i = particles.size()-1; i >= 0; i--) {
- Particle p = particles.get(i);
- p.run();
- if (p.isDead()) {
- particles.remove(i);
- }
- }
- }
-}
-
-
-
diff --git a/java/examples/Books/Nature of Code/chp4_systems/Exercise_4_04_asteroids/Spaceship.pde b/java/examples/Books/Nature of Code/chp4_systems/Exercise_4_04_asteroids/Spaceship.pde
deleted file mode 100644
index bdc11f6c1..000000000
--- a/java/examples/Books/Nature of Code/chp4_systems/Exercise_4_04_asteroids/Spaceship.pde
+++ /dev/null
@@ -1,110 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Chapter 3: Asteroids
-
-class Spaceship {
- // All of our regular motion stuff
- PVector location;
- PVector velocity;
- PVector acceleration;
-
- ParticleSystem ps;
-
- // Arbitrary damping to slow down ship
- float damping = 0.995;
- float topspeed = 6;
-
- // Variable for heading!
- float heading = 0;
-
- // Size
- float r = 16;
-
- // Are we thrusting (to color boosters)
- boolean thrusting = false;
-
- Spaceship() {
- location = new PVector(width/2,height/2);
- velocity = new PVector();
- acceleration = new PVector();
-
- ps = new ParticleSystem();
- }
-
- // Standard Euler integration
- void update() {
- velocity.add(acceleration);
- velocity.mult(damping);
- velocity.limit(topspeed);
- location.add(velocity);
- acceleration.mult(0);
-
- ps.run();
- }
-
- // Newton's law: F = M * A
- void applyForce(PVector force) {
- PVector f = force.get();
- //f.div(mass); // ignoring mass right now
- acceleration.add(f);
- }
-
- // Turn changes angle
- void turn(float a) {
- heading += a;
- }
-
- // Apply a thrust force
- void thrust() {
- // Offset the angle since we drew the ship vertically
- float angle = heading - PI/2;
- // Polar to cartesian for force vector!
- PVector force = PVector.fromAngle(angle);
- force.mult(0.1);
- applyForce(force);
-
- force.mult(-2);
- ps.addParticle(location.x,location.y+r,force);
-
-
- // To draw booster
- thrusting = true;
- }
-
- void wrapEdges() {
- float buffer = r*2;
- if (location.x > width + buffer) location.x = -buffer;
- else if (location.x < -buffer) location.x = width+buffer;
- if (location.y > height + buffer) location.y = -buffer;
- else if (location.y < -buffer) location.y = height+buffer;
- }
-
-
- // Draw the ship
- void display() {
- stroke(0);
- strokeWeight(2);
- pushMatrix();
- translate(location.x,location.y+r);
- rotate(heading);
- fill(175);
- if (thrusting) fill(255,0,0);
- // Booster rockets
- rect(-r/2,r,r/3,r/2);
- rect(r/2,r,r/3,r/2);
- fill(175);
- // A triangle
- beginShape();
- vertex(-r,r);
- vertex(0,-r);
- vertex(r,r);
- endShape(CLOSE);
- rectMode(CENTER);
- popMatrix();
-
- thrusting = false;
- }
-}
-
diff --git a/java/examples/Books/Nature of Code/chp4_systems/Exercise_4_06_Shatter/Exercise_4_06_Shatter.pde b/java/examples/Books/Nature of Code/chp4_systems/Exercise_4_06_Shatter/Exercise_4_06_Shatter.pde
deleted file mode 100644
index f7026ae40..000000000
--- a/java/examples/Books/Nature of Code/chp4_systems/Exercise_4_06_Shatter/Exercise_4_06_Shatter.pde
+++ /dev/null
@@ -1,21 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-ParticleSystem ps;
-
-void setup() {
- size(640,360);
- ps = new ParticleSystem(100,100,5);
-}
-
-void draw() {
- background(255);
-
- ps.display();
- ps.update();
-}
-
-void mousePressed() {
- ps.shatter();
-}
diff --git a/java/examples/Books/Nature of Code/chp4_systems/Exercise_4_06_Shatter/Particle.pde b/java/examples/Books/Nature of Code/chp4_systems/Exercise_4_06_Shatter/Particle.pde
deleted file mode 100644
index d160a42c8..000000000
--- a/java/examples/Books/Nature of Code/chp4_systems/Exercise_4_06_Shatter/Particle.pde
+++ /dev/null
@@ -1,54 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Simple Particle System
-
-class Particle {
- PVector location;
- PVector velocity;
- PVector acceleration;
- float lifespan;
-
- float r;
-
- Particle(float x, float y, float r_) {
- acceleration = new PVector(0,0.01);
- velocity = PVector.random2D();
- velocity.mult(0.5);
- location = new PVector(x,y);
- lifespan = 255.0;
- r = r_;
- }
-
- void run() {
- update();
- display();
- }
-
- // Method to update location
- void update() {
- velocity.add(acceleration);
- location.add(velocity);
- lifespan -= 2.0;
- }
-
- // Method to display
- void display() {
- stroke(0);
- fill(0);
- rectMode(CENTER);
- rect(location.x,location.y,r,r);
- }
-
- // Is the particle still useful?
- boolean isDead() {
- if (lifespan < 0.0) {
- return true;
- } else {
- return false;
- }
- }
-}
-
-
diff --git a/java/examples/Books/Nature of Code/chp4_systems/Exercise_4_06_Shatter/ParticleSystem.pde b/java/examples/Books/Nature of Code/chp4_systems/Exercise_4_06_Shatter/ParticleSystem.pde
deleted file mode 100644
index 611b1218b..000000000
--- a/java/examples/Books/Nature of Code/chp4_systems/Exercise_4_06_Shatter/ParticleSystem.pde
+++ /dev/null
@@ -1,45 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Using Generics now! comment and annotate, etc.
-
-class ParticleSystem {
- ArrayList particles;
-
- int rows = 20;
- int cols = 20;
-
- boolean intact = true;
-
- ParticleSystem(float x, float y, float r) {
- particles = new ArrayList();
-
- for (int i = 0; i < rows*cols; i++) {
- addParticle(x + (i%cols)*r, y + (i/rows)*r, r);
- }
- }
-
- void addParticle(float x, float y, float r) {
- particles.add(new Particle(x, y, r));
- }
-
- void display() {
- for (Particle p : particles) {
- p.display();
- }
- }
-
- void shatter() {
- intact = false;
- }
-
- void update() {
- if (!intact) {
- for (Particle p : particles) {
- p.update();
- }
- }
- }
-}
-
diff --git a/java/examples/Books/Nature of Code/chp4_systems/Exercise_4_10_particleintersection/Exercise_4_10_particleintersection.pde b/java/examples/Books/Nature of Code/chp4_systems/Exercise_4_10_particleintersection/Exercise_4_10_particleintersection.pde
deleted file mode 100644
index d27427366..000000000
--- a/java/examples/Books/Nature of Code/chp4_systems/Exercise_4_10_particleintersection/Exercise_4_10_particleintersection.pde
+++ /dev/null
@@ -1,18 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-ParticleSystem ps;
-
-void setup() {
- size(640,360);
- ps = new ParticleSystem(new PVector(width/2,50));
-}
-
-void draw() {
- background(255);
- ps.addParticle(mouseX,mouseY);
- ps.update();
- ps.intersection();
- ps.display();
-}
diff --git a/java/examples/Books/Nature of Code/chp4_systems/Exercise_4_10_particleintersection/Particle.pde b/java/examples/Books/Nature of Code/chp4_systems/Exercise_4_10_particleintersection/Particle.pde
deleted file mode 100644
index 90c4dec0c..000000000
--- a/java/examples/Books/Nature of Code/chp4_systems/Exercise_4_10_particleintersection/Particle.pde
+++ /dev/null
@@ -1,73 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Simple Particle System
-
-class Particle {
- PVector location;
- PVector velocity;
- PVector acceleration;
- float lifespan;
-
- float r = 6;
- boolean highlight;
-
- Particle(float x, float y) {
- acceleration = new PVector(0, 0.05);
- velocity = new PVector(random(-1, 1), random(-2, 0));
- location = new PVector(x, y);
- lifespan = 255.0;
- }
-
- void run() {
- update();
- display();
- }
-
- void intersects(ArrayList particles) {
- highlight = false;
- for (Particle other : particles) {
- if (other != this) {
- float d = PVector.dist(other.location, location);
- if (d < r + other.r) {
- highlight = true;
- }
- }
- }
- }
-
- void applyForce(PVector f) {
- acceleration.add(f);
- }
-
- // Method to update location
- void update() {
- velocity.add(acceleration);
- location.add(velocity);
- acceleration.mult(0);
- lifespan -= 2.0;
- }
-
- // Method to display
- void display() {
- stroke(0, lifespan);
- strokeWeight(2);
- fill(127, lifespan);
- if (highlight) {
- fill(127,0,0);
- }
- ellipse(location.x, location.y, r*2, r*2);
- }
-
- // Is the particle still useful?
- boolean isDead() {
- if (lifespan < 0.0) {
- return true;
- }
- else {
- return false;
- }
- }
-}
-
diff --git a/java/examples/Books/Nature of Code/chp4_systems/Exercise_4_10_particleintersection/ParticleSystem.pde b/java/examples/Books/Nature of Code/chp4_systems/Exercise_4_10_particleintersection/ParticleSystem.pde
deleted file mode 100644
index 3b3367656..000000000
--- a/java/examples/Books/Nature of Code/chp4_systems/Exercise_4_10_particleintersection/ParticleSystem.pde
+++ /dev/null
@@ -1,43 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Using Generics now! comment and annotate, etc.
-
-class ParticleSystem {
- ArrayList particles;
-
- ParticleSystem(PVector location) {
- particles = new ArrayList();
- }
-
- void addParticle(float x, float y) {
- particles.add(new Particle(x, y));
- }
-
-
- void display() {
- for (Particle p : particles) {
- p.display();
- }
- }
-
- void intersection() {
- for (Particle p : particles) {
- p.intersects(particles);
- }
- }
-
-
- void update() {
- for (int i = particles.size()-1; i >= 0; i--) {
- Particle p = particles.get(i);
- p.update();
- if (p.isDead()) {
- particles.remove(i);
- }
- }
- }
-}
-
-
diff --git a/java/examples/Books/Nature of Code/chp4_systems/Exercise_4_10_particlerepel/Exercise_4_10_particlerepel.pde b/java/examples/Books/Nature of Code/chp4_systems/Exercise_4_10_particlerepel/Exercise_4_10_particlerepel.pde
deleted file mode 100644
index 408ce3edd..000000000
--- a/java/examples/Books/Nature of Code/chp4_systems/Exercise_4_10_particlerepel/Exercise_4_10_particlerepel.pde
+++ /dev/null
@@ -1,21 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-ParticleSystem ps;
-
-void setup() {
- size(640,360);
- ps = new ParticleSystem(new PVector(width/2,50));
-}
-
-void draw() {
- background(255);
- ps.addParticle(random(width),random(height));
-
- //PVector gravity = new PVector(0,0.1);
- //ps.applyForce(gravity);
- ps.update();
- ps.intersection();
- ps.display();
-}
diff --git a/java/examples/Books/Nature of Code/chp4_systems/Exercise_4_10_particlerepel/Particle.pde b/java/examples/Books/Nature of Code/chp4_systems/Exercise_4_10_particlerepel/Particle.pde
deleted file mode 100644
index dcd577cec..000000000
--- a/java/examples/Books/Nature of Code/chp4_systems/Exercise_4_10_particlerepel/Particle.pde
+++ /dev/null
@@ -1,70 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Simple Particle System
-
-class Particle {
- PVector location;
- PVector velocity;
- PVector acceleration;
- float lifespan;
-
- float r = 6;
-
-
- Particle(float x, float y) {
- acceleration = new PVector();
- velocity = PVector.random2D();
- location = new PVector(x, y);
- lifespan = 255.0;
- }
-
- void run() {
- update();
- display();
- }
-
- void intersects(ArrayList particles) {
- for (Particle other : particles) {
- if (other != this) {
- PVector dir = PVector.sub(location, other.location);
- if (dir.mag() < r*2) {
- dir.setMag(0.5);
- applyForce(dir);
- }
- }
- }
- }
-
- void applyForce(PVector f) {
- acceleration.add(f);
- }
-
- // Method to update location
- void update() {
- velocity.add(acceleration);
- location.add(velocity);
- acceleration.mult(0);
- lifespan -= 0.5;
- }
-
- // Method to display
- void display() {
- stroke(0, lifespan);
- strokeWeight(2);
- fill(127, lifespan);
- ellipse(location.x, location.y, r*2, r*2);
- }
-
- // Is the particle still useful?
- boolean isDead() {
- if (lifespan < 0.0) {
- return true;
- }
- else {
- return false;
- }
- }
-}
-
diff --git a/java/examples/Books/Nature of Code/chp4_systems/Exercise_4_10_particlerepel/ParticleSystem.pde b/java/examples/Books/Nature of Code/chp4_systems/Exercise_4_10_particlerepel/ParticleSystem.pde
deleted file mode 100644
index 4168dc229..000000000
--- a/java/examples/Books/Nature of Code/chp4_systems/Exercise_4_10_particlerepel/ParticleSystem.pde
+++ /dev/null
@@ -1,48 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Using Generics now! comment and annotate, etc.
-
-class ParticleSystem {
- ArrayList particles;
-
- ParticleSystem(PVector location) {
- particles = new ArrayList();
- }
-
- void addParticle(float x, float y) {
- particles.add(new Particle(x, y));
- }
-
-
- void display() {
- for (Particle p : particles) {
- p.display();
- }
- }
-
- void applyForce(PVector f) {
- for (Particle p : particles) {
- p.applyForce(f);
- }
- }
-
- void intersection() {
- for (Particle p : particles) {
- p.intersects(particles);
- }
- }
-
-
- void update() {
- for (int i = particles.size()-1; i >= 0; i--) {
- Particle p = particles.get(i);
- p.update();
- if (p.isDead()) {
- particles.remove(i);
- }
- }
- }
-}
-
diff --git a/java/examples/Books/Nature of Code/chp4_systems/Exercise_4_12_ArrayofImages/Exercise_4_12_ArrayofImages.pde b/java/examples/Books/Nature of Code/chp4_systems/Exercise_4_12_ArrayofImages/Exercise_4_12_ArrayofImages.pde
deleted file mode 100644
index dbc8ac3c5..000000000
--- a/java/examples/Books/Nature of Code/chp4_systems/Exercise_4_12_ArrayofImages/Exercise_4_12_ArrayofImages.pde
+++ /dev/null
@@ -1,39 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Array of Images for particle textures
-
-ParticleSystem ps;
-
-PImage[] imgs;
-
-void setup() {
- size(640, 360, P2D);
-
- imgs = new PImage[5];
- imgs[0] = loadImage("corona.png");
- imgs[1] = loadImage("emitter.png");
- imgs[2] = loadImage("particle.png");
- imgs[3] = loadImage("texture.png");
- imgs[4] = loadImage("reflection.png");
-
- ps = new ParticleSystem(imgs, new PVector(width/2, 50));
-}
-
-void draw() {
-
- // Additive blending!
- blendMode(ADD);
-
- background(0);
-
- PVector up = new PVector(0,-0.2);
- ps.applyForce(up);
-
- ps.run();
- for (int i = 0; i < 5; i++) {
- ps.addParticle(mouseX,mouseY);
- }
-}
-
diff --git a/java/examples/Books/Nature of Code/chp4_systems/Exercise_4_12_ArrayofImages/Particle.pde b/java/examples/Books/Nature of Code/chp4_systems/Exercise_4_12_ArrayofImages/Particle.pde
deleted file mode 100644
index adb3431f3..000000000
--- a/java/examples/Books/Nature of Code/chp4_systems/Exercise_4_12_ArrayofImages/Particle.pde
+++ /dev/null
@@ -1,59 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Simple Particle System
-
-class Particle {
- PVector loc;
- PVector vel;
- PVector acc;
- float lifespan;
-
- PImage img;
-
- // Another constructor (the one we are using here)
- Particle(float x, float y, PImage img_) {
- // Boring example with constant acceleration
- acc = new PVector(0, 0);
- vel = PVector.random2D();
- loc = new PVector(x, y);
- lifespan = 255;
- img = img_;
- }
-
- void run() {
- update();
- render();
- }
-
- void applyForce(PVector f) {
- acc.add(f);
- }
-
- // Method to update location
- void update() {
- vel.add(acc);
- loc.add(vel);
- acc.mult(0);
- lifespan -= 2.0;
- }
-
- // Method to display
- void render() {
- imageMode(CENTER);
- tint(lifespan);
- image(img, loc.x, loc.y, 32, 32);
- }
-
- // Is the particle still useful?
- boolean isDead() {
- if (lifespan <= 0.0) {
- return true;
- }
- else {
- return false;
- }
- }
-}
-
diff --git a/java/examples/Books/Nature of Code/chp4_systems/Exercise_4_12_ArrayofImages/ParticleSystem.pde b/java/examples/Books/Nature of Code/chp4_systems/Exercise_4_12_ArrayofImages/ParticleSystem.pde
deleted file mode 100644
index 98208b71e..000000000
--- a/java/examples/Books/Nature of Code/chp4_systems/Exercise_4_12_ArrayofImages/ParticleSystem.pde
+++ /dev/null
@@ -1,55 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// A class to describe a group of Particles
-// An ArrayList is used to manage the list of Particles
-
-class ParticleSystem {
-
- ArrayList particles; // An arraylist for all the particles
-
- PImage[] textures;
-
- ParticleSystem(PImage[] imgs, PVector v) {
- textures = imgs;
- particles = new ArrayList(); // Initialize the arraylist
- }
-
- void run() {
- for (int i = particles.size()-1; i >= 0; i--) {
- Particle p = particles.get(i);
- p.run();
- if (p.isDead()) {
- particles.remove(i);
- }
- }
- }
-
- void addParticle(float x, float y) {
- int r = int(random(textures.length));
- particles.add(new Particle(x,y,textures[r]));
- }
-
-
- void applyForce(PVector f) {
- for (Particle p : particles) {
- p.applyForce(f);
- }
- }
-
- void addParticle(Particle p) {
- particles.add(p);
- }
-
- // A method to test if the particle system still has particles
- boolean dead() {
- if (particles.isEmpty()) {
- return true;
- }
- else {
- return false;
- }
- }
-}
-
diff --git a/java/examples/Books/Nature of Code/chp4_systems/Exercise_4_12_ArrayofImages/data/texture.psd b/java/examples/Books/Nature of Code/chp4_systems/Exercise_4_12_ArrayofImages/data/texture.psd
deleted file mode 100644
index d532f15aa..000000000
Binary files a/java/examples/Books/Nature of Code/chp4_systems/Exercise_4_12_ArrayofImages/data/texture.psd and /dev/null differ
diff --git a/java/examples/Books/Nature of Code/chp4_systems/NOC_4_01_SingleParticle/NOC_4_01_SingleParticle.pde b/java/examples/Books/Nature of Code/chp4_systems/NOC_4_01_SingleParticle/NOC_4_01_SingleParticle.pde
deleted file mode 100644
index 1ab939148..000000000
--- a/java/examples/Books/Nature of Code/chp4_systems/NOC_4_01_SingleParticle/NOC_4_01_SingleParticle.pde
+++ /dev/null
@@ -1,25 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-Particle p;
-
-void setup() {
- size(800,200);
- p = new Particle(new PVector(width/2,20));
- background(255);
- smooth();
-}
-
-void draw() {
- background(255);
-
- p.run();
- if (p.isDead()) {
- p = new Particle(new PVector(width/2,20));
- //println("Particle dead!");
- }
-}
-
-
-
diff --git a/java/examples/Books/Nature of Code/chp4_systems/NOC_4_01_SingleParticle/Particle.pde b/java/examples/Books/Nature of Code/chp4_systems/NOC_4_01_SingleParticle/Particle.pde
deleted file mode 100644
index ca927c34a..000000000
--- a/java/examples/Books/Nature of Code/chp4_systems/NOC_4_01_SingleParticle/Particle.pde
+++ /dev/null
@@ -1,52 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Simple Particle System
-
-// A simple Particle class
-
-class Particle {
- PVector location;
- PVector velocity;
- PVector acceleration;
- float lifespan;
-
- Particle(PVector l) {
- acceleration = new PVector(0, 0.05);
- velocity = new PVector(random(-1, 1), random(-1, 0));
- location = l.get();
- lifespan = 255.0;
- }
-
- void run() {
- update();
- display();
- }
-
- // Method to update location
- void update() {
- velocity.add(acceleration);
- location.add(velocity);
- lifespan -= 2.0;
- }
-
- // Method to display
- void display() {
- stroke(0, lifespan);
- strokeWeight(2);
- fill(127, lifespan);
- ellipse(location.x, location.y, 12, 12);
- }
-
- // Is the particle still useful?
- boolean isDead() {
- if (lifespan < 0.0) {
- return true;
- }
- else {
- return false;
- }
- }
-}
-
diff --git a/java/examples/Books/Nature of Code/chp4_systems/NOC_4_01_SingleParticle_trail/NOC_4_01_SingleParticle_trail.pde b/java/examples/Books/Nature of Code/chp4_systems/NOC_4_01_SingleParticle_trail/NOC_4_01_SingleParticle_trail.pde
deleted file mode 100644
index e372ea14e..000000000
--- a/java/examples/Books/Nature of Code/chp4_systems/NOC_4_01_SingleParticle_trail/NOC_4_01_SingleParticle_trail.pde
+++ /dev/null
@@ -1,27 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-Particle p;
-
-void setup() {
- size(800, 200);
- p = new Particle(new PVector(width/2, 20));
- background(255);
- smooth();
-}
-
-void draw() {
- if (mousePressed) {
- noStroke();
- fill(255, 5);
- rect(0, 0, width, height);
-
- p.run();
- if (p.isDead()) {
- println("Particle dead!");
- }
- }
-}
-
-
diff --git a/java/examples/Books/Nature of Code/chp4_systems/NOC_4_01_SingleParticle_trail/Particle.pde b/java/examples/Books/Nature of Code/chp4_systems/NOC_4_01_SingleParticle_trail/Particle.pde
deleted file mode 100644
index 5e78f8545..000000000
--- a/java/examples/Books/Nature of Code/chp4_systems/NOC_4_01_SingleParticle_trail/Particle.pde
+++ /dev/null
@@ -1,50 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Simple Particle System
-
-class Particle {
- PVector location;
- PVector velocity;
- PVector acceleration;
- float lifespan;
-
- Particle(PVector l) {
- acceleration = new PVector(0, 0.05);
- velocity = new PVector(random(-1, 1), -1);
- location = l.get();
- lifespan = 255.0;
- }
-
- void run() {
- update();
- display();
- }
-
- // Method to update location
- void update() {
- velocity.add(acceleration);
- location.add(velocity);
- lifespan -= 2.0;
- }
-
- // Method to display
- void display() {
- stroke(0, lifespan);
- strokeWeight(2);
- fill(127);
- ellipse(location.x, location.y, 12, 12);
- }
-
- // Is the particle still useful?
- boolean isDead() {
- if (lifespan < 0.0) {
- return true;
- }
- else {
- return false;
- }
- }
-}
-
diff --git a/java/examples/Books/Nature of Code/chp4_systems/NOC_4_02_ArrayListParticles/NOC_4_02_ArrayListParticles.pde b/java/examples/Books/Nature of Code/chp4_systems/NOC_4_02_ArrayListParticles/NOC_4_02_ArrayListParticles.pde
deleted file mode 100644
index c0820f600..000000000
--- a/java/examples/Books/Nature of Code/chp4_systems/NOC_4_02_ArrayListParticles/NOC_4_02_ArrayListParticles.pde
+++ /dev/null
@@ -1,29 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-ArrayList particles;
-
-void setup() {
- size(640,360);
- particles = new ArrayList();
-}
-
-void draw() {
- background(255);
-
- particles.add(new Particle(new PVector(width/2,50)));
-
- // Looping through backwards to delete
- for (int i = particles.size()-1; i >= 0; i--) {
- Particle p = particles.get(i);
- p.run();
- if (p.isDead()) {
- particles.remove(i);
- }
- }
-}
-
-
-
-
diff --git a/java/examples/Books/Nature of Code/chp4_systems/NOC_4_02_ArrayListParticles/Particle.pde b/java/examples/Books/Nature of Code/chp4_systems/NOC_4_02_ArrayListParticles/Particle.pde
deleted file mode 100644
index a4c372ac4..000000000
--- a/java/examples/Books/Nature of Code/chp4_systems/NOC_4_02_ArrayListParticles/Particle.pde
+++ /dev/null
@@ -1,50 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Simple Particle System
-
-class Particle {
- PVector location;
- PVector velocity;
- PVector acceleration;
- float lifespan;
-
- Particle(PVector l) {
- acceleration = new PVector(0, 0.05);
- velocity = new PVector(random(-1, 1), random(-2, 0));
- location = l.get();
- lifespan = 255.0;
- }
-
- void run() {
- update();
- display();
- }
-
- // Method to update location
- void update() {
- velocity.add(acceleration);
- location.add(velocity);
- lifespan -= 2.0;
- }
-
- // Method to display
- void display() {
- stroke(0, lifespan);
- strokeWeight(2);
- fill(127, lifespan);
- ellipse(location.x, location.y, 12, 12);
- }
-
- // Is the particle still useful?
- boolean isDead() {
- if (lifespan < 0.0) {
- return true;
- }
- else {
- return false;
- }
- }
-}
-
diff --git a/java/examples/Books/Nature of Code/chp4_systems/NOC_4_03_ParticleSystemClass/NOC_4_03_ParticleSystemClass.pde b/java/examples/Books/Nature of Code/chp4_systems/NOC_4_03_ParticleSystemClass/NOC_4_03_ParticleSystemClass.pde
deleted file mode 100644
index 935a214da..000000000
--- a/java/examples/Books/Nature of Code/chp4_systems/NOC_4_03_ParticleSystemClass/NOC_4_03_ParticleSystemClass.pde
+++ /dev/null
@@ -1,16 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-ParticleSystem ps;
-
-void setup() {
- size(640,360);
- ps = new ParticleSystem(new PVector(width/2,50));
-}
-
-void draw() {
- background(255);
- ps.addParticle();
- ps.run();
-}
diff --git a/java/examples/Books/Nature of Code/chp4_systems/NOC_4_03_ParticleSystemClass/Particle.pde b/java/examples/Books/Nature of Code/chp4_systems/NOC_4_03_ParticleSystemClass/Particle.pde
deleted file mode 100644
index 12d1ef02a..000000000
--- a/java/examples/Books/Nature of Code/chp4_systems/NOC_4_03_ParticleSystemClass/Particle.pde
+++ /dev/null
@@ -1,50 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Simple Particle System
-
-class Particle {
- PVector location;
- PVector velocity;
- PVector acceleration;
- float lifespan;
-
- Particle(PVector l) {
- acceleration = new PVector(0,0.05);
- velocity = new PVector(random(-1,1),random(-2,0));
- location = l.get();
- lifespan = 255.0;
- }
-
- void run() {
- update();
- display();
- }
-
- // Method to update location
- void update() {
- velocity.add(acceleration);
- location.add(velocity);
- lifespan -= 2.0;
- }
-
- // Method to display
- void display() {
- stroke(0,lifespan);
- strokeWeight(2);
- fill(127,lifespan);
- ellipse(location.x,location.y,12,12);
- }
-
- // Is the particle still useful?
- boolean isDead() {
- if (lifespan < 0.0) {
- return true;
- } else {
- return false;
- }
- }
-}
-
-
diff --git a/java/examples/Books/Nature of Code/chp4_systems/NOC_4_03_ParticleSystemClass/ParticleSystem.pde b/java/examples/Books/Nature of Code/chp4_systems/NOC_4_03_ParticleSystemClass/ParticleSystem.pde
deleted file mode 100644
index ffddfc873..000000000
--- a/java/examples/Books/Nature of Code/chp4_systems/NOC_4_03_ParticleSystemClass/ParticleSystem.pde
+++ /dev/null
@@ -1,33 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Using Generics now! comment and annotate, etc.
-
-class ParticleSystem {
- ArrayList particles;
- PVector origin;
-
- ParticleSystem(PVector location) {
- origin = location.get();
- particles = new ArrayList();
- }
-
- void addParticle() {
- particles.add(new Particle(origin));
- }
-
- void run() {
- for (int i = particles.size()-1; i >= 0; i--) {
- Particle p = particles.get(i);
- p.run();
- if (p.isDead()) {
- particles.remove(i);
- }
- }
- }
-}
-
-
-
-
diff --git a/java/examples/Books/Nature of Code/chp4_systems/NOC_4_04_SystemofSystems/NOC_4_04_SystemofSystems.pde b/java/examples/Books/Nature of Code/chp4_systems/NOC_4_04_SystemofSystems/NOC_4_04_SystemofSystems.pde
deleted file mode 100644
index 2fe6ee428..000000000
--- a/java/examples/Books/Nature of Code/chp4_systems/NOC_4_04_SystemofSystems/NOC_4_04_SystemofSystems.pde
+++ /dev/null
@@ -1,34 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-// Simple Particle System
-
-// Particles are generated each cycle through draw(),
-// fall with gravity and fade out over time
-// A ParticleSystem object manages a variable size (ArrayList)
-// list of particles.
-
-ArrayList systems;
-
-void setup() {
- size(640,360);
- systems = new ArrayList();
-}
-
-void draw() {
- background(255);
- for (ParticleSystem ps: systems) {
- ps.run();
- ps.addParticle();
- }
-
- fill(0);
- text("click mouse to add particle systems",10,height-30);
-}
-
-void mousePressed() {
- systems.add(new ParticleSystem(1,new PVector(mouseX,mouseY)));
-}
-
-
-
diff --git a/java/examples/Books/Nature of Code/chp4_systems/NOC_4_04_SystemofSystems/Particle.pde b/java/examples/Books/Nature of Code/chp4_systems/NOC_4_04_SystemofSystems/Particle.pde
deleted file mode 100644
index 12d1ef02a..000000000
--- a/java/examples/Books/Nature of Code/chp4_systems/NOC_4_04_SystemofSystems/Particle.pde
+++ /dev/null
@@ -1,50 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Simple Particle System
-
-class Particle {
- PVector location;
- PVector velocity;
- PVector acceleration;
- float lifespan;
-
- Particle(PVector l) {
- acceleration = new PVector(0,0.05);
- velocity = new PVector(random(-1,1),random(-2,0));
- location = l.get();
- lifespan = 255.0;
- }
-
- void run() {
- update();
- display();
- }
-
- // Method to update location
- void update() {
- velocity.add(acceleration);
- location.add(velocity);
- lifespan -= 2.0;
- }
-
- // Method to display
- void display() {
- stroke(0,lifespan);
- strokeWeight(2);
- fill(127,lifespan);
- ellipse(location.x,location.y,12,12);
- }
-
- // Is the particle still useful?
- boolean isDead() {
- if (lifespan < 0.0) {
- return true;
- } else {
- return false;
- }
- }
-}
-
-
diff --git a/java/examples/Books/Nature of Code/chp4_systems/NOC_4_04_SystemofSystems/ParticleSystem.pde b/java/examples/Books/Nature of Code/chp4_systems/NOC_4_04_SystemofSystems/ParticleSystem.pde
deleted file mode 100644
index 06f1ff3a9..000000000
--- a/java/examples/Books/Nature of Code/chp4_systems/NOC_4_04_SystemofSystems/ParticleSystem.pde
+++ /dev/null
@@ -1,48 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Simple Particle System
-
-// A class to describe a group of Particles
-// An ArrayList is used to manage the list of Particles
-
-class ParticleSystem {
-
- ArrayList particles; // An arraylist for all the particles
- PVector origin; // An origin point for where particles are birthed
-
- ParticleSystem(int num, PVector v) {
- particles = new ArrayList(); // Initialize the arraylist
- origin = v.get(); // Store the origin point
- for (int i = 0; i < num; i++) {
- particles.add(new Particle(origin)); // Add "num" amount of particles to the arraylist
- }
- }
-
- void run() {
- for (int i = particles.size()-1; i >= 0; i--) {
- Particle p = particles.get(i);
- p.run();
- if (p.isDead()) {
- particles.remove(i);
- }
- }
- }
-
- void addParticle() {
- particles.add(new Particle(origin));
- }
-
- // A method to test if the particle system still has particles
- boolean dead() {
- if (particles.isEmpty()) {
- return true;
- }
- else {
- return false;
- }
- }
-}
-
-
diff --git a/java/examples/Books/Nature of Code/chp4_systems/NOC_4_05_ParticleSystemInheritancePolymorphism/Confetti.pde b/java/examples/Books/Nature of Code/chp4_systems/NOC_4_05_ParticleSystemInheritancePolymorphism/Confetti.pde
deleted file mode 100644
index e86ce8d5b..000000000
--- a/java/examples/Books/Nature of Code/chp4_systems/NOC_4_05_ParticleSystemInheritancePolymorphism/Confetti.pde
+++ /dev/null
@@ -1,29 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-class Confetti extends Particle {
-
- // We could add variables for only Confetti here if we so
-
- Confetti(PVector l) {
- super(l);
- }
-
- // Inherits update() from parent
-
- // Override the display method
- void display() {
- rectMode(CENTER);
- fill(127,lifespan);
- stroke(0,lifespan);
- strokeWeight(2);
- pushMatrix();
- translate(location.x,location.y);
- float theta = map(location.x,0,width,0,TWO_PI*2);
- rotate(theta);
- rect(0,0,12,12);
- popMatrix();
- }
-}
-
diff --git a/java/examples/Books/Nature of Code/chp4_systems/NOC_4_05_ParticleSystemInheritancePolymorphism/NOC_4_05_ParticleSystemInheritancePolymorphism.pde b/java/examples/Books/Nature of Code/chp4_systems/NOC_4_05_ParticleSystemInheritancePolymorphism/NOC_4_05_ParticleSystemInheritancePolymorphism.pde
deleted file mode 100644
index 935a214da..000000000
--- a/java/examples/Books/Nature of Code/chp4_systems/NOC_4_05_ParticleSystemInheritancePolymorphism/NOC_4_05_ParticleSystemInheritancePolymorphism.pde
+++ /dev/null
@@ -1,16 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-ParticleSystem ps;
-
-void setup() {
- size(640,360);
- ps = new ParticleSystem(new PVector(width/2,50));
-}
-
-void draw() {
- background(255);
- ps.addParticle();
- ps.run();
-}
diff --git a/java/examples/Books/Nature of Code/chp4_systems/NOC_4_05_ParticleSystemInheritancePolymorphism/Particle.pde b/java/examples/Books/Nature of Code/chp4_systems/NOC_4_05_ParticleSystemInheritancePolymorphism/Particle.pde
deleted file mode 100644
index b38b30cf7..000000000
--- a/java/examples/Books/Nature of Code/chp4_systems/NOC_4_05_ParticleSystemInheritancePolymorphism/Particle.pde
+++ /dev/null
@@ -1,51 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Simple Particle System
-
-class Particle {
-
- PVector location;
- PVector velocity;
- PVector acceleration;
- float lifespan;
-
- Particle(PVector l) {
- acceleration = new PVector(0,0.05);
- velocity = new PVector(random(-1,1),random(-2,0));
- location = l.get();
- lifespan = 255.0;
- }
-
- void run() {
- update();
- display();
- }
-
- // Method to update location
- void update() {
- velocity.add(acceleration);
- location.add(velocity);
- lifespan -= 2.0;
- }
-
- // Method to display
- void display() {
- stroke(0,lifespan);
- strokeWeight(2);
- fill(127,lifespan);
- ellipse(location.x,location.y,12,12);
- }
-
- // Is the particle still useful?
- boolean isDead() {
- if (lifespan < 0.0) {
- return true;
- } else {
- return false;
- }
- }
-}
-
-
diff --git a/java/examples/Books/Nature of Code/chp4_systems/NOC_4_05_ParticleSystemInheritancePolymorphism/ParticleSystem.pde b/java/examples/Books/Nature of Code/chp4_systems/NOC_4_05_ParticleSystemInheritancePolymorphism/ParticleSystem.pde
deleted file mode 100644
index 28fde7c2e..000000000
--- a/java/examples/Books/Nature of Code/chp4_systems/NOC_4_05_ParticleSystemInheritancePolymorphism/ParticleSystem.pde
+++ /dev/null
@@ -1,36 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-class ParticleSystem {
- ArrayList particles;
- PVector origin;
-
- ParticleSystem(PVector location) {
- origin = location.get();
- particles = new ArrayList();
- }
-
- void addParticle() {
- float r = random(1);
- if (r < 0.5) {
- particles.add(new Particle(origin));
- }
- else {
- particles.add(new Confetti(origin));
- }
- }
-
- void run() {
- for (int i = particles.size()-1; i >= 0; i--) {
- Particle p = particles.get(i);
- p.run();
- if (p.isDead()) {
- particles.remove(i);
- }
- }
- }
-}
-
-
-
diff --git a/java/examples/Books/Nature of Code/chp4_systems/NOC_4_06_ParticleSystemForces/NOC_4_06_ParticleSystemForces.pde b/java/examples/Books/Nature of Code/chp4_systems/NOC_4_06_ParticleSystemForces/NOC_4_06_ParticleSystemForces.pde
deleted file mode 100644
index eef4c0555..000000000
--- a/java/examples/Books/Nature of Code/chp4_systems/NOC_4_06_ParticleSystemForces/NOC_4_06_ParticleSystemForces.pde
+++ /dev/null
@@ -1,21 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-ParticleSystem ps;
-
-void setup() {
- size(640,360);
- ps = new ParticleSystem(new PVector(width/2,50));
-}
-
-void draw() {
- background(255);
-
- // Apply gravity force to all Particles
- PVector gravity = new PVector(0,0.1);
- ps.applyForce(gravity);
-
- ps.addParticle();
- ps.run();
-}
diff --git a/java/examples/Books/Nature of Code/chp4_systems/NOC_4_06_ParticleSystemForces/Particle.pde b/java/examples/Books/Nature of Code/chp4_systems/NOC_4_06_ParticleSystemForces/Particle.pde
deleted file mode 100644
index 971ea0c5c..000000000
--- a/java/examples/Books/Nature of Code/chp4_systems/NOC_4_06_ParticleSystemForces/Particle.pde
+++ /dev/null
@@ -1,56 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-class Particle {
- PVector location;
- PVector velocity;
- PVector acceleration;
- float lifespan;
-
- float mass = 1; // Let's do something better here!
-
- Particle(PVector l) {
- acceleration = new PVector(0,0);
- velocity = new PVector(random(-1,1),random(-2,0));
- location = l.get();
- lifespan = 255.0;
- }
-
- void run() {
- update();
- display();
- }
-
- void applyForce(PVector force) {
- PVector f = force.get();
- f.div(mass);
- acceleration.add(f);
- }
-
- // Method to update location
- void update() {
- velocity.add(acceleration);
- location.add(velocity);
- acceleration.mult(0);
- lifespan -= 2.0;
- }
-
- // Method to display
- void display() {
- stroke(0,lifespan);
- strokeWeight(2);
- fill(127,lifespan);
- ellipse(location.x,location.y,12,12);
- }
-
- // Is the particle still useful?
- boolean isDead() {
- if (lifespan < 0.0) {
- return true;
- } else {
- return false;
- }
- }
-}
-
diff --git a/java/examples/Books/Nature of Code/chp4_systems/NOC_4_06_ParticleSystemForces/ParticleSystem.pde b/java/examples/Books/Nature of Code/chp4_systems/NOC_4_06_ParticleSystemForces/ParticleSystem.pde
deleted file mode 100644
index c840ffd5b..000000000
--- a/java/examples/Books/Nature of Code/chp4_systems/NOC_4_06_ParticleSystemForces/ParticleSystem.pde
+++ /dev/null
@@ -1,35 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-class ParticleSystem {
- ArrayList particles;
- PVector origin;
-
- ParticleSystem(PVector location) {
- origin = location.get();
- particles = new ArrayList();
- }
-
- void addParticle() {
- particles.add(new Particle(origin));
- }
-
- // A function to apply a force to all Particles
- void applyForce(PVector f) {
- for (Particle p: particles) {
- p.applyForce(f);
- }
- }
-
- void run() {
- for (int i = particles.size()-1; i >= 0; i--) {
- Particle p = particles.get(i);
- p.run();
- if (p.isDead()) {
- particles.remove(i);
- }
- }
- }
-}
-
diff --git a/java/examples/Books/Nature of Code/chp4_systems/NOC_4_07_ParticleSystemForcesRepeller/NOC_4_07_ParticleSystemForcesRepeller.pde b/java/examples/Books/Nature of Code/chp4_systems/NOC_4_07_ParticleSystemForcesRepeller/NOC_4_07_ParticleSystemForcesRepeller.pde
deleted file mode 100644
index c7de70143..000000000
--- a/java/examples/Books/Nature of Code/chp4_systems/NOC_4_07_ParticleSystemForcesRepeller/NOC_4_07_ParticleSystemForcesRepeller.pde
+++ /dev/null
@@ -1,26 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-ParticleSystem ps;
-Repeller repeller;
-
-void setup() {
- size(640,360);
- ps = new ParticleSystem(new PVector(width/2,50));
- repeller = new Repeller(width/2-20,height/2);
-}
-
-void draw() {
- background(255);
- ps.addParticle();
-
- // Apply gravity force to all Particles
- PVector gravity = new PVector(0,0.1);
- ps.applyForce(gravity);
-
- ps.applyRepeller(repeller);
-
- repeller.display();
- ps.run();
-}
diff --git a/java/examples/Books/Nature of Code/chp4_systems/NOC_4_07_ParticleSystemForcesRepeller/Particle.pde b/java/examples/Books/Nature of Code/chp4_systems/NOC_4_07_ParticleSystemForcesRepeller/Particle.pde
deleted file mode 100644
index 971ea0c5c..000000000
--- a/java/examples/Books/Nature of Code/chp4_systems/NOC_4_07_ParticleSystemForcesRepeller/Particle.pde
+++ /dev/null
@@ -1,56 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-class Particle {
- PVector location;
- PVector velocity;
- PVector acceleration;
- float lifespan;
-
- float mass = 1; // Let's do something better here!
-
- Particle(PVector l) {
- acceleration = new PVector(0,0);
- velocity = new PVector(random(-1,1),random(-2,0));
- location = l.get();
- lifespan = 255.0;
- }
-
- void run() {
- update();
- display();
- }
-
- void applyForce(PVector force) {
- PVector f = force.get();
- f.div(mass);
- acceleration.add(f);
- }
-
- // Method to update location
- void update() {
- velocity.add(acceleration);
- location.add(velocity);
- acceleration.mult(0);
- lifespan -= 2.0;
- }
-
- // Method to display
- void display() {
- stroke(0,lifespan);
- strokeWeight(2);
- fill(127,lifespan);
- ellipse(location.x,location.y,12,12);
- }
-
- // Is the particle still useful?
- boolean isDead() {
- if (lifespan < 0.0) {
- return true;
- } else {
- return false;
- }
- }
-}
-
diff --git a/java/examples/Books/Nature of Code/chp4_systems/NOC_4_07_ParticleSystemForcesRepeller/ParticleSystem.pde b/java/examples/Books/Nature of Code/chp4_systems/NOC_4_07_ParticleSystemForcesRepeller/ParticleSystem.pde
deleted file mode 100644
index d4ad80fa7..000000000
--- a/java/examples/Books/Nature of Code/chp4_systems/NOC_4_07_ParticleSystemForcesRepeller/ParticleSystem.pde
+++ /dev/null
@@ -1,44 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-class ParticleSystem {
- ArrayList particles;
- PVector origin;
-
- ParticleSystem(PVector location) {
- origin = location.get();
- particles = new ArrayList();
- }
-
- void addParticle() {
- particles.add(new Particle(origin));
- }
-
- // A function to apply a force to all Particles
- void applyForce(PVector f) {
- for (Particle p: particles) {
- p.applyForce(f);
- }
- }
-
- void applyRepeller(Repeller r) {
- for (Particle p: particles) {
- PVector force = r.repel(p);
- p.applyForce(force);
- }
- }
-
-
- void run() {
- for (int i = particles.size()-1; i >= 0; i--) {
- Particle p = particles.get(i);
- p.run();
- if (p.isDead()) {
- particles.remove(i);
- }
- }
- }
-}
-
-
diff --git a/java/examples/Books/Nature of Code/chp4_systems/NOC_4_07_ParticleSystemForcesRepeller/Repeller.pde b/java/examples/Books/Nature of Code/chp4_systems/NOC_4_07_ParticleSystemForcesRepeller/Repeller.pde
deleted file mode 100644
index 351780121..000000000
--- a/java/examples/Books/Nature of Code/chp4_systems/NOC_4_07_ParticleSystemForcesRepeller/Repeller.pde
+++ /dev/null
@@ -1,39 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Particles + Forces
-
-// A very basic Repeller class
-class Repeller {
-
- // Gravitational Constant
- float G = 100;
- // Location
- PVector location;
- float r = 10;
-
- Repeller(float x, float y) {
- location = new PVector(x,y);
- }
-
- void display() {
- stroke(0);
- strokeWeight(2);
- fill(175);
- ellipse(location.x,location.y,48,48);
- }
-
- // Calculate a force to push particle away from repeller
- PVector repel(Particle p) {
- PVector dir = PVector.sub(location,p.location); // Calculate direction of force
- float d = dir.mag(); // Distance between objects
- dir.normalize(); // Normalize vector (distance doesn't matter here, we just want this vector for direction)
- d = constrain(d,5,100); // Keep distance within a reasonable range
- float force = -1 * G / (d * d); // Repelling force is inversely proportional to distance
- dir.mult(force); // Get force vector --> magnitude * direction
- return dir;
- }
-}
-
-
diff --git a/java/examples/Books/Nature of Code/chp4_systems/NOC_4_08_ParticleSystemSmoke/NOC_4_08_ParticleSystemSmoke.pde b/java/examples/Books/Nature of Code/chp4_systems/NOC_4_08_ParticleSystemSmoke/NOC_4_08_ParticleSystemSmoke.pde
deleted file mode 100644
index fb11356e4..000000000
--- a/java/examples/Books/Nature of Code/chp4_systems/NOC_4_08_ParticleSystemSmoke/NOC_4_08_ParticleSystemSmoke.pde
+++ /dev/null
@@ -1,54 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Smoke Particle System
-
-// A basic smoke effect using a particle system
-// Each particle is rendered as an alpha masked image
-
-/* @pjs preload="processingjs/chapter04/_4_08_ParticleSystemSmoke/data/texture.png"; */
-
-ParticleSystem ps;
-
-void setup() {
- size(640,360);
- PImage img = loadImage("texture.png");
- ps = new ParticleSystem(0,new PVector(width/2,height-75),img);
-}
-
-void draw() {
- background(0);
-
- // Calculate a "wind" force based on mouse horizontal position
- float dx = map(mouseX,0,width,-0.2,0.2);
- PVector wind = new PVector(dx,0);
- ps.applyForce(wind);
- ps.run();
- for (int i = 0; i < 2; i++) {
- ps.addParticle();
- }
-
- // Draw an arrow representing the wind force
- drawVector(wind, new PVector(width/2,50,0),500);
-
-}
-
-// Renders a vector object 'v' as an arrow and a location 'loc'
-void drawVector(PVector v, PVector loc, float scayl) {
- pushMatrix();
- float arrowsize = 4;
- // Translate to location to render vector
- translate(loc.x,loc.y);
- stroke(255);
- // Call vector heading function to get direction (note that pointing up is a heading of 0) and rotate
- rotate(v.heading2D());
- // Calculate length of vector & scale it to be bigger or smaller if necessary
- float len = v.mag()*scayl;
- // Draw three lines to make an arrow (draw pointing up since we've rotate to the proper direction)
- line(0,0,len,0);
- line(len,0,len-arrowsize,+arrowsize/2);
- line(len,0,len-arrowsize,-arrowsize/2);
- popMatrix();
-}
-
diff --git a/java/examples/Books/Nature of Code/chp4_systems/NOC_4_08_ParticleSystemSmoke/Particle.pde b/java/examples/Books/Nature of Code/chp4_systems/NOC_4_08_ParticleSystemSmoke/Particle.pde
deleted file mode 100644
index b3dce76be..000000000
--- a/java/examples/Books/Nature of Code/chp4_systems/NOC_4_08_ParticleSystemSmoke/Particle.pde
+++ /dev/null
@@ -1,61 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-class Particle {
- PVector loc;
- PVector vel;
- PVector acc;
- float lifespan;
- PImage img;
-
- Particle(PVector l,PImage img_) {
- acc = new PVector(0,0);
- float vx = randomGaussian()*0.3;
- float vy = randomGaussian()*0.3 - 1.0;
- vel = new PVector(vx,vy);
- loc = l.get();
- lifespan = 100.0;
- img = img_;
- }
-
- void run() {
- update();
- render();
- }
-
- // Method to apply a force vector to the Particle object
- // Note we are ignoring "mass" here
- void applyForce(PVector f) {
- acc.add(f);
- }
-
- // Method to update location
- void update() {
- vel.add(acc);
- loc.add(vel);
- lifespan -= 2.5;
- acc.mult(0); // clear Acceleration
- }
-
- // Method to display
- void render() {
- imageMode(CENTER);
- tint(255,lifespan);
- image(img,loc.x,loc.y);
- // Drawing a circle instead
- // fill(255,lifespan);
- // noStroke();
- // ellipse(loc.x,loc.y,img.width,img.height);
- }
-
- // Is the particle still useful?
- boolean isDead() {
- if (lifespan <= 0.0) {
- return true;
- } else {
- return false;
- }
- }
-}
-
diff --git a/java/examples/Books/Nature of Code/chp4_systems/NOC_4_08_ParticleSystemSmoke/ParticleSystem.pde b/java/examples/Books/Nature of Code/chp4_systems/NOC_4_08_ParticleSystemSmoke/ParticleSystem.pde
deleted file mode 100644
index 93fee68fa..000000000
--- a/java/examples/Books/Nature of Code/chp4_systems/NOC_4_08_ParticleSystemSmoke/ParticleSystem.pde
+++ /dev/null
@@ -1,49 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Smoke Particle System
-
-// A class to describe a group of Particles
-// An ArrayList is used to manage the list of Particles
-
-class ParticleSystem {
-
- ArrayList particles; // An arraylist for all the particles
- PVector origin; // An origin point for where particles are birthed
- PImage img;
-
- ParticleSystem(int num, PVector v, PImage img_) {
- particles = new ArrayList(); // Initialize the arraylist
- origin = v.get(); // Store the origin point
- img = img_;
- for (int i = 0; i < num; i++) {
- particles.add(new Particle(origin, img)); // Add "num" amount of particles to the arraylist
- }
- }
-
- void run() {
- for (int i = particles.size()-1; i >= 0; i--) {
- Particle p = particles.get(i);
- p.run();
- if (p.isDead()) {
- particles.remove(i);
- }
- }
- }
-
- // Method to add a force vector to all particles currently in the system
- void applyForce(PVector dir) {
- // Enhanced loop!!!
- for (Particle p: particles) {
- p.applyForce(dir);
- }
- }
-
- void addParticle() {
- particles.add(new Particle(origin, img));
- }
-
-}
-
-
diff --git a/java/examples/Books/Nature of Code/chp4_systems/NOC_4_08_ParticleSystemSmoke/data/texture.psd b/java/examples/Books/Nature of Code/chp4_systems/NOC_4_08_ParticleSystemSmoke/data/texture.psd
deleted file mode 100644
index 8208feb02..000000000
Binary files a/java/examples/Books/Nature of Code/chp4_systems/NOC_4_08_ParticleSystemSmoke/data/texture.psd and /dev/null differ
diff --git a/java/examples/Books/Nature of Code/chp4_systems/NOC_4_08_ParticleSystemSmoke_b/NOC_4_08_ParticleSystemSmoke_b.pde b/java/examples/Books/Nature of Code/chp4_systems/NOC_4_08_ParticleSystemSmoke_b/NOC_4_08_ParticleSystemSmoke_b.pde
deleted file mode 100644
index 52e945c60..000000000
--- a/java/examples/Books/Nature of Code/chp4_systems/NOC_4_08_ParticleSystemSmoke_b/NOC_4_08_ParticleSystemSmoke_b.pde
+++ /dev/null
@@ -1,59 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Smoke Particle System
-
-// A basic smoke effect using a particle system
-// Each particle is rendered as an alpha masked image
-
-/* @pjs preload="processingjs/chapter04/_4_08_ParticleSystemSmoke/data/texture.png"; */
-
-import java.util.Random;
-
-ParticleSystem ps;
-Random generator;
-
-void setup() {
- size(640,360);
- generator = new Random();
- PImage img = loadImage("texture.png");
- ps = new ParticleSystem(0,new PVector(width/2,height-75),img);
- smooth();
-}
-
-void draw() {
- background(0);
-
- // Calculate a "wind" force based on mouse horizontal position
- float dx = map(mouseX,0,width,-0.2,0.2);
- PVector wind = new PVector(dx,0);
- ps.applyForce(wind);
- ps.run();
- for (int i = 0; i < 2; i++) {
- ps.addParticle();
- }
-
- // Draw an arrow representing the wind force
- drawVector(wind, new PVector(width/2,50,0),500);
-
-}
-
-// Renders a vector object 'v' as an arrow and a location 'loc'
-void drawVector(PVector v, PVector loc, float scayl) {
- pushMatrix();
- float arrowsize = 4;
- // Translate to location to render vector
- translate(loc.x,loc.y);
- stroke(255);
- // Call vector heading function to get direction (note that pointing up is a heading of 0) and rotate
- rotate(v.heading2D());
- // Calculate length of vector & scale it to be bigger or smaller if necessary
- float len = v.mag()*scayl;
- // Draw three lines to make an arrow (draw pointing up since we've rotate to the proper direction)
- line(0,0,len,0);
- line(len,0,len-arrowsize,+arrowsize/2);
- line(len,0,len-arrowsize,-arrowsize/2);
- popMatrix();
-}
-
diff --git a/java/examples/Books/Nature of Code/chp4_systems/NOC_4_08_ParticleSystemSmoke_b/Particle.pde b/java/examples/Books/Nature of Code/chp4_systems/NOC_4_08_ParticleSystemSmoke_b/Particle.pde
deleted file mode 100644
index c5516d104..000000000
--- a/java/examples/Books/Nature of Code/chp4_systems/NOC_4_08_ParticleSystemSmoke_b/Particle.pde
+++ /dev/null
@@ -1,64 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-// Simple Particle System
-
-// A simple Particle class, renders the particle as an image
-
-class Particle {
- PVector loc;
- PVector vel;
- PVector acc;
- float lifespan;
- PImage img;
-
- Particle(PVector l,PImage img_) {
- acc = new PVector(0,0);
- float vx = (float) generator.nextGaussian()*0.3;
- float vy = (float) generator.nextGaussian()*0.3 - 1.0;
- vel = new PVector(vx,vy);
- loc = l.get();
- lifespan = 100.0;
- img = img_;
- }
-
- void run() {
- update();
- render();
- }
-
- // Method to apply a force vector to the Particle object
- // Note we are ignoring "mass" here
- void applyForce(PVector f) {
- acc.add(f);
- }
-
- // Method to update location
- void update() {
- vel.add(acc);
- loc.add(vel);
- lifespan -= 2.5;
- acc.mult(0); // clear Acceleration
- }
-
- // Method to display
- void render() {
- //imageMode(CENTER);
- //tint(255,lifespan);
- //image(img,loc.x,loc.y);
- // Drawing a circle instead
- fill(255,lifespan);
- noStroke();
- ellipse(loc.x,loc.y,img.width,img.height);
- }
-
- // Is the particle still useful?
- boolean isDead() {
- if (lifespan <= 0.0) {
- return true;
- } else {
- return false;
- }
- }
-}
-
diff --git a/java/examples/Books/Nature of Code/chp4_systems/NOC_4_08_ParticleSystemSmoke_b/ParticleSystem.pde b/java/examples/Books/Nature of Code/chp4_systems/NOC_4_08_ParticleSystemSmoke_b/ParticleSystem.pde
deleted file mode 100644
index 43296a098..000000000
--- a/java/examples/Books/Nature of Code/chp4_systems/NOC_4_08_ParticleSystemSmoke_b/ParticleSystem.pde
+++ /dev/null
@@ -1,63 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-// Smoke Particle Syste
-
-// A class to describe a group of Particles
-// An ArrayList is used to manage the list of Particles
-
-class ParticleSystem {
-
- ArrayList particles; // An arraylist for all the particles
- PVector origin; // An origin point for where particles are birthed
- PImage img;
-
- ParticleSystem(int num, PVector v, PImage img_) {
- particles = new ArrayList(); // Initialize the arraylist
- origin = v.get(); // Store the origin point
- img = img_;
- for (int i = 0; i < num; i++) {
- particles.add(new Particle(origin, img)); // Add "num" amount of particles to the arraylist
- }
- }
-
- void run() {
- for (int i = particles.size()-1; i >= 0; i--) {
- Particle p = particles.get(i);
- p.run();
- if (p.isDead()) {
- particles.remove(i);
- }
- }
- }
-
- // Method to add a force vector to all particles currently in the system
- void applyForce(PVector dir) {
- // Enhanced loop!!!
- for (Particle p: particles) {
- p.applyForce(dir);
- }
-
- }
-
- void addParticle() {
- particles.add(new Particle(origin,img));
- }
-
- void addParticle(Particle p) {
- particles.add(p);
- }
-
- // A method to test if the particle system still has particles
- boolean dead() {
- if (particles.isEmpty()) {
- return true;
- } else {
- return false;
- }
- }
-
-}
-
-
-
diff --git a/java/examples/Books/Nature of Code/chp4_systems/NOC_4_08_ParticleSystemSmoke_b/data/texture.psd b/java/examples/Books/Nature of Code/chp4_systems/NOC_4_08_ParticleSystemSmoke_b/data/texture.psd
deleted file mode 100644
index 8208feb02..000000000
Binary files a/java/examples/Books/Nature of Code/chp4_systems/NOC_4_08_ParticleSystemSmoke_b/data/texture.psd and /dev/null differ
diff --git a/java/examples/Books/Nature of Code/chp4_systems/NOC_4_09_AdditiveBlending/NOC_4_09_AdditiveBlending.pde b/java/examples/Books/Nature of Code/chp4_systems/NOC_4_09_AdditiveBlending/NOC_4_09_AdditiveBlending.pde
deleted file mode 100644
index d0341315f..000000000
--- a/java/examples/Books/Nature of Code/chp4_systems/NOC_4_09_AdditiveBlending/NOC_4_09_AdditiveBlending.pde
+++ /dev/null
@@ -1,37 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Additive Blending
-
-// This example demonstrates a "glow" like effect using
-// additive blending with a Particle system. By playing
-// with colors, textures, etc. you can achieve a variety
-// of looks.
-
-ParticleSystem ps;
-
-PImage img;
-
-void setup() {
- size(640, 360, P2D);
-
- // Create an alpha masked image to be applied as the particle's texture
- img = loadImage("texture.png");
-
- ps = new ParticleSystem(0, new PVector(width/2, 50));
-}
-
-void draw() {
-
- // Additive blending!
- blendMode(ADD);
-
- background(0);
-
- ps.run();
- for (int i = 0; i < 10; i++) {
- ps.addParticle();
- }
-}
-
diff --git a/java/examples/Books/Nature of Code/chp4_systems/NOC_4_09_AdditiveBlending/Particle.pde b/java/examples/Books/Nature of Code/chp4_systems/NOC_4_09_AdditiveBlending/Particle.pde
deleted file mode 100644
index d9853841b..000000000
--- a/java/examples/Books/Nature of Code/chp4_systems/NOC_4_09_AdditiveBlending/Particle.pde
+++ /dev/null
@@ -1,52 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Simple Particle System
-
-class Particle {
- PVector loc;
- PVector vel;
- PVector acc;
- float lifespan;
-
- // Another constructor (the one we are using here)
- Particle(PVector l) {
- // Boring example with constant acceleration
- acc = new PVector(0,0.05,0);
- vel = new PVector(random(-1,1),random(-1,0),0);
- vel.mult(2);
- loc = l.get();
- lifespan = 255;
- }
-
- void run() {
- update();
- render();
- }
-
- // Method to update location
- void update() {
- vel.add(acc);
- loc.add(vel);
- lifespan -= 2.0;
- }
-
- // Method to display
- void render() {
- imageMode(CENTER);
- tint(lifespan);
- image(img,loc.x,loc.y);
- }
-
- // Is the particle still useful?
- boolean isDead() {
- if (lifespan <= 0.0) {
- return true;
- } else {
- return false;
- }
- }
-}
-
-
diff --git a/java/examples/Books/Nature of Code/chp4_systems/NOC_4_09_AdditiveBlending/ParticleSystem.pde b/java/examples/Books/Nature of Code/chp4_systems/NOC_4_09_AdditiveBlending/ParticleSystem.pde
deleted file mode 100644
index 208bd5418..000000000
--- a/java/examples/Books/Nature of Code/chp4_systems/NOC_4_09_AdditiveBlending/ParticleSystem.pde
+++ /dev/null
@@ -1,52 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// A class to describe a group of Particles
-// An ArrayList is used to manage the list of Particles
-
-class ParticleSystem {
-
- ArrayList particles; // An arraylist for all the particles
- PVector origin; // An origin point for where particles are birthed
-
- PImage tex;
-
- ParticleSystem(int num, PVector v) {
- particles = new ArrayList(); // Initialize the arraylist
- origin = v.get(); // Store the origin point
- for (int i = 0; i < num; i++) {
- particles.add(new Particle(origin)); // Add "num" amount of particles to the arraylist
- }
- }
-
- void run() {
- for (int i = particles.size()-1; i >= 0; i--) {
- Particle p = particles.get(i);
- p.run();
- if (p.isDead()) {
- particles.remove(i);
- }
- }
- }
-
- void addParticle() {
- particles.add(new Particle(origin));
- }
-
- void addParticle(Particle p) {
- particles.add(p);
- }
-
- // A method to test if the particle system still has particles
- boolean dead() {
- if (particles.isEmpty()) {
- return true;
- }
- else {
- return false;
- }
- }
-}
-
-
diff --git a/java/examples/Books/Nature of Code/chp4_systems/NOC_4_09_AdditiveBlending/data/texture.psd b/java/examples/Books/Nature of Code/chp4_systems/NOC_4_09_AdditiveBlending/data/texture.psd
deleted file mode 100644
index d532f15aa..000000000
Binary files a/java/examples/Books/Nature of Code/chp4_systems/NOC_4_09_AdditiveBlending/data/texture.psd and /dev/null differ
diff --git a/java/examples/Books/Nature of Code/chp4_systems/ParticleSystemInheritance_pushpop/Particle.pde b/java/examples/Books/Nature of Code/chp4_systems/ParticleSystemInheritance_pushpop/Particle.pde
deleted file mode 100644
index bc2e58cb3..000000000
--- a/java/examples/Books/Nature of Code/chp4_systems/ParticleSystemInheritance_pushpop/Particle.pde
+++ /dev/null
@@ -1,61 +0,0 @@
-// Simple Particle System
-// Daniel Shiffman
-
-// A simple Particle class
-
-class Particle {
-
- PVector location;
- PVector velocity;
- PVector acceleration;
- float lifespan;
-
- Particle(PVector l) {
- acceleration = new PVector(0,0.05);
- velocity = new PVector(random(-1,1),random(-2,0));
- location = l.get();
- lifespan = 255.0;
- }
-
- void run() {
- update();
- push();
- display();
- pop();
- }
-
- // Method to update location
- void update() {
- velocity.add(acceleration);
- location.add(velocity);
- lifespan -= 2.0;
- }
-
-
- void push() {
- pushMatrix();
- }
-
- void pop() {
- popMatrix();
- }
-
- // Method to display
- void display() {
- stroke(0,lifespan);
- fill(0,lifespan);
- translate(location.x,location.y);
- ellipse(0,0,8,8);
- }
-
- // Is the particle still useful?
- boolean isDead() {
- if (lifespan < 0.0) {
- return true;
- } else {
- return false;
- }
- }
-}
-
-
diff --git a/java/examples/Books/Nature of Code/chp4_systems/ParticleSystemInheritance_pushpop/ParticleChild.pde b/java/examples/Books/Nature of Code/chp4_systems/ParticleSystemInheritance_pushpop/ParticleChild.pde
deleted file mode 100644
index 95b089aa3..000000000
--- a/java/examples/Books/Nature of Code/chp4_systems/ParticleSystemInheritance_pushpop/ParticleChild.pde
+++ /dev/null
@@ -1,24 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-class ParticleChild extends Particle {
-
- // We could add variables for only Confetti here if we so
-
- ParticleChild(PVector l) {
- super(l);
- }
-
- // Inherits update() from parent
-
- // Override the display method
- void display() {
- super.display();
- float theta = map(location.x,0,width,0,TWO_PI*2);
- rotate(theta);
- stroke(0);
- line(0,0,50,0);
- }
-}
-
diff --git a/java/examples/Books/Nature of Code/chp4_systems/ParticleSystemInheritance_pushpop/ParticleSystem.pde b/java/examples/Books/Nature of Code/chp4_systems/ParticleSystemInheritance_pushpop/ParticleSystem.pde
deleted file mode 100644
index 3e439bd84..000000000
--- a/java/examples/Books/Nature of Code/chp4_systems/ParticleSystemInheritance_pushpop/ParticleSystem.pde
+++ /dev/null
@@ -1,36 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-class ParticleSystem {
- ArrayList particles;
- PVector origin;
-
- ParticleSystem(PVector location) {
- origin = location.get();
- particles = new ArrayList();
- }
-
- void addParticle() {
- float r = random(1);
- if (r < 0.5) {
- particles.add(new Particle(origin));
- }
- else {
- particles.add(new ParticleChild(origin));
- }
- }
-
- void run() {
- for (int i = particles.size()-1; i >= 0; i--) {
- Particle p = particles.get(i);
- p.run();
- if (p.isDead()) {
- particles.remove(i);
- }
- }
- }
-}
-
-
-
diff --git a/java/examples/Books/Nature of Code/chp4_systems/ParticleSystemInheritance_pushpop/ParticleSystemInheritance_pushpop.pde b/java/examples/Books/Nature of Code/chp4_systems/ParticleSystemInheritance_pushpop/ParticleSystemInheritance_pushpop.pde
deleted file mode 100644
index 935a214da..000000000
--- a/java/examples/Books/Nature of Code/chp4_systems/ParticleSystemInheritance_pushpop/ParticleSystemInheritance_pushpop.pde
+++ /dev/null
@@ -1,16 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-ParticleSystem ps;
-
-void setup() {
- size(640,360);
- ps = new ParticleSystem(new PVector(width/2,50));
-}
-
-void draw() {
- background(255);
- ps.addParticle();
- ps.run();
-}
diff --git a/java/examples/Books/Nature of Code/chp4_systems/flight404/flight404_particles_1_simple/NOC_gl.pde b/java/examples/Books/Nature of Code/chp4_systems/flight404/flight404_particles_1_simple/NOC_gl.pde
deleted file mode 100755
index f96fc9d07..000000000
--- a/java/examples/Books/Nature of Code/chp4_systems/flight404/flight404_particles_1_simple/NOC_gl.pde
+++ /dev/null
@@ -1,13 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-void renderImage(PImage img, Vec3D _loc, float _diam, color _col, float _alpha ) {
- pushMatrix();
- translate( _loc.x, _loc.y, _loc.z );
- tint(red(_col), green(_col), blue(_col), _alpha);
- imageMode(CENTER);
- image(img,0,0,_diam,_diam);
- popMatrix();
-}
-
diff --git a/java/examples/Books/Nature of Code/chp4_systems/flight404/flight404_particles_1_simple/emitter.pde b/java/examples/Books/Nature of Code/chp4_systems/flight404/flight404_particles_1_simple/emitter.pde
deleted file mode 100755
index 0e6eb38fe..000000000
--- a/java/examples/Books/Nature of Code/chp4_systems/flight404/flight404_particles_1_simple/emitter.pde
+++ /dev/null
@@ -1,89 +0,0 @@
-
-/*
-The emitter is just an object that follows the cursor and
-can spawn new particle objects. It would be easier to just make
-the location vector match the cursor position but I have opted
-to use a velocity vector because later I will be allowing for
-multiple emitters.
-*/
-
-class Emitter{
- Vec3D loc;
- Vec3D vel;
- Vec3D velToMouse;
-
- color myColor;
-
- ArrayList particles;
-
- Emitter( ){
- loc = new Vec3D();
- vel = new Vec3D();
- velToMouse = new Vec3D();
-
- myColor = color( 1, 1, 1 );
-
- particles = new ArrayList();
- }
-
- void exist(){
- setVelToMouse();
- findVelocity();
- setPosition();
- iterateListExist();
- render();
-
- pgl.disable( PGL.TEXTURE_2D );
-
- if( ALLOWTRAILS )
- iterateListRenderTrails();
- }
-
- void setVelToMouse(){
- velToMouse.set( mouseX - loc.x, mouseY - loc.y, 0 );
- }
-
- void findVelocity(){
- vel.interpolateToSelf( velToMouse, .35 );
- }
-
- void setPosition(){
- loc.addSelf( vel );
-
- if( ALLOWFLOOR ){
- if( loc.y > floorLevel ){
- loc.y = floorLevel;
- vel.y = 0;
- }
- }
- }
-
- void iterateListExist(){
- for( Iterator it = particles.iterator(); it.hasNext(); ){
- Particle p = (Particle) it.next();
- if( !p.ISDEAD ){
- p.exist();
- } else {
- it.remove();
- }
- }
- }
-
-
- void render(){
- renderImage( emitterImg, loc, 150, myColor, 1.0 );
- }
-
- void iterateListRenderTrails(){
- for( Iterator it = particles.iterator(); it.hasNext(); ){
- Particle p = (Particle) it.next();
- p.renderTrails();
- }
- }
-
- void addParticles( int _amt ){
- for( int i=0; i<_amt; i++ ){
- particles.add( new Particle( loc, vel ) );
- }
- }
-}
diff --git a/java/examples/Books/Nature of Code/chp4_systems/flight404/flight404_particles_1_simple/flight404_particles_1_simple.pde b/java/examples/Books/Nature of Code/chp4_systems/flight404/flight404_particles_1_simple/flight404_particles_1_simple.pde
deleted file mode 100644
index 549c8dccc..000000000
--- a/java/examples/Books/Nature of Code/chp4_systems/flight404/flight404_particles_1_simple/flight404_particles_1_simple.pde
+++ /dev/null
@@ -1,158 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Updated version of flight404 Particle Emitter release 1
-// This works with Processing 2.0
-
-// February 28 2011
-// Daniel Shiffman
-
-// Source Code release 1
-// Particle Emitter
-//
-// February 11th 2008
-//
-// Built with Processing v.135 which you can download at http://www.processing.org/download
-//
-// Robert Hodgin
-// flight404.com
-// barbariangroup.com
-
-// features:
-// Toxi's magnificent Vec3D library
-// perlin noise flow fields
-// ribbon trails
-// OpenGL additive blending
-// OpenGL display lists
-//
-// Uses the very useful Vec3D library by Karsten Schmidt (toxi)
-// You can download it at http://code.google.com/p/toxiclibs/downloads/list
-//
-// Please post suggestions and improvements at the flight404 blog. When nicer/faster/better
-// practices are suggested, I will incorporate them into the source and repost. I think that
-// will be a reasonable system for now.
-//
-// Future additions will include:
-// Rudimentary camera movement
-// Magnetic repulsion
-// More textures means more iron
-//
-// UPDATES
-//
-// February 11th 2008
-// Reorganized some of the OpenGL calls as per Simon Gelfius' suggestion.
-// http://www.kinesis.be/
-
-
-import toxi.geom.*;
-import java.util.*;
-
-PGL pgl;
-
-Emitter emitter;
-Vec3D gravity;
-float floorLevel;
-
-PImage particleImg;
-PImage emitterImg;
-
-int counter;
-
-
-boolean ALLOWGRAVITY; // add gravity vector?
-boolean ALLOWPERLIN; // add perlin noise flow field vector?
-boolean ALLOWTRAILS; // render particle trails?
-boolean ALLOWFLOOR; // add a floor?
- // Turning on all of these options will make things
- // slow down.
-
-void setup(){
- size( 600, 600, P3D );
- smooth(4);
- // Lately I have gotten into the habit of limiting the color range to be
- // 0.0 to 1.0. It works this way in OpenGL so I might as well get used to it.
- colorMode( RGB, 1.0 );
-
- // Turn on 4X antialiasing
- //hint( ENABLE_OPENGL_4X_SMOOTH );
-
- // More OpenGL necessity.
- pgl = ((PGraphicsOpenGL) g).pgl;
-
- // Loads in a particle image from the data folder. Image size should be a power of 2.
- particleImg = loadImage( "particle.png" );
- emitterImg = loadImage( "emitter.png" );
-
- emitter = new Emitter();
- gravity = new Vec3D( 0, .35, 0 ); // gravity vector
- floorLevel = 400;
-}
-
-void draw(){
- background( 0.0 );
- perspective( PI/3.0, (float)width/(float)height, 1, 5000 );
-
- // Turns on additive blending so we can draw a bunch of glowing images without
- // needing to do any depth testing.
- pgl.depthMask(false);
- pgl.enable( PGL.BLEND );
- pgl.blendFunc(PGL.SRC_ALPHA, PGL.ONE);
-
- emitter.exist();
-
- // If the mouse button is pressed, then add 10 new particles.
- if( mousePressed ){
- if( ALLOWTRAILS && ALLOWFLOOR ){
- emitter.addParticles( 5 );
- } else {
- emitter.addParticles( 10 );
- }
- }
-
- counter ++;
-}
-
-
-void keyPressed(){
- if( key == 'g' || key == 'G' )
- ALLOWGRAVITY = !ALLOWGRAVITY;
-
- if( key == 'p' || key == 'P' )
- ALLOWPERLIN = !ALLOWPERLIN;
-
- if( key == 't' || key == 'T' )
- ALLOWTRAILS = !ALLOWTRAILS;
-
- if( key == 'f' || key == 'F' )
- ALLOWFLOOR = !ALLOWFLOOR;
-
-}
-
-
-// This method should be nicer, but it isnt. I use getRads to get a perlin noise
-// based angle in radians based on the x and y position of the object asking for it.
-// Perlin noise is supposed to give you back a number between 0 and 1, but it wont
-// necessarily give you numbers that range from 0 to 1. A usual result is more like
-// .25 to .75.
-//
-// So the point of this method is to try to normalize the values to a
-// range of 0 to 1. It's not perfect, and I still get weird results.
-// For instance, the mult variable is supposed to be the multiplier for the range.
-// So if i wanted a random angle between 0 and TWO_PI, I would set the mult = TWO_PI.
-// But when I do that, I find the Perlin noise tends to give me a left-pointing angle.
-// To counteract, I end up setting the mult to 10.0 in order to increase the chances
-// that I get a nice range from at least 0 to TWO_PI.
-float minNoise = 0.499;
-float maxNoise = 0.501;
-float getRads(float val1, float val2, float mult, float div){
- float rads = noise(val1/div, val2/div, counter/div);
-
- if (rads < minNoise) minNoise = rads;
- if (rads > maxNoise) maxNoise = rads;
-
- rads -= minNoise;
- rads *= 1.0/(maxNoise - minNoise);
-
- return rads * mult;
-}
diff --git a/java/examples/Books/Nature of Code/chp4_systems/flight404/flight404_particles_1_simple/particle.pde b/java/examples/Books/Nature of Code/chp4_systems/flight404/flight404_particles_1_simple/particle.pde
deleted file mode 100755
index 16441c9c5..000000000
--- a/java/examples/Books/Nature of Code/chp4_systems/flight404/flight404_particles_1_simple/particle.pde
+++ /dev/null
@@ -1,208 +0,0 @@
-/*
-General Structure notes.
- My classes tend to have a similar naming scheme and flow. I start with the 'exist' method.
- Exist is what an object needs to do every frame. Usually 'existing' consists of four main things.
- 1) Find the velocity. This involves determining what influences there are on the velocity.
- 2) Apply the velocity to the location.
- 3) Render the object.
- 4) Age the object.
-
- I also use the metaphor of aging and death. When first made, a particle's age will be zero.
- Every frame, the age will increment. If the age reaches the lifeSpan (which is a random number
- that I set in the constructor), then the boolean ISDEAD is set to true and the arraylist iterator
- removes the dead element from the list.
- */
-
-
-
-class Particle {
- int len; // number of elements in position array
- Vec3D[] loc; // array of position vectors
- Vec3D startLoc; // just used to make sure every loc[] is initialized to the same position
- Vec3D vel; // velocity vector
- Vec3D perlin; // perlin noise vector
- float radius; // particle's size
- float age; // current age of particle
- int lifeSpan; // max allowed age of particle
- float agePer; // range from 1.0 (birth) to 0.0 (death)
- float bounceAge; // amount to age particle when it bounces off floor
- boolean ISDEAD; // if age == lifeSpan, make particle die
- boolean ISBOUNCING; // if particle hits the floor...
-
-
- Particle( Vec3D _loc, Vec3D _vel ) {
- radius = random( 10, 40 );
- len = (int)( radius );
- loc = new Vec3D[ len ];
-
- // This confusing-looking line does three things at once.
- // First, you make a random vector.
- // new Vec3D().randomVector()
- // Next, you multiply that vector by a random number from 0.0 to 5.0.
- // scaleSelf( 5.0 );
- // Finally, you add this new vector to the original sent vector.
- // _loc.add( );
- // This is just a way to make sure all the particles made this frame
- // don't all start on the exact same pixel. This staggering will be useful
- // when we incorporate magnetic repulsion in a later tutorial.
- startLoc = new Vec3D( _loc.add( new Vec3D().randomVector().scaleSelf( random( 5.0 ) ) ) );
-
- for( int i=0; i floorLevel ) {
- ISBOUNCING = true;
- }
- else {
- ISBOUNCING = false;
- }
- }
-
- if( ISBOUNCING ) {
- vel.scaleSelf( .75 );
- vel.y *= -.5;
- }
- }
-
- void setPosition() {
- // Every frame, the current location will be passed on to
- // the next element in the location array. Think 'cursor trail effect'.
- for( int i=len-1; i>0; i-- ) {
- loc[i].set( loc[i-1] );
- }
-
- // Set the initial location.
- // loc[0] represents the current position of the particle.
- loc[0].addSelf( vel );
- }
-
- void render() {
- // As the particle ages, it will gain blue but will lose red and green.
- color c = color( agePer, agePer*.75, 1.0 - agePer );
- renderImage(particleImg, loc[0], radius * agePer, c, 1.0 );
- }
-
- void renderTrails() {
- float xp, yp, zp;
- float xOff, yOff, zOff;
- beginShape(QUAD_STRIP);
- for ( int i=0; i lifeSpan ) {
- ISDEAD = true;
- }
- else {
- // When spawned, the agePer is 1.0.
- // When death occurs, the agePer is 0.0.
- agePer = 1.0 - age/(float)lifeSpan;
- }
- }
-}
-
diff --git a/java/examples/Books/Nature of Code/chp4_systems/flight404/flight404_particles_2_GLtexture/NOC_gl.pde b/java/examples/Books/Nature of Code/chp4_systems/flight404/flight404_particles_2_GLtexture/NOC_gl.pde
deleted file mode 100644
index 2f91c0f1b..000000000
--- a/java/examples/Books/Nature of Code/chp4_systems/flight404/flight404_particles_2_GLtexture/NOC_gl.pde
+++ /dev/null
@@ -1,49 +0,0 @@
-
-int squareList;
-void initGL(){
- pgl.beginGL();
- squareList = gl.glGenLists(1);
- gl.glNewList(squareList, GL.GL_COMPILE);
- gl.glBegin(GL.GL_POLYGON);
- gl.glTexCoord2f(0, 0); gl.glVertex2f(-.5, -.5);
- gl.glTexCoord2f(1, 0); gl.glVertex2f( .5, -.5);
- gl.glTexCoord2f(1, 1); gl.glVertex2f( .5, .5);
- gl.glTexCoord2f(0, 1); gl.glVertex2f(-.5, .5);
- gl.glEnd();
- gl.glEndList();
- pgl.endGL();
-}
-
-void renderImage( Vec3D _loc, float _diam, color _col, float _alpha ){
- gl.glPushMatrix();
- gl.glTranslatef( _loc.x, -_loc.y, _loc.z );
- pov.glReverseCamera();
- gl.glScalef( _diam, _diam, _diam );
- gl.glColor4f( red(_col), green(_col), blue(_col), _alpha );
- gl.glCallList( squareList );
- gl.glPopMatrix();
-}
-
-// This will allow you to draw images that are oriented to the floor plane.
-void renderImageOnFloor( Vec3D _loc, float _diam, color _col, float _aa ){
- gl.glPushMatrix();
- gl.glTranslatef( _loc.x, -_loc.y, _loc.z );
- gl.glScalef( _diam, _diam, _diam );
- gl.glRotatef( 90, 1.0, 0.0, 0.0 );
- gl.glColor4f( red(_col), green(_col), blue(_col), _aa );
- gl.glCallList( squareList );
- gl.glPopMatrix();
-}
-
-// This will allow you to specify a rotation for images that are oriented perpendicular to the eyeNormal
-// which is the vector pointing from the camera's eye to the camera's point of interest.
-void renderImageAndRotate( Vec3D _loc, float _diam, color _col, float _aa, float _rot ){
- gl.glPushMatrix();
- gl.glTranslatef( _loc.x, -_loc.y, _loc.z );
- gl.glRotatef( degrees( _rot ), pov.eyeNormal.x, pov.eyeNormal.y, pov.eyeNormal.z );
- pov.glReverseCamera();
- gl.glScalef( _diam, _diam, _diam );
- gl.glColor4f( red(_col), green(_col), blue(_col), _aa );
- gl.glCallList( squareList );
- gl.glPopMatrix();
-}
diff --git a/java/examples/Books/Nature of Code/chp4_systems/flight404/flight404_particles_2_GLtexture/cursor.pde b/java/examples/Books/Nature of Code/chp4_systems/flight404/flight404_particles_2_GLtexture/cursor.pde
deleted file mode 100644
index ee2909cb9..000000000
--- a/java/examples/Books/Nature of Code/chp4_systems/flight404/flight404_particles_2_GLtexture/cursor.pde
+++ /dev/null
@@ -1,25 +0,0 @@
-class Cursor{
- Vec3D loc;
- Vec3D vel;
-
- Cursor(){
- loc = new Vec3D();
- vel = new Vec3D();
- }
-
- void exist(){
- // 2.35 is an arbitrary number. Ideally, this cursor would function
- // properly regardless of the camera's rotation and distance from the object.
- // Im not sure how to make that happen... 3D interaction with the cursor has
- // been low on my research list. Think of this as a crappy placeholder.
- loc.set( ( mouseX - xMid ) * 2.25, ( mouseY - yMid ) * 2.25, 0 );
- }
-
- void render(){
- pushMatrix();
- translate( loc.x, loc.y, loc.z );
- fill( 1, 0, 0 );
- sphere( 10 );
- popMatrix();
- }
-}
diff --git a/java/examples/Books/Nature of Code/chp4_systems/flight404/flight404_particles_2_GLtexture/emitter.pde b/java/examples/Books/Nature of Code/chp4_systems/flight404/flight404_particles_2_GLtexture/emitter.pde
deleted file mode 100644
index 04eb2045a..000000000
--- a/java/examples/Books/Nature of Code/chp4_systems/flight404/flight404_particles_2_GLtexture/emitter.pde
+++ /dev/null
@@ -1,182 +0,0 @@
-class Emitter{
- Vec3D loc;
- Vec3D vel;
- Vec3D velToMouse;
- float radius;
-
- Texture coronaTex;
- Texture emitterTex;
- Texture particleTex;
- Texture reflectionTex;
-
- color myColor;
-
- ArrayList particles;
- ArrayList nebulae;
-
- Emitter( ){
-
- try {
- coronaTex = TextureIO.newTexture(new File(dataPath("corona.png")), true);
- emitterTex = TextureIO.newTexture(new File(dataPath("emitter.png")), true);
- particleTex = TextureIO.newTexture(new File(dataPath("particle.png")), true);
- reflectionTex = TextureIO.newTexture(new File(dataPath("reflection.png")), true);
- }
- catch (IOException e) {
- println("Texture file is missing");
- exit(); // or handle it some other way
- }
-
- loc = new Vec3D();
- vel = new Vec3D();
- velToMouse = new Vec3D();
-
- radius = 100;
-
- myColor = color( 1, 1, 1 );
-
- particles = new ArrayList();
- nebulae = new ArrayList();
- }
-
- void exist(){
- findVelocity();
- setPosition();
- iterateListExist();
- render();
-
- gl.glDisable( GL.GL_TEXTURE_2D );
-
- if( ALLOWTRAILS )
- iterateListRenderTrails();
- }
-
- void findVelocity(){
- Vec3D dirToMouse = new Vec3D( mouse.loc.sub( loc ).scale( .15 ) );
- vel.set( dirToMouse );
- }
-
- void setPosition(){
- loc.addSelf( vel );
-
- if( ALLOWFLOOR ){
- if( loc.y > floorLevel ){
- loc.y = floorLevel;
- vel.y = 0;
- }
- }
- }
-
- void iterateListExist(){
- gl.glEnable( GL.GL_TEXTURE_2D );
-
-
- int mylength = particles.size();
- for( int i=mylength-1; i>=0; i-- ){
- Particle p = ( Particle )particles.get(i);
- if( p.ISSPLIT )
- addParticles( p );
-
- if ( !p.ISDEAD ){
- // pgl.bindTexture( images.particle );
- particleTex.bind();
- particleTex.enable();
- p.exist();
- particleTex.disable();
-
- }
- else {
- particles.set( i, particles.get( particles.size() - 1 ) );
- particles.remove( particles.size() - 1 );
- }
- }
-
- if( ALLOWFLOOR ){
- // pgl.bindTexture( images.reflection );
- reflectionTex.bind();
- reflectionTex.enable();
- for( Iterator it = particles.iterator(); it.hasNext(); ){
- Particle p = (Particle) it.next();
- p.renderReflection();
- }
- reflectionTex.disable();
- }
-
- // pgl.bindTexture( images.corona );
- coronaTex.bind();
- coronaTex.enable();
- for( Iterator it = nebulae.iterator(); it.hasNext(); ){
- Nebula n = (Nebula) it.next();
- if( !n.ISDEAD ){
- n.exist();
- }
- else {
- it.remove();
- }
- }
- coronaTex.disable();
- }
-
-
- void render(){
- // pgl.bindTexture( images.emitter );
- emitterTex.bind();
- emitterTex.enable();
- renderImage( loc, radius, myColor, 1.0 );
- emitterTex.enable();
-
- if( ALLOWNEBULA ){
- nebulae.add( new Nebula( loc, 15.0, true ) );
- nebulae.add( new Nebula( loc, 45.0, true ) );
- }
-
-
- if( ALLOWFLOOR ){
- // pgl.bindTexture( images.reflection );
- reflectionTex.bind();
- reflectionTex.enable();
- renderReflection();
- reflectionTex.disable();
- }
- }
-
- void renderReflection(){
- float altitude = floorLevel - loc.y;
- float reflectMaxAltitude = 300.0;
- float yPer = 1.0 - altitude/reflectMaxAltitude;
-
- if( yPer > .05 )
- renderImageOnFloor( new Vec3D( loc.x, floorLevel, loc.z ), radius * 10.0, color( 0.5, 1.0, yPer*.25 ), yPer );
-
- if( mousePressed )
- renderImageOnFloor( new Vec3D( loc.x, floorLevel, loc.z ), radius + ( yPer + 1.0 ) * radius * random( 2.0, 3.5 ), color( 1.0, 0, 0 ), yPer );
- }
-
- void iterateListRenderTrails(){
- for( Iterator it = particles.iterator(); it.hasNext(); ){
- Particle p = (Particle) it.next();
- p.renderTrails();
- }
- }
-
- void addParticles( int _amt ){
- for( int i=0; i<_amt; i++ ){
- particles.add( new Particle( 1, loc, vel ) );
- }
-
- if( ALLOWNEBULA ){
- nebulae.add( new Nebula( loc, 40.0, false ) );
- nebulae.add( new Nebula( loc, 100.0, false ) );
- }
- }
-
- void addParticles( Particle _p ){
- // play with amt if you want to control how many particles spawn when splitting
- int amt = (int)( _p.radius * .15 );
- for( int i=0; i maxNoise) maxNoise = rads;
-
- rads -= minNoise;
- rads *= 1.0/(maxNoise - minNoise);
-
- return rads * mult;
-}
diff --git a/java/examples/Books/Nature of Code/chp4_systems/flight404/flight404_particles_2_GLtexture/images.pde b/java/examples/Books/Nature of Code/chp4_systems/flight404/flight404_particles_2_GLtexture/images.pde
deleted file mode 100644
index 821c91230..000000000
--- a/java/examples/Books/Nature of Code/chp4_systems/flight404/flight404_particles_2_GLtexture/images.pde
+++ /dev/null
@@ -1,13 +0,0 @@
-class Images{
- PImage particle;
- PImage emitter;
- PImage corona;
- PImage reflection;
-
- Images(){
- particle = loadImage( "particle.png" );
- emitter = loadImage( "emitter.png" );
- corona = loadImage( "corona.png" );
- reflection = loadImage( "reflection.png" );
- }
-}
diff --git a/java/examples/Books/Nature of Code/chp4_systems/flight404/flight404_particles_2_GLtexture/nebula.pde b/java/examples/Books/Nature of Code/chp4_systems/flight404/flight404_particles_2_GLtexture/nebula.pde
deleted file mode 100644
index 573378708..000000000
--- a/java/examples/Books/Nature of Code/chp4_systems/flight404/flight404_particles_2_GLtexture/nebula.pde
+++ /dev/null
@@ -1,56 +0,0 @@
-class Nebula{
- Vec3D loc;
- Vec3D vel;
- float radius;
- float scaleFac;
- float age;
- int lifeSpan;
- float agePer;
- float rot;
- color c;
-
- boolean ISDEAD;
- boolean ISGROUNDED;
-
- Nebula( Vec3D _loc, float _radius, boolean _ISGROUNDED ){
- loc = new Vec3D( _loc );
- vel = new Vec3D( pov.eyeNormal.scale( 2.0 ) );
- radius = random( _radius*.8, _radius*1.75 );
-
- scaleFac = random( 1.005, 1.10 );
- age = 0;
- lifeSpan = (int)random(10,30);
- rot = random( TWO_PI );
- c = color( random(.75, 1.0), random(.5,.75), random(.2,.8) );
- ISGROUNDED = _ISGROUNDED;
-
- if( ISGROUNDED ){
- scaleFac = random( 1.01, 1.025 );
- vel.y -= random( 1.0 );
- radius *= 2.0;
- }
- }
-
- void exist(){
- move();
- render();
- checkAge();
- }
-
- void move(){
- radius *= scaleFac;
- loc.addSelf( vel );
- }
-
- void render(){
- renderImageAndRotate( loc, radius, c, sin(agePer*PI) * .4, rot );
- }
-
- void checkAge(){
- age ++;
- agePer = 1.0 - age/(float)lifeSpan;
-
- if (age > lifeSpan)
- ISDEAD = true;
- }
-}
diff --git a/java/examples/Books/Nature of Code/chp4_systems/flight404/flight404_particles_2_GLtexture/particle.pde b/java/examples/Books/Nature of Code/chp4_systems/flight404/flight404_particles_2_GLtexture/particle.pde
deleted file mode 100644
index 53cbf839b..000000000
--- a/java/examples/Books/Nature of Code/chp4_systems/flight404/flight404_particles_2_GLtexture/particle.pde
+++ /dev/null
@@ -1,171 +0,0 @@
-
-class Particle{
- int len; // number of elements in position array
- Vec3D[] loc; // array of position vectors
- Vec3D startLoc; // just used to make sure every loc[] is initialized to the same position
- Vec3D vel; // velocity vector
- Vec3D perlin; // perlin noise vector
- float radius; // particle's size
- float age; // current age of particle
- int lifeSpan; // max allowed age of particle
- float agePer; // range from 1.0 (birth) to 0.0 (death)
- int gen; // number of times particle has been involved in a SPLIT
- float bounceAge; // amount to age particle when it bounces off floor
- float bounceVel; // speed at impact
- boolean ISDEAD; // if age == lifeSpan, make particle die
- boolean ISBOUNCING; // if particle hits the floor...
- boolean ISSPLIT; // if particle hits the floor with enough speed...
-
-
- Particle( int _gen, Vec3D _loc, Vec3D _vel ){
- gen = _gen;
- radius = random( 10 - gen, 50 - ( gen-1)*10 );
-
- len = (int)( radius*.5 );
- loc = new Vec3D[ len ];
- startLoc = new Vec3D( _loc.add( new Vec3D().randomVector().scaleSelf( random( 1.0 ) ) ) );
-
- for( int i=0; i 1 ){
- vel.addSelf( new Vec3D().randomVector().scaleSelf( random( 7.0 ) ) );
- } else {
- vel.addSelf( new Vec3D().randomVector().scaleSelf( random( 10.0 ) ) );
- }
-
- perlin = new Vec3D();
-
- age = 0;
- bounceAge = 2;
- lifeSpan = (int)( radius );
- }
-
- void exist(){
- if( ALLOWPERLIN )
- findPerlin();
-
- findVelocity();
- setPosition();
- render();
- setAge();
- }
-
- void findPerlin(){
- float xyRads = getRads( loc[0].x, loc[0].z, 20.0, 50.0 );
- float yRads = getRads( loc[0].x, loc[0].y, 20.0, 50.0 );
- perlin.set( cos(xyRads), -sin(yRads), sin(xyRads) );
- perlin.scaleSelf( .5 );
- }
-
- void findVelocity(){
- if( ALLOWGRAVITY )
- vel.addSelf( gravity );
-
- if( ALLOWPERLIN )
- vel.addSelf( perlin );
-
- if( ALLOWFLOOR ){
- if( loc[0].y + vel.y > floorLevel ){
- ISBOUNCING = true;
- } else {
- ISBOUNCING = false;
- }
- }
-
- // if the particle is moving fast enough, when it hits the ground it can
- // split into a bunch of smaller particles.
- if( ISBOUNCING ){
- bounceVel = vel.magnitude();
-
- vel.scaleSelf( .7 );
- vel.y *= -( ( radius/40.0 ) * .5 );
-
- if( bounceVel > 15.0 && gen < 4 )
- ISSPLIT = true;
-
- } else {
- ISSPLIT = false;
- }
- }
-
- void setPosition(){
- for( int i=len-1; i>0; i-- ){
- loc[i].set( loc[i-1] );
- }
-
- loc[0].addSelf( vel );
- }
-
- void render(){
- color c = color( agePer - .5, agePer*.25, 1.5 - agePer );
- renderImage( loc[0], radius * agePer, c, 1.0 );
-
- // Rendering two graphics here. Makes the particles more vivid,
- // but will hinder the performance.
- c = color( 1, agePer, agePer );
- renderImage( loc[0], radius * agePer * .5, c, agePer );
- }
-
- void renderReflection(){
- float altitude = floorLevel - loc[0].y;
- float reflectMaxAltitude = 25.0;
- float yPer = ( 1.0 - ( altitude/reflectMaxAltitude ) ) * .5;
-
- if( yPer > .05 )
- renderImageOnFloor( new Vec3D( loc[0].x, floorLevel, loc[0].z ), radius * agePer * 8.0 * yPer, color( agePer, agePer*.25, 0 ), yPer + random( .2 ) );
- }
-
- void renderTrails(){
- float xp, yp, zp;
- float xOff, yOff, zOff;
-
- gl.glBegin( GL.GL_QUAD_STRIP );
-
- for ( int i=0; i lifeSpan ){
- ISDEAD = true;
- } else {
- agePer = 1.0 - age/(float)lifeSpan;
- }
- }
-}
diff --git a/java/examples/Books/Nature of Code/chp4_systems/flight404/flight404_particles_2_GLtexture/pov.pde b/java/examples/Books/Nature of Code/chp4_systems/flight404/flight404_particles_2_GLtexture/pov.pde
deleted file mode 100644
index 1d5bf01d7..000000000
--- a/java/examples/Books/Nature of Code/chp4_systems/flight404/flight404_particles_2_GLtexture/pov.pde
+++ /dev/null
@@ -1,62 +0,0 @@
-// Camera class which uses Kristian Damkjer's OCD library
-// http://www.cise.ufl.edu/~kdamkjer/processing/libraries/ocd/
-
-class POV{
- PApplet parent;
- Camera cam;
-
- Vec3D eye;
- Vec3D center;
-
- Vec3D eyeNormal;
-
- boolean ISDRAGGING;
-
- POV( PApplet _parent ){
- parent = _parent;
- cam = new Camera( parent, 0, 100, 1500 );
-
- eye = new Vec3D();
- center = new Vec3D();
- eyeNormal = new Vec3D();
- }
-
- void exist(){
- perspective( PI/3.0, (float)xSize/(float)ySize, .5, 5000 );
- if( ISDRAGGING ){
- cam.circle( radians( ( mouseX - pmouseX ) * .25 ) );
- cam.arc( radians( ( mouseY - pmouseY ) * .25 ) );
- }
-
- cam.feed();
- setPosition();
- }
-
-
- // Code by JohnG from the Processing forum
- // http://processing.org/discourse/yabb_beta/YaBB.cgi?board=Programs;action=display;num=1170790832
- //
- // Does the camera transformations in reverse to allow for images that always face the camera.
- void glReverseCamera(){
- float deltaX = eye.x - center.x;
- float deltaY = eye.y - center.y;
- float deltaZ = eye.z - center.z;
-
- float angleZ = atan2( deltaY,deltaX );
- float hyp = sqrt( sq( deltaX ) + sq( deltaY ) );
- float angleY = atan2( hyp,deltaZ );
-
- gl.glRotatef( degrees( angleZ ), 0, 0, 1.0 );
- gl.glRotatef( degrees( angleY ), 0, 1.0, 0 );
- }
-
-
- void setPosition(){
- float[] e = cam.position();
- float[] c = cam.target();
-
- eye.set( e[0], e[1], e[2] );
- center.set( c[0], c[1], c[2] );
- eyeNormal = eye.sub(center).normalize();
- }
-}
diff --git a/java/examples/Books/Nature of Code/chp4_systems/flight404/flight404_particles_2_simple/NOC_gl.pde b/java/examples/Books/Nature of Code/chp4_systems/flight404/flight404_particles_2_simple/NOC_gl.pde
deleted file mode 100755
index 44705cdbd..000000000
--- a/java/examples/Books/Nature of Code/chp4_systems/flight404/flight404_particles_2_simple/NOC_gl.pde
+++ /dev/null
@@ -1,31 +0,0 @@
-
-void renderImage(PImage img, Vec3D _loc, float _diam, color _col, float _alpha ) {
- pushMatrix();
- translate( _loc.x, _loc.y, _loc.z );
- pov.glReverseCamera();
- tint(red(_col), green(_col), blue(_col), _alpha);
- imageMode(CENTER);
- image(img,0,0,_diam,_diam);
- popMatrix();
-}
-
-void renderImageOnFloor(PImage img, Vec3D _loc, float _diam, color _col, float _aa ) {
- pushMatrix();
- translate( _loc.x, _loc.y, _loc.z );
- rotateX(PI/2);
- //pov.glReverseCamera();
- tint(red(_col), green(_col), blue(_col), _aa);
- imageMode(CENTER);
- image(img,0,0,_diam,_diam);
- popMatrix();
-}
-
-void renderImageAndRotate(PImage img, Vec3D _loc, float _diam, color _col, float _aa, float _rot ) {
- pushMatrix();
- translate( _loc.x, _loc.y, _loc.z );
- pov.glReverseCamera();
- tint(red(_col), green(_col), blue(_col), _aa);
- imageMode(CENTER);
- image(img,0,0,_diam,_diam);
- popMatrix();
-}
diff --git a/java/examples/Books/Nature of Code/chp4_systems/flight404/flight404_particles_2_simple/cursor.pde b/java/examples/Books/Nature of Code/chp4_systems/flight404/flight404_particles_2_simple/cursor.pde
deleted file mode 100755
index ee2909cb9..000000000
--- a/java/examples/Books/Nature of Code/chp4_systems/flight404/flight404_particles_2_simple/cursor.pde
+++ /dev/null
@@ -1,25 +0,0 @@
-class Cursor{
- Vec3D loc;
- Vec3D vel;
-
- Cursor(){
- loc = new Vec3D();
- vel = new Vec3D();
- }
-
- void exist(){
- // 2.35 is an arbitrary number. Ideally, this cursor would function
- // properly regardless of the camera's rotation and distance from the object.
- // Im not sure how to make that happen... 3D interaction with the cursor has
- // been low on my research list. Think of this as a crappy placeholder.
- loc.set( ( mouseX - xMid ) * 2.25, ( mouseY - yMid ) * 2.25, 0 );
- }
-
- void render(){
- pushMatrix();
- translate( loc.x, loc.y, loc.z );
- fill( 1, 0, 0 );
- sphere( 10 );
- popMatrix();
- }
-}
diff --git a/java/examples/Books/Nature of Code/chp4_systems/flight404/flight404_particles_2_simple/emitter.pde b/java/examples/Books/Nature of Code/chp4_systems/flight404/flight404_particles_2_simple/emitter.pde
deleted file mode 100755
index d405be8fd..000000000
--- a/java/examples/Books/Nature of Code/chp4_systems/flight404/flight404_particles_2_simple/emitter.pde
+++ /dev/null
@@ -1,149 +0,0 @@
-class Emitter{
- Vec3D loc;
- Vec3D vel;
- Vec3D velToMouse;
- float radius;
-
- color myColor;
-
- ArrayList particles;
- ArrayList nebulae;
-
- Emitter( ){
- loc = new Vec3D();
- vel = new Vec3D();
- velToMouse = new Vec3D();
-
- radius = 100;
-
- myColor = color( 1, 1, 1 );
-
- particles = new ArrayList();
- nebulae = new ArrayList();
- }
-
- void exist(){
- findVelocity();
- setPosition();
- iterateListExist();
- render();
-
- pgl.disable( PGL.TEXTURE_2D );
-
- if( ALLOWTRAILS )
- iterateListRenderTrails();
- }
-
- void findVelocity(){
- Vec3D dirToMouse = new Vec3D( mouse.loc.sub( loc ).scale( .15 ) );
- vel.set( dirToMouse );
- }
-
- void setPosition(){
- loc.addSelf( vel );
-
- if( ALLOWFLOOR ){
- if( loc.y > floorLevel ){
- loc.y = floorLevel;
- vel.y = 0;
- }
- }
- }
-
- void iterateListExist(){
- pgl.enable( PGL.TEXTURE_2D );
-
-
- int mylength = particles.size();
- for( int i=mylength-1; i>=0; i-- ){
- Particle p = ( Particle )particles.get(i);
- if( p.ISSPLIT )
- addParticles( p );
-
- if ( !p.ISDEAD ){
- //pgl.bindTexture( images.particle );
- p.exist();
-
- } else {
- particles.set( i, particles.get( particles.size() - 1 ) );
- particles.remove( particles.size() - 1 );
- }
- }
-
- if( ALLOWFLOOR ){
- //pgl.bindTexture( images.reflection );
- for( Iterator it = particles.iterator(); it.hasNext(); ){
- Particle p = (Particle) it.next();
- p.renderReflection();
- }
- }
-
- //pgl.bindTexture( images.corona );
- for( Iterator it = nebulae.iterator(); it.hasNext(); ){
- Nebula n = (Nebula) it.next();
- if( !n.ISDEAD ){
- n.exist();
- } else {
- it.remove();
- }
- }
- }
-
-
- void render(){
- //pgl.bindTexture( images.emitter );
- renderImage( images.emitter,loc, radius, myColor, 1.0 );
-
-
- if( ALLOWNEBULA ){
- nebulae.add( new Nebula( loc, 15.0, true ) );
- nebulae.add( new Nebula( loc, 45.0, true ) );
- }
-
-
- if( ALLOWFLOOR ){
- //pgl.bindTexture( images.reflection );
- renderReflection(images.reflection);
- }
- }
-
- void renderReflection(PImage img){
- float altitude = floorLevel - loc.y;
- float reflectMaxAltitude = 300.0;
- float yPer = 1.0 - altitude/reflectMaxAltitude;
-
- if( yPer > .05 )
- renderImageOnFloor(img, new Vec3D( loc.x, floorLevel, loc.z ), radius * 10.0, color( 0.5, 1.0, yPer*.25 ), yPer );
-
- if( mousePressed )
- renderImageOnFloor(img, new Vec3D( loc.x, floorLevel, loc.z ), radius + ( yPer + 1.0 ) * radius * random( 2.0, 3.5 ), color( 1.0, 0, 0 ), yPer );
- }
-
- void iterateListRenderTrails(){
- for( Iterator it = particles.iterator(); it.hasNext(); ){
- Particle p = (Particle) it.next();
- p.renderTrails();
- }
- }
-
- void addParticles( int _amt ){
- for( int i=0; i<_amt; i++ ){
- particles.add( new Particle( 1, loc, vel ) );
- }
-
- if( ALLOWNEBULA ){
- nebulae.add( new Nebula( loc, 40.0, false ) );
- nebulae.add( new Nebula( loc, 100.0, false ) );
- }
- }
-
- void addParticles( Particle _p ){
- // play with amt if you want to control how many particles spawn when splitting
- int amt = (int)( _p.radius * .15 );
- for( int i=0; i maxNoise) maxNoise = rads;
-
- rads -= minNoise;
- rads *= 1.0/(maxNoise - minNoise);
-
- return rads * mult;
-}
-
diff --git a/java/examples/Books/Nature of Code/chp4_systems/flight404/flight404_particles_2_simple/images.pde b/java/examples/Books/Nature of Code/chp4_systems/flight404/flight404_particles_2_simple/images.pde
deleted file mode 100755
index 821c91230..000000000
--- a/java/examples/Books/Nature of Code/chp4_systems/flight404/flight404_particles_2_simple/images.pde
+++ /dev/null
@@ -1,13 +0,0 @@
-class Images{
- PImage particle;
- PImage emitter;
- PImage corona;
- PImage reflection;
-
- Images(){
- particle = loadImage( "particle.png" );
- emitter = loadImage( "emitter.png" );
- corona = loadImage( "corona.png" );
- reflection = loadImage( "reflection.png" );
- }
-}
diff --git a/java/examples/Books/Nature of Code/chp4_systems/flight404/flight404_particles_2_simple/nebula.pde b/java/examples/Books/Nature of Code/chp4_systems/flight404/flight404_particles_2_simple/nebula.pde
deleted file mode 100755
index 3412c110f..000000000
--- a/java/examples/Books/Nature of Code/chp4_systems/flight404/flight404_particles_2_simple/nebula.pde
+++ /dev/null
@@ -1,56 +0,0 @@
-class Nebula{
- Vec3D loc;
- Vec3D vel;
- float radius;
- float scaleFac;
- float age;
- int lifeSpan;
- float agePer;
- float rot;
- color c;
-
- boolean ISDEAD;
- boolean ISGROUNDED;
-
- Nebula( Vec3D _loc, float _radius, boolean _ISGROUNDED ){
- loc = new Vec3D( _loc );
- vel = new Vec3D( pov.eyeNormal.scale( 2.0 ) );
- radius = random( _radius*.8, _radius*1.75 );
-
- scaleFac = random( 1.005, 1.10 );
- age = 0;
- lifeSpan = (int)random(10,30);
- rot = random( TWO_PI );
- c = color( random(.75, 1.0), random(.5,.75), random(.2,.8) );
- ISGROUNDED = _ISGROUNDED;
-
- if( ISGROUNDED ){
- scaleFac = random( 1.01, 1.025 );
- vel.y -= random( 1.0 );
- radius *= 2.0;
- }
- }
-
- void exist(){
- move();
- render();
- checkAge();
- }
-
- void move(){
- radius *= scaleFac;
- loc.addSelf( vel );
- }
-
- void render(){
- renderImageAndRotate(images.corona, loc, radius, c, sin(agePer*PI) * .4, rot );
- }
-
- void checkAge(){
- age ++;
- agePer = 1.0 - age/(float)lifeSpan;
-
- if (age > lifeSpan)
- ISDEAD = true;
- }
-}
diff --git a/java/examples/Books/Nature of Code/chp4_systems/flight404/flight404_particles_2_simple/particle.pde b/java/examples/Books/Nature of Code/chp4_systems/flight404/flight404_particles_2_simple/particle.pde
deleted file mode 100755
index 893d3631f..000000000
--- a/java/examples/Books/Nature of Code/chp4_systems/flight404/flight404_particles_2_simple/particle.pde
+++ /dev/null
@@ -1,172 +0,0 @@
-
-class Particle{
- int len; // number of elements in position array
- Vec3D[] loc; // array of position vectors
- Vec3D startLoc; // just used to make sure every loc[] is initialized to the same position
- Vec3D vel; // velocity vector
- Vec3D perlin; // perlin noise vector
- float radius; // particle's size
- float age; // current age of particle
- int lifeSpan; // max allowed age of particle
- float agePer; // range from 1.0 (birth) to 0.0 (death)
- int gen; // number of times particle has been involved in a SPLIT
- float bounceAge; // amount to age particle when it bounces off floor
- float bounceVel; // speed at impact
- boolean ISDEAD; // if age == lifeSpan, make particle die
- boolean ISBOUNCING; // if particle hits the floor...
- boolean ISSPLIT; // if particle hits the floor with enough speed...
-
-
- Particle( int _gen, Vec3D _loc, Vec3D _vel ){
- gen = _gen;
- radius = random( 10 - gen, 50 - ( gen-1)*10 );
-
- len = (int)( radius*.5 );
- loc = new Vec3D[ len ];
- startLoc = new Vec3D( _loc.add( new Vec3D().randomVector().scaleSelf( random( 1.0 ) ) ) );
-
- for( int i=0; i 1 ){
- vel.addSelf( new Vec3D().randomVector().scaleSelf( random( 7.0 ) ) );
- } else {
- vel.addSelf( new Vec3D().randomVector().scaleSelf( random( 10.0 ) ) );
- }
-
- perlin = new Vec3D();
-
- age = 0;
- bounceAge = 2;
- lifeSpan = (int)( radius );
- }
-
- void exist(){
- if( ALLOWPERLIN )
- findPerlin();
-
- findVelocity();
- setPosition();
- render();
- setAge();
- }
-
- void findPerlin(){
- float xyRads = getRads( loc[0].x, loc[0].z, 20.0, 50.0 );
- float yRads = getRads( loc[0].x, loc[0].y, 20.0, 50.0 );
- perlin.set( cos(xyRads), -sin(yRads), sin(xyRads) );
- perlin.scaleSelf( .5 );
- }
-
- void findVelocity(){
- if( ALLOWGRAVITY )
- vel.addSelf( gravity );
-
- if( ALLOWPERLIN )
- vel.addSelf( perlin );
-
- if( ALLOWFLOOR ){
- if( loc[0].y + vel.y > floorLevel ){
- ISBOUNCING = true;
- } else {
- ISBOUNCING = false;
- }
- }
-
- // if the particle is moving fast enough, when it hits the ground it can
- // split into a bunch of smaller particles.
- if( ISBOUNCING ){
- bounceVel = vel.magnitude();
-
- vel.scaleSelf( .7 );
- vel.y *= -( ( radius/40.0 ) * .5 );
-
- if( bounceVel > 15.0 && gen < 4 )
- ISSPLIT = true;
-
- } else {
- ISSPLIT = false;
- }
- }
-
- void setPosition(){
- for( int i=len-1; i>0; i-- ){
- loc[i].set( loc[i-1] );
- }
-
- loc[0].addSelf( vel );
- }
-
- void render(){
- color c = color( agePer - .5, agePer*.25, 1.5 - agePer );
- renderImage(images.particle, loc[0], radius * agePer, c, 1.0 );
-
- // Rendering two graphics here. Makes the particles more vivid,
- // but will hinder the performance.
- c = color( 1, agePer, agePer );
- renderImage(images.particle, loc[0], radius * agePer * .5, c, agePer );
- }
-
- void renderReflection(){
- float altitude = floorLevel - loc[0].y;
- float reflectMaxAltitude = 25.0;
- float yPer = ( 1.0 - ( altitude/reflectMaxAltitude ) ) * .5;
-
- if( yPer > .05 )
- renderImageOnFloor(images.particle, new Vec3D( loc[0].x, floorLevel, loc[0].z ), radius * agePer * 8.0 * yPer, color( agePer, agePer*.25, 0 ), yPer + random( .2 ) );
- }
-
- void renderTrails(){
- float xp, yp, zp;
- float xOff, yOff, zOff;
-
- beginShape(QUAD_STRIP);
-
- for ( int i=0; i lifeSpan ){
- ISDEAD = true;
- } else {
- agePer = 1.0 - age/(float)lifeSpan;
- }
- }
-}
diff --git a/java/examples/Books/Nature of Code/chp4_systems/flight404/flight404_particles_2_simple/pov.pde b/java/examples/Books/Nature of Code/chp4_systems/flight404/flight404_particles_2_simple/pov.pde
deleted file mode 100755
index cc41c1360..000000000
--- a/java/examples/Books/Nature of Code/chp4_systems/flight404/flight404_particles_2_simple/pov.pde
+++ /dev/null
@@ -1,64 +0,0 @@
-// Camera class which uses Kristian Damkjer's OCD library
-// http://www.cise.ufl.edu/~kdamkjer/processing/libraries/ocd/
-
-class POV{
- PApplet parent;
- Camera cam;
-
- Vec3D eye;
- Vec3D center;
-
- Vec3D eyeNormal;
-
- boolean ISDRAGGING;
-
- POV( PApplet _parent ){
- parent = _parent;
- cam = new Camera( parent, 0, -100, 1500 );
-
- eye = new Vec3D();
- center = new Vec3D();
- eyeNormal = new Vec3D();
- }
-
- void exist(){
- perspective( PI/3.0, (float)xSize/(float)ySize, .5, 5000 );
- if( ISDRAGGING ){
- cam.circle( radians( ( mouseX - pmouseX ) * .25 ) );
- cam.arc( radians( ( mouseY - pmouseY ) * .25 ) );
- }
-
- cam.feed();
- setPosition();
- }
-
-
- // Code by JohnG from the Processing forum
- // http://processing.org/discourse/yabb_beta/YaBB.cgi?board=Programs;action=display;num=1170790832
- //
- // Does the camera transformations in reverse to allow for images that always face the camera.
- void glReverseCamera(){
- float deltaX = eye.x - center.x;
- float deltaY = eye.y - center.y;
- float deltaZ = eye.z - center.z;
-
- float angleZ = atan2( deltaY,deltaX );
- float hyp = sqrt( sq( deltaX ) + sq( deltaY ) );
- float angleY = atan2( hyp,deltaZ );
-
- rotateZ(angleZ);
- rotateY(angleY);
- //gl.glRotatef( degrees( angleZ ), 0, 0, 1.0 );
- //gl.glRotatef( degrees( angleY ), 0, 1.0, 0 );
- }
-
-
- void setPosition(){
- float[] e = cam.position();
- float[] c = cam.target();
-
- eye.set( e[0], e[1], e[2] );
- center.set( c[0], c[1], c[2] );
- eyeNormal = eye.sub(center).normalize();
- }
-}
diff --git a/java/examples/Books/Nature of Code/chp4_systems/simpleInheritance/Circle.pde b/java/examples/Books/Nature of Code/chp4_systems/simpleInheritance/Circle.pde
deleted file mode 100644
index f45630f37..000000000
--- a/java/examples/Books/Nature of Code/chp4_systems/simpleInheritance/Circle.pde
+++ /dev/null
@@ -1,34 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-class Circle extends Shape {
-
- // Inherits all instance variables from parent + adding one
- color c;
-
- Circle(float x_, float y_, float r_, color c_) {
- super(x_,y_,r_); // Call the parent constructor
- c = c_; // Also deal with this new instance variable
- }
-
- // Call the parent jiggle, but do some more stuff too
- void jiggle() {
- super.jiggle();
- // The Circle jiggles its size as well as its x,y location.
- r += random(-1,1);
- r = constrain(r,0,100);
- }
-
- // The changeColor() function is unique to the Circle class.
- void changeColor() {
- c = color(random(255));
- }
-
- void display() {
- ellipseMode(CENTER);
- fill(c);
- stroke(0);
- ellipse(x,y,r,r);
- }
-}
diff --git a/java/examples/Books/Nature of Code/chp4_systems/simpleInheritance/Shape.pde b/java/examples/Books/Nature of Code/chp4_systems/simpleInheritance/Shape.pde
deleted file mode 100644
index a4d8a723a..000000000
--- a/java/examples/Books/Nature of Code/chp4_systems/simpleInheritance/Shape.pde
+++ /dev/null
@@ -1,28 +0,0 @@
-// Learning Processing
-// Daniel Shiffman
-// http://www.learningprocessing.com
-
-// Example 22-1: Inheritance
-
-class Shape {
- float x;
- float y;
- float r;
-
- Shape(float x_, float y_, float r_) {
- x = x_;
- y = y_;
- r = r_;
- }
-
- void jiggle() {
- x += random(-1,1);
- y += random(-1,1);
- }
-
- // A generic shape does not really know how to be displayed.
- // This will be overridden in the child classes.
- void display() {
- point(x,y);
- }
-}
diff --git a/java/examples/Books/Nature of Code/chp4_systems/simpleInheritance/Square.pde b/java/examples/Books/Nature of Code/chp4_systems/simpleInheritance/Square.pde
deleted file mode 100644
index 72831cabe..000000000
--- a/java/examples/Books/Nature of Code/chp4_systems/simpleInheritance/Square.pde
+++ /dev/null
@@ -1,23 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-class Square extends Shape {
- // Variables are inherited from the parent.
- // We could also add variables unique to the Square class if we so desire
-
- Square(float x_, float y_, float r_) {
- // If the parent constructor takes arguments then super() needs to pass in those arguments.
- super(x_,y_,r_);
- }
-
- // Inherits jiggle() from parent
-
- // The square overrides its parent for display.
- void display() {
- rectMode(CENTER);
- fill(175);
- stroke(0);
- rect(x,y,r,r);
- }
-}
diff --git a/java/examples/Books/Nature of Code/chp4_systems/simpleInheritance/simpleInheritance.pde b/java/examples/Books/Nature of Code/chp4_systems/simpleInheritance/simpleInheritance.pde
deleted file mode 100644
index d76add5e3..000000000
--- a/java/examples/Books/Nature of Code/chp4_systems/simpleInheritance/simpleInheritance.pde
+++ /dev/null
@@ -1,25 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Object oriented programming allows us to defi ne classes in terms of other classes.
-// A class can be a subclass (aka " child " ) of a super class (aka "parent").
-// This is a simple example demonstrating this concept, known as "inheritance."
-
-Square s;
-Circle c;
-
-void setup() {
- size(200,200);
- // A square and circle
- s = new Square(75,75,10);
- c = new Circle(125,125,20,color(175));
-}
-
-void draw() {
- background(255);
- c.jiggle();
- s.jiggle();
- c.display();
- s.display();
-}
diff --git a/java/examples/Books/Nature of Code/chp4_systems/simplePolymorphism/Circle.pde b/java/examples/Books/Nature of Code/chp4_systems/simplePolymorphism/Circle.pde
deleted file mode 100644
index f45630f37..000000000
--- a/java/examples/Books/Nature of Code/chp4_systems/simplePolymorphism/Circle.pde
+++ /dev/null
@@ -1,34 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-class Circle extends Shape {
-
- // Inherits all instance variables from parent + adding one
- color c;
-
- Circle(float x_, float y_, float r_, color c_) {
- super(x_,y_,r_); // Call the parent constructor
- c = c_; // Also deal with this new instance variable
- }
-
- // Call the parent jiggle, but do some more stuff too
- void jiggle() {
- super.jiggle();
- // The Circle jiggles its size as well as its x,y location.
- r += random(-1,1);
- r = constrain(r,0,100);
- }
-
- // The changeColor() function is unique to the Circle class.
- void changeColor() {
- c = color(random(255));
- }
-
- void display() {
- ellipseMode(CENTER);
- fill(c);
- stroke(0);
- ellipse(x,y,r,r);
- }
-}
diff --git a/java/examples/Books/Nature of Code/chp4_systems/simplePolymorphism/Shape.pde b/java/examples/Books/Nature of Code/chp4_systems/simplePolymorphism/Shape.pde
deleted file mode 100644
index 671b45edf..000000000
--- a/java/examples/Books/Nature of Code/chp4_systems/simplePolymorphism/Shape.pde
+++ /dev/null
@@ -1,26 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-class Shape {
- float x;
- float y;
- float r;
-
- Shape(float x_, float y_, float r_) {
- x = x_;
- y = y_;
- r = r_;
- }
-
- void jiggle() {
- x += random(-1,1);
- y += random(-1,1);
- }
-
- // A generic shape does not really know how to be displayed.
- // This will be overridden in the child classes.
- void display() {
- point(x,y);
- }
-}
diff --git a/java/examples/Books/Nature of Code/chp4_systems/simplePolymorphism/Square.pde b/java/examples/Books/Nature of Code/chp4_systems/simplePolymorphism/Square.pde
deleted file mode 100644
index 72831cabe..000000000
--- a/java/examples/Books/Nature of Code/chp4_systems/simplePolymorphism/Square.pde
+++ /dev/null
@@ -1,23 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-class Square extends Shape {
- // Variables are inherited from the parent.
- // We could also add variables unique to the Square class if we so desire
-
- Square(float x_, float y_, float r_) {
- // If the parent constructor takes arguments then super() needs to pass in those arguments.
- super(x_,y_,r_);
- }
-
- // Inherits jiggle() from parent
-
- // The square overrides its parent for display.
- void display() {
- rectMode(CENTER);
- fill(175);
- stroke(0);
- rect(x,y,r,r);
- }
-}
diff --git a/java/examples/Books/Nature of Code/chp4_systems/simplePolymorphism/simplePolymorphism.pde b/java/examples/Books/Nature of Code/chp4_systems/simplePolymorphism/simplePolymorphism.pde
deleted file mode 100644
index b7e667acf..000000000
--- a/java/examples/Books/Nature of Code/chp4_systems/simplePolymorphism/simplePolymorphism.pde
+++ /dev/null
@@ -1,28 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// One array of Shapes
-Shape[] shapes = new Shape[30];
-
-void setup() {
- size(200,200);
- for (int i = 0; i < shapes.length; i++ ) {
- int r = int(random(2));
- // Randomly put either circles or squares in our array
- if (r == 0) {
- shapes[i] = new Circle(100,100,10,color(random(255),100));
- } else {
- shapes[i] = new Square(100,100,10);
- }
- }
-}
-
-void draw() {
- background(255);
- // Jiggle and display all shapes
- for (int i = 0; i < shapes.length; i++ ) {
- shapes[i].jiggle();
- shapes[i].display();
- }
-}
diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/CollisionsEqualMass/CollisionsEqualMass.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/CollisionsEqualMass/CollisionsEqualMass.pde
deleted file mode 100644
index bbb54b071..000000000
--- a/java/examples/Books/Nature of Code/chp5_physicslibraries/CollisionsEqualMass/CollisionsEqualMass.pde
+++ /dev/null
@@ -1,34 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Collisions -- Elastic, Equal Mass, Two objects only
-
-// Based off of Chapter 9: Resolving Collisions
-// Mathematics and Physics for Programmers by Danny Kodicek
-
-// A Thing class for idealized collisions
-
-Mover a;
-Mover b;
-
-boolean showVectors = true;
-
-void setup() {
- size(200,200);
- a = new Mover(new PVector(random(5),random(-5,5)),new PVector(10,10));
- b = new Mover(new PVector(-2,1),new PVector(150,150));
-}
-
-void draw() {
- background(255);
- a.go();
- b.go();
-
- // Note this function will ONLY WORK with two objects
- // Needs to be revised in the case of an array of objects
- a.collideEqualMass(b);
-}
-
-
-
diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/CollisionsEqualMass/Mover.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/CollisionsEqualMass/Mover.pde
deleted file mode 100644
index 3281a9850..000000000
--- a/java/examples/Books/Nature of Code/chp5_physicslibraries/CollisionsEqualMass/Mover.pde
+++ /dev/null
@@ -1,100 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Collisions
-
-class Mover {
-
- PVector loc;
- PVector vel;
- float bounce = 1.0;
- float r = 20;
- boolean colliding = false;
-
- Mover(PVector v, PVector l) {
- vel = v.get();
- loc = l.get();
- }
-
- // Main method to operate object
- void go() {
- update();
- borders();
- display();
- }
-
- // Method to update location
- void update() {
- loc.add(vel);
- }
-
- // Check for bouncing off borders
- void borders() {
- if (loc.y > height) {
- vel.y *= -bounce;
- loc.y = height;
- }
- else if (loc.y < 0) {
- vel.y *= -bounce;
- loc.y = 0;
- }
- if (loc.x > width) {
- vel.x *= -bounce;
- loc.x = width;
- }
- else if (loc.x < 0) {
- vel.x *= -bounce;
- loc.x = 0;
- }
- }
-
- // Method to display
- void display() {
- ellipseMode(CENTER);
- stroke(0);
- fill(175,200);
- ellipse(loc.x,loc.y,r*2,r*2);
- if (showVectors) {
- drawVector(vel,loc,10);
- }
- }
-
- void collideEqualMass(Mover other) {
- float d = PVector.dist(loc,other.loc);
- float sumR = r + other.r;
- // Are they colliding?
- if (!colliding && d < sumR) {
- // Yes, make new velocities!
- colliding = true;
- // Direction of one object another
- PVector n = PVector.sub(other.loc,loc);
- n.normalize();
-
- // Difference of velocities so that we think of one object as stationary
- PVector u = PVector.sub(vel,other.vel);
-
- // Separate out components -- one in direction of normal
- PVector un = componentVector(u,n);
- // Other component
- u.sub(un);
- // These are the new velocities plus the velocity of the object we consider as stastionary
- vel = PVector.add(u,other.vel);
- other.vel = PVector.add(un,other.vel);
- }
- else if (d > sumR) {
- colliding = false;
- }
- }
-}
-
-PVector componentVector (PVector vector, PVector directionVector) {
- //--! ARGUMENTS: vector, directionVector (2D vectors)
- //--! RETURNS: the component vector of vector in the direction directionVector
- //-- normalize directionVector
- directionVector.normalize();
- directionVector.mult(vector.dot(directionVector));
- return directionVector;
-}
-
-
diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/CollisionsEqualMass/drawVector.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/CollisionsEqualMass/drawVector.pde
deleted file mode 100644
index 141c06960..000000000
--- a/java/examples/Books/Nature of Code/chp5_physicslibraries/CollisionsEqualMass/drawVector.pde
+++ /dev/null
@@ -1,25 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-void drawVector(PVector v, PVector loc, float scayl) {
- pushMatrix();
- float arrowsize = 4;
- // Translate to location to render vector
- translate(loc.x,loc.y);
- stroke(0);
- // Call vector heading function to get direction (note that pointing up is a heading of 0) and rotate
- rotate(v.heading2D());
- // Calculate length of vector & scale it to be bigger or smaller if necessary
- float len = v.mag()*scayl;
- // Draw three lines to make an arrow (draw pointing up since we've rotate to the proper direction)
- line(0,0,len,0);
- line(len,0,len-arrowsize,+arrowsize/2);
- line(len,0,len-arrowsize,-arrowsize/2);
- popMatrix();
-}
-
-
-void mousePressed() {
- showVectors = !showVectors;
-}
diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/BlobSkeleton/Blob.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/BlobSkeleton/Blob.pde
deleted file mode 100644
index d2cd65eb1..000000000
--- a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/BlobSkeleton/Blob.pde
+++ /dev/null
@@ -1,195 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// A blob skeleton
-// Could be used to create blobbly characters a la Nokia Friends
-// http://postspectacular.com/work/nokia/friends/start
-
-class Skeleton {
-
- // A list to keep track of all the bodies and joints
- ArrayList bodies;
- ArrayList joints;
-
- float bodyRadius; // The radius of each body that makes up the skeleton
- float radius; // The radius of the entire blob
- float totalPoints; // How many points make up the blob
-
-
- // We should modify this constructor to receive arguments
- // So that we can make many different types of blobs
- Skeleton() {
-
- // Create the empty ArrayLists
- bodies = new ArrayList();
- joints = new ArrayList();
-
- // Where and how big is the blob
- Vec2 center = new Vec2(width/2, height/2);
- radius = 100;
- totalPoints = 32;
- bodyRadius = 10;
-
- // Initialize all the points in a circle
- for (int i = 0; i < totalPoints; i++) {
- // Look polar to cartesian coordinate transformation!
- float theta = PApplet.map(i, 0, totalPoints, 0, TWO_PI);
- float x = center.x + radius * sin(theta);
- float y = center.y + radius * cos(theta);
-
- // Make each individual body
- BodyDef bd = new BodyDef();
- bd.type = BodyType.DYNAMIC;
-
- bd.fixedRotation = true; // no rotation!
- bd.position.set(box2d.coordPixelsToWorld(x, y));
- Body body = box2d.createBody(bd);
-
- // The body is a circle
- CircleShape cs = new CircleShape();
- cs.m_radius = box2d.scalarPixelsToWorld(bodyRadius);
-
- // Define a fixture
- FixtureDef fd = new FixtureDef();
- fd.shape = cs;
- fd.density = 1;
- fd.friction = 0.5;
- fd.restitution = 0.3;
-
- // Finalize the body
- body.createFixture(fd);
-
- // Store our own copy for later rendering
- bodies.add(body);
- }
-
- // Now connect the outline of the shape all with joints
- for (int i = 0; i < bodies.size(); i++) {
- DistanceJointDef djd = new DistanceJointDef();
- Body a = bodies.get(i);
- int next = i+1;
- if (i == bodies.size()-1) {
- next = 0;
- }
- Body b = bodies.get(next);
- // Connection between previous particle and this one
- djd.bodyA = a;
- djd.bodyB = b;
- // Equilibrium length is distance between these bodies
- Vec2 apos = a.getWorldCenter();
- Vec2 bpos = b.getWorldCenter();
- float d = dist(apos.x, apos.y, bpos.x, bpos.y);
- djd.length = d;
- // These properties affect how springy the joint is
- djd.frequencyHz = 10;
- djd.dampingRatio = 0.9;
-
- // Make the joint.
- DistanceJoint dj = (DistanceJoint) box2d.world.createJoint(djd);
- joints.add(dj);
- }
-
-
- // Make some joints that cross the center of the blob between bodies
- for (int i = 0; i < bodies.size(); i++) {
- for (int j = i+2; j < bodies.size(); j+=4) {
- DistanceJointDef djd = new DistanceJointDef();
- Body a = bodies.get(i);
- Body b = bodies.get(j);
- // Connection between two bides
- djd.bodyA = a;
- djd.bodyB = b;
- // Equilibrium length is distance between these bodies
- Vec2 apos = a.getWorldCenter();
- Vec2 bpos = b.getWorldCenter();
- float d = dist(apos.x, apos.y, bpos.x, bpos.y);
-
- djd.length = d;
- // These properties affect how springy the joint is
- djd.frequencyHz = 3;
- djd.dampingRatio = 0.1;
-
- // Make the joint.
- DistanceJoint dj = (DistanceJoint) box2d.world.createJoint(djd);
- joints.add(dj);
- }
- }
- }
-
-
- // Draw the skeleton as circles for bodies and lines for joints
- void displaySkeleton() {
- // Draw the outline
- stroke(0);
- strokeWeight(1);
- for (Joint j: joints) {
- Body a = j.getBodyA();
- Body b = j.getBodyB();
- Vec2 posa = box2d.getBodyPixelCoord(a);
- Vec2 posb = box2d.getBodyPixelCoord(b);
- line(posa.x, posa.y, posb.x, posb.y);
- }
-
- // Draw the individual circles
- for (Body b: bodies) {
- // We look at each body and get its screen position
- Vec2 pos = box2d.getBodyPixelCoord(b);
- // Get its angle of rotation
- float a = b.getAngle();
- pushMatrix();
- translate(pos.x, pos.y);
- rotate(a);
- fill(175);
- stroke(0);
- strokeWeight(1);
- ellipse(0, 0, bodyRadius*2, bodyRadius*2);
- popMatrix();
- }
- }
-
-
- // Draw it as a creature
- void displayCreature() {
- // Let's compute the center!
- Vec2 center = new Vec2(0, 0);
-
- // Make a curvy polygon
- beginShape();
- stroke(175);
- strokeWeight(bodyRadius*2);
- fill(175);
- for (Body b: bodies) {
- // We look at each body and get its screen position
- Vec2 pos = box2d.getBodyPixelCoord(b);
- curveVertex(pos.x, pos.y);
- center.addLocal(pos);
- }
- endShape(CLOSE);
- // Center is average of all points
- center.mulLocal(1.0/bodies.size());
-
- // Find angle between center and side body
- Vec2 pos = box2d.getBodyPixelCoord(bodies.get(0));
- float dx = pos.x - center.x;
- float dy = pos.y - center.y;
- float angle = atan2(dy, dx)-PI/2;
-
- // Draw eyes and mouth relative to center
- pushMatrix();
- strokeWeight(1);
- stroke(0);
- translate(center.x, center.y);
- rotate(angle);
- fill(0);
- ellipse(-25, -50, 16, 16);
- ellipse(25, -50, 16, 16);
- line(-50, 50, 50, 50);
- popMatrix();
- }
-
- Body getFirstBody() {
- return bodies.get(0);
- }
-}
-
diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/BlobSkeleton/BlobSkeleton.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/BlobSkeleton/BlobSkeleton.pde
deleted file mode 100644
index c9f4ee0a0..000000000
--- a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/BlobSkeleton/BlobSkeleton.pde
+++ /dev/null
@@ -1,109 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// A blob skeleton
-// Could be used to create blobbly characters a la Nokia Friends
-// http://postspectacular.com/work/nokia/friends/start
-
-import pbox2d.*;
-
-import org.jbox2d.collision.shapes.*;
-import org.jbox2d.common.*;
-import org.jbox2d.dynamics.*;
-import org.jbox2d.dynamics.joints.*;
-
-// A reference to our box2d world
-PBox2D box2d;
-
-// A list we'll use to track fixed objects
-ArrayList boundaries;
-
-// Our "blob" object
-Skeleton blob;
-
-// Just a single box this time
-Box box;
-// The Spring that will attach to the box from the mouse
-Spring spring;
-
-// Draw creature design or skeleton?
-boolean skeleton;
-
-void setup() {
- size(640, 360);
- // Initialize box2d physics and create the world
- box2d = new PBox2D(this);
- box2d.createWorld();
-
- // Add some boundaries
- boundaries = new ArrayList();
- boundaries.add(new Boundary(width/2, height-5, width, 10));
- boundaries.add(new Boundary(width/2, 5, width, 10));
- boundaries.add(new Boundary(width-5, height/2, 10, height));
- boundaries.add(new Boundary(5, height/2, 10, height));
-
- // Make a new blob
- blob = new Skeleton();
-
- // Make the box
- box = new Box(width/2, 100);
-
- // Make the spring (it doesn't really get initialized until the mouse is clicked)
- spring = new Spring();
-}
-
-// When the mouse is released we're done with the spring
-void mouseReleased() {
- spring.destroy();
-}
-
-// When the mouse is pressed we. . .
-void mousePressed() {
- // Check to see if the mouse was clicked on the box
- if (box.contains(mouseX, mouseY)) {
- // And if so, bind the mouse location to the box with a spring
- spring.bind(mouseX, mouseY, box);
- }
-}
-
-void draw() {
- background(255);
-
- // We must always step through time!
-
- box2d.step();
-
-
- // Show the blob!
- if (skeleton) {
- blob.displaySkeleton();
- }
- else {
- blob.displayCreature();
- }
-
- // Show the boundaries!
- for (Boundary wall: boundaries) {
- wall.display();
- }
-
- // Always alert the spring to the new mouse location
- spring.update(mouseX, mouseY);
-
- // Draw the box
- box.display();
- // Draw the spring (it only appears when active)
- spring.display();
-
- fill(0);
- text("Space bar to toggle creature/skeleton.\nClick and drag the box.", 20, height-30);
-}
-
-
-void keyPressed() {
- if (key == ' ') {
- skeleton = !skeleton;
- }
-}
-
diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/BlobSkeleton/Boundary.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/BlobSkeleton/Boundary.pde
deleted file mode 100644
index 9a17026a1..000000000
--- a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/BlobSkeleton/Boundary.pde
+++ /dev/null
@@ -1,53 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// A fixed boundary class
-
-class Boundary {
-
- // A boundary is a simple rectangle with x,y,width,and height
- float x;
- float y;
- float w;
- float h;
-
- // But we also have to make a body for box2d to know about it
- Body b;
-
- Boundary(float x_,float y_, float w_, float h_) {
- x = x_;
- y = y_;
- w = w_;
- h = h_;
-
- // Define the polygon
- PolygonShape sd = new PolygonShape();
- // Figure out the box2d coordinates
- float box2dW = box2d.scalarPixelsToWorld(w/2);
- float box2dH = box2d.scalarPixelsToWorld(h/2);
- // We're just a box
- sd.setAsBox(box2dW, box2dH);
-
-
- // Create the body
- BodyDef bd = new BodyDef();
- bd.type = BodyType.STATIC;
- bd.position.set(box2d.coordPixelsToWorld(x,y));
- b = box2d.createBody(bd);
-
- // Attached the shape to the body using a Fixture
- b.createFixture(sd,1);
- }
-
- // Draw the boundary, if it were at an angle we'd have to do something fancier
- void display() {
- fill(0);
- stroke(0);
- rectMode(CENTER);
- rect(x,y,w,h);
- }
-
-}
-
-
diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/BlobSkeleton/Box.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/BlobSkeleton/Box.pde
deleted file mode 100644
index 16a2c18b2..000000000
--- a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/BlobSkeleton/Box.pde
+++ /dev/null
@@ -1,85 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// A rectangular box
-
-class Box {
-
- // We need to keep track of a Body and a width and height
- Body body;
- float w;
- float h;
-
- // Constructor
- Box(float x_, float y_) {
- float x = x_;
- float y = y_;
- w = 50;
- h = 50;
- // Add the box to the box2d world
- makeBody(new Vec2(x, y), w, h);
- body.setUserData(this);
- }
-
- // This function removes the particle from the box2d world
- void killBody() {
- box2d.destroyBody(body);
- }
-
- boolean contains(float x, float y) {
- Vec2 worldPoint = box2d.coordPixelsToWorld(x, y);
- Fixture f = body.getFixtureList();
- boolean inside = f.testPoint(worldPoint);
- return inside;
- }
-
- // Drawing the box
- void display() {
- // We look at each body and get its screen position
- Vec2 pos = box2d.getBodyPixelCoord(body);
- // Get its angle of rotation
- float a = body.getAngle();
-
- rectMode(PConstants.CENTER);
- pushMatrix();
- translate(pos.x, pos.y);
- rotate(-a);
- fill(50);
- stroke(0);
- rect(0, 0, w, h);
- popMatrix();
- }
-
- // This function adds the rectangle to the box2d world
- void makeBody(Vec2 center, float w_, float h_) {
- // Define and create the body
- BodyDef bd = new BodyDef();
- bd.type = BodyType.DYNAMIC;
- bd.position.set(box2d.coordPixelsToWorld(center));
- body = box2d.createBody(bd);
-
- // Define a polygon (this is what we use for a rectangle)
- PolygonShape sd = new PolygonShape();
- float box2dW = box2d.scalarPixelsToWorld(w_/2);
- float box2dH = box2d.scalarPixelsToWorld(h_/2);
- sd.setAsBox(box2dW, box2dH);
-
- // Define a fixture
- FixtureDef fd = new FixtureDef();
- fd.shape = sd;
- // Parameters that affect physics
- fd.density = 1;
- fd.friction = 0.3;
- fd.restitution = 0.5;
-
- body.createFixture(fd);
- //body.setMassFromShapes();
-
- // Give it some initial random velocity
- body.setLinearVelocity(new Vec2(random(-5, 5), random(2, 5)));
- body.setAngularVelocity(random(-5, 5));
- }
-}
-
-
diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/BlobSkeleton/Spring.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/BlobSkeleton/Spring.pde
deleted file mode 100644
index 02fd1612b..000000000
--- a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/BlobSkeleton/Spring.pde
+++ /dev/null
@@ -1,75 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Class to describe the spring joint (displayed as a line)
-
-class Spring {
-
- // This is the box2d object we need to create
- MouseJoint mouseJoint;
-
- Spring() {
- // At first it doesn't exist
- mouseJoint = null;
- }
-
- // If it exists we set its target to the mouse location
- void update(float x, float y) {
- if (mouseJoint != null) {
- // Always convert to world coordinates!
- Vec2 mouseWorld = box2d.coordPixelsToWorld(x,y);
- mouseJoint.setTarget(mouseWorld);
- }
- }
-
- void display() {
- if (mouseJoint != null) {
- // We can get the two anchor points
- Vec2 v1 = new Vec2(0,0);
- mouseJoint.getAnchorA(v1);
- Vec2 v2 = new Vec2(0,0);
- mouseJoint.getAnchorB(v2);
- // Convert them to screen coordinates
- v1 = box2d.coordWorldToPixels(v1);
- v2 = box2d.coordWorldToPixels(v2);
- // And just draw a line
- stroke(0);
- strokeWeight(1);
- line(v1.x,v1.y,v2.x,v2.y);
- }
- }
-
-
- // This is the key function where
- // we attach the spring to an x,y location
- // and the Box object's location
- void bind(float x, float y, Box box) {
- // Define the joint
- MouseJointDef md = new MouseJointDef();
- // Body A is just a fake ground body for simplicity (there isn't anything at the mouse)
- md.bodyA = box2d.getGroundBody();
- // Body 2 is the box's boxy
- md.bodyB = box.body;
- // Get the mouse location in world coordinates
- Vec2 mp = box2d.coordPixelsToWorld(x,y);
- // And that's the target
- md.target.set(mp);
- // Some stuff about how strong and bouncy the spring should be
- md.maxForce = 1000.0 * box.body.m_mass;
- md.frequencyHz = 5.0;
- md.dampingRatio = 0.9;
-
- // Make the joint!
- mouseJoint = (MouseJoint) box2d.world.createJoint(md);
- }
-
- void destroy() {
- // We can get rid of the joint when the mouse is released
- if (mouseJoint != null) {
- box2d.world.destroyJoint(mouseJoint);
- mouseJoint = null;
- }
- }
-
-}
diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Blobby/Blob.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Blobby/Blob.pde
deleted file mode 100644
index 1919d79e2..000000000
--- a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Blobby/Blob.pde
+++ /dev/null
@@ -1,118 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// PBox2D example
-
-// A blob skeleton
-// Could be used to create blobbly characters a la Nokia Friends
-// http://postspectacular.com/work/nokia/friends/start
-
-class Blob {
-
- // A list to keep track of all the points in our blob
- ArrayList skeleton;
-
- float bodyRadius; // The radius of each body that makes up the skeleton
- float radius; // The radius of the entire blob
- float totalPoints; // How many points make up the blob
-
-
- // We should modify this constructor to receive arguments
- // So that we can make many different types of blobs
- Blob() {
-
- // Create the empty
- skeleton = new ArrayList();
-
- // Let's make a volume of joints!
- ConstantVolumeJointDef cvjd = new ConstantVolumeJointDef();
-
- // Where and how big is the blob
- Vec2 center = new Vec2(width/2, height/2);
- radius = 100;
- totalPoints = 20;
- bodyRadius = 12;
-
-
- // Initialize all the points
- for (int i = 0; i < totalPoints; i++) {
- // Look polar to cartesian coordinate transformation!
- float theta = PApplet.map(i, 0, totalPoints, 0, TWO_PI);
- float x = center.x + radius * sin(theta);
- float y = center.y + radius * cos(theta);
-
- // Make each individual body
- BodyDef bd = new BodyDef();
- bd.type = BodyType.DYNAMIC;
-
- bd.fixedRotation = true; // no rotation!
- bd.position.set(box2d.coordPixelsToWorld(x, y));
- Body body = box2d.createBody(bd);
-
- // The body is a circle
- CircleShape cs = new CircleShape();
- cs.m_radius = box2d.scalarPixelsToWorld(bodyRadius);
-
- // Define a fixture
- FixtureDef fd = new FixtureDef();
- fd.shape = cs;
-
- // For filtering out collisions
- //fd.filter.groupIndex = -2;
-
- // Parameters that affect physics
- fd.density = 1;
-
- // Finalize the body
- body.createFixture(fd);
- // Add it to the volume
- cvjd.addBody(body);
-
-
- // Store our own copy for later rendering
- skeleton.add(body);
- }
-
- // These parameters control how stiff vs. jiggly the blob is
- cvjd.frequencyHz = 10.0f;
- cvjd.dampingRatio = 1.0f;
-
- // Put the joint thing in our world!
- box2d.world.createJoint(cvjd);
- }
-
-
- // Time to draw the blob!
- // Can you make it a cute character, a la http://postspectacular.com/work/nokia/friends/start
- void display() {
-
- // Draw the outline
- beginShape();
- noFill();
- stroke(0);
- strokeWeight(1);
- for (Body b: skeleton) {
- Vec2 pos = box2d.getBodyPixelCoord(b);
- vertex(pos.x, pos.y);
- }
- endShape(CLOSE);
-
- // Draw the individual circles
- for (Body b: skeleton) {
- // We look at each body and get its screen position
- Vec2 pos = box2d.getBodyPixelCoord(b);
- // Get its angle of rotation
- float a = b.getAngle();
- pushMatrix();
- translate(pos.x, pos.y);
- rotate(a);
- fill(175);
- stroke(0);
- strokeWeight(1);
- ellipse(0, 0, bodyRadius*2, bodyRadius*2);
- popMatrix();
- }
- }
-}
-
diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Blobby/Blobby.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Blobby/Blobby.pde
deleted file mode 100644
index d5df8e919..000000000
--- a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Blobby/Blobby.pde
+++ /dev/null
@@ -1,63 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// A blob skeleton
-// Could be used to create blobbly characters a la Nokia Friends
-// http://postspectacular.com/work/nokia/friends/start
-
-// This seems to be broken with the Box2D 2.1.2 version I'm using
-
-import pbox2d.*;
-
-import org.jbox2d.collision.shapes.*;
-import org.jbox2d.common.*;
-import org.jbox2d.dynamics.*;
-import org.jbox2d.dynamics.joints.*;
-
-// A reference to our box2d world
-PBox2D box2d;
-
-// A list we'll use to track fixed objects
-ArrayList boundaries;
-
-// Our "blob" object
-Blob blob;
-
- void setup() {
- size(400,300);
- // Initialize box2d physics and create the world
- box2d = new PBox2D(this);
- box2d.createWorld();
-
- // Add some boundaries
- boundaries = new ArrayList();
- boundaries.add(new Boundary(width/2,height-5,width,10));
- boundaries.add(new Boundary(width/2,5,width,10));
- boundaries.add(new Boundary(width-5,height/2,10,height));
- boundaries.add(new Boundary(5,height/2,10,height));
-
- // Make a new blob
- blob = new Blob();
-}
-
- void draw() {
- background(255);
-
- // We must always step through time!
- box2d.step();
-
- // Show the blob!
- blob.display();
-
- // Show the boundaries!
- for (Boundary wall: boundaries) {
- wall.display();
- }
-
-
-}
-
-
-
-
diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Blobby/Boundary.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Blobby/Boundary.pde
deleted file mode 100644
index 9a17026a1..000000000
--- a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Blobby/Boundary.pde
+++ /dev/null
@@ -1,53 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// A fixed boundary class
-
-class Boundary {
-
- // A boundary is a simple rectangle with x,y,width,and height
- float x;
- float y;
- float w;
- float h;
-
- // But we also have to make a body for box2d to know about it
- Body b;
-
- Boundary(float x_,float y_, float w_, float h_) {
- x = x_;
- y = y_;
- w = w_;
- h = h_;
-
- // Define the polygon
- PolygonShape sd = new PolygonShape();
- // Figure out the box2d coordinates
- float box2dW = box2d.scalarPixelsToWorld(w/2);
- float box2dH = box2d.scalarPixelsToWorld(h/2);
- // We're just a box
- sd.setAsBox(box2dW, box2dH);
-
-
- // Create the body
- BodyDef bd = new BodyDef();
- bd.type = BodyType.STATIC;
- bd.position.set(box2d.coordPixelsToWorld(x,y));
- b = box2d.createBody(bd);
-
- // Attached the shape to the body using a Fixture
- b.createFixture(sd,1);
- }
-
- // Draw the boundary, if it were at an angle we'd have to do something fancier
- void display() {
- fill(0);
- stroke(0);
- rectMode(CENTER);
- rect(x,y,w,h);
- }
-
-}
-
-
diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/CollisionListeningDeletionExercise/Boundary.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/CollisionListeningDeletionExercise/Boundary.pde
deleted file mode 100644
index ff6226252..000000000
--- a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/CollisionListeningDeletionExercise/Boundary.pde
+++ /dev/null
@@ -1,55 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// A fixed boundary class
-
-class Boundary {
-
- // A boundary is a simple rectangle with x,y,width,and height
- float x;
- float y;
- float w;
- float h;
-
- // But we also have to make a body for box2d to know about it
- Body b;
-
- Boundary(float x_,float y_, float w_, float h_) {
- x = x_;
- y = y_;
- w = w_;
- h = h_;
-
- // Define the polygon
- PolygonShape sd = new PolygonShape();
- // Figure out the box2d coordinates
- float box2dW = box2d.scalarPixelsToWorld(w/2);
- float box2dH = box2d.scalarPixelsToWorld(h/2);
- // We're just a box
- sd.setAsBox(box2dW, box2dH);
-
-
- // Create the body
- BodyDef bd = new BodyDef();
- bd.type = BodyType.STATIC;
- bd.position.set(box2d.coordPixelsToWorld(x,y));
- b = box2d.createBody(bd);
-
- // Attached the shape to the body using a Fixture
- b.createFixture(sd,1);
-
- b.setUserData(this);
- }
-
- // Draw the boundary, if it were at an angle we'd have to do something fancier
- void display() {
- fill(0);
- stroke(0);
- rectMode(CENTER);
- rect(x,y,w,h);
- }
-
-}
-
-
diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/CollisionListeningDeletionExercise/CollisionListeningDeletionExercise.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/CollisionListeningDeletionExercise/CollisionListeningDeletionExercise.pde
deleted file mode 100644
index 37c6ee51d..000000000
--- a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/CollisionListeningDeletionExercise/CollisionListeningDeletionExercise.pde
+++ /dev/null
@@ -1,118 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Basic example of controlling an object with our own motion (by attaching a MouseJoint)
-// Also demonstrates how to know which object was hit
-
-import pbox2d.*;
-import org.jbox2d.common.*;
-import org.jbox2d.dynamics.joints.*;
-import org.jbox2d.collision.shapes.*;
-import org.jbox2d.collision.shapes.Shape;
-import org.jbox2d.common.*;
-import org.jbox2d.dynamics.*;
-import org.jbox2d.dynamics.contacts.*;
-
-// A reference to our box2d world
-PBox2D box2d;
-
-// An ArrayList of particles that will fall on the surface
-ArrayList particles;
-
-Boundary wall;
-
-void setup() {
- size(400, 300);
- // Initialize box2d physics and create the world
- box2d = new PBox2D(this);
- box2d.createWorld();
-
- // Turn on collision listening!
- box2d.listenForCollisions();
-
- // Create the empty list
- particles = new ArrayList();
-
- wall = new Boundary(width/2, height-5, width, 10);
-}
-
-void draw() {
- background(255);
-
- if (random(1) < 0.1) {
- float sz = random(4, 8);
- particles.add(new Particle(random(width), 20, sz));
- }
-
-
- // We must always step through time!
- box2d.step();
-
- // Look at all particles
- for (int i = particles.size()-1; i >= 0; i--) {
- Particle p = particles.get(i);
- p.display();
- // Particles that leave the screen, we delete them
- // (note they have to be deleted from both the box2d world and our list
- if (p.done()) {
- particles.remove(i);
- }
- }
-
- wall.display();
-}
-
-
-// Collision event functions!
-void beginContact(Contact cp) {
- // Get both shapes
- Fixture f1 = cp.getFixtureA();
- Fixture f2 = cp.getFixtureB();
- // Get both bodies
- Body b1 = f1.getBody();
- Body b2 = f2.getBody();
-
- // Get our objects that reference these bodies
- Object o1 = b1.getUserData();
- Object o2 = b2.getUserData();
-
- if (o1.getClass() == Particle.class && o2.getClass() == Particle.class) {
- Particle p1 = (Particle) o1;
- p1.delete();
- Particle p2 = (Particle) o2;
- p2.delete();
- }
-
- if (o1.getClass() == Boundary.class) {
- Particle p = (Particle) o2;
- p.change();
- }
- if (o2.getClass() == Boundary.class) {
- Particle p = (Particle) o1;
- p.change();
- }
-
-
-}
-
-// Objects stop touching each other
-void endContact(Contact cp) {
-}
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/CollisionListeningDeletionExercise/Particle.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/CollisionListeningDeletionExercise/Particle.pde
deleted file mode 100644
index 5a4017c84..000000000
--- a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/CollisionListeningDeletionExercise/Particle.pde
+++ /dev/null
@@ -1,95 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// A circular particle
-
-class Particle {
-
- // We need to keep track of a Body and a radius
- Body body;
- float r;
-
- color col;
-
- boolean delete = false;
-
- Particle(float x, float y, float r_) {
- r = r_;
- // This function puts the particle in the Box2d world
- makeBody(x, y, r);
- body.setUserData(this);
- col = color(175);
- }
-
- // This function removes the particle from the box2d world
- void killBody() {
- box2d.destroyBody(body);
- }
-
- void delete() {
- delete = true;
- }
-
- // Change color when hit
- void change() {
- col = color(255, 0, 0);
- }
-
- // Is the particle ready for deletion?
- // Is the particle ready for deletion?
- boolean done() {
- // Let's find the screen position of the particle
- Vec2 pos = box2d.getBodyPixelCoord(body);
- // Is it off the bottom of the screen?
- if (pos.y > height+r*2 || delete) {
- killBody();
- return true;
- }
- return false;
- }
- //
- void display() {
- // We look at each body and get its screen position
- Vec2 pos = box2d.getBodyPixelCoord(body);
- // Get its angle of rotation
- float a = body.getAngle();
- pushMatrix();
- translate(pos.x, pos.y);
- rotate(a);
- fill(col);
- stroke(0);
- strokeWeight(1);
- ellipse(0, 0, r*2, r*2);
- // Let's add a line so we can see the rotation
- line(0, 0, r, 0);
- popMatrix();
- }
-
- // Here's our function that adds the particle to the Box2D world
- void makeBody(float x, float y, float r) {
- // Define a body
- BodyDef bd = new BodyDef();
- // Set its position
- bd.position = box2d.coordPixelsToWorld(x, y);
- bd.type = BodyType.DYNAMIC;
- body = box2d.createBody(bd);
-
- // Make the body's shape a circle
- CircleShape cs = new CircleShape();
- cs.m_radius = box2d.scalarPixelsToWorld(r);
-
- FixtureDef fd = new FixtureDef();
- fd.shape = cs;
- // Parameters that affect physics
- fd.density = 1;
- fd.friction = 0.01;
- fd.restitution = 0.3;
-
- // Attach fixture to body
- body.createFixture(fd);
-
- body.setAngularVelocity(random(-10, 10));
- }
-}
-
diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/CollisionsAndControl/Box.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/CollisionsAndControl/Box.pde
deleted file mode 100644
index 1fb05d066..000000000
--- a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/CollisionsAndControl/Box.pde
+++ /dev/null
@@ -1,85 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// A rectangular box
-
-class Box {
-
- // We need to keep track of a Body and a width and height
- Body body;
- float w;
- float h;
-
- // Constructor
- Box(float x_, float y_) {
- float x = x_;
- float y = y_;
- w = 24;
- h = 24;
- // Add the box to the box2d world
- makeBody(new Vec2(x, y), w, h);
- body.setUserData(this);
- }
-
- // This function removes the particle from the box2d world
- void killBody() {
- box2d.destroyBody(body);
- }
-
- boolean contains(float x, float y) {
- Vec2 worldPoint = box2d.coordPixelsToWorld(x, y);
- Fixture f = body.getFixtureList();
- boolean inside = f.testPoint(worldPoint);
- return inside;
- }
-
- // Drawing the box
- void display() {
- // We look at each body and get its screen position
- Vec2 pos = box2d.getBodyPixelCoord(body);
- // Get its angle of rotation
- float a = body.getAngle();
-
- rectMode(PConstants.CENTER);
- pushMatrix();
- translate(pos.x, pos.y);
- rotate(-a);
- fill(175);
- stroke(0);
- rect(0, 0, w, h);
- popMatrix();
- }
-
- // This function adds the rectangle to the box2d world
- void makeBody(Vec2 center, float w_, float h_) {
- // Define and create the body
- BodyDef bd = new BodyDef();
- bd.type = BodyType.DYNAMIC;
- bd.position.set(box2d.coordPixelsToWorld(center));
- body = box2d.createBody(bd);
-
- // Define a polygon (this is what we use for a rectangle)
- PolygonShape sd = new PolygonShape();
- float box2dW = box2d.scalarPixelsToWorld(w_/2);
- float box2dH = box2d.scalarPixelsToWorld(h_/2);
- sd.setAsBox(box2dW, box2dH);
-
- // Define a fixture
- FixtureDef fd = new FixtureDef();
- fd.shape = sd;
- // Parameters that affect physics
- fd.density = 1;
- fd.friction = 0.3;
- fd.restitution = 0.5;
-
- body.createFixture(fd);
- //body.setMassFromShapes();
-
- // Give it some initial random velocity
- body.setLinearVelocity(new Vec2(random(-5, 5), random(2, 5)));
- body.setAngularVelocity(random(-5, 5));
- }
-}
-
-
diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/CollisionsAndControl/CollisionsAndControl.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/CollisionsAndControl/CollisionsAndControl.pde
deleted file mode 100644
index 7ddaa71b6..000000000
--- a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/CollisionsAndControl/CollisionsAndControl.pde
+++ /dev/null
@@ -1,150 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Basic example of controlling an object with our own motion (by attaching a MouseJoint)
-// Also demonstrates how to know which object was hit
-
-import pbox2d.*;
-import org.jbox2d.common.*;
-import org.jbox2d.dynamics.joints.*;
-import org.jbox2d.collision.shapes.*;
-import org.jbox2d.collision.shapes.Shape;
-import org.jbox2d.common.*;
-import org.jbox2d.dynamics.*;
-import org.jbox2d.dynamics.contacts.*;
-
-// A reference to our box2d world
-PBox2D box2d;
-
-// Just a single box this time
-Box box;
-
-// An ArrayList of particles that will fall on the surface
-ArrayList particles;
-
-// The Spring that will attach to the box from the mouse
-Spring spring;
-
-// Perlin noise values
-float xoff = 0;
-float yoff = 1000;
-
-
-void setup() {
- size(400,300);
- // Initialize box2d physics and create the world
- box2d = new PBox2D(this);
- box2d.createWorld();
-
- // Turn on collision listening!
- box2d.listenForCollisions();
-
- // Make the box
- box = new Box(width/2,height/2);
-
- // Make the spring (it doesn't really get initialized until the mouse is clicked)
- spring = new Spring();
- spring.bind(width/2,height/2,box);
-
- // Create the empty list
- particles = new ArrayList();
-
-
-}
-
-void draw() {
- background(255);
-
- if (random(1) < 0.2) {
- float sz = random(4,8);
- particles.add(new Particle(width/2,-20,sz));
- }
-
-
- // We must always step through time!
- box2d.step();
-
- // Make an x,y coordinate out of perlin noise
- float x = noise(xoff)*width;
- float y = noise(yoff)*height;
- xoff += 0.01;
- yoff += 0.01;
-
- // This is tempting but will not work!
- // box.body.setXForm(box2d.screenToWorld(x,y),0);
-
- // Instead update the spring which pulls the mouse along
- if (mousePressed) {
- spring.update(mouseX,mouseY);
- spring.display();
- } else {
- spring.update(x,y);
- }
- box.body.setAngularVelocity(0);
-
- // Look at all particles
- for (int i = particles.size()-1; i >= 0; i--) {
- Particle p = particles.get(i);
- p.display();
- // Particles that leave the screen, we delete them
- // (note they have to be deleted from both the box2d world and our list
- if (p.done()) {
- particles.remove(i);
- }
- }
-
- // Draw the box
- box.display();
-
- // Draw the spring
- // spring.display();
-}
-
-
-// Collision event functions!
-void beginContact(Contact cp) {
- // Get both fixtures
- Fixture f1 = cp.getFixtureA();
- Fixture f2 = cp.getFixtureB();
- // Get both bodies
- Body b1 = f1.getBody();
- Body b2 = f2.getBody();
- // Get our objects that reference these bodies
- Object o1 = b1.getUserData();
- Object o2 = b2.getUserData();
-
- // If object 1 is a Box, then object 2 must be a particle
- // Note we are ignoring particle on particle collisions
- if (o1.getClass() == Box.class) {
- Particle p = (Particle) o2;
- p.change();
- }
- // If object 2 is a Box, then object 1 must be a particle
- else if (o2.getClass() == Box.class) {
- Particle p = (Particle) o1;
- p.change();
- }
-}
-
-
-// Objects stop touching each other
-void endContact(Contact cp) {
-}
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/CollisionsAndControl/Particle.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/CollisionsAndControl/Particle.pde
deleted file mode 100644
index 50be57e86..000000000
--- a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/CollisionsAndControl/Particle.pde
+++ /dev/null
@@ -1,91 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// A circular particle
-
-class Particle {
-
- // We need to keep track of a Body and a radius
- Body body;
- float r;
-
- color col;
-
-
- Particle(float x, float y, float r_) {
- r = r_;
- // This function puts the particle in the Box2d world
- makeBody(x, y, r);
- body.setUserData(this);
- col = color(175);
- }
-
- // This function removes the particle from the box2d world
- void killBody() {
- box2d.destroyBody(body);
- }
-
- // Change color when hit
- void change() {
- col = color(255, 0, 0);
- }
-
- // Is the particle ready for deletion?
- boolean done() {
- // Let's find the screen position of the particle
- Vec2 pos = box2d.getBodyPixelCoord(body);
- // Is it off the bottom of the screen?
- if (pos.y > height+r*2) {
- killBody();
- return true;
- }
- return false;
- }
-
-
- //
- void display() {
- // We look at each body and get its screen position
- Vec2 pos = box2d.getBodyPixelCoord(body);
- // Get its angle of rotation
- float a = body.getAngle();
- pushMatrix();
- translate(pos.x, pos.y);
- rotate(a);
- fill(col);
- stroke(0);
- strokeWeight(1);
- ellipse(0, 0, r*2, r*2);
- // Let's add a line so we can see the rotation
- line(0, 0, r, 0);
- popMatrix();
- }
-
- // Here's our function that adds the particle to the Box2D world
- void makeBody(float x, float y, float r) {
- // Define a body
- BodyDef bd = new BodyDef();
- // Set its position
- bd.position = box2d.coordPixelsToWorld(x, y);
- bd.type = BodyType.DYNAMIC;
- body = box2d.createBody(bd);
-
- // Make the body's shape a circle
- CircleShape cs = new CircleShape();
- cs.m_radius = box2d.scalarPixelsToWorld(r);
-
- FixtureDef fd = new FixtureDef();
- fd.shape = cs;
- // Parameters that affect physics
- fd.density = 1;
- fd.friction = 0.01;
- fd.restitution = 0.3;
-
- // Attach fixture to body
- body.createFixture(fd);
-
- body.setAngularVelocity(random(-10, 10));
- }
-}
-
diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/CollisionsAndControl/Spring.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/CollisionsAndControl/Spring.pde
deleted file mode 100644
index cca069b90..000000000
--- a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/CollisionsAndControl/Spring.pde
+++ /dev/null
@@ -1,81 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Class to describe the spring joint (displayed as a line)
-
-class Spring {
-
- // This is the box2d object we need to create
- MouseJoint mouseJoint;
-
- Spring() {
- // At first it doesn't exist
- mouseJoint = null;
- }
-
- // If it exists we set its target to the mouse location
- void update(float x, float y) {
- if (mouseJoint != null) {
- // Always convert to world coordinates!
- Vec2 mouseWorld = box2d.coordPixelsToWorld(x,y);
- mouseJoint.setTarget(mouseWorld);
- }
- }
-
- void display() {
- if (mouseJoint != null) {
- // We can get the two anchor points
- Vec2 v1 = new Vec2(0,0);
- mouseJoint.getAnchorA(v1);
- Vec2 v2 = new Vec2(0,0);
- mouseJoint.getAnchorB(v2);
- // Convert them to screen coordinates
- v1 = box2d.coordWorldToPixels(v1);
- v2 = box2d.coordWorldToPixels(v2);
- // And just draw a line
- stroke(0);
- strokeWeight(1);
- line(v1.x,v1.y,v2.x,v2.y);
- }
- }
-
-
- // This is the key function where
- // we attach the spring to an x,y location
- // and the Box object's location
- void bind(float x, float y, Box box) {
- // Define the joint
- MouseJointDef md = new MouseJointDef();
-
- // Body A is just a fake ground body for simplicity (there isn't anything at the mouse)
- md.bodyA = box2d.getGroundBody();
- // Body 2 is the box's boxy
- md.bodyB = box.body;
- // Get the mouse location in world coordinates
- Vec2 mp = box2d.coordPixelsToWorld(x,y);
- // And that's the target
- md.target.set(mp);
- // Some stuff about how strong and bouncy the spring should be
- md.maxForce = 1000.0 * box.body.m_mass;
- md.frequencyHz = 5.0;
- md.dampingRatio = 0.9;
-
- // Wake up body!
- //box.body.wakeUp();
-
- // Make the joint!
- mouseJoint = (MouseJoint) box2d.world.createJoint(md);
- }
-
- void destroy() {
- // We can get rid of the joint when the mouse is released
- if (mouseJoint != null) {
- box2d.world.destroyJoint(mouseJoint);
- mouseJoint = null;
- }
- }
-
-}
-
-
diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/CollisionsAndControlInterface/Box.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/CollisionsAndControlInterface/Box.pde
deleted file mode 100644
index 1fb05d066..000000000
--- a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/CollisionsAndControlInterface/Box.pde
+++ /dev/null
@@ -1,85 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// A rectangular box
-
-class Box {
-
- // We need to keep track of a Body and a width and height
- Body body;
- float w;
- float h;
-
- // Constructor
- Box(float x_, float y_) {
- float x = x_;
- float y = y_;
- w = 24;
- h = 24;
- // Add the box to the box2d world
- makeBody(new Vec2(x, y), w, h);
- body.setUserData(this);
- }
-
- // This function removes the particle from the box2d world
- void killBody() {
- box2d.destroyBody(body);
- }
-
- boolean contains(float x, float y) {
- Vec2 worldPoint = box2d.coordPixelsToWorld(x, y);
- Fixture f = body.getFixtureList();
- boolean inside = f.testPoint(worldPoint);
- return inside;
- }
-
- // Drawing the box
- void display() {
- // We look at each body and get its screen position
- Vec2 pos = box2d.getBodyPixelCoord(body);
- // Get its angle of rotation
- float a = body.getAngle();
-
- rectMode(PConstants.CENTER);
- pushMatrix();
- translate(pos.x, pos.y);
- rotate(-a);
- fill(175);
- stroke(0);
- rect(0, 0, w, h);
- popMatrix();
- }
-
- // This function adds the rectangle to the box2d world
- void makeBody(Vec2 center, float w_, float h_) {
- // Define and create the body
- BodyDef bd = new BodyDef();
- bd.type = BodyType.DYNAMIC;
- bd.position.set(box2d.coordPixelsToWorld(center));
- body = box2d.createBody(bd);
-
- // Define a polygon (this is what we use for a rectangle)
- PolygonShape sd = new PolygonShape();
- float box2dW = box2d.scalarPixelsToWorld(w_/2);
- float box2dH = box2d.scalarPixelsToWorld(h_/2);
- sd.setAsBox(box2dW, box2dH);
-
- // Define a fixture
- FixtureDef fd = new FixtureDef();
- fd.shape = sd;
- // Parameters that affect physics
- fd.density = 1;
- fd.friction = 0.3;
- fd.restitution = 0.5;
-
- body.createFixture(fd);
- //body.setMassFromShapes();
-
- // Give it some initial random velocity
- body.setLinearVelocity(new Vec2(random(-5, 5), random(2, 5)));
- body.setAngularVelocity(random(-5, 5));
- }
-}
-
-
diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/CollisionsAndControlInterface/CollisionsAndControlInterface.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/CollisionsAndControlInterface/CollisionsAndControlInterface.pde
deleted file mode 100644
index 08df03156..000000000
--- a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/CollisionsAndControlInterface/CollisionsAndControlInterface.pde
+++ /dev/null
@@ -1,111 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Basic example of controlling an object with our own motion (by attaching a MouseJoint)
-// Also demonstrates how to know which object was hit
-
-import pbox2d.*;
-import org.jbox2d.common.*;
-import org.jbox2d.dynamics.joints.*;
-import org.jbox2d.collision.shapes.*;
-import org.jbox2d.collision.shapes.Shape;
-import org.jbox2d.common.*;
-import org.jbox2d.dynamics.*;
-import org.jbox2d.dynamics.contacts.*;
-
-// A reference to our box2d world
-PBox2D box2d;
-
-// Just a single box this time
-Box box;
-
-// An ArrayList of particles that will fall on the surface
-ArrayList particles;
-
-// The Spring that will attach to the box from the mouse
-Spring spring;
-
-// Perlin noise values
-float xoff = 0;
-float yoff = 1000;
-
-
-void setup() {
- size(400,300);
- // Initialize box2d physics and create the world
- box2d = new PBox2D(this);
- box2d.createWorld();
-
- // Add a listener to listen for collisions!
- box2d.world.setContactListener(new CustomListener());
-
- // Make the box
- box = new Box(width/2,height/2);
-
- // Make the spring (it doesn't really get initialized until the mouse is clicked)
- spring = new Spring();
- spring.bind(width/2,height/2,box);
-
- // Create the empty list
- particles = new ArrayList();
-
-
-}
-
-void draw() {
- background(255);
-
- if (random(1) < 0.2) {
- float sz = random(4,8);
- particles.add(new Particle(width/2,-20,sz));
- }
-
-
- // We must always step through time!
- box2d.step();
-
- // Make an x,y coordinate out of perlin noise
- float x = noise(xoff)*width;
- float y = noise(yoff)*height;
- xoff += 0.01;
- yoff += 0.01;
-
- // This is tempting but will not work!
- // box.body.setXForm(box2d.screenToWorld(x,y),0);
-
- // Instead update the spring which pulls the mouse along
- if (mousePressed) {
- spring.update(mouseX,mouseY);
- } else {
- spring.update(x,y);
- }
- //box.body.setAngularVelocity(0);
-
- // Look at all particles
- for (int i = particles.size()-1; i >= 0; i--) {
- Particle p = particles.get(i);
- p.display();
- // Particles that leave the screen, we delete them
- // (note they have to be deleted from both the box2d world and our list
- if (p.done()) {
- particles.remove(i);
- }
- }
-
- // Draw the box
- box.display();
-
- // Draw the spring
- // spring.display();
-}
-
-
-
-
-
-
-
-
-
-
diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/CollisionsAndControlInterface/ContactListener.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/CollisionsAndControlInterface/ContactListener.pde
deleted file mode 100644
index 48b5f659e..000000000
--- a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/CollisionsAndControlInterface/ContactListener.pde
+++ /dev/null
@@ -1,56 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// ContactListener to listen for collisions!
-
-import org.jbox2d.callbacks.ContactImpulse;
-import org.jbox2d.callbacks.ContactListener;
-import org.jbox2d.collision.Manifold;
-import org.jbox2d.dynamics.contacts.Contact;
-
- class CustomListener implements ContactListener {
- CustomListener() {
- }
-
- // This function is called when a new collision occurs
- void beginContact(Contact cp) {
- // Get both fixtures
- Fixture f1 = cp.getFixtureA();
- Fixture f2 = cp.getFixtureB();
- // Get both bodies
- Body b1 = f1.getBody();
- Body b2 = f2.getBody();
- // Get our objects that reference these bodies
- Object o1 = b1.getUserData();
- Object o2 = b2.getUserData();
-
- // If object 1 is a Box, then object 2 must be a particle
- // Note we are ignoring particle on particle collisions
- if (o1.getClass() == Box.class) {
- Particle p = (Particle) o2;
- p.change();
- }
- // If object 2 is a Box, then object 1 must be a particle
- else if (o2.getClass() == Box.class) {
- Particle p = (Particle) o1;
- p.change();
- }
- }
-
- void endContact(Contact contact) {
- // TODO Auto-generated method stub
- }
-
- void preSolve(Contact contact, Manifold oldManifold) {
- // TODO Auto-generated method stub
- }
-
- void postSolve(Contact contact, ContactImpulse impulse) {
- // TODO Auto-generated method stub
- }
-}
-
-
-
-
diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/CollisionsAndControlInterface/Particle.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/CollisionsAndControlInterface/Particle.pde
deleted file mode 100644
index 50be57e86..000000000
--- a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/CollisionsAndControlInterface/Particle.pde
+++ /dev/null
@@ -1,91 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// A circular particle
-
-class Particle {
-
- // We need to keep track of a Body and a radius
- Body body;
- float r;
-
- color col;
-
-
- Particle(float x, float y, float r_) {
- r = r_;
- // This function puts the particle in the Box2d world
- makeBody(x, y, r);
- body.setUserData(this);
- col = color(175);
- }
-
- // This function removes the particle from the box2d world
- void killBody() {
- box2d.destroyBody(body);
- }
-
- // Change color when hit
- void change() {
- col = color(255, 0, 0);
- }
-
- // Is the particle ready for deletion?
- boolean done() {
- // Let's find the screen position of the particle
- Vec2 pos = box2d.getBodyPixelCoord(body);
- // Is it off the bottom of the screen?
- if (pos.y > height+r*2) {
- killBody();
- return true;
- }
- return false;
- }
-
-
- //
- void display() {
- // We look at each body and get its screen position
- Vec2 pos = box2d.getBodyPixelCoord(body);
- // Get its angle of rotation
- float a = body.getAngle();
- pushMatrix();
- translate(pos.x, pos.y);
- rotate(a);
- fill(col);
- stroke(0);
- strokeWeight(1);
- ellipse(0, 0, r*2, r*2);
- // Let's add a line so we can see the rotation
- line(0, 0, r, 0);
- popMatrix();
- }
-
- // Here's our function that adds the particle to the Box2D world
- void makeBody(float x, float y, float r) {
- // Define a body
- BodyDef bd = new BodyDef();
- // Set its position
- bd.position = box2d.coordPixelsToWorld(x, y);
- bd.type = BodyType.DYNAMIC;
- body = box2d.createBody(bd);
-
- // Make the body's shape a circle
- CircleShape cs = new CircleShape();
- cs.m_radius = box2d.scalarPixelsToWorld(r);
-
- FixtureDef fd = new FixtureDef();
- fd.shape = cs;
- // Parameters that affect physics
- fd.density = 1;
- fd.friction = 0.01;
- fd.restitution = 0.3;
-
- // Attach fixture to body
- body.createFixture(fd);
-
- body.setAngularVelocity(random(-10, 10));
- }
-}
-
diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/CollisionsAndControlInterface/Spring.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/CollisionsAndControlInterface/Spring.pde
deleted file mode 100644
index c16494932..000000000
--- a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/CollisionsAndControlInterface/Spring.pde
+++ /dev/null
@@ -1,81 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Class to describe the spring joint (displayed as a line)
-
-class Spring {
-
- // This is the box2d object we need to create
- MouseJoint mouseJoint;
-
- Spring() {
- // At first it doesn't exist
- mouseJoint = null;
- }
-
- // If it exists we set its target to the mouse location
- void update(float x, float y) {
- if (mouseJoint != null) {
- // Always convert to world coordinates!
- Vec2 mouseWorld = box2d.coordPixelsToWorld(x,y);
- mouseJoint.setTarget(mouseWorld);
- }
- }
-
- void display() {
- if (mouseJoint != null) {
- // We can get the two anchor points
- Vec2 v1 = null;
- mouseJoint.getAnchorA(v1);
- Vec2 v2 = null;
- mouseJoint.getAnchorB(v2);
- // Convert them to screen coordinates
- v1 = box2d.coordWorldToPixels(v1);
- v2 = box2d.coordWorldToPixels(v2);
- // And just draw a line
- stroke(0);
- strokeWeight(1);
- line(v1.x,v1.y,v2.x,v2.y);
- }
- }
-
-
- // This is the key function where
- // we attach the spring to an x,y location
- // and the Box object's location
- void bind(float x, float y, Box box) {
- // Define the joint
- MouseJointDef md = new MouseJointDef();
-
- // Body A is just a fake ground body for simplicity (there isn't anything at the mouse)
- md.bodyA = box2d.getGroundBody();
- // Body 2 is the box's boxy
- md.bodyB = box.body;
- // Get the mouse location in world coordinates
- Vec2 mp = box2d.coordPixelsToWorld(x,y);
- // And that's the target
- md.target.set(mp);
- // Some stuff about how strong and bouncy the spring should be
- md.maxForce = 1000.0f * box.body.m_mass;
- md.frequencyHz = 5.0f;
- md.dampingRatio = 0.9f;
-
- // Wake up body!
- //box.body.wakeUp();
-
- // Make the joint!
- mouseJoint = (MouseJoint) box2d.world.createJoint(md);
- }
-
- void destroy() {
- // We can get rid of the joint when the mouse is released
- if (mouseJoint != null) {
- box2d.world.destroyJoint(mouseJoint);
- mouseJoint = null;
- }
- }
-
-}
-
-
diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Exercise_5_10_ApplyForceAttractMouse/Boundary.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Exercise_5_10_ApplyForceAttractMouse/Boundary.pde
deleted file mode 100644
index 9a17026a1..000000000
--- a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Exercise_5_10_ApplyForceAttractMouse/Boundary.pde
+++ /dev/null
@@ -1,53 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// A fixed boundary class
-
-class Boundary {
-
- // A boundary is a simple rectangle with x,y,width,and height
- float x;
- float y;
- float w;
- float h;
-
- // But we also have to make a body for box2d to know about it
- Body b;
-
- Boundary(float x_,float y_, float w_, float h_) {
- x = x_;
- y = y_;
- w = w_;
- h = h_;
-
- // Define the polygon
- PolygonShape sd = new PolygonShape();
- // Figure out the box2d coordinates
- float box2dW = box2d.scalarPixelsToWorld(w/2);
- float box2dH = box2d.scalarPixelsToWorld(h/2);
- // We're just a box
- sd.setAsBox(box2dW, box2dH);
-
-
- // Create the body
- BodyDef bd = new BodyDef();
- bd.type = BodyType.STATIC;
- bd.position.set(box2d.coordPixelsToWorld(x,y));
- b = box2d.createBody(bd);
-
- // Attached the shape to the body using a Fixture
- b.createFixture(sd,1);
- }
-
- // Draw the boundary, if it were at an angle we'd have to do something fancier
- void display() {
- fill(0);
- stroke(0);
- rectMode(CENTER);
- rect(x,y,w,h);
- }
-
-}
-
-
diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Exercise_5_10_ApplyForceAttractMouse/Box.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Exercise_5_10_ApplyForceAttractMouse/Box.pde
deleted file mode 100644
index 7847ff65f..000000000
--- a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Exercise_5_10_ApplyForceAttractMouse/Box.pde
+++ /dev/null
@@ -1,96 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// A rectangular box
-class Box {
-
- // We need to keep track of a Body and a width and height
- Body body;
- float w;
- float h;
-
- // Constructor
- Box(float x, float y) {
- w = random(8,16);
- h = w;
- // Add the box to the box2d world
- makeBody(new Vec2(x,y),w,h);
- }
-
- // This function removes the particle from the box2d world
- void killBody() {
- box2d.destroyBody(body);
- }
-
- // Is the particle ready for deletion?
- boolean done() {
- // Let's find the screen position of the particle
- Vec2 pos = box2d.getBodyPixelCoord(body);
- // Is it off the bottom of the screen?
- if (pos.y > height+w*h) {
- killBody();
- return true;
- }
- return false;
- }
-
- void attract(float x,float y) {
- // From BoxWrap2D example
- Vec2 worldTarget = box2d.coordPixelsToWorld(x,y);
- Vec2 bodyVec = body.getWorldCenter();
- // First find the vector going from this body to the specified point
- worldTarget.subLocal(bodyVec);
- // Then, scale the vector to the specified force
- worldTarget.normalize();
- worldTarget.mulLocal((float) 50);
- // Now apply it to the body's center of mass.
- body.applyForce(worldTarget, bodyVec);
- }
-
-
- // Drawing the box
- void display() {
- // We look at each body and get its screen position
- Vec2 pos = box2d.getBodyPixelCoord(body);
- // Get its angle of rotation
- float a = body.getAngle();
-
- rectMode(CENTER);
- pushMatrix();
- translate(pos.x,pos.y);
- rotate(-a);
- fill(175);
- stroke(0);
- rect(0,0,w,h);
- popMatrix();
- }
-
- // This function adds the rectangle to the box2d world
- void makeBody(Vec2 center, float w_, float h_) {
-
- // Define a polygon (this is what we use for a rectangle)
- PolygonShape sd = new PolygonShape();
- float box2dW = box2d.scalarPixelsToWorld(w_/2);
- float box2dH = box2d.scalarPixelsToWorld(h_/2);
- sd.setAsBox(box2dW, box2dH);
-
- // Define a fixture
- FixtureDef fd = new FixtureDef();
- fd.shape = sd;
- // Parameters that affect physics
- fd.density = 1;
- fd.friction = 0.3;
- fd.restitution = 0.5;
-
- // Define the body and make it from the shape
- BodyDef bd = new BodyDef();
- bd.type = BodyType.DYNAMIC;
- bd.position.set(box2d.coordPixelsToWorld(center));
-
- body = box2d.createBody(bd);
- body.createFixture(fd);
- }
-}
-
-
diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Exercise_5_10_ApplyForceAttractMouse/Exercise_5_10_ApplyForceAttractMouse.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Exercise_5_10_ApplyForceAttractMouse/Exercise_5_10_ApplyForceAttractMouse.pde
deleted file mode 100644
index 63bf2617b..000000000
--- a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Exercise_5_10_ApplyForceAttractMouse/Exercise_5_10_ApplyForceAttractMouse.pde
+++ /dev/null
@@ -1,82 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Basic example of falling rectangles
-
-import pbox2d.*;
-import org.jbox2d.collision.shapes.*;
-import org.jbox2d.common.*;
-import org.jbox2d.dynamics.*;
-
-// A reference to our box2d world
-PBox2D box2d;
-
-// A list we'll use to track fixed objects
-ArrayList boundaries;
-// A list for all of our rectangles
-ArrayList boxes;
-
-void setup() {
- size(640,360);
- // Initialize box2d physics and create the world
- box2d = new PBox2D(this);
- box2d.createWorld();
- // We are setting a custom gravity
- box2d.setGravity(0, -20);
-
- // Create ArrayLists
- boxes = new ArrayList();
- boundaries = new ArrayList();
-
- // Add a bunch of fixed boundaries
- boundaries.add(new Boundary(width/4,height-5,width/2-50,10));
- boundaries.add(new Boundary(3*width/4,height-5,width/2-50,10));
- boundaries.add(new Boundary(width-5,height/2,10,height));
- boundaries.add(new Boundary(5,height/2,10,height));
-}
-
-void draw() {
- background(255);
-
- // We must always step through time!
- box2d.step();
-
- // When the mouse is clicked, add a new Box object
- if (random(1) < 0.1) {
- Box p = new Box(random(width),10);
- boxes.add(p);
- }
-
- if (mousePressed) {
- for (Box b: boxes) {
- b.attract(mouseX,mouseY);
- }
- }
-
- // Display all the boundaries
- for (Boundary wall: boundaries) {
- wall.display();
- }
-
- // Display all the boxes
- for (Box b: boxes) {
- b.display();
- }
-
- // Boxes that leave the screen, we delete them
- // (note they have to be deleted from both the box2d world and our list
- for (int i = boxes.size()-1; i >= 0; i--) {
- Box b = boxes.get(i);
- if (b.done()) {
- boxes.remove(i);
- }
- }
-
- fill(0);
- text("Click mouse to attract boxes",20,20);
-}
-
-
-
-
diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Exercise_5_10_ApplyForceSimpleWind/Boundary.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Exercise_5_10_ApplyForceSimpleWind/Boundary.pde
deleted file mode 100644
index 9a17026a1..000000000
--- a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Exercise_5_10_ApplyForceSimpleWind/Boundary.pde
+++ /dev/null
@@ -1,53 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// A fixed boundary class
-
-class Boundary {
-
- // A boundary is a simple rectangle with x,y,width,and height
- float x;
- float y;
- float w;
- float h;
-
- // But we also have to make a body for box2d to know about it
- Body b;
-
- Boundary(float x_,float y_, float w_, float h_) {
- x = x_;
- y = y_;
- w = w_;
- h = h_;
-
- // Define the polygon
- PolygonShape sd = new PolygonShape();
- // Figure out the box2d coordinates
- float box2dW = box2d.scalarPixelsToWorld(w/2);
- float box2dH = box2d.scalarPixelsToWorld(h/2);
- // We're just a box
- sd.setAsBox(box2dW, box2dH);
-
-
- // Create the body
- BodyDef bd = new BodyDef();
- bd.type = BodyType.STATIC;
- bd.position.set(box2d.coordPixelsToWorld(x,y));
- b = box2d.createBody(bd);
-
- // Attached the shape to the body using a Fixture
- b.createFixture(sd,1);
- }
-
- // Draw the boundary, if it were at an angle we'd have to do something fancier
- void display() {
- fill(0);
- stroke(0);
- rectMode(CENTER);
- rect(x,y,w,h);
- }
-
-}
-
-
diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Exercise_5_10_ApplyForceSimpleWind/Box.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Exercise_5_10_ApplyForceSimpleWind/Box.pde
deleted file mode 100644
index 92c4f0280..000000000
--- a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Exercise_5_10_ApplyForceSimpleWind/Box.pde
+++ /dev/null
@@ -1,87 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// A rectangular box
-class Box {
-
- // We need to keep track of a Body and a width and height
- Body body;
- float w;
- float h;
-
- // Constructor
- Box(float x, float y) {
- w = random(8, 16);
- h = w;
- // Add the box to the box2d world
- makeBody(new Vec2(x, y), w, h);
- }
-
- // This function removes the particle from the box2d world
- void killBody() {
- box2d.destroyBody(body);
- }
-
- // Is the particle ready for deletion?
- boolean done() {
- // Let's find the screen position of the particle
- Vec2 pos = box2d.getBodyPixelCoord(body);
- // Is it off the bottom of the screen?
- if (pos.y > height+w*h) {
- killBody();
- return true;
- }
- return false;
- }
-
- void applyForce(Vec2 force) {
- Vec2 pos = body.getWorldCenter();
- body.applyForce(force, pos);
- }
-
- // Drawing the box
- void display() {
- // We look at each body and get its screen position
- Vec2 pos = box2d.getBodyPixelCoord(body);
- // Get its angle of rotation
- float a = body.getAngle();
-
- rectMode(CENTER);
- pushMatrix();
- translate(pos.x, pos.y);
- rotate(-a);
- fill(175);
- stroke(0);
- rect(0, 0, w, h);
- popMatrix();
- }
-
- // This function adds the rectangle to the box2d world
- void makeBody(Vec2 center, float w_, float h_) {
-
- // Define a polygon (this is what we use for a rectangle)
- PolygonShape sd = new PolygonShape();
- float box2dW = box2d.scalarPixelsToWorld(w_/2);
- float box2dH = box2d.scalarPixelsToWorld(h_/2);
- sd.setAsBox(box2dW, box2dH);
-
- // Define a fixture
- FixtureDef fd = new FixtureDef();
- fd.shape = sd;
- // Parameters that affect physics
- fd.density = 1;
- fd.friction = 0.3;
- fd.restitution = 0.2;
-
- // Define the body and make it from the shape
- BodyDef bd = new BodyDef();
- bd.type = BodyType.DYNAMIC;
- bd.position.set(box2d.coordPixelsToWorld(center));
- bd.angle = random(TWO_PI);
-
- body = box2d.createBody(bd);
- body.createFixture(fd);
- }
-}
-
diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Exercise_5_10_ApplyForceSimpleWind/Exercise_5_10_ApplyForceSimpleWind.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Exercise_5_10_ApplyForceSimpleWind/Exercise_5_10_ApplyForceSimpleWind.pde
deleted file mode 100644
index fa0b3f89c..000000000
--- a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Exercise_5_10_ApplyForceSimpleWind/Exercise_5_10_ApplyForceSimpleWind.pde
+++ /dev/null
@@ -1,83 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Basic example of falling rectangles
-
-import pbox2d.*;
-import org.jbox2d.collision.shapes.*;
-import org.jbox2d.common.*;
-import org.jbox2d.dynamics.*;
-
-// A reference to our box2d world
-PBox2D box2d;
-
-// A list we'll use to track fixed objects
-ArrayList boundaries;
-// A list for all of our rectangles
-ArrayList boxes;
-
-void setup() {
- size(640,360);
- // Initialize box2d physics and create the world
- box2d = new PBox2D(this);
- box2d.createWorld();
- // We are setting a custom gravity
- box2d.setGravity(0, -20);
-
- // Create ArrayLists
- boxes = new ArrayList();
- boundaries = new ArrayList();
-
- // Add a bunch of fixed boundaries
- boundaries.add(new Boundary(width/4,height-5,width/2-100,10));
- boundaries.add(new Boundary(3*width/4,height-5,width/2-100,10));
- boundaries.add(new Boundary(width-5,height/2,10,height));
- boundaries.add(new Boundary(5,height/2,10,height));
-}
-
-void draw() {
- background(255);
-
- // We must always step through time!
- box2d.step();
-
- // When the mouse is clicked, add a new Box object
- if (random(1) < 0.1) {
- Box p = new Box(random(width),10);
- boxes.add(p);
- }
-
- if (mousePressed) {
- for (Box b: boxes) {
- Vec2 wind = new Vec2(20,0);
- b.applyForce(wind);
- }
- }
-
- // Display all the boundaries
- for (Boundary wall: boundaries) {
- wall.display();
- }
-
- // Display all the boxes
- for (Box b: boxes) {
- b.display();
- }
-
- // Boxes that leave the screen, we delete them
- // (note they have to be deleted from both the box2d world and our list
- for (int i = boxes.size()-1; i >= 0; i--) {
- Box b = boxes.get(i);
- if (b.done()) {
- boxes.remove(i);
- }
- }
-
- fill(0);
- text("Click mouse to apply a wind force.",20,20);
-}
-
-
-
-
diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Exercise_5_10_AttractionApplyForce/Attractor.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Exercise_5_10_AttractionApplyForce/Attractor.pde
deleted file mode 100644
index 2a9bd9e38..000000000
--- a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Exercise_5_10_AttractionApplyForce/Attractor.pde
+++ /dev/null
@@ -1,69 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Showing how to use applyForce() with box2d
-
-// Fixed Attractor (this is redundant with Mover)
-
-class Attractor {
-
- // We need to keep track of a Body and a radius
- Body body;
- float r;
-
- Attractor(float r_, float x, float y) {
- r = r_;
- // Define a body
- BodyDef bd = new BodyDef();
- bd.type = BodyType.STATIC;
- // Set its position
- bd.position = box2d.coordPixelsToWorld(x,y);
- body = box2d.world.createBody(bd);
-
- // Make the body's shape a circle
- CircleShape cs = new CircleShape();
- cs.m_radius = box2d.scalarPixelsToWorld(r);
-
- body.createFixture(cs,1);
-
- }
-
-
- // Formula for gravitational attraction
- // We are computing this in "world" coordinates
- // No need to convert to pixels and back
- Vec2 attract(Mover m) {
- float G = 100; // Strength of force
- // clone() makes us a copy
- Vec2 pos = body.getWorldCenter();
- Vec2 moverPos = m.body.getWorldCenter();
- // Vector pointing from mover to attractor
- Vec2 force = pos.sub(moverPos);
- float distance = force.length();
- // Keep force within bounds
- distance = constrain(distance,1,5);
- force.normalize();
- // Note the attractor's mass is 0 because it's fixed so can't use that
- float strength = (G * 1 * m.body.m_mass) / (distance * distance); // Calculate gravitional force magnitude
- force.mulLocal(strength); // Get force vector --> magnitude * direction
- return force;
- }
-
- void display() {
- // We look at each body and get its screen position
- Vec2 pos = box2d.getBodyPixelCoord(body);
- // Get its angle of rotation
- float a = body.getAngle();
- pushMatrix();
- translate(pos.x,pos.y);
- rotate(a);
- fill(175);
- stroke(0);
- strokeWeight(2);
- ellipse(0,0,r*2,r*2);
- popMatrix();
- }
-}
-
-
diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Exercise_5_10_AttractionApplyForce/Exercise_5_10_AttractionApplyForce.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Exercise_5_10_AttractionApplyForce/Exercise_5_10_AttractionApplyForce.pde
deleted file mode 100644
index c85c91956..000000000
--- a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Exercise_5_10_AttractionApplyForce/Exercise_5_10_AttractionApplyForce.pde
+++ /dev/null
@@ -1,57 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Showing how to use applyForce() with box2d
-
-import pbox2d.*;
-import org.jbox2d.collision.shapes.*;
-import org.jbox2d.common.*;
-import org.jbox2d.dynamics.*;
-
-// A reference to our box2d world
-PBox2D box2d;
-
-// Movers, jsut like before!
-Mover[] movers = new Mover[25];
-
-// Attractor, just like before!
-Attractor a;
-
-void setup() {
- size(800,200);
- box2d = new PBox2D(this);
- box2d.createWorld();
- // No global gravity force
- box2d.setGravity(0,0);
-
- for (int i = 0; i < movers.length; i++) {
- movers[i] = new Mover(random(8,16),random(width),random(height));
- }
- a = new Attractor(32,width/2,height/2);
-}
-
-void draw() {
- background(255);
-
- // We must always step through time!
- box2d.step();
-
- a.display();
-
- for (int i = 0; i < movers.length; i++) {
- // Look, this is just like what we had before!
- Vec2 force = a.attract(movers[i]);
- movers[i].applyForce(force);
- movers[i].display();
- }
-}
-
-
-
-
-
-
-
-
-
diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Exercise_5_10_AttractionApplyForce/Mover.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Exercise_5_10_AttractionApplyForce/Mover.pde
deleted file mode 100644
index df8cafcc5..000000000
--- a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Exercise_5_10_AttractionApplyForce/Mover.pde
+++ /dev/null
@@ -1,63 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Showing how to use applyForce() with box2d
-
-class Mover {
-
- // We need to keep track of a Body and a radius
- Body body;
- float r;
-
- Mover(float r_, float x, float y) {
- r = r_;
- // Define a body
- BodyDef bd = new BodyDef();
- bd.type = BodyType.DYNAMIC;
-
- // Set its position
- bd.position = box2d.coordPixelsToWorld(x,y);
- body = box2d.world.createBody(bd);
-
- // Make the body's shape a circle
- CircleShape cs = new CircleShape();
- cs.m_radius = box2d.scalarPixelsToWorld(r);
-
- // Define a fixture
- FixtureDef fd = new FixtureDef();
- fd.shape = cs;
- // Parameters that affect physics
- fd.density = 1;
- fd.friction = 0.3;
- fd.restitution = 0.5;
-
- body.createFixture(fd);
-
- body.setLinearVelocity(new Vec2(random(-5,5),random(-5,-5)));
- body.setAngularVelocity(random(-1,1));
- }
-
- void applyForce(Vec2 v) {
- body.applyForce(v, body.getWorldCenter());
- }
-
-
- void display() {
- // We look at each body and get its screen position
- Vec2 pos = box2d.getBodyPixelCoord(body);
- // Get its angle of rotation
- float a = body.getAngle();
- pushMatrix();
- translate(pos.x,pos.y);
- rotate(a);
- fill(127);
- stroke(0);
- strokeWeight(2);
- ellipse(0,0,r*2,r*2);
- // Let's add a line so we can see the rotation
- line(0,0,r,0);
- popMatrix();
- }
-}
-
diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Exercise_5_3_NoiseChain/Exercise_5_3_NoiseChain.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Exercise_5_3_NoiseChain/Exercise_5_3_NoiseChain.pde
deleted file mode 100644
index d4f75ecd5..000000000
--- a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Exercise_5_3_NoiseChain/Exercise_5_3_NoiseChain.pde
+++ /dev/null
@@ -1,69 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// An uneven surface
-
-import pbox2d.*;
-import org.jbox2d.collision.shapes.*;
-import org.jbox2d.common.*;
-import org.jbox2d.dynamics.*;
-import org.jbox2d.dynamics.*;
-
-// A reference to our box2d world
-PBox2D box2d;
-
-// An ArrayList of particles that will fall on the surface
-ArrayList particles;
-
-// An object to store information about the uneven surface
-Surface surface;
-
-void setup() {
- size(383,200);
- // Initialize box2d physics and create the world
- box2d = new PBox2D(this);
- box2d.createWorld();
- // We are setting a custom gravity
- box2d.setGravity(0, -20);
-
- // Create the empty list
- particles = new ArrayList();
- // Create the surface
- surface = new Surface();
-}
-
-void draw() {
- // If the mouse is pressed, we make new particles
- if (mousePressed) {
- float sz = random(2,6);
- particles.add(new Particle(mouseX,mouseY,sz));
- }
-
- // We must always step through time!
- box2d.step();
-
- background(255);
-
- // Draw the surface
- surface.display();
-
- // Draw all particles
- for (Particle p: particles) {
- p.display();
- }
-
- // Particles that leave the screen, we delete them
- // (note they have to be deleted from both the box2d world and our list
- for (int i = particles.size()-1; i >= 0; i--) {
- Particle p = particles.get(i);
- if (p.done()) {
- particles.remove(i);
- }
- }
-}
-
-
-
-
-
diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Exercise_5_3_NoiseChain/Particle.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Exercise_5_3_NoiseChain/Particle.pde
deleted file mode 100644
index 05783d49e..000000000
--- a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Exercise_5_3_NoiseChain/Particle.pde
+++ /dev/null
@@ -1,89 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// A circular particle
-
-class Particle {
-
- // We need to keep track of a Body and a radius
- Body body;
- float r;
-
- Particle(float x, float y, float r_) {
- r = r_;
- // This function puts the particle in the Box2d world
- makeBody(x,y,r);
- }
-
- // This function removes the particle from the box2d world
- void killBody() {
- box2d.destroyBody(body);
- }
-
- // Is the particle ready for deletion?
- boolean done() {
- // Let's find the screen position of the particle
- Vec2 pos = box2d.getBodyPixelCoord(body);
- // Is it off the bottom of the screen?
- if (pos.y > height+r*2) {
- killBody();
- return true;
- }
- return false;
- }
-
- //
- void display() {
- // We look at each body and get its screen position
- Vec2 pos = box2d.getBodyPixelCoord(body);
- // Get its angle of rotation
- float a = body.getAngle();
- pushMatrix();
- translate(pos.x,pos.y);
- rotate(-a);
- fill(175);
- stroke(0);
- strokeWeight(1);
- ellipse(0,0,r*2,r*2);
- // Let's add a line so we can see the rotation
- line(0,0,r,0);
- popMatrix();
- }
-
- // Here's our function that adds the particle to the Box2D world
- void makeBody(float x, float y, float r) {
- // Define a body
- BodyDef bd = new BodyDef();
- // Set its position
- bd.position = box2d.coordPixelsToWorld(x,y);
- bd.type = BodyType.DYNAMIC;
- body = box2d.world.createBody(bd);
-
- // Make the body's shape a circle
- CircleShape cs = new CircleShape();
- cs.m_radius = box2d.scalarPixelsToWorld(r);
-
- FixtureDef fd = new FixtureDef();
- fd.shape = cs;
- // Parameters that affect physics
- fd.density = 1;
- fd.friction = 0.01;
- fd.restitution = 0.3;
-
- // Attach fixture to body
- body.createFixture(fd);
-
- // Give it a random initial velocity (and angular velocity)
- body.setLinearVelocity(new Vec2(random(-10f,10f),random(5f,10f)));
- body.setAngularVelocity(random(-10,10));
- }
-
-
-
-
-
-
-}
-
-
diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Exercise_5_3_NoiseChain/Surface.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Exercise_5_3_NoiseChain/Surface.pde
deleted file mode 100644
index 211874b0d..000000000
--- a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Exercise_5_3_NoiseChain/Surface.pde
+++ /dev/null
@@ -1,78 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// An uneven surface boundary
-
-class Surface {
- // We'll keep track of all of the surface points
- ArrayList surface;
-
-
- Surface() {
- surface = new ArrayList();
-
- // This is what box2d uses to put the surface in its world
- ChainShape chain = new ChainShape();
-
- // Perlin noise argument
- float xoff = 0.0;
-
- // This has to go backwards so that the objects bounce off the top of the surface
- // This "edgechain" will only work in one direction!
- for (float x = width+10; x > -10; x -= 5) {
-
- // Doing some stuff with perlin noise to calculate a surface that points down on one side
- // and up on the other
- float y;
- if (x > width/2) {
- y = 50 + (width - x)*1.1 + map(noise(xoff),0,1,-80,80);
- }
- else {
- y = 50 + x*1.1 + map(noise(xoff),0,1,-40,40);
- }
-
- // Store the vertex in screen coordinates
- surface.add(new Vec2(x,y));
-
- // Move through perlin noise
- xoff += 0.1;
-
- }
-
- // Build an array of vertices in Box2D coordinates
- // from the ArrayList we made
- Vec2[] vertices = new Vec2[surface.size()];
- for (int i = 0; i < vertices.length; i++) {
- Vec2 edge = box2d.coordPixelsToWorld(surface.get(i));
- vertices[i] = edge;
- }
-
- // Create the chain!
- chain.createChain(vertices,vertices.length);
-
- // The edge chain is now attached to a body via a fixture
- BodyDef bd = new BodyDef();
- bd.position.set(0.0f,0.0f);
- Body body = box2d.createBody(bd);
- // Shortcut, we could define a fixture if we
- // want to specify frictions, restitution, etc.
- body.createFixture(chain,1);
-
- }
-
- // A simple function to just draw the edge chain as a series of vertex points
- void display() {
- strokeWeight(2);
- stroke(0);
- noFill();
- beginShape();
- for (Vec2 v: surface) {
- vertex(v.x,v.y);
- }
- endShape();
- }
-
-}
-
-
diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Exercise_5_3_SineChain/Exercise_5_3_SineChain.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Exercise_5_3_SineChain/Exercise_5_3_SineChain.pde
deleted file mode 100644
index b313ef3ce..000000000
--- a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Exercise_5_3_SineChain/Exercise_5_3_SineChain.pde
+++ /dev/null
@@ -1,69 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// An uneven surface
-
-import pbox2d.*;
-import org.jbox2d.collision.shapes.*;
-import org.jbox2d.common.*;
-import org.jbox2d.dynamics.*;
-import org.jbox2d.dynamics.*;
-
-// A reference to our box2d world
-PBox2D box2d;
-
-// An ArrayList of particles that will fall on the surface
-ArrayList particles;
-
-// An object to store information about the uneven surface
-Surface surface;
-
-void setup() {
- size(383,200);
- // Initialize box2d physics and create the world
- box2d = new PBox2D(this);
- box2d.createWorld();
- // We are setting a custom gravity
- box2d.setGravity(0, -10);
-
- // Create the empty list
- particles = new ArrayList();
- // Create the surface
- surface = new Surface();
-}
-
-void draw() {
- // If the mouse is pressed, we make new particles
- if (random(1) < 0.5) {
- float sz = random(2,6);
- particles.add(new Particle(width/2,10,sz));
- }
-
- // We must always step through time!
- box2d.step();
-
- background(255);
-
- // Draw the surface
- surface.display();
-
- // Draw all particles
- for (Particle p: particles) {
- p.display();
- }
-
- // Particles that leave the screen, we delete them
- // (note they have to be deleted from both the box2d world and our list
- for (int i = particles.size()-1; i >= 0; i--) {
- Particle p = particles.get(i);
- if (p.done()) {
- particles.remove(i);
- }
- }
-}
-
-
-
-
-
diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Exercise_5_3_SineChain/Particle.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Exercise_5_3_SineChain/Particle.pde
deleted file mode 100644
index 05783d49e..000000000
--- a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Exercise_5_3_SineChain/Particle.pde
+++ /dev/null
@@ -1,89 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// A circular particle
-
-class Particle {
-
- // We need to keep track of a Body and a radius
- Body body;
- float r;
-
- Particle(float x, float y, float r_) {
- r = r_;
- // This function puts the particle in the Box2d world
- makeBody(x,y,r);
- }
-
- // This function removes the particle from the box2d world
- void killBody() {
- box2d.destroyBody(body);
- }
-
- // Is the particle ready for deletion?
- boolean done() {
- // Let's find the screen position of the particle
- Vec2 pos = box2d.getBodyPixelCoord(body);
- // Is it off the bottom of the screen?
- if (pos.y > height+r*2) {
- killBody();
- return true;
- }
- return false;
- }
-
- //
- void display() {
- // We look at each body and get its screen position
- Vec2 pos = box2d.getBodyPixelCoord(body);
- // Get its angle of rotation
- float a = body.getAngle();
- pushMatrix();
- translate(pos.x,pos.y);
- rotate(-a);
- fill(175);
- stroke(0);
- strokeWeight(1);
- ellipse(0,0,r*2,r*2);
- // Let's add a line so we can see the rotation
- line(0,0,r,0);
- popMatrix();
- }
-
- // Here's our function that adds the particle to the Box2D world
- void makeBody(float x, float y, float r) {
- // Define a body
- BodyDef bd = new BodyDef();
- // Set its position
- bd.position = box2d.coordPixelsToWorld(x,y);
- bd.type = BodyType.DYNAMIC;
- body = box2d.world.createBody(bd);
-
- // Make the body's shape a circle
- CircleShape cs = new CircleShape();
- cs.m_radius = box2d.scalarPixelsToWorld(r);
-
- FixtureDef fd = new FixtureDef();
- fd.shape = cs;
- // Parameters that affect physics
- fd.density = 1;
- fd.friction = 0.01;
- fd.restitution = 0.3;
-
- // Attach fixture to body
- body.createFixture(fd);
-
- // Give it a random initial velocity (and angular velocity)
- body.setLinearVelocity(new Vec2(random(-10f,10f),random(5f,10f)));
- body.setAngularVelocity(random(-10,10));
- }
-
-
-
-
-
-
-}
-
-
diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Exercise_5_3_SineChain/Surface.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Exercise_5_3_SineChain/Surface.pde
deleted file mode 100644
index 3be00b5a9..000000000
--- a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Exercise_5_3_SineChain/Surface.pde
+++ /dev/null
@@ -1,69 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// An uneven surface boundary
-
-class Surface {
- // We'll keep track of all of the surface points
- ArrayList surface;
-
-
- Surface() {
- surface = new ArrayList();
-
- // This is what box2d uses to put the surface in its world
- ChainShape chain = new ChainShape();
-
- float theta = 0;
-
- // This has to go backwards so that the objects bounce off the top of the surface
- // This "edgechain" will only work in one direction!
- for (float x = width+10; x > -10; x -= 5) {
-
- // Doing some stuff with perlin noise to calculate a surface that points down on one side
- // and up on the other
- float y = map(cos(theta),-1,1,75,height-10);
- theta += 0.15;
-
- // Store the vertex in screen coordinates
- surface.add(new Vec2(x,y));
-
- }
-
- // Build an array of vertices in Box2D coordinates
- // from the ArrayList we made
- Vec2[] vertices = new Vec2[surface.size()];
- for (int i = 0; i < vertices.length; i++) {
- Vec2 edge = box2d.coordPixelsToWorld(surface.get(i));
- vertices[i] = edge;
- }
-
- // Create the chain!
- chain.createChain(vertices,vertices.length);
-
- // The edge chain is now attached to a body via a fixture
- BodyDef bd = new BodyDef();
- bd.position.set(0.0f,0.0f);
- Body body = box2d.createBody(bd);
- // Shortcut, we could define a fixture if we
- // want to specify frictions, restitution, etc.
- body.createFixture(chain,1);
-
- }
-
- // A simple function to just draw the edge chain as a series of vertex points
- void display() {
- strokeWeight(2);
- stroke(0);
- noFill();
- beginShape();
- for (Vec2 v: surface) {
- vertex(v.x,v.y);
- }
- endShape();
- }
-
-}
-
-
diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Exercise_5_6_Bridge/Box.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Exercise_5_6_Bridge/Box.pde
deleted file mode 100644
index f872679b9..000000000
--- a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Exercise_5_6_Bridge/Box.pde
+++ /dev/null
@@ -1,88 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// A rectangular box
-class Box {
-
- // We need to keep track of a Body and a width and height
- Body body;
- float w;
- float h;
-
- // Constructor
- Box(float x, float y) {
- w = random(4, 16);
- h = random(4, 16);
- // Add the box to the box2d world
- makeBody(new Vec2(x, y), w, h);
- }
-
- // This function removes the particle from the box2d world
- void killBody() {
- box2d.destroyBody(body);
- }
-
- // Is the particle ready for deletion?
- boolean done() {
- // Let's find the screen position of the particle
- Vec2 pos = box2d.getBodyPixelCoord(body);
- // Is it off the bottom of the screen?
- if (pos.y > height+w*h) {
- killBody();
- return true;
- }
- return false;
- }
-
- // Drawing the box
- void display() {
- // We look at each body and get its screen position
- Vec2 pos = box2d.getBodyPixelCoord(body);
- // Get its angle of rotation
- float a = body.getAngle();
-
- rectMode(CENTER);
- pushMatrix();
- translate(pos.x, pos.y);
- rotate(-a);
- stroke(0);
- fill(127);
- strokeWeight(2);
- rect(0, 0, w, h);
- popMatrix();
- }
-
- // This function adds the rectangle to the box2d world
- void makeBody(Vec2 center, float w_, float h_) {
-
- // Define a polygon (this is what we use for a rectangle)
- PolygonShape sd = new PolygonShape();
- float box2dW = box2d.scalarPixelsToWorld(w_/2);
- float box2dH = box2d.scalarPixelsToWorld(h_/2);
- sd.setAsBox(box2dW, box2dH);
-
- // Define a fixture
- FixtureDef fd = new FixtureDef();
- fd.shape = sd;
- // Parameters that affect physics
- fd.density = 1;
- fd.friction = 0.3;
- fd.restitution = 0.5;
-
- // Define the body and make it from the shape
- BodyDef bd = new BodyDef();
- bd.type = BodyType.DYNAMIC;
- bd.position.set(box2d.coordPixelsToWorld(center));
-
- body = box2d.createBody(bd);
- body.createFixture(fd);
- //body.setMassFromShapes();
-
- // Give it some initial random velocity
- body.setLinearVelocity(new Vec2(random(-5, 5), random(2, 5)));
- body.setAngularVelocity(random(-5, 5));
- }
-}
-
-
diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Exercise_5_6_Bridge/Bridge.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Exercise_5_6_Bridge/Bridge.pde
deleted file mode 100644
index eafb42cdc..000000000
--- a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Exercise_5_6_Bridge/Bridge.pde
+++ /dev/null
@@ -1,66 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Series of Particles connected with distance joints
-
-class Bridge {
-
- // Bridge properties
- float totalLength; // How long
- int numPoints; // How many points
-
- // Our chain is a list of particles
- ArrayList particles;
-
- // Chain constructor
- Bridge(float l, int n) {
-
- totalLength = l;
- numPoints = n;
-
- particles = new ArrayList();
-
- float len = totalLength / numPoints;
-
- // Here is the real work, go through and add particles to the chain itself
- for(int i=0; i < numPoints+1; i++) {
- // Make a new particle
- Particle p = null;
-
- // First and last particles are made with density of zero
- if (i == 0 || i == numPoints) p = new Particle(i*len,height/4,4,true);
- else p = new Particle(i*len,height/4,4,false);
- particles.add(p);
-
- // Connect the particles with a distance joint
- if (i > 0) {
- DistanceJointDef djd = new DistanceJointDef();
- Particle previous = particles.get(i-1);
- // Connection between previous particle and this one
- djd.bodyA = previous.body;
- djd.bodyB = p.body;
- // Equilibrium length
- djd.length = box2d.scalarPixelsToWorld(len);
- // These properties affect how springy the joint is
- djd.frequencyHz = 0;
- djd.dampingRatio = 0;
-
- // Make the joint. Note we aren't storing a reference to the joint ourselves anywhere!
- // We might need to someday, but for now it's ok
- DistanceJoint dj = (DistanceJoint) box2d.world.createJoint(djd);
- }
- }
- }
-
- // Draw the bridge
- void display() {
- for (Particle p: particles) {
- p.display();
- }
- }
-
-}
-
-
-
diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Exercise_5_6_Bridge/Exercise_5_6_Bridge.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Exercise_5_6_Bridge/Exercise_5_6_Bridge.pde
deleted file mode 100644
index 2946efe93..000000000
--- a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Exercise_5_6_Bridge/Exercise_5_6_Bridge.pde
+++ /dev/null
@@ -1,82 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Example demonstrating distance joints
-// A bridge is formed by connected a series of particles with joints
-
-import pbox2d.*;
-import org.jbox2d.common.*;
-import org.jbox2d.dynamics.joints.*;
-import org.jbox2d.collision.shapes.*;
-import org.jbox2d.collision.shapes.Shape;
-import org.jbox2d.common.*;
-import org.jbox2d.dynamics.*;
-import org.jbox2d.dynamics.contacts.*;
-
-// A reference to our box2d world
-PBox2D box2d;
-
-// An object to describe a Bridget (a list of particles with joint connections)
-Bridge bridge;
-
-// A list for all of our rectangles
-ArrayList boxes;
-
-void setup() {
- size(800, 200);
- // Initialize box2d physics and create the world
- box2d = new PBox2D(this);
- box2d.createWorld();
-
-
- // Make the bridge
- bridge = new Bridge(width, width/10);
-
- // Create ArrayLists
- boxes = new ArrayList();
-}
-
-void draw() {
- background(255);
-
- // We must always step through time!
- box2d.step();
-
-
- // When the mouse is clicked, add a new Box object
- if (mousePressed) {
- Box p = new Box(mouseX, mouseY);
- boxes.add(p);
- }
-
- // Display all the boxes
- for (Box b: boxes) {
- b.display();
- }
-
- // Boxes that leave the screen, we delete them
- // (note they have to be deleted from both the box2d world and our list
- for (int i = boxes.size()-1; i >= 0; i--) {
- Box b = boxes.get(i);
- if (b.done()) {
- boxes.remove(i);
- }
- }
-
- // Draw the windmill
- bridge.display();
-
-
- fill(0);
- //text("Click mouse to add boxes.", 10, height-10);
-}
-
-
-
-
-
-
-
-
-
diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Exercise_5_6_Bridge/Particle.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Exercise_5_6_Bridge/Particle.pde
deleted file mode 100644
index c545127cc..000000000
--- a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Exercise_5_6_Bridge/Particle.pde
+++ /dev/null
@@ -1,78 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// A circular particle
-
-class Particle {
-
- // We need to keep track of a Body and a radius
- Body body;
- float r;
-
- Particle(float x, float y, float r_, boolean fixed) {
- r = r_;
-
- // Define a body
- BodyDef bd = new BodyDef();
- if (fixed) bd.type = BodyType.STATIC;
- else bd.type = BodyType.DYNAMIC;
-
- // Set its position
- bd.position = box2d.coordPixelsToWorld(x,y);
- body = box2d.world.createBody(bd);
-
- // Make the body's shape a circle
- // Make the body's shape a circle
- CircleShape cs = new CircleShape();
- cs.m_radius = box2d.scalarPixelsToWorld(r);
-
- FixtureDef fd = new FixtureDef();
- fd.shape = cs;
- // Parameters that affect physics
- fd.density = 1;
- fd.friction = 0.3;
- fd.restitution = 0.5;
-
- body.createFixture(fd);
- }
-
- // This function removes the particle from the box2d world
- void killBody() {
- box2d.destroyBody(body);
- }
-
- // Is the particle ready for deletion?
- boolean done() {
- // Let's find the screen position of the particle
- Vec2 pos = box2d.getBodyPixelCoord(body);
- // Is it off the bottom of the screen?
- if (pos.y > height+r*2) {
- killBody();
- return true;
- }
- return false;
- }
-
- //
- void display() {
- // We look at each body and get its screen position
- Vec2 pos = box2d.getBodyPixelCoord(body);
- // Get its angle of rotation
- float a = body.getAngle();
- pushMatrix();
- translate(pos.x,pos.y);
- rotate(a);
- stroke(0);
- fill(127);
- strokeWeight(2);
- ellipse(0,0,r*2,r*2);
- // Let's add a line so we can see the rotation
- line(0,0,r,0);
- popMatrix();
- }
-
-
-}
-
-
diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/KinematicTest/Box.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/KinematicTest/Box.pde
deleted file mode 100644
index c6a8aed73..000000000
--- a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/KinematicTest/Box.pde
+++ /dev/null
@@ -1,102 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// A rectangular box
-
-class Box {
-
- // We need to keep track of a Body and a width and height
- Body body;
- float w;
- float h;
-
- boolean dragged = false;
-
- // Constructor
- Box(float x_, float y_) {
- float x = x_;
- float y = y_;
- w = 24;
- h = 24;
- // Add the box to the box2d world
- makeBody(new Vec2(x,y),w,h);
- body.setUserData(this);
- }
-
- // This function removes the particle from the box2d world
- void killBody() {
- box2d.destroyBody(body);
- }
-
- boolean contains(float x, float y) {
- Vec2 worldPoint = box2d.coordPixelsToWorld(x, y);
- Fixture f = body.getFixtureList();
- boolean inside = f.testPoint(worldPoint);
- return inside;
- }
-
- void setAngularVelocity(float a) {
- body.setAngularVelocity(a);
- }
- void setVelocity(Vec2 v) {
- body.setLinearVelocity(v);
- }
-
- void setLocation(float x, float y) {
- Vec2 pos = body.getWorldCenter();
- Vec2 target = box2d.coordPixelsToWorld(x,y);
- Vec2 diff = new Vec2(target.x-pos.x,target.y-pos.y);
- diff.mulLocal(50);
- setVelocity(diff);
- setAngularVelocity(0);
- }
-
- // Drawing the box
- void display() {
- // We look at each body and get its screen position
- Vec2 pos = box2d.getBodyPixelCoord(body);
- // Get its angle of rotation
- float a = body.getAngle();
-
- rectMode(PConstants.CENTER);
- pushMatrix();
- translate(pos.x,pos.y);
- rotate(a);
- fill(175);
- stroke(0);
- rect(0,0,w,h);
- popMatrix();
- }
-
-
- // This function adds the rectangle to the box2d world
- void makeBody(Vec2 center, float w_, float h_) {
- // Define and create the body
- BodyDef bd = new BodyDef();
- bd.type = BodyType.KINEMATIC;
- bd.position.set(box2d.coordPixelsToWorld(center));
- bd.fixedRotation = true;
- body = box2d.createBody(bd);
-
- // Define a polygon (this is what we use for a rectangle)
- PolygonShape ps = new PolygonShape();
- float box2dW = box2d.scalarPixelsToWorld(w_/2);
- float box2dH = box2d.scalarPixelsToWorld(h_/2);
- ps.setAsBox(box2dW, box2dH);
-
- // Define a fixture
- FixtureDef fd = new FixtureDef();
- fd.shape = ps;
- // Parameters that affect physics
- fd.density = 1;
- fd.friction = 0.3;
- fd.restitution = 0.5;
-
- body.createFixture(fd);
- }
-
-}
-
-
-
diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/KinematicTest/KinematicTest.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/KinematicTest/KinematicTest.pde
deleted file mode 100644
index 758299639..000000000
--- a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/KinematicTest/KinematicTest.pde
+++ /dev/null
@@ -1,141 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Basic example of controlling an object with our own motion (by attaching a MouseJoint)
-// Also demonstrates how to know which object was hit
-
-import pbox2d.*;
-import org.jbox2d.common.*;
-import org.jbox2d.dynamics.joints.*;
-import org.jbox2d.collision.shapes.*;
-import org.jbox2d.collision.shapes.Shape;
-import org.jbox2d.common.*;
-import org.jbox2d.dynamics.*;
-import org.jbox2d.dynamics.contacts.*;
-
-// A reference to our box2d world
-PBox2D box2d;
-
-// Just a single box this time
-Box box;
-
-// An ArrayList of particles that will fall on the surface
-ArrayList particles;
-
-// Perlin noise values
-float xoff = 0;
-float yoff = 1000;
-
-
-void setup() {
- size(640,360);
- // Initialize box2d physics and create the world
- box2d = new PBox2D(this);
- box2d.createWorld();
-
- // Turn on collision listening!
- box2d.listenForCollisions();
-
- // Make the box
- box = new Box(width/2,height/2);
-
- // Create the empty list
- particles = new ArrayList();
-
-
-}
-
-void draw() {
- background(255);
-
- if (random(1) < 0.2) {
- float sz = random(4,8);
- particles.add(new Particle(width/2,-20,sz));
- }
-
-
- // We must always step through time!
- box2d.step();
-
- // Make an x,y coordinate out of perlin noise
- float x = noise(xoff)*width;
- float y = noise(yoff)*height;
- xoff += 0.01;
- yoff += 0.01;
-
- // This is tempting but will not work!
- // box.body.setXForm(box2d.screenToWorld(x,y),0);
-
- // Instead update the spring which pulls the mouse along
- if (mousePressed) {
- box.setLocation(mouseX,mouseY);
- } else {
- //box.setLocation(x,y);
- }
-
- // Look at all particles
- for (int i = particles.size()-1; i >= 0; i--) {
- Particle p = particles.get(i);
- p.display();
- // Particles that leave the screen, we delete them
- // (note they have to be deleted from both the box2d world and our list
- if (p.done()) {
- particles.remove(i);
- }
- }
-
- // Draw the box
- box.display();
-
- // Draw the spring
- // spring.display();
-}
-
-
-// Collision event functions!
-void beginContact(Contact cp) {
- // Get both fixtures
- Fixture f1 = cp.getFixtureA();
- Fixture f2 = cp.getFixtureB();
- // Get both bodies
- Body b1 = f1.getBody();
- Body b2 = f2.getBody();
- // Get our objects that reference these bodies
- Object o1 = b1.getUserData();
- Object o2 = b2.getUserData();
-
- // If object 1 is a Box, then object 2 must be a particle
- // Note we are ignoring particle on particle collisions
- if (o1.getClass() == Box.class) {
- Particle p = (Particle) o2;
- p.change();
- }
- // If object 2 is a Box, then object 1 must be a particle
- else if (o2.getClass() == Box.class) {
- Particle p = (Particle) o1;
- p.change();
- }
-}
-
-
-// Objects stop touching each other
-void endContact(Contact cp) {
-}
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/KinematicTest/Particle.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/KinematicTest/Particle.pde
deleted file mode 100644
index 12c50f772..000000000
--- a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/KinematicTest/Particle.pde
+++ /dev/null
@@ -1,93 +0,0 @@
-// The Nature of Code
-//
-// Spring 2010
-// PBox2D example
-
-// A circular particle
-
-class Particle {
-
- // We need to keep track of a Body and a radius
- Body body;
- float r;
-
- color col;
-
-
- Particle(float x, float y, float r_) {
- r = r_;
- // This function puts the particle in the Box2d world
- makeBody(x, y, r);
- body.setUserData(this);
- col = color(175);
- }
-
- // This function removes the particle from the box2d world
- void killBody() {
- box2d.destroyBody(body);
- }
-
- // Change color when hit
- void change() {
- col = color(255, 0, 0);
- }
-
- // Is the particle ready for deletion?
- boolean done() {
- // Let's find the screen position of the particle
- Vec2 pos = box2d.getBodyPixelCoord(body);
- // Is it off the bottom of the screen?
- if (pos.y > height+r*2) {
- killBody();
- return true;
- }
- return false;
- }
-
-
- //
- void display() {
- // We look at each body and get its screen position
- Vec2 pos = box2d.getBodyPixelCoord(body);
- // Get its angle of rotation
- float a = body.getAngle();
- pushMatrix();
- translate(pos.x, pos.y);
- rotate(a);
- fill(col);
- stroke(0);
- strokeWeight(1);
- ellipse(0, 0, r*2, r*2);
- // Let's add a line so we can see the rotation
- line(0, 0, r, 0);
- popMatrix();
- }
-
- // Here's our function that adds the particle to the Box2D world
- void makeBody(float x, float y, float r) {
- // Define a body
- BodyDef bd = new BodyDef();
- // Set its position
- bd.position = box2d.coordPixelsToWorld(x, y);
- bd.type = BodyType.DYNAMIC;
-
- body = box2d.createBody(bd);
-
- // Make the body's shape a circle
- CircleShape cs = new CircleShape();
- cs.m_radius = box2d.scalarPixelsToWorld(r);
-
- FixtureDef fd = new FixtureDef();
- fd.shape = cs;
- // Parameters that affect physics
- fd.density = 1;
- fd.friction = 0.01;
- fd.restitution = 0.3;
-
- // Attach fixture to body
- body.createFixture(fd);
-
- body.setAngularVelocity(random(-10, 10));
- }
-}
-
diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Liquidy/Boundary.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Liquidy/Boundary.pde
deleted file mode 100644
index 71c6a82d0..000000000
--- a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Liquidy/Boundary.pde
+++ /dev/null
@@ -1,61 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// A fixed boundary class (now incorporates angle)
-
-class Boundary {
-
- // A boundary is a simple rectangle with x,y,width,and height
- float x;
- float y;
- float w;
- float h;
- // But we also have to make a body for box2d to know about it
- Body b;
-
- Boundary(float x_,float y_, float w_, float h_, float a) {
- x = x_;
- y = y_;
- w = w_;
- h = h_;
-
- // Define the polygon
- PolygonShape sd = new PolygonShape();
- // Figure out the box2d coordinates
- float box2dW = box2d.scalarPixelsToWorld(w/2);
- float box2dH = box2d.scalarPixelsToWorld(h/2);
- // We're just a box
- sd.setAsBox(box2dW, box2dH);
-
-
- // Create the body
- BodyDef bd = new BodyDef();
- bd.type = BodyType.STATIC;
- bd.angle = a;
- bd.position.set(box2d.coordPixelsToWorld(x,y));
- b = box2d.createBody(bd);
-
- // Attached the shape to the body using a Fixture
- b.createFixture(sd,1);
- }
-
- // Draw the boundary, if it were at an angle we'd have to do something fancier
- void display() {
- noFill();
- stroke(0);
- strokeWeight(1);
- rectMode(CENTER);
-
- float a = b.getAngle();
-
- pushMatrix();
- translate(x,y);
- rotate(-a);
- rect(0,0,w,h);
- popMatrix();
- }
-
-}
-
-
diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Liquidy/Liquidy.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Liquidy/Liquidy.pde
deleted file mode 100644
index fa7ab19aa..000000000
--- a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Liquidy/Liquidy.pde
+++ /dev/null
@@ -1,71 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Box2D particle system example
-
-import pbox2d.*;
-import org.jbox2d.collision.shapes.*;
-import org.jbox2d.common.*;
-import org.jbox2d.dynamics.*;
-
-
-
-// A reference to our box2d world
-PBox2D box2d;
-
-// A list we'll use to track fixed objects
-ArrayList boundaries;
-
-// A list for all particle systems
-ArrayList systems;
-
-void setup() {
- size(400,300);
- // Initialize box2d physics and create the world
- box2d = new PBox2D(this);
- box2d.createWorld();
-
- // We are setting a custom gravity
- box2d.setGravity(0, -20);
-
- // Create ArrayLists
- systems = new ArrayList();
- boundaries = new ArrayList();
-
- // Add a bunch of fixed boundaries
- boundaries.add(new Boundary(50,100,300,5,-0.3));
- boundaries.add(new Boundary(250,175,300,5,0.5));
-
-}
-
-void draw() {
- background(255);
-
- // We must always step through time!
- box2d.step();
-
- // Run all the particle systems
- for (ParticleSystem system: systems) {
- system.run();
-
- int n = (int) random(0,2);
- system.addParticles(n);
- }
-
- // Display all the boundaries
- for (Boundary wall: boundaries) {
- wall.display();
- }
-}
-
-
-void mousePressed() {
- // Add a new Particle System whenever the mouse is clicked
- systems.add(new ParticleSystem(0, new PVector(mouseX,mouseY)));
-}
-
-
-
-
-
diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Liquidy/Particle.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Liquidy/Particle.pde
deleted file mode 100644
index dd1f4f564..000000000
--- a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Liquidy/Particle.pde
+++ /dev/null
@@ -1,98 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// A Particle
-
-class Particle {
-
- // We need to keep track of a Body
- Body body;
-
- PVector[] trail;
-
- // Constructor
- Particle(float x_, float y_) {
- float x = x_;
- float y = y_;
- trail = new PVector[6];
- for (int i = 0; i < trail.length; i++) {
- trail[i] = new PVector(x, y);
- }
-
- // Add the box to the box2d world
- // Here's a little trick, let's make a tiny tiny radius
- // This way we have collisions, but they don't overwhelm the system
- makeBody(new Vec2(x, y), 0.2f);
- }
-
- // This function removes the particle from the box2d world
- void killBody() {
- box2d.destroyBody(body);
- }
-
- // Is the particle ready for deletion?
- boolean done() {
- // Let's find the screen position of the particle
- Vec2 pos = box2d.getBodyPixelCoord(body);
- // Is it off the bottom of the screen?
- if (pos.y > height+20) {
- killBody();
- return true;
- }
- return false;
- }
-
- // Drawing the box
- void display() {
- // We look at each body and get its screen position
- Vec2 pos = box2d.getBodyPixelCoord(body);
-
- // Keep track of a history of screen positions in an array
- for (int i = 0; i < trail.length-1; i++) {
- trail[i] = trail[i+1];
- }
- trail[trail.length-1] = new PVector(pos.x, pos.y);
-
- // Draw particle as a trail
- beginShape();
- noFill();
- strokeWeight(2);
- stroke(0, 150);
- for (int i = 0; i < trail.length; i++) {
- vertex(trail[i].x, trail[i].y);
- }
- endShape();
- }
-
- // This function adds the rectangle to the box2d world
- void makeBody(Vec2 center, float r) {
- // Define and create the body
- BodyDef bd = new BodyDef();
- bd.type = BodyType.DYNAMIC;
-
- bd.position.set(box2d.coordPixelsToWorld(center));
- body = box2d.createBody(bd);
-
- // Give it some initial random velocity
- body.setLinearVelocity(new Vec2(random(-1, 1), random(-1, 1)));
-
- // Make the body's shape a circle
- CircleShape cs = new CircleShape();
- cs.m_radius = box2d.scalarPixelsToWorld(r);
-
- FixtureDef fd = new FixtureDef();
- fd.shape = cs;
-
- fd.density = 1;
- fd.friction = 0; // Slippery when wet!
- fd.restitution = 0.5;
-
- // We could use this if we want to turn collisions off
- //cd.filter.groupIndex = -10;
-
- // Attach fixture to body
- body.createFixture(fd);
- }
-}
-
diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Liquidy/ParticleSystem.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Liquidy/ParticleSystem.pde
deleted file mode 100644
index 08e74e0b4..000000000
--- a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/Liquidy/ParticleSystem.pde
+++ /dev/null
@@ -1,61 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Box2D Particle System
-
-// A class to describe a group of Particles
-// An ArrayList is used to manage the list of Particles
-
-class ParticleSystem {
-
- ArrayList particles; // An ArrayList for all the particles
- PVector origin; // An origin point for where particles are birthed
-
- ParticleSystem(int num, PVector v) {
- particles = new ArrayList(); // Initialize the ArrayList
- origin = v.get(); // Store the origin point
-
- for (int i = 0; i < num; i++) {
- particles.add(new Particle(origin.x,origin.y)); // Add "num" amount of particles to the ArrayList
- }
- }
-
- void run() {
- // Display all the particles
- for (Particle p: particles) {
- p.display();
- }
-
- // Particles that leave the screen, we delete them
- // (note they have to be deleted from both the box2d world and our list
- for (int i = particles.size()-1; i >= 0; i--) {
- Particle p = particles.get(i);
- if (p.done()) {
- particles.remove(i);
- }
- }
- }
-
- void addParticles(int n) {
- for (int i = 0; i < n; i++) {
- particles.add(new Particle(origin.x,origin.y));
- }
- }
-
- // A method to test if the particle system still has particles
- boolean dead() {
- if (particles.isEmpty()) {
- return true;
- }
- else {
- return false;
- }
- }
-
-}
-
-
-
-
-
diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/MouseKinematic/Boundary.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/MouseKinematic/Boundary.pde
deleted file mode 100644
index 71c6a82d0..000000000
--- a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/MouseKinematic/Boundary.pde
+++ /dev/null
@@ -1,61 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// A fixed boundary class (now incorporates angle)
-
-class Boundary {
-
- // A boundary is a simple rectangle with x,y,width,and height
- float x;
- float y;
- float w;
- float h;
- // But we also have to make a body for box2d to know about it
- Body b;
-
- Boundary(float x_,float y_, float w_, float h_, float a) {
- x = x_;
- y = y_;
- w = w_;
- h = h_;
-
- // Define the polygon
- PolygonShape sd = new PolygonShape();
- // Figure out the box2d coordinates
- float box2dW = box2d.scalarPixelsToWorld(w/2);
- float box2dH = box2d.scalarPixelsToWorld(h/2);
- // We're just a box
- sd.setAsBox(box2dW, box2dH);
-
-
- // Create the body
- BodyDef bd = new BodyDef();
- bd.type = BodyType.STATIC;
- bd.angle = a;
- bd.position.set(box2d.coordPixelsToWorld(x,y));
- b = box2d.createBody(bd);
-
- // Attached the shape to the body using a Fixture
- b.createFixture(sd,1);
- }
-
- // Draw the boundary, if it were at an angle we'd have to do something fancier
- void display() {
- noFill();
- stroke(0);
- strokeWeight(1);
- rectMode(CENTER);
-
- float a = b.getAngle();
-
- pushMatrix();
- translate(x,y);
- rotate(-a);
- rect(0,0,w,h);
- popMatrix();
- }
-
-}
-
-
diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/MouseKinematic/Box.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/MouseKinematic/Box.pde
deleted file mode 100644
index 806f51daa..000000000
--- a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/MouseKinematic/Box.pde
+++ /dev/null
@@ -1,105 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// A rectangular box
-
-class Box {
-
- // We need to keep track of a Body and a width and height
- Body body;
- float w;
- float h;
-
- boolean dragged = false;
-
- // Constructor
- Box(float x_, float y_) {
- float x = x_;
- float y = y_;
- w = 24;
- h = 24;
- // Add the box to the box2d world
- makeBody(new Vec2(x,y),w,h);
- }
-
- // This function removes the particle from the box2d world
- void killBody() {
- box2d.destroyBody(body);
- }
-
- boolean contains(float x, float y) {
- Vec2 worldPoint = box2d.coordPixelsToWorld(x, y);
- Fixture f = body.getFixtureList();
- boolean inside = f.testPoint(worldPoint);
- return inside;
- }
-
- void setAngularVelocity(float a) {
- body.setAngularVelocity(a);
- }
- void setVelocity(Vec2 v) {
- body.setLinearVelocity(v);
- }
-
- void setLocation(float x, float y) {
- Vec2 pos = body.getWorldCenter();
- Vec2 target = box2d.coordPixelsToWorld(x,y);
- Vec2 diff = target.sub(pos);
- diff.mulLocal(50);
- setVelocity(diff);
- setAngularVelocity(0);
- }
-
- // Drawing the box
- void display() {
- // We look at each body and get its screen position
- Vec2 pos = box2d.getBodyPixelCoord(body);
- // Get its angle of rotation
- float a = body.getAngle();
-
- rectMode(PConstants.CENTER);
- pushMatrix();
- translate(pos.x,pos.y);
- rotate(a);
- fill(175);
- stroke(0);
- rect(0,0,w,h);
- popMatrix();
- }
-
-
- // This function adds the rectangle to the box2d world
- void makeBody(Vec2 center, float w_, float h_) {
- // Define and create the body
- BodyDef bd = new BodyDef();
- bd.type = BodyType.KINEMATIC;
- bd.position.set(box2d.coordPixelsToWorld(center));
- body = box2d.createBody(bd);
-
- // Define a polygon (this is what we use for a rectangle)
- PolygonShape sd = new PolygonShape();
- float box2dW = box2d.scalarPixelsToWorld(w_/2);
- float box2dH = box2d.scalarPixelsToWorld(h_/2);
- sd.setAsBox(box2dW, box2dH);
-
- // Define a fixture
- FixtureDef fd = new FixtureDef();
- fd.shape = sd;
- // Parameters that affect physics
- fd.density = 1;
- fd.friction = 0.3;
- fd.restitution = 0.5;
-
- body.createFixture(fd);
- //body.setMassFromShapes();
-
- // Give it some initial random velocity
- body.setLinearVelocity(new Vec2(random(-5, 5), random(2, 5)));
- body.setAngularVelocity(random(-5, 5));
- }
-
-}
-
-
-
diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/MouseKinematic/MouseKinematic.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/MouseKinematic/MouseKinematic.pde
deleted file mode 100644
index a2e2bdba3..000000000
--- a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/MouseKinematic/MouseKinematic.pde
+++ /dev/null
@@ -1,75 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Basic example of controlling an object with the mouse (by attaching a spring)
-
-import pbox2d.*;
-import org.jbox2d.common.*;
-import org.jbox2d.dynamics.joints.*;
-import org.jbox2d.collision.shapes.*;
-import org.jbox2d.collision.shapes.Shape;
-import org.jbox2d.common.*;
-import org.jbox2d.dynamics.*;
-
-// A reference to our box2d world
-PBox2D box2d;
-
-// A list we'll use to track fixed objects
-ArrayList boundaries;
-
-// Just a single box this time
-Box box;
-
-void setup() {
- size(640,360);
- // Initialize box2d physics and create the world
- box2d = new PBox2D(this);
- box2d.createWorld();
-
- // Make the box
- box = new Box(width/2,height/2);
-
- // Add a bunch of fixed boundaries
- boundaries = new ArrayList();
- boundaries.add(new Boundary(width/2,height-5,width,10,0));
- boundaries.add(new Boundary(width/2,5,width,10,0));
- boundaries.add(new Boundary(width-5,height/2,10,height,0));
- boundaries.add(new Boundary(5,height/2,10,height,0));
-}
-
-
-void draw() {
- background(255);
-
- // We must always step through time!
-
- //if (box.dragged) {
- box.setLocation(mouseX,mouseY);
- //}
-
- box2d.step();
-
- // Draw the boundaries
- for (Boundary wall : boundaries) {
- wall.display();
- }
-
- // Draw the box
- box.display();
-
-
-}
-
-void mousePressed() {
- if (box.contains(mouseX,mouseY)) {
- box.dragged = true;
- }
-}
-
-void mouseReleased() {
- box.dragged = false;
-}
-
-
-
diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_1_box2d_exercise/Box.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_1_box2d_exercise/Box.pde
deleted file mode 100644
index e9774abf0..000000000
--- a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_1_box2d_exercise/Box.pde
+++ /dev/null
@@ -1,27 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// A rectangular box
-class Box {
-
- float x,y;
- float w,h;
-
- // Constructor
- Box(float x_, float y_) {
- x = x_;
- y = y_;
- w = 16;
- h = 16;
- }
-
- // Drawing the box
- void display() {
- fill(127);
- stroke(0);
- strokeWeight(2);
- rectMode(CENTER);
- rect(x,y,w,h);
- }
-}
diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_1_box2d_exercise/NOC_5_1_box2d_exercise.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_1_box2d_exercise/NOC_5_1_box2d_exercise.pde
deleted file mode 100644
index 111643b0c..000000000
--- a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_1_box2d_exercise/NOC_5_1_box2d_exercise.pde
+++ /dev/null
@@ -1,27 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// A list for all of our rectangles
-ArrayList boxes;
-
-void setup() {
- size(640,360);
- // Create ArrayLists
- boxes = new ArrayList();
-}
-
-void draw() {
- background(255);
-
- // When the mouse is clicked, add a new Box object
- if (mousePressed) {
- Box p = new Box(mouseX,mouseY);
- boxes.add(p);
- }
-
- // Display all the boxes
- for (Box b: boxes) {
- b.display();
- }
-}
diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_1_box2d_exercise_solved/Box.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_1_box2d_exercise_solved/Box.pde
deleted file mode 100644
index 2be8fa137..000000000
--- a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_1_box2d_exercise_solved/Box.pde
+++ /dev/null
@@ -1,59 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// A rectangular box
-class Box {
- // Instead of any of the usual variables, we will store a reference to a Box2D Body
- Body body;
-
- float w,h;
-
- Box(float x, float y) {
- w = 16;
- h = 16;
-
- // Build Body
- BodyDef bd = new BodyDef();
- bd.type = BodyType.DYNAMIC;
- bd.position.set(box2d.coordPixelsToWorld(x,y));
- body = box2d.createBody(bd);
-
-
- // Define a polygon (this is what we use for a rectangle)
- PolygonShape ps = new PolygonShape();
- float box2dW = box2d.scalarPixelsToWorld(w/2);
- float box2dH = box2d.scalarPixelsToWorld(h/2); // Box2D considers the width and height of a
- ps.setAsBox(box2dW, box2dH); // rectangle to be the distance from the
- // center to the edge (so half of what we
- // normally think of as width or height.)
- // Define a fixture
- FixtureDef fd = new FixtureDef();
- fd.shape = ps;
- // Parameters that affect physics
- fd.density = 1;
- fd.friction = 0.3;
- fd.restitution = 0.5;
-
- // Attach Fixture to Body
- body.createFixture(fd);
- }
-
- void display() {
- // We need the Body’s location and angle
- Vec2 pos = box2d.getBodyPixelCoord(body);
- float a = body.getAngle();
-
- pushMatrix();
- translate(pos.x,pos.y); // Using the Vec2 position and float angle to
- rotate(-a); // translate and rotate the rectangle
- fill(127);
- stroke(0);
- strokeWeight(2);
- rectMode(CENTER);
- rect(0,0,w,h);
- popMatrix();
- }
-
-}
-
diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_1_box2d_exercise_solved/NOC_5_1_box2d_exercise_solved.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_1_box2d_exercise_solved/NOC_5_1_box2d_exercise_solved.pde
deleted file mode 100644
index 22d39e2a9..000000000
--- a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_1_box2d_exercise_solved/NOC_5_1_box2d_exercise_solved.pde
+++ /dev/null
@@ -1,40 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-import pbox2d.*;
-import org.jbox2d.collision.shapes.*;
-import org.jbox2d.common.*;
-import org.jbox2d.dynamics.*;
-
-// A list for all of our rectangles
-ArrayList boxes;
-
-PBox2D box2d;
-
-void setup() {
- size(640, 360);
- // Initialize and create the Box2D world
- box2d = new PBox2D(this);
- box2d.createWorld();
-
- // Create ArrayLists
- boxes = new ArrayList();
-}
-
-void draw() {
- background(255);
-
- // We must always step through time!
- box2d.step();
-
- // When the mouse is clicked, add a new Box object
- Box p = new Box(mouseX, mouseY);
- boxes.add(p);
-
- // Display all the boxes
- for (Box b: boxes) {
- b.display();
- }
-}
-
diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_2_Boxes/Boundary.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_2_Boxes/Boundary.pde
deleted file mode 100644
index 54e662ceb..000000000
--- a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_2_Boxes/Boundary.pde
+++ /dev/null
@@ -1,53 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// A fixed boundary class
-
-class Boundary {
-
- // A boundary is a simple rectangle with x,y,width,and height
- float x;
- float y;
- float w;
- float h;
-
- // But we also have to make a body for box2d to know about it
- Body b;
-
- Boundary(float x_,float y_, float w_, float h_) {
- x = x_;
- y = y_;
- w = w_;
- h = h_;
-
- // Define the polygon
- PolygonShape ps = new PolygonShape();
- // Figure out the box2d coordinates
- float box2dW = box2d.scalarPixelsToWorld(w/2);
- float box2dH = box2d.scalarPixelsToWorld(h/2);
- // We're just a box
- ps.setAsBox(box2dW, box2dH);
-
-
- // Create the body
- BodyDef bd = new BodyDef();
- bd.type = BodyType.STATIC;
- bd.position.set(box2d.coordPixelsToWorld(x,y));
- b = box2d.createBody(bd);
-
- // Attached the shape to the body using a Fixture
- b.createFixture(ps,1);
- }
-
- // Draw the boundary, if it were at an angle we'd have to do something fancier
- void display() {
- fill(0);
- stroke(0);
- rectMode(CENTER);
- rect(x,y,w,h);
- }
-
-}
-
-
diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_2_Boxes/Box.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_2_Boxes/Box.pde
deleted file mode 100644
index 344e1f108..000000000
--- a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_2_Boxes/Box.pde
+++ /dev/null
@@ -1,87 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// A rectangular box
-class Box {
-
- // We need to keep track of a Body and a width and height
- Body body;
- float w;
- float h;
-
- // Constructor
- Box(float x, float y) {
- w = random(4, 16);
- h = random(4, 16);
- // Add the box to the box2d world
- makeBody(new Vec2(x, y), w, h);
- }
-
- // This function removes the particle from the box2d world
- void killBody() {
- box2d.destroyBody(body);
- }
-
- // Is the particle ready for deletion?
- boolean done() {
- // Let's find the screen position of the particle
- Vec2 pos = box2d.getBodyPixelCoord(body);
- // Is it off the bottom of the screen?
- if (pos.y > height+w*h) {
- killBody();
- return true;
- }
- return false;
- }
-
- // Drawing the box
- void display() {
- // We look at each body and get its screen position
- Vec2 pos = box2d.getBodyPixelCoord(body);
- // Get its angle of rotation
- float a = body.getAngle();
-
- rectMode(CENTER);
- pushMatrix();
- translate(pos.x, pos.y);
- rotate(-a);
- fill(127);
- stroke(0);
- strokeWeight(2);
- rect(0, 0, w, h);
- popMatrix();
- }
-
- // This function adds the rectangle to the box2d world
- void makeBody(Vec2 center, float w_, float h_) {
-
- // Define a polygon (this is what we use for a rectangle)
- PolygonShape sd = new PolygonShape();
- float box2dW = box2d.scalarPixelsToWorld(w_/2);
- float box2dH = box2d.scalarPixelsToWorld(h_/2);
- sd.setAsBox(box2dW, box2dH);
-
- // Define a fixture
- FixtureDef fd = new FixtureDef();
- fd.shape = sd;
- // Parameters that affect physics
- fd.density = 1;
- fd.friction = 0.3;
- fd.restitution = 0.5;
-
- // Define the body and make it from the shape
- BodyDef bd = new BodyDef();
- bd.type = BodyType.DYNAMIC;
- bd.position.set(box2d.coordPixelsToWorld(center));
-
- body = box2d.createBody(bd);
- body.createFixture(fd);
-
- // Give it some initial random velocity
- body.setLinearVelocity(new Vec2(random(-5, 5), random(2, 5)));
- body.setAngularVelocity(random(-5, 5));
- }
-}
-
-
diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_2_Boxes/NOC_5_2_Boxes.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_2_Boxes/NOC_5_2_Boxes.pde
deleted file mode 100644
index 23193aa97..000000000
--- a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_2_Boxes/NOC_5_2_Boxes.pde
+++ /dev/null
@@ -1,71 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Basic example of falling rectangles
-
-import pbox2d.*;
-import org.jbox2d.collision.shapes.*;
-import org.jbox2d.common.*;
-import org.jbox2d.dynamics.*;
-
-// A reference to our box2d world
-PBox2D box2d;
-
-// A list we'll use to track fixed objects
-ArrayList boundaries;
-// A list for all of our rectangles
-ArrayList boxes;
-
-void setup() {
- size(640,360);
- // Initialize box2d physics and create the world
- box2d = new PBox2D(this);
- box2d.createWorld();
- // We are setting a custom gravity
- box2d.setGravity(0, -10);
-
- // Create ArrayLists
- boxes = new ArrayList();
- boundaries = new ArrayList();
-
- // Add a bunch of fixed boundaries
- boundaries.add(new Boundary(width/4,height-5,width/2-50,10));
- boundaries.add(new Boundary(3*width/4,height-50,width/2-50,10));
-}
-
-void draw() {
- background(255);
-
- // We must always step through time!
- box2d.step();
-
- // Boxes fall from the top every so often
- if (random(1) < 0.2) {
- Box p = new Box(width/2,30);
- boxes.add(p);
- }
-
- // Display all the boundaries
- for (Boundary wall: boundaries) {
- wall.display();
- }
-
- // Display all the boxes
- for (Box b: boxes) {
- b.display();
- }
-
- // Boxes that leave the screen, we delete them
- // (note they have to be deleted from both the box2d world and our list
- for (int i = boxes.size()-1; i >= 0; i--) {
- Box b = boxes.get(i);
- if (b.done()) {
- boxes.remove(i);
- }
- }
-}
-
-
-
-
diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_3_ChainShape_Simple/NOC_5_3_ChainShape_Simple.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_3_ChainShape_Simple/NOC_5_3_ChainShape_Simple.pde
deleted file mode 100644
index cee4a66e1..000000000
--- a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_3_ChainShape_Simple/NOC_5_3_ChainShape_Simple.pde
+++ /dev/null
@@ -1,69 +0,0 @@
-// The Nature of Code
-//
-// Spring 2011
-// PBox2D example
-
-// An uneven surface
-
-import pbox2d.*;
-import org.jbox2d.collision.shapes.*;
-import org.jbox2d.common.*;
-import org.jbox2d.dynamics.*;
-
-// A reference to our box2d world
-PBox2D box2d;
-
-// An ArrayList of particles that will fall on the surface
-ArrayList particles;
-
-// An object to store information about the uneven surface
-Surface surface;
-
-void setup() {
- size(640,360);
- // Initialize box2d physics and create the world
- box2d = new PBox2D(this);
- box2d.createWorld();
- // We are setting a custom gravity
- box2d.setGravity(0, -10);
-
- // Create the empty list
- particles = new ArrayList();
- // Create the surface
- surface = new Surface();
-}
-
-void draw() {
- // If the mouse is pressed, we make new particles
- if (random(1) < 0.5) {
- float sz = random(4,8);
- particles.add(new Particle(width/2,10,sz));
- }
-
- // We must always step through time!
- box2d.step();
-
- background(255);
-
- // Draw the surface
- surface.display();
-
- // Draw all particles
- for (Particle p: particles) {
- p.display();
- }
-
- // Particles that leave the screen, we delete them
- // (note they have to be deleted from both the box2d world and our list
- for (int i = particles.size()-1; i >= 0; i--) {
- Particle p = particles.get(i);
- if (p.done()) {
- particles.remove(i);
- }
- }
-}
-
-
-
-
-
diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_3_ChainShape_Simple/Particle.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_3_ChainShape_Simple/Particle.pde
deleted file mode 100644
index a7d390361..000000000
--- a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_3_ChainShape_Simple/Particle.pde
+++ /dev/null
@@ -1,89 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// A circular particle
-
-class Particle {
-
- // We need to keep track of a Body and a radius
- Body body;
- float r;
-
- Particle(float x, float y, float r_) {
- r = r_;
- // This function puts the particle in the Box2d world
- makeBody(x,y,r);
- }
-
- // This function removes the particle from the box2d world
- void killBody() {
- box2d.destroyBody(body);
- }
-
- // Is the particle ready for deletion?
- boolean done() {
- // Let's find the screen position of the particle
- Vec2 pos = box2d.getBodyPixelCoord(body);
- // Is it off the bottom of the screen?
- if (pos.y > height+r*2) {
- killBody();
- return true;
- }
- return false;
- }
-
- //
- void display() {
- // We look at each body and get its screen position
- Vec2 pos = box2d.getBodyPixelCoord(body);
- // Get its angle of rotation
- float a = body.getAngle();
- pushMatrix();
- translate(pos.x,pos.y);
- rotate(-a);
- fill(127);
- stroke(0);
- strokeWeight(2);
- ellipse(0,0,r*2,r*2);
- // Let's add a line so we can see the rotation
- line(0,0,r,0);
- popMatrix();
- }
-
- // Here's our function that adds the particle to the Box2D world
- void makeBody(float x, float y, float r) {
- // Define a body
- BodyDef bd = new BodyDef();
- // Set its position
- bd.position = box2d.coordPixelsToWorld(x,y);
- bd.type = BodyType.DYNAMIC;
- body = box2d.world.createBody(bd);
-
- // Make the body's shape a circle
- CircleShape cs = new CircleShape();
- cs.m_radius = box2d.scalarPixelsToWorld(r);
-
- FixtureDef fd = new FixtureDef();
- fd.shape = cs;
- // Parameters that affect physics
- fd.density = 1;
- fd.friction = 0.01;
- fd.restitution = 0.3;
-
- // Attach fixture to body
- body.createFixture(fd);
-
- // Give it a random initial velocity (and angular velocity)
- body.setLinearVelocity(new Vec2(random(-10f,10f),random(5f,10f)));
- body.setAngularVelocity(random(-10,10));
- }
-
-
-
-
-
-
-}
-
-
diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_3_ChainShape_Simple/Surface.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_3_ChainShape_Simple/Surface.pde
deleted file mode 100644
index 09da0d535..000000000
--- a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_3_ChainShape_Simple/Surface.pde
+++ /dev/null
@@ -1,52 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// An uneven surface boundary
-
-class Surface {
- // We'll keep track of all of the surface points
- ArrayList surface;
-
-
- Surface() {
- surface = new ArrayList();
- // Here we keep track of the screen coordinates of the chain
- surface.add(new Vec2(0, height/2));
- surface.add(new Vec2(width/2, height/2+50));
- surface.add(new Vec2(width, height/2));
-
- // This is what box2d uses to put the surface in its world
- ChainShape chain = new ChainShape();
-
- // We can add 3 vertices by making an array of 3 Vec2 objects
- Vec2[] vertices = new Vec2[surface.size()];
- for (int i = 0; i < vertices.length; i++) {
- vertices[i] = box2d.coordPixelsToWorld(surface.get(i));
- }
-
- chain.createChain(vertices, vertices.length);
-
- // The edge chain is now a body!
- BodyDef bd = new BodyDef();
- Body body = box2d.world.createBody(bd);
- // Shortcut, we could define a fixture if we
- // want to specify frictions, restitution, etc.
- body.createFixture(chain, 1);
- }
-
- // A simple function to just draw the edge chain as a series of vertex points
- void display() {
- strokeWeight(1);
- stroke(0);
- fill(0);
- beginShape();
- for (Vec2 v: surface) {
- vertex(v.x, v.y);
- }
- vertex(width, height);
- vertex(0, height);
- endShape(CLOSE);
- }
-}
-
diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_4_Polygons/Boundary.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_4_Polygons/Boundary.pde
deleted file mode 100644
index ebf6b04bf..000000000
--- a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_4_Polygons/Boundary.pde
+++ /dev/null
@@ -1,59 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// A fixed boundary class (now incorporates angle)
-
-class Boundary {
-
- // A boundary is a simple rectangle with x,y,width,and height
- float x;
- float y;
- float w;
- float h;
- // But we also have to make a body for box2d to know about it
- Body b;
-
- Boundary(float x_,float y_, float w_, float h_, float a) {
- x = x_;
- y = y_;
- w = w_;
- h = h_;
-
- // Define the polygon
- PolygonShape sd = new PolygonShape();
- // Figure out the box2d coordinates
- float box2dW = box2d.scalarPixelsToWorld(w/2);
- float box2dH = box2d.scalarPixelsToWorld(h/2);
- // We're just a box
- sd.setAsBox(box2dW, box2dH);
-
-
- // Create the body
- BodyDef bd = new BodyDef();
- bd.type = BodyType.STATIC;
- bd.angle = a;
- bd.position.set(box2d.coordPixelsToWorld(x,y));
- b = box2d.createBody(bd);
-
- // Attached the shape to the body using a Fixture
- b.createFixture(sd,1);
- }
-
- // Draw the boundary, it doesn't move so we don't have to ask the Body for location
- void display() {
- fill(0);
- stroke(0);
- strokeWeight(1);
- rectMode(CENTER);
- float a = b.getAngle();
- pushMatrix();
- translate(x,y);
- rotate(-a);
- rect(0,0,w,h);
- popMatrix();
- }
-
-}
-
-
diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_4_Polygons/CustomShape.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_4_Polygons/CustomShape.pde
deleted file mode 100644
index 9e0180a59..000000000
--- a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_4_Polygons/CustomShape.pde
+++ /dev/null
@@ -1,90 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// A rectangular box
-class CustomShape {
-
- // We need to keep track of a Body and a width and height
- Body body;
-
- // Constructor
- CustomShape(float x, float y) {
- // Add the box to the box2d world
- makeBody(new Vec2(x, y));
- }
-
- // This function removes the particle from the box2d world
- void killBody() {
- box2d.destroyBody(body);
- }
-
- // Is the particle ready for deletion?
- boolean done() {
- // Let's find the screen position of the particle
- Vec2 pos = box2d.getBodyPixelCoord(body);
- // Is it off the bottom of the screen?
- if (pos.y > height) {
- killBody();
- return true;
- }
- return false;
- }
-
- // Drawing the box
- void display() {
- // We look at each body and get its screen position
- Vec2 pos = box2d.getBodyPixelCoord(body);
- // Get its angle of rotation
- float a = body.getAngle();
-
- Fixture f = body.getFixtureList();
- PolygonShape ps = (PolygonShape) f.getShape();
-
-
- rectMode(CENTER);
- pushMatrix();
- translate(pos.x, pos.y);
- rotate(-a);
- fill(127);
- stroke(0);
- strokeWeight(2);
- beginShape();
- //println(vertices.length);
- // For every vertex, convert to pixel vector
- for (int i = 0; i < ps.getVertexCount(); i++) {
- Vec2 v = box2d.vectorWorldToPixels(ps.getVertex(i));
- vertex(v.x, v.y);
- }
- endShape(CLOSE);
- popMatrix();
- }
-
- // This function adds the rectangle to the box2d world
- void makeBody(Vec2 center) {
-
- Vec2[] vertices = new Vec2[4];
- vertices[0] = box2d.vectorPixelsToWorld(new Vec2(-15, 25));
- vertices[1] = box2d.vectorPixelsToWorld(new Vec2(15, 0));
- vertices[2] = box2d.vectorPixelsToWorld(new Vec2(20, -15));
- vertices[3] = box2d.vectorPixelsToWorld(new Vec2(-10, -10));
-
- // Define a polygon (this is what we use for a rectangle)
- PolygonShape ps = new PolygonShape();
- ps.set(vertices, vertices.length);
-
- // Define the body and make it from the shape
- BodyDef bd = new BodyDef();
- bd.type = BodyType.DYNAMIC;
- bd.position.set(box2d.coordPixelsToWorld(center));
- body = box2d.createBody(bd);
-
- body.createFixture(ps, 1.0);
-
-
- // Give it some initial random velocity
- body.setLinearVelocity(new Vec2(random(-5, 5), random(2, 5)));
- body.setAngularVelocity(random(-5, 5));
- }
-}
-
diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_4_Polygons/NOC_5_4_Polygons.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_4_Polygons/NOC_5_4_Polygons.pde
deleted file mode 100644
index 283741835..000000000
--- a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_4_Polygons/NOC_5_4_Polygons.pde
+++ /dev/null
@@ -1,71 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Basic example of falling rectangles
-
-import pbox2d.*;
-import org.jbox2d.collision.shapes.*;
-import org.jbox2d.common.*;
-import org.jbox2d.dynamics.*;
-
-// A reference to our box2d world
-PBox2D box2d;
-
-// A list we'll use to track fixed objects
-ArrayList boundaries;
-// A list for all of our rectangles
-ArrayList polygons;
-
-void setup() {
- size(640,360);
- // Initialize box2d physics and create the world
- box2d = new PBox2D(this);
- box2d.createWorld();
- // We are setting a custom gravity
- box2d.setGravity(0, -20);
-
- // Create ArrayLists
- polygons = new ArrayList();
- boundaries = new ArrayList();
-
- // Add a bunch of fixed boundaries
- boundaries.add(new Boundary(width/4,height-5,width/2-50,10,0));
- boundaries.add(new Boundary(3*width/4,height-50,width/2-50,10,0));
- boundaries.add(new Boundary(width-5,height/2,10,height,0));
- boundaries.add(new Boundary(5,height/2,10,height,0));
-}
-
-void draw() {
- background(255);
-
- // We must always step through time!
- box2d.step();
-
- // Display all the boundaries
- for (Boundary wall: boundaries) {
- wall.display();
- }
-
- // Display all the people
- for (CustomShape cs: polygons) {
- cs.display();
- }
-
- // people that leave the screen, we delete them
- // (note they have to be deleted from both the box2d world and our list
- for (int i = polygons.size()-1; i >= 0; i--) {
- CustomShape cs = polygons.get(i);
- if (cs.done()) {
- polygons.remove(i);
- }
- }
-}
-
-void mousePressed() {
- CustomShape cs = new CustomShape(mouseX,mouseY);
- polygons.add(cs);
-}
-
-
-
diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_5_MultiShapes/Boundary.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_5_MultiShapes/Boundary.pde
deleted file mode 100644
index afe2ab2f5..000000000
--- a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_5_MultiShapes/Boundary.pde
+++ /dev/null
@@ -1,61 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// A fixed boundary class (now incorporates angle)
-
-class Boundary {
-
- // A boundary is a simple rectangle with x,y,width,and height
- float x;
- float y;
- float w;
- float h;
- // But we also have to make a body for box2d to know about it
- Body b;
-
- Boundary(float x_,float y_, float w_, float h_, float a) {
- x = x_;
- y = y_;
- w = w_;
- h = h_;
-
- // Define the polygon
- PolygonShape sd = new PolygonShape();
- // Figure out the box2d coordinates
- float box2dW = box2d.scalarPixelsToWorld(w/2);
- float box2dH = box2d.scalarPixelsToWorld(h/2);
- // We're just a box
- sd.setAsBox(box2dW, box2dH);
-
-
- // Create the body
- BodyDef bd = new BodyDef();
- bd.type = BodyType.STATIC;
- bd.angle = a;
- bd.position.set(box2d.coordPixelsToWorld(x,y));
- b = box2d.createBody(bd);
-
- // Attached the shape to the body using a Fixture
- b.createFixture(sd,1);
- }
-
- // Draw the boundary, if it were at an angle we'd have to do something fancier
- void display() {
- fill(0);
- stroke(0);
- strokeWeight(1);
- rectMode(CENTER);
-
- float a = b.getAngle();
-
- pushMatrix();
- translate(x,y);
- rotate(-a);
- rect(0,0,w,h);
- popMatrix();
- }
-
-}
-
-
diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_5_MultiShapes/Lollipop.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_5_MultiShapes/Lollipop.pde
deleted file mode 100644
index 65805e008..000000000
--- a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_5_MultiShapes/Lollipop.pde
+++ /dev/null
@@ -1,88 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// A rectangular box
-class Lollipop {
-
- // We need to keep track of a Body and a width and height
- Body body;
- float w;
- float h;
- float r;
-
- // Constructor
- Lollipop(float x, float y) {
- w = 8;
- h = 24;
- r = 8;
- // Add the box to the box2d world
- makeBody(new Vec2(x, y));
- }
-
- // This function removes the particle from the box2d world
- void killBody() {
- box2d.destroyBody(body);
- }
-
- // Is the particle ready for deletion?
- boolean done() {
- // Let's find the screen position of the particle
- Vec2 pos = box2d.getBodyPixelCoord(body);
- // Is it off the bottom of the screen?
- if (pos.y > height+w*h) {
- killBody();
- return true;
- }
- return false;
- }
-
- // Drawing the lollipop
- void display() {
- // We look at each body and get its screen position
- Vec2 pos = box2d.getBodyPixelCoord(body);
- // Get its angle of rotation
- float a = body.getAngle();
-
- rectMode(CENTER);
- pushMatrix();
- translate(pos.x, pos.y);
- rotate(-a);
- fill(127);
- stroke(0);
- strokeWeight(2);
-
- rect(0,0,w,h);
- ellipse(0, -h/2, r*2, r*2);
- popMatrix();
- }
-
- // This function adds the rectangle to the box2d world
- void makeBody(Vec2 center) {
-
- // Define the body and make it from the shape
- BodyDef bd = new BodyDef();
- bd.type = BodyType.DYNAMIC;
- bd.position.set(box2d.coordPixelsToWorld(center));
- body = box2d.createBody(bd);
-
- CircleShape circle = new CircleShape();
- circle.m_radius = box2d.scalarPixelsToWorld(r);
- Vec2 offset = new Vec2(0,-h/2);
- offset = box2d.vectorPixelsToWorld(offset);
- circle.m_p.set(offset.x,offset.y);
-
- PolygonShape ps = new PolygonShape();
- float box2dW = box2d.scalarPixelsToWorld(w/2);
- float box2dH = box2d.scalarPixelsToWorld(h/2);
- ps.setAsBox(box2dW, box2dH);
-
- body.createFixture(ps,1.0);
- body.createFixture(circle, 1.0);
-
- // Give it some initial random velocity
- body.setLinearVelocity(new Vec2(random(-5, 5), random(2, 5)));
- body.setAngularVelocity(random(-5, 5));
- }
-}
-
diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_5_MultiShapes/NOC_5_5_MultiShapes.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_5_MultiShapes/NOC_5_5_MultiShapes.pde
deleted file mode 100644
index 132b03ba6..000000000
--- a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_5_MultiShapes/NOC_5_5_MultiShapes.pde
+++ /dev/null
@@ -1,71 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Basic example of falling rectangles
-
-import pbox2d.*;
-import org.jbox2d.collision.shapes.*;
-import org.jbox2d.common.*;
-import org.jbox2d.dynamics.*;
-
-// A reference to our box2d world
-PBox2D box2d;
-
-// A list we'll use to track fixed objects
-ArrayList boundaries;
-// A list for all of our rectangles
-ArrayList pops;
-
-void setup() {
- size(640,360);
- // Initialize box2d physics and create the world
- box2d = new PBox2D(this,20);
- box2d.createWorld();
- // We are setting a custom gravity
- box2d.setGravity(0, -20);
-
- // Create ArrayLists
- pops = new ArrayList();
- boundaries = new ArrayList();
-
- // Add a bunch of fixed boundaries
- boundaries.add(new Boundary(width/4,height-5,width/2-50,10,0));
- boundaries.add(new Boundary(3*width/4,height-50,width/2-50,10,0));
- boundaries.add(new Boundary(width-5,height/2,10,height,0));
- boundaries.add(new Boundary(5,height/2,10,height,0));
-}
-
-void draw() {
- background(255);
-
- // We must always step through time!
- box2d.step();
-
- // Display all the boundaries
- for (Boundary wall: boundaries) {
- wall.display();
- }
-
- // Display all the people
- for (Lollipop p: pops) {
- p.display();
- }
-
- // people that leave the screen, we delete them
- // (note they have to be deleted from both the box2d world and our list
- for (int i = pops.size()-1; i >= 0; i--) {
- Lollipop p = pops.get(i);
- if (p.done()) {
- pops.remove(i);
- }
- }
-}
-
-void mousePressed() {
- Lollipop p = new Lollipop(mouseX,mouseY);
- pops.add(p);
-}
-
-
-
diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_6_DistanceJoint/Boundary.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_6_DistanceJoint/Boundary.pde
deleted file mode 100644
index 9a17026a1..000000000
--- a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_6_DistanceJoint/Boundary.pde
+++ /dev/null
@@ -1,53 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// A fixed boundary class
-
-class Boundary {
-
- // A boundary is a simple rectangle with x,y,width,and height
- float x;
- float y;
- float w;
- float h;
-
- // But we also have to make a body for box2d to know about it
- Body b;
-
- Boundary(float x_,float y_, float w_, float h_) {
- x = x_;
- y = y_;
- w = w_;
- h = h_;
-
- // Define the polygon
- PolygonShape sd = new PolygonShape();
- // Figure out the box2d coordinates
- float box2dW = box2d.scalarPixelsToWorld(w/2);
- float box2dH = box2d.scalarPixelsToWorld(h/2);
- // We're just a box
- sd.setAsBox(box2dW, box2dH);
-
-
- // Create the body
- BodyDef bd = new BodyDef();
- bd.type = BodyType.STATIC;
- bd.position.set(box2d.coordPixelsToWorld(x,y));
- b = box2d.createBody(bd);
-
- // Attached the shape to the body using a Fixture
- b.createFixture(sd,1);
- }
-
- // Draw the boundary, if it were at an angle we'd have to do something fancier
- void display() {
- fill(0);
- stroke(0);
- rectMode(CENTER);
- rect(x,y,w,h);
- }
-
-}
-
-
diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_6_DistanceJoint/NOC_5_6_DistanceJoint.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_6_DistanceJoint/NOC_5_6_DistanceJoint.pde
deleted file mode 100644
index 489468ebb..000000000
--- a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_6_DistanceJoint/NOC_5_6_DistanceJoint.pde
+++ /dev/null
@@ -1,78 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Example demonstrating distance joints
-// A bridge is formed by connected a series of particles with joints
-
-import pbox2d.*;
-import org.jbox2d.common.*;
-import org.jbox2d.dynamics.joints.*;
-import org.jbox2d.collision.shapes.*;
-import org.jbox2d.collision.shapes.Shape;
-import org.jbox2d.common.*;
-import org.jbox2d.dynamics.*;
-import org.jbox2d.dynamics.contacts.*;
-
-// A reference to our box2d world
-PBox2D box2d;
-
-// A list we'll use to track fixed objects
-ArrayList boundaries;
-
-
-// A list for all of our rectangles
-ArrayList pairs;
-
-void setup() {
- size(640,360);
- // Initialize box2d physics and create the world
- box2d = new PBox2D(this);
- box2d.createWorld();
-
- // Create ArrayLists
- pairs = new ArrayList();
-
- boundaries = new ArrayList();
-
- // Add a bunch of fixed boundaries
- boundaries.add(new Boundary(width/4,height-5,width/2-50,10));
- boundaries.add(new Boundary(3*width/4,height-50,width/2-50,10));
-
-}
-
-void draw() {
- background(255);
-
- // We must always step through time!
- box2d.step();
-
- // When the mouse is clicked, add a new Box object
-
- // Display all the boxes
- for (Pair p: pairs) {
- p.display();
- }
-
- // Display all the boundaries
- for (Boundary wall: boundaries) {
- wall.display();
- }
-
- fill(0);
- text("Click mouse to add connected particles.",10,20);
-}
-
-void mousePressed() {
- Pair p = new Pair(mouseX,mouseY);
- pairs.add(p);
-}
-
-
-
-
-
-
-
-
-
diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_6_DistanceJoint/Pair.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_6_DistanceJoint/Pair.pde
deleted file mode 100644
index 780a8e316..000000000
--- a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_6_DistanceJoint/Pair.pde
+++ /dev/null
@@ -1,47 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Series of Particles connected with distance joints
-
-class Pair {
-
- Particle p1;
- Particle p2;
-
- float len;
- // Chain constructor
- Pair(float x, float y) {
- len = 32;
-
- p1 = new Particle(x,y);
- p2 = new Particle(x+random(-1,1),y+random(-1,1));
-
- DistanceJointDef djd = new DistanceJointDef();
- // Connection between previous particle and this one
- djd.bodyA = p1.body;
- djd.bodyB = p2.body;
- // Equilibrium length
- djd.length = box2d.scalarPixelsToWorld(len);
-
- // These properties affect how springy the joint is
- djd.frequencyHz = 3; // Try a value less than 5 (0 for no elasticity)
- djd.dampingRatio = 0.1; // Ranges between 0 and 1 (1 for no springiness)
-
- // Make the joint. Note we aren't storing a reference to the joint ourselves anywhere!
- // We might need to someday, but for now it's ok
- DistanceJoint dj = (DistanceJoint) box2d.world.createJoint(djd);
- }
-
- void display() {
- Vec2 pos1 = box2d.getBodyPixelCoord(p1.body);
- Vec2 pos2 = box2d.getBodyPixelCoord(p2.body);
- stroke(0);
- strokeWeight(2);
- line(pos1.x,pos1.y,pos2.x,pos2.y);
-
- p1.display();
- p2.display();
- }
-}
-
diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_6_DistanceJoint/Particle.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_6_DistanceJoint/Particle.pde
deleted file mode 100644
index ed3d34199..000000000
--- a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_6_DistanceJoint/Particle.pde
+++ /dev/null
@@ -1,76 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// A circular particle
-
-class Particle {
-
- // We need to keep track of a Body and a radius
- Body body;
- float r;
-
- Particle(float x, float y) {
- r = 8;
-
- // Define a body
- BodyDef bd = new BodyDef();
- // Set its position
- bd.position = box2d.coordPixelsToWorld(x,y);
- bd.type = BodyType.DYNAMIC;
- body = box2d.world.createBody(bd);
-
- // Make the body's shape a circle
- CircleShape cs = new CircleShape();
- cs.m_radius = box2d.scalarPixelsToWorld(r);
-
- FixtureDef fd = new FixtureDef();
- fd.shape = cs;
- // Parameters that affect physics
- fd.density = 1;
- fd.friction = 0.01;
- fd.restitution = 0.3;
-
- // Attach fixture to body
- body.createFixture(fd);
- body.setLinearVelocity(new Vec2(random(-5, 5), random(2, 5)));
- }
-
- // This function removes the particle from the box2d world
- void killBody() {
- box2d.destroyBody(body);
- }
-
- // Is the particle ready for deletion?
- boolean done() {
- // Let's find the screen position of the particle
- Vec2 pos = box2d.getBodyPixelCoord(body);
- // Is it off the bottom of the screen?
- if (pos.y > height+r*2) {
- killBody();
- return true;
- }
- return false;
- }
-
- void display() {
- // We look at each body and get its screen position
- Vec2 pos = box2d.getBodyPixelCoord(body);
- // Get its angle of rotation
- float a = body.getAngle();
- pushMatrix();
- translate(pos.x,pos.y);
- rotate(a);
- fill(127);
- stroke(0);
- strokeWeight(2);
- ellipse(0,0,r*2,r*2);
- // Let's add a line so we can see the rotation
- line(0,0,r,0);
- popMatrix();
- }
-
-
-}
-
-
diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_7_RevoluteJoint/Box.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_7_RevoluteJoint/Box.pde
deleted file mode 100644
index acf4abdec..000000000
--- a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_7_RevoluteJoint/Box.pde
+++ /dev/null
@@ -1,72 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// A rectangular box
-
-class Box {
-
- // We need to keep track of a Body and a width and height
- Body body;
- float w;
- float h;
-
- // Constructor
- Box(float x, float y, float w_, float h_, boolean lock) {
- w = w_;
- h = h_;
-
- // Define and create the body
- BodyDef bd = new BodyDef();
- bd.position.set(box2d.coordPixelsToWorld(new Vec2(x,y)));
- if (lock) bd.type = BodyType.STATIC;
- else bd.type = BodyType.DYNAMIC;
-
- body = box2d.createBody(bd);
-
- // Define the shape -- a (this is what we use for a rectangle)
- PolygonShape sd = new PolygonShape();
- float box2dW = box2d.scalarPixelsToWorld(w/2);
- float box2dH = box2d.scalarPixelsToWorld(h/2);
- sd.setAsBox(box2dW, box2dH);
-
- // Define a fixture
- FixtureDef fd = new FixtureDef();
- fd.shape = sd;
- // Parameters that affect physics
- fd.density = 1;
- fd.friction = 0.3;
- fd.restitution = 0.5;
-
- body.createFixture(fd);
-
- // Give it some initial random velocity
- body.setLinearVelocity(new Vec2(random(-5,5),random(2,5)));
- body.setAngularVelocity(random(-5,5));
- }
-
- // This function removes the particle from the box2d world
- void killBody() {
- box2d.destroyBody(body);
- }
-
- // Drawing the box
- void display() {
- // We look at each body and get its screen position
- Vec2 pos = box2d.getBodyPixelCoord(body);
- // Get its angle of rotation
- float a = body.getAngle();
-
- rectMode(PConstants.CENTER);
- pushMatrix();
- translate(pos.x,pos.y);
- rotate(-a);
- fill(127);
- stroke(0);
- strokeWeight(2);
- rect(0,0,w,h);
- popMatrix();
- }
-}
-
-
diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_7_RevoluteJoint/NOC_5_7_RevoluteJoint.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_7_RevoluteJoint/NOC_5_7_RevoluteJoint.pde
deleted file mode 100644
index 74ab0e3f2..000000000
--- a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_7_RevoluteJoint/NOC_5_7_RevoluteJoint.pde
+++ /dev/null
@@ -1,87 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Example demonstrating revolute joint
-
-import pbox2d.*;
-import org.jbox2d.common.*;
-import org.jbox2d.dynamics.joints.*;
-import org.jbox2d.collision.shapes.*;
-import org.jbox2d.collision.shapes.Shape;
-import org.jbox2d.common.*;
-import org.jbox2d.dynamics.*;
-import org.jbox2d.dynamics.contacts.*;
-
-// A reference to our box2d world
-PBox2D box2d;
-
-// An object to describe a Windmill (two bodies and one joint)
-Windmill windmill;
-
-// An ArrayList of particles that will fall on the surface
-ArrayList particles;
-
-void setup() {
- size(640,360);
- // Initialize box2d physics and create the world
- box2d = new PBox2D(this);
- box2d.createWorld();
-
- // Make the windmill at an x,y location
- windmill = new Windmill(width/2,175);
-
- // Create the empty list
- particles = new ArrayList();
-
-}
-
-// Click the mouse to turn on or off the motor
-void mousePressed() {
- windmill.toggleMotor();
-}
-
-void draw() {
- background(255);
-
- if (random(1) < 0.1) {
- float sz = random(4,8);
- particles.add(new Particle(random(width/2-100,width/2+100),-20,sz));
- }
-
-
- // We must always step through time!
- box2d.step();
-
- // Look at all particles
- for (int i = particles.size()-1; i >= 0; i--) {
- Particle p = particles.get(i);
- p.display();
- // Particles that leave the screen, we delete them
- // (note they have to be deleted from both the box2d world and our list
- if (p.done()) {
- particles.remove(i);
- }
- }
-
- // Draw the windmill
- windmill.display();
-
- String status = "OFF";
- if (windmill.motorOn()) status = "ON";
-
- fill(0);
- text("Click mouse to toggle motor.\nMotor: " + status,10,height-30);
-
-
-}
-
-
-
-
-
-
-
-
-
-
diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_7_RevoluteJoint/Particle.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_7_RevoluteJoint/Particle.pde
deleted file mode 100644
index 89fb8b443..000000000
--- a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_7_RevoluteJoint/Particle.pde
+++ /dev/null
@@ -1,84 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// A circular particle
-
-class Particle {
-
- // We need to keep track of a Body and a radius
- Body body;
- float r;
-
- Particle(float x, float y, float r_) {
- r = r_;
- // This function puts the particle in the Box2d world
- makeBody(x, y, r);
- body.setUserData(this);
- }
-
- // This function removes the particle from the box2d world
- void killBody() {
- box2d.destroyBody(body);
- }
-
- // Is the particle ready for deletion?
- boolean done() {
- // Let's find the screen position of the particle
- Vec2 pos = box2d.getBodyPixelCoord(body);
- // Is it off the bottom of the screen?
- if (pos.y > height+r*2) {
- killBody();
- return true;
- }
- return false;
- }
-
- //
- void display() {
- // We look at each body and get its screen position
- Vec2 pos = box2d.getBodyPixelCoord(body);
- // Get its angle of rotation
- float a = body.getAngle();
- pushMatrix();
- translate(pos.x, pos.y);
-
- rotate(-a);
- fill(127);
- stroke(0);
- strokeWeight(2);
- ellipse(0, 0, r*2, r*2);
- // Let's add a line so we can see the rotation
- line(0, 0, r, 0);
- popMatrix();
- }
-
- // Here's our function that adds the particle to the Box2D world
- void makeBody(float x, float y, float r) {
- // Define a body
- BodyDef bd = new BodyDef();
- // Set its position
- bd.position = box2d.coordPixelsToWorld(x, y);
- bd.type = BodyType.DYNAMIC;
-
- body = box2d.world.createBody(bd);
-
- // Make the body's shape a circle
- CircleShape cs = new CircleShape();
- cs.m_radius = box2d.scalarPixelsToWorld(r);
-
- FixtureDef fd = new FixtureDef();
- fd.shape = cs;
-
- fd.density = 2.0;
- fd.friction = 0.01;
- fd.restitution = 0.3; // Restitution is bounciness
-
- body.createFixture(fd);
-
- // Give it a random initial velocity (and angular velocity)
- //body.setLinearVelocity(new Vec2(random(-10f,10f),random(5f,10f)));
- body.setAngularVelocity(random(-10, 10));
- }
-}
-
diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_7_RevoluteJoint/Windmill.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_7_RevoluteJoint/Windmill.pde
deleted file mode 100644
index 5a819a81e..000000000
--- a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_7_RevoluteJoint/Windmill.pde
+++ /dev/null
@@ -1,61 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Class to describe a fixed spinning object
-
-class Windmill {
-
- // Our object is two boxes and one joint
- // Consider making the fixed box much smaller and not drawing it
- RevoluteJoint joint;
- Box box1;
- Box box2;
-
- Windmill(float x, float y) {
-
- // Initialize locations of two boxes
- box1 = new Box(x, y-20, 120, 10, false);
- box2 = new Box(x, y, 10, 40, true);
-
- // Define joint as between two bodies
- RevoluteJointDef rjd = new RevoluteJointDef();
-
- rjd.initialize(box1.body, box2.body, box1.body.getWorldCenter());
-
- // Turning on a motor (optional)
- rjd.motorSpeed = PI*2; // how fast?
- rjd.maxMotorTorque = 1000.0; // how powerful?
- rjd.enableMotor = false; // is it on?
-
- // There are many other properties you can set for a Revolute joint
- // For example, you can limit its angle between a minimum and a maximum
- // See box2d manual for more
-
-
- // Create the joint
- joint = (RevoluteJoint) box2d.world.createJoint(rjd);
- }
-
- // Turn the motor on or off
- void toggleMotor() {
- joint.enableMotor(!joint.isMotorEnabled());
- }
-
- boolean motorOn() {
- return joint.isMotorEnabled();
- }
-
-
- void display() {
- box2.display();
- box1.display();
-
- // Draw anchor just for debug
- Vec2 anchor = box2d.coordWorldToPixels(box1.body.getWorldCenter());
- fill(0);
- noStroke();
- ellipse(anchor.x, anchor.y, 8, 8);
- }
-}
-
diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_8_MouseJoint/Boundary.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_8_MouseJoint/Boundary.pde
deleted file mode 100644
index 61491af26..000000000
--- a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_8_MouseJoint/Boundary.pde
+++ /dev/null
@@ -1,62 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// A fixed boundary class (now incorporates angle)
-
-class Boundary {
-
- // A boundary is a simple rectangle with x,y,width,and height
- float x;
- float y;
- float w;
- float h;
- // But we also have to make a body for box2d to know about it
- Body b;
-
- Boundary(float x_,float y_, float w_, float h_, float a) {
- x = x_;
- y = y_;
- w = w_;
- h = h_;
-
- // Define the polygon
- PolygonShape sd = new PolygonShape();
- // Figure out the box2d coordinates
- float box2dW = box2d.scalarPixelsToWorld(w/2);
- float box2dH = box2d.scalarPixelsToWorld(h/2);
- // We're just a box
- sd.setAsBox(box2dW, box2dH);
-
-
- // Create the body
- BodyDef bd = new BodyDef();
- bd.type = BodyType.STATIC;
- bd.angle = a;
- bd.position.set(box2d.coordPixelsToWorld(x,y));
- b = box2d.createBody(bd);
-
- // Attached the shape to the body using a Fixture
- b.createFixture(sd,1);
- }
-
- // Draw the boundary, if it were at an angle we'd have to do something fancier
- void display() {
- noFill();
- stroke(127);
- fill(127);
- strokeWeight(1);
- rectMode(CENTER);
-
- float a = b.getAngle();
-
- pushMatrix();
- translate(x,y);
- rotate(-a);
- rect(0,0,w,h);
- popMatrix();
- }
-
-}
-
-
diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_8_MouseJoint/Box.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_8_MouseJoint/Box.pde
deleted file mode 100644
index db935b7a4..000000000
--- a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_8_MouseJoint/Box.pde
+++ /dev/null
@@ -1,88 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// A rectangular box
-
-class Box {
-
- // We need to keep track of a Body and a width and height
- Body body;
- float w;
- float h;
-
- // Constructor
- Box(float x_, float y_) {
- float x = x_;
- float y = y_;
- w = 24;
- h = 24;
- // Add the box to the box2d world
- makeBody(new Vec2(x,y),w,h);
- }
-
- // This function removes the particle from the box2d world
- void killBody() {
- box2d.destroyBody(body);
- }
-
- boolean contains(float x, float y) {
- Vec2 worldPoint = box2d.coordPixelsToWorld(x, y);
- Fixture f = body.getFixtureList();
- boolean inside = f.testPoint(worldPoint);
- return inside;
- }
-
- // Drawing the box
- void display() {
- // We look at each body and get its screen position
- Vec2 pos = box2d.getBodyPixelCoord(body);
- // Get its angle of rotation
- float a = body.getAngle();
-
- rectMode(PConstants.CENTER);
- pushMatrix();
- translate(pos.x,pos.y);
- rotate(a);
- fill(127);
- stroke(0);
- strokeWeight(2);
- rect(0,0,w,h);
- popMatrix();
- }
-
-
- // This function adds the rectangle to the box2d world
- void makeBody(Vec2 center, float w_, float h_) {
- // Define and create the body
- BodyDef bd = new BodyDef();
- bd.type = BodyType.DYNAMIC;
- bd.position.set(box2d.coordPixelsToWorld(center));
- body = box2d.createBody(bd);
-
- // Define a polygon (this is what we use for a rectangle)
- PolygonShape sd = new PolygonShape();
- float box2dW = box2d.scalarPixelsToWorld(w_/2);
- float box2dH = box2d.scalarPixelsToWorld(h_/2);
- sd.setAsBox(box2dW, box2dH);
-
- // Define a fixture
- FixtureDef fd = new FixtureDef();
- fd.shape = sd;
- // Parameters that affect physics
- fd.density = 1;
- fd.friction = 0.3;
- fd.restitution = 0.5;
-
- body.createFixture(fd);
- //body.setMassFromShapes();
-
- // Give it some initial random velocity
- body.setLinearVelocity(new Vec2(random(-5, 5), random(2, 5)));
- body.setAngularVelocity(random(-5, 5));
- }
-
-}
-
-
-
diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_8_MouseJoint/NOC_5_8_MouseJoint.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_8_MouseJoint/NOC_5_8_MouseJoint.pde
deleted file mode 100644
index 0d77536d6..000000000
--- a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_8_MouseJoint/NOC_5_8_MouseJoint.pde
+++ /dev/null
@@ -1,83 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Basic example of controlling an object with the mouse (by attaching a spring)
-
-import pbox2d.*;
-import org.jbox2d.common.*;
-import org.jbox2d.dynamics.joints.*;
-import org.jbox2d.collision.shapes.*;
-import org.jbox2d.collision.shapes.Shape;
-import org.jbox2d.common.*;
-import org.jbox2d.dynamics.*;
-
-// A reference to our box2d world
-PBox2D box2d;
-
-// A list we'll use to track fixed objects
-ArrayList boundaries;
-
-// Just a single box this time
-Box box;
-
-// The Spring that will attach to the box from the mouse
-Spring spring;
-
-void setup() {
- size(640,360);
- // Initialize box2d physics and create the world
- box2d = new PBox2D(this);
- box2d.createWorld();
-
- // Make the box
- box = new Box(width/2,height/2);
-
- // Make the spring (it doesn't really get initialized until the mouse is clicked)
- spring = new Spring();
-
- // Add a bunch of fixed boundaries
- boundaries = new ArrayList();
- boundaries.add(new Boundary(width/2,height-5,width,10,0));
- boundaries.add(new Boundary(width/2,5,width,10,0));
- boundaries.add(new Boundary(width-5,height/2,10,height,0));
- boundaries.add(new Boundary(5,height/2,10,height,0));
-}
-
-// When the mouse is released we're done with the spring
-void mouseReleased() {
- spring.destroy();
-}
-
-// When the mouse is pressed we. . .
-void mousePressed() {
- // Check to see if the mouse was clicked on the box
- if (box.contains(mouseX, mouseY)) {
- // And if so, bind the mouse location to the box with a spring
- spring.bind(mouseX,mouseY,box);
- }
-}
-
-void draw() {
- background(255);
-
- // We must always step through time!
- box2d.step();
-
- // Always alert the spring to the new mouse location
- spring.update(mouseX,mouseY);
-
- // Draw the boundaries
- for (int i = 0; i < boundaries.size(); i++) {
- Boundary wall = (Boundary) boundaries.get(i);
- wall.display();
- }
-
- // Draw the box
- box.display();
- // Draw the spring (it only appears when active)
- spring.display();
-}
-
-
-
diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_8_MouseJoint/Spring.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_8_MouseJoint/Spring.pde
deleted file mode 100644
index 4daa97765..000000000
--- a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_8_MouseJoint/Spring.pde
+++ /dev/null
@@ -1,77 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Class to describe the spring joint (displayed as a line)
-
-class Spring {
-
- // This is the box2d object we need to create
- MouseJoint mouseJoint;
-
- Spring() {
- // At first it doesn't exist
- mouseJoint = null;
- }
-
- // If it exists we set its target to the mouse location
- void update(float x, float y) {
- if (mouseJoint != null) {
- // Always convert to world coordinates!
- Vec2 mouseWorld = box2d.coordPixelsToWorld(x,y);
- mouseJoint.setTarget(mouseWorld);
- }
- }
-
- void display() {
- if (mouseJoint != null) {
- // We can get the two anchor points
- Vec2 v1 = new Vec2(0,0);
- mouseJoint.getAnchorA(v1);
- Vec2 v2 = new Vec2(0,0);
- mouseJoint.getAnchorB(v2);
- // Convert them to screen coordinates
- v1 = box2d.coordWorldToPixels(v1);
- v2 = box2d.coordWorldToPixels(v2);
- // And just draw a line
- stroke(0);
- strokeWeight(1);
- line(v1.x,v1.y,v2.x,v2.y);
- }
- }
-
-
- // This is the key function where
- // we attach the spring to an x,y location
- // and the Box object's location
- void bind(float x, float y, Box box) {
- // Define the joint
- MouseJointDef md = new MouseJointDef();
- // Body A is just a fake ground body for simplicity (there isn't anything at the mouse)
- md.bodyA = box2d.getGroundBody();
- // Body 2 is the box's boxy
- md.bodyB = box.body;
- // Get the mouse location in world coordinates
- Vec2 mp = box2d.coordPixelsToWorld(x,y);
- // And that's the target
- md.target.set(mp);
- // Some stuff about how strong and bouncy the spring should be
- md.maxForce = 1000.0 * box.body.m_mass;
- md.frequencyHz = 5.0;
- md.dampingRatio = 0.9;
-
- // Make the joint!
- mouseJoint = (MouseJoint) box2d.world.createJoint(md);
- }
-
- void destroy() {
- // We can get rid of the joint when the mouse is released
- if (mouseJoint != null) {
- box2d.world.destroyJoint(mouseJoint);
- mouseJoint = null;
- }
- }
-
-}
-
-
diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_9_CollisionListening/Boundary.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_9_CollisionListening/Boundary.pde
deleted file mode 100644
index ff6226252..000000000
--- a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_9_CollisionListening/Boundary.pde
+++ /dev/null
@@ -1,55 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// A fixed boundary class
-
-class Boundary {
-
- // A boundary is a simple rectangle with x,y,width,and height
- float x;
- float y;
- float w;
- float h;
-
- // But we also have to make a body for box2d to know about it
- Body b;
-
- Boundary(float x_,float y_, float w_, float h_) {
- x = x_;
- y = y_;
- w = w_;
- h = h_;
-
- // Define the polygon
- PolygonShape sd = new PolygonShape();
- // Figure out the box2d coordinates
- float box2dW = box2d.scalarPixelsToWorld(w/2);
- float box2dH = box2d.scalarPixelsToWorld(h/2);
- // We're just a box
- sd.setAsBox(box2dW, box2dH);
-
-
- // Create the body
- BodyDef bd = new BodyDef();
- bd.type = BodyType.STATIC;
- bd.position.set(box2d.coordPixelsToWorld(x,y));
- b = box2d.createBody(bd);
-
- // Attached the shape to the body using a Fixture
- b.createFixture(sd,1);
-
- b.setUserData(this);
- }
-
- // Draw the boundary, if it were at an angle we'd have to do something fancier
- void display() {
- fill(0);
- stroke(0);
- rectMode(CENTER);
- rect(x,y,w,h);
- }
-
-}
-
-
diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_9_CollisionListening/NOC_5_9_CollisionListening.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_9_CollisionListening/NOC_5_9_CollisionListening.pde
deleted file mode 100644
index c4b1688c7..000000000
--- a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_9_CollisionListening/NOC_5_9_CollisionListening.pde
+++ /dev/null
@@ -1,108 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Basic example of controlling an object with our own motion (by attaching a MouseJoint)
-// Also demonstrates how to know which object was hit
-
-import pbox2d.*;
-import org.jbox2d.common.*;
-import org.jbox2d.dynamics.joints.*;
-import org.jbox2d.collision.shapes.*;
-import org.jbox2d.collision.shapes.Shape;
-import org.jbox2d.common.*;
-import org.jbox2d.dynamics.*;
-import org.jbox2d.dynamics.contacts.*;
-
-// A reference to our box2d world
-PBox2D box2d;
-
-// An ArrayList of particles that will fall on the surface
-ArrayList particles;
-
-Boundary wall;
-
-void setup() {
- size(640, 360);
- // Initialize box2d physics and create the world
- box2d = new PBox2D(this);
- box2d.createWorld();
-
- // Turn on collision listening!
- box2d.listenForCollisions();
-
- // Create the empty list
- particles = new ArrayList();
-
- wall = new Boundary(width/2, height-5, width, 10);
-}
-
-void draw() {
- background(255);
-
- if (random(1) < 0.1) {
- float sz = random(4, 8);
- particles.add(new Particle(random(width), 20, sz));
- }
-
-
- // We must always step through time!
- box2d.step();
-
- // Look at all particles
- for (int i = particles.size()-1; i >= 0; i--) {
- Particle p = particles.get(i);
- p.display();
- // Particles that leave the screen, we delete them
- // (note they have to be deleted from both the box2d world and our list
- if (p.done()) {
- particles.remove(i);
- }
- }
-
- wall.display();
-}
-
-
-// Collision event functions!
-void beginContact(Contact cp) {
- // Get both fixtures
- Fixture f1 = cp.getFixtureA();
- Fixture f2 = cp.getFixtureB();
- // Get both bodies
- Body b1 = f1.getBody();
- Body b2 = f2.getBody();
-
- // Get our objects that reference these bodies
- Object o1 = b1.getUserData();
- Object o2 = b2.getUserData();
-
- if (o1.getClass() == Particle.class && o2.getClass() == Particle.class) {
- Particle p1 = (Particle) o1;
- p1.change();
- Particle p2 = (Particle) o2;
- p2.change();
- }
-
-}
-
-// Objects stop touching each other
-void endContact(Contact cp) {
-}
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_9_CollisionListening/Particle.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_9_CollisionListening/Particle.pde
deleted file mode 100644
index 6d3bf38d5..000000000
--- a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/NOC_5_9_CollisionListening/Particle.pde
+++ /dev/null
@@ -1,90 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// A circular particle
-
-class Particle {
-
- // We need to keep track of a Body and a radius
- Body body;
- float r;
-
- color col;
-
- Particle(float x, float y, float r_) {
- r = r_;
- // This function puts the particle in the Box2d world
- makeBody(x, y, r);
- body.setUserData(this);
- col = color(127);
- }
-
- // This function removes the particle from the box2d world
- void killBody() {
- box2d.destroyBody(body);
- }
-
- // Change color when hit
- void change() {
- col = color(255, 0, 0);
- }
-
- // Is the particle ready for deletion?
- boolean done() {
- // Let's find the screen position of the particle
- Vec2 pos = box2d.getBodyPixelCoord(body);
- // Is it off the bottom of the screen?
- if (pos.y > height+r*2) {
- killBody();
- return true;
- }
- return false;
- }
-
-
- //
- void display() {
- // We look at each body and get its screen position
- Vec2 pos = box2d.getBodyPixelCoord(body);
- // Get its angle of rotation
- float a = body.getAngle();
- pushMatrix();
- translate(pos.x, pos.y);
- rotate(a);
- fill(col);
- stroke(0);
- strokeWeight(2);
- ellipse(0, 0, r*2, r*2);
- // Let's add a line so we can see the rotation
- line(0, 0, r, 0);
- popMatrix();
- }
-
- // Here's our function that adds the particle to the Box2D world
- void makeBody(float x, float y, float r) {
- // Define a body
- BodyDef bd = new BodyDef();
- // Set its position
- bd.position = box2d.coordPixelsToWorld(x, y);
- bd.type = BodyType.DYNAMIC;
- body = box2d.createBody(bd);
-
- // Make the body's shape a circle
- CircleShape cs = new CircleShape();
- cs.m_radius = box2d.scalarPixelsToWorld(r);
-
- FixtureDef fd = new FixtureDef();
- fd.shape = cs;
- // Parameters that affect physics
- fd.density = 1;
- fd.friction = 0.01;
- fd.restitution = 0.3;
-
- // Attach fixture to body
- body.createFixture(fd);
-
- body.setAngularVelocity(random(-10, 10));
- }
-}
-
diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/VectorStuff/VectorStuff.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/VectorStuff/VectorStuff.pde
deleted file mode 100644
index 49345575d..000000000
--- a/java/examples/Books/Nature of Code/chp5_physicslibraries/box2d/VectorStuff/VectorStuff.pde
+++ /dev/null
@@ -1,56 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Just demo-ing the basics of Vec2 vs. PVector
-
-import org.jbox2d.common.*;
-
-void setup() {
- size(400,300);
-// PVector a = new PVector(1,-1);
-// PVector b = new PVector(3,4);
-// a.add(b);
-//
-// PVector a = new PVector(1,-1);
-// PVector b = new PVector(3,4);
-// PVector c = PVector.add(a,b);
-//
-// Vec2 a = new Vec2(1,-1);
-// Vec2 b = new Vec2(3,4);
-// a.addLocal(b);
-//
-// Vec2 a = new Vec2(1,-1);
-// Vec2 b = new Vec2(3,4);
-// Vec2 c = a.add(b);
-//
-// PVector a = new PVector(1,-1);
-// float n = 5;
-// a.mult(n);
-//
-// PVector a = new PVector(1,-1);
-// float n = 5;
-// PVector c = PVector.mult(a,n);
-//
-// Vec2 a = new Vec2(1,-1);
-// float n = 5;
-// a.mulLocal(n);
-//
-// Vec2 a = new Vec2(1,-1);
-// float n = 5;
-// Vec2 c = a.mul(n);
-//
-// PVector a = new PVector(1,-1);
-// float m = a.mag();
-// a.normalize();
-
- Vec2 a = new Vec2(1,-1);
- float m = a.length();
- a.normalize();
- println(a.x + "," + a.y);
-}
-
-void draw() {
- noLoop();
-}
-
diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/readme.txt b/java/examples/Books/Nature of Code/chp5_physicslibraries/readme.txt
deleted file mode 100644
index 99d3a27ad..000000000
--- a/java/examples/Books/Nature of Code/chp5_physicslibraries/readme.txt
+++ /dev/null
@@ -1,3 +0,0 @@
-For the box2d examples you will need PBox2D!
-
-https://github.com/shiffman/PBox2D
\ No newline at end of file
diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/toxiclibs/Exercise_5_13_SoftBodySquareAdapted/Blanket.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/toxiclibs/Exercise_5_13_SoftBodySquareAdapted/Blanket.pde
deleted file mode 100644
index 1efcdb2ef..000000000
--- a/java/examples/Books/Nature of Code/chp5_physicslibraries/toxiclibs/Exercise_5_13_SoftBodySquareAdapted/Blanket.pde
+++ /dev/null
@@ -1,55 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-class Blanket {
- ArrayList particles;
- ArrayList springs;
-
- Blanket() {
- particles = new ArrayList();
- springs = new ArrayList();
-
- int w = 20;
- int h = 20;
-
- float len = 10;
- float strength = 0.125;
-
- for(int y=0; y< h; y++) {
- for(int x=0; x < w; x++) {
-
- Particle p = new Particle(new Vec2D(width/2+x*len-w*len/2,y*len));
- physics.addParticle(p);
- particles.add(p);
-
- if (x > 0) {
- Particle previous = particles.get(particles.size()-2);
- Connection c = new Connection(p,previous,len,strength);
- physics.addSpring(c);
- springs.add(c);
- }
-
- if (y > 0) {
- Particle above = particles.get(particles.size()-w-1);
- Connection c=new Connection(p,above,len,strength);
- physics.addSpring(c);
- springs.add(c);
- }
- }
- }
-
- Particle topleft= particles.get(0);
- topleft.lock();
-
- Particle topright = particles.get(w-1);
- topright.lock();
- }
-
- void display() {
- for (Connection c : springs) {
- c.display();
- }
- }
-}
-
diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/toxiclibs/Exercise_5_13_SoftBodySquareAdapted/Connection.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/toxiclibs/Exercise_5_13_SoftBodySquareAdapted/Connection.pde
deleted file mode 100644
index bbbe2655c..000000000
--- a/java/examples/Books/Nature of Code/chp5_physicslibraries/toxiclibs/Exercise_5_13_SoftBodySquareAdapted/Connection.pde
+++ /dev/null
@@ -1,15 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-class Connection extends VerletSpring2D {
- Connection(Particle p1, Particle p2, float len, float strength) {
- super(p1,p2,len,strength);
- }
-
- void display() {
- stroke(0);
- line(a.x,a.y,b.x,b.y);
- }
-}
-
diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/toxiclibs/Exercise_5_13_SoftBodySquareAdapted/Exercise_5_13_SoftBodySquareAdapted.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/toxiclibs/Exercise_5_13_SoftBodySquareAdapted/Exercise_5_13_SoftBodySquareAdapted.pde
deleted file mode 100644
index cf2b469c7..000000000
--- a/java/examples/Books/Nature of Code/chp5_physicslibraries/toxiclibs/Exercise_5_13_SoftBodySquareAdapted/Exercise_5_13_SoftBodySquareAdapted.pde
+++ /dev/null
@@ -1,64 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-/**
- * This example is adapted from Karsten Schmidt's SoftBodySquare example
- */
-
-/*
Softbody square demo is showing how to create a 2D square mesh out of
- * verlet particles and make it stable enough to avoid total structural
- * deformation by including an inner skeleton.
- *
- *
Usage: move mouse to drag/deform the square
- */
-
-/*
- * Copyright (c) 2008-2009 Karsten Schmidt
- *
- * This demo & library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * http://creativecommons.org/licenses/LGPL/2.1/
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-
-import toxi.physics2d.behaviors.*;
-import toxi.physics2d.*;
-
-import toxi.geom.*;
-import toxi.math.*;
-
-VerletPhysics2D physics;
-
-Blanket b;
-
-
-void setup() {
- size(640,360);
- physics=new VerletPhysics2D();
- physics.addBehavior(new GravityBehavior(new Vec2D(0,0.1)));
-
- b = new Blanket();
-}
-
-void draw() {
-
- background(255);
-
- physics.update();
-
- b.display();
-}
-
diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/toxiclibs/Exercise_5_13_SoftBodySquareAdapted/Particle.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/toxiclibs/Exercise_5_13_SoftBodySquareAdapted/Particle.pde
deleted file mode 100644
index c4fef5474..000000000
--- a/java/examples/Books/Nature of Code/chp5_physicslibraries/toxiclibs/Exercise_5_13_SoftBodySquareAdapted/Particle.pde
+++ /dev/null
@@ -1,21 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Notice how we are using inheritance here!
-// We could have just stored a reference to a VerletParticle object
-// inside the Particle class, but inheritance is a nice alternative
-
-class Particle extends VerletParticle2D {
-
- Particle(Vec2D loc) {
- super(loc);
- }
-
- // All we're doing really is adding a display() function to a VerletParticle
- void display() {
- fill(175);
- stroke(0);
- ellipse(x,y,16,16);
- }
-}
diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/toxiclibs/Exercise_5_15_ForceDirectedGraph/Cluster.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/toxiclibs/Exercise_5_15_ForceDirectedGraph/Cluster.pde
deleted file mode 100644
index db0cfe2c2..000000000
--- a/java/examples/Books/Nature of Code/chp5_physicslibraries/toxiclibs/Exercise_5_15_ForceDirectedGraph/Cluster.pde
+++ /dev/null
@@ -1,98 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Force directed graph
-// Heavily based on: http://code.google.com/p/fidgen/
-
-class Cluster {
-
- // A cluster is a grouping of nodes
- ArrayList nodes;
-
- float diameter;
-
- // We initialize a Cluster with a number of nodes, a diameter, and centerpoint
- Cluster(int n, float d, Vec2D center) {
-
- // Initialize the ArrayList
- nodes = new ArrayList();
-
- // Set the diameter
- diameter = d;
-
- // Create the nodes
- for (int i = 0; i < n; i++) {
- // We can't put them right on top of each other
- nodes.add(new Node(center.add(Vec2D.randomVector())));
- }
-
- // Connect all the nodes with a Spring
- for (int i = 1; i < nodes.size(); i++) {
- VerletParticle2D pi = (VerletParticle2D) nodes.get(i);
- for (int j = 0; j < i; j++) {
- VerletParticle2D pj = (VerletParticle2D) nodes.get(j);
- // A Spring needs two particles, a resting length, and a strength
- physics.addSpring(new VerletSpring2D(pi,pj,diameter,0.01));
- }
- }
- }
-
- void display() {
- // Show all the nodes
- for (int i = 0; i < nodes.size(); i++) {
- Node n = (Node) nodes.get(i);
- n.display();
- }
- }
-
- // This functons connects one cluster to another
- // Each point of one cluster connects to each point of the other cluster
- // The connection is a "VerletMinDistanceSpring"
- // A VerletMinDistanceSpring is a string which only enforces its rest length if the
- // current distance is less than its rest length. This is handy if you just want to
- // ensure objects are at least a certain distance from each other, but don't
- // care if it's bigger than the enforced minimum.
- void connect(Cluster other) {
- ArrayList otherNodes = other.getNodes();
- for (int i = 0; i < nodes.size(); i++) {
- VerletParticle2D pi = (VerletParticle2D) nodes.get(i);
- for (int j = 0; j < otherNodes.size(); j++) {
- VerletParticle2D pj = (VerletParticle2D) otherNodes.get(j);
- // Create the spring
- physics.addSpring(new VerletMinDistanceSpring2D(pi,pj,(diameter+other.diameter)*0.5,0.05));
- }
- }
- }
-
-
- // Draw all the internal connections
- void showConnections() {
- stroke(0,150);
- for (int i = 0; i < nodes.size(); i++) {
- VerletParticle2D pi = (VerletParticle2D) nodes.get(i);
- for (int j = i+1; j < nodes.size(); j++) {
- VerletParticle2D pj = (VerletParticle2D) nodes.get(j);
- line(pi.x,pi.y,pj.x,pj.y);
- }
- }
- }
-
- // Draw all the connections between this Cluster and another Cluster
- void showConnections(Cluster other) {
- stroke(0,50);
- strokeWeight(2);
- ArrayList otherNodes = other.getNodes();
- for (int i = 0; i < nodes.size(); i++) {
- VerletParticle2D pi = (VerletParticle2D) nodes.get(i);
- for (int j = 0; j < otherNodes.size(); j++) {
- VerletParticle2D pj = (VerletParticle2D) otherNodes.get(j);
- line(pi.x,pi.y,pj.x,pj.y);
- }
- }
- }
-
- ArrayList getNodes() {
- return nodes;
- }
-}
diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/toxiclibs/Exercise_5_15_ForceDirectedGraph/Exercise_5_15_ForceDirectedGraph.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/toxiclibs/Exercise_5_15_ForceDirectedGraph/Exercise_5_15_ForceDirectedGraph.pde
deleted file mode 100644
index f3dd8e190..000000000
--- a/java/examples/Books/Nature of Code/chp5_physicslibraries/toxiclibs/Exercise_5_15_ForceDirectedGraph/Exercise_5_15_ForceDirectedGraph.pde
+++ /dev/null
@@ -1,133 +0,0 @@
-/**
- *
- */
-
-/*
- * Copyright (c) 2010 Daniel Shiffman
- *
- * This demo & library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * http://creativecommons.org/licenses/LGPL/2.1/
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-import toxi.geom.*;
-import toxi.physics2d.*;
-import toxi.physics2d.behaviors.*;
-
-// Reference to physics world
-VerletPhysics2D physics;
-
-// A list of cluster objects
-ArrayList clusters;
-
-// Boolean that indicates whether we draw connections or not
-boolean showPhysics = true;
-boolean showParticles = true;
-
-// Font
-PFont f;
-
-void setup() {
- size(640,360);
- f = createFont("Georgia",12,true);
-
- // Initialize the physics
- physics=new VerletPhysics2D();
- physics.setWorldBounds(new Rect(10,10,width-20,height-20));
-
- // Spawn a new random graph
- newGraph();
-
-}
-
-// Spawn a new random graph
-void newGraph() {
-
- // Clear physics
- physics.clear();
-
- // Create new ArrayList (clears old one)
- clusters = new ArrayList();
-
- // Create 8 random clusters
- for (int i = 0; i < 8; i++) {
- Vec2D center = new Vec2D(width/2,height/2);
- clusters.add(new Cluster((int) random(3,8),random(20,100),center));
- }
-
- // All clusters connect to all clusters
- for (int i = 0; i < clusters.size(); i++) {
- for (int j = i+1; j < clusters.size(); j++) {
- Cluster ci = (Cluster) clusters.get(i);
- Cluster cj = (Cluster) clusters.get(j);
- ci.connect(cj);
- }
- }
-
-}
-
-void draw() {
-
- // Update the physics world
- physics.update();
-
- background(255);
-
- // Display all points
- if (showParticles) {
- for (int i = 0; i < clusters.size(); i++) {
- Cluster c = (Cluster) clusters.get(i);
- c.display();
- }
- }
-
- // If we want to see the physics
- if (showPhysics) {
- for (int i = 0; i < clusters.size(); i++) {
- // Cluster internal connections
- Cluster ci = (Cluster) clusters.get(i);
- ci.showConnections();
-
- // Cluster connections to other clusters
- for (int j = i+1; j < clusters.size(); j++) {
- Cluster cj = (Cluster) clusters.get(j);
- ci.showConnections(cj);
- }
- }
- }
-
- // Instructions
- fill(0);
- textFont(f);
- text("'p' to display or hide particles\n'c' to display or hide connections\n'n' for new graph",10,20);
-}
-
-// Key press commands
-void keyPressed() {
- if (key == 'c') {
- showPhysics = !showPhysics;
- if (!showPhysics) showParticles = true;
- }
- else if (key == 'p') {
- showParticles = !showParticles;
- if (!showParticles) showPhysics = true;
- }
- else if (key == 'n') {
- newGraph();
- }
-}
diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/toxiclibs/Exercise_5_15_ForceDirectedGraph/Node.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/toxiclibs/Exercise_5_15_ForceDirectedGraph/Node.pde
deleted file mode 100644
index 54dc835b4..000000000
--- a/java/examples/Books/Nature of Code/chp5_physicslibraries/toxiclibs/Exercise_5_15_ForceDirectedGraph/Node.pde
+++ /dev/null
@@ -1,26 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Force directed graph
-// Heavily based on: http://code.google.com/p/fidgen/
-
-// Notice how we are using inheritance here!
-// We could have just stored a reference to a VerletParticle object
-// inside the Node class, but inheritance is a nice alternative
-
-class Node extends VerletParticle2D {
-
- Node(Vec2D pos) {
- super(pos);
- }
-
- // All we're doing really is adding a display() function to a VerletParticle
- void display() {
- fill(0,150);
- stroke(0);
- strokeWeight(2);
- ellipse(x,y,16,16);
- }
-}
-
diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/toxiclibs/NOC_5_10_SimpleSpring/NOC_5_10_SimpleSpring.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/toxiclibs/NOC_5_10_SimpleSpring/NOC_5_10_SimpleSpring.pde
deleted file mode 100644
index eeaaf48e0..000000000
--- a/java/examples/Books/Nature of Code/chp5_physicslibraries/toxiclibs/NOC_5_10_SimpleSpring/NOC_5_10_SimpleSpring.pde
+++ /dev/null
@@ -1,68 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Simple Toxiclibs Spring
-
-import toxi.physics2d.*;
-import toxi.physics2d.behaviors.*;
-import toxi.geom.*;
-
-// Reference to physics world
-VerletPhysics2D physics;
-
-Particle p1;
-Particle p2;
-
-void setup() {
- size(640,360);
-
- // Initialize the physics
- physics=new VerletPhysics2D();
- physics.addBehavior(new GravityBehavior(new Vec2D(0,0.5)));
-
- // Set the world's bounding box
- physics.setWorldBounds(new Rect(0,0,width,height));
-
- // Make two particles
- p1 = new Particle(new Vec2D(width/2,20));
- p2 = new Particle(new Vec2D(width/2+160,20));
- // Lock one in place
- p1.lock();
-
- // Make a spring connecting both Particles
- VerletSpring2D spring=new VerletSpring2D(p1,p2,160,0.01);
-
- // Anything we make, we have to add into the physics world
- physics.addParticle(p1);
- physics.addParticle(p2);
- physics.addSpring(spring);
-}
-
-void draw() {
-
- // Update the physics world
- physics.update();
-
- background(255);
-
- // Draw a line between the particles
- stroke(0);
- strokeWeight(2);
- line(p1.x,p1.y,p2.x,p2.y);
-
- // Display the particles
- p1.display();
- p2.display();
-
- // Move the second one according to the mouse
- if (mousePressed) {
- p2.lock();
- p2.x = mouseX;
- p2.y = mouseY;
- p2.unlock();
- }
-}
-
-
-
diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/toxiclibs/NOC_5_10_SimpleSpring/Particle.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/toxiclibs/NOC_5_10_SimpleSpring/Particle.pde
deleted file mode 100644
index 06bb533dc..000000000
--- a/java/examples/Books/Nature of Code/chp5_physicslibraries/toxiclibs/NOC_5_10_SimpleSpring/Particle.pde
+++ /dev/null
@@ -1,22 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-// Notice how we are using inheritance here!
-
-// We could have just stored a reference to a VerletParticle object
-// inside the Particle class, but inheritance is a nice alternative
-
-class Particle extends VerletParticle2D {
-
- Particle(Vec2D loc) {
- super(loc);
- }
-
- // All we're doing really is adding a display() function to a VerletParticle
- void display() {
- fill(127);
- stroke(0);
- strokeWeight(2);
- ellipse(x,y,32,32);
- }
-}
diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/toxiclibs/NOC_5_11_SoftStringPendulum/Chain.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/toxiclibs/NOC_5_11_SoftStringPendulum/Chain.pde
deleted file mode 100644
index 91b68c9b6..000000000
--- a/java/examples/Books/Nature of Code/chp5_physicslibraries/toxiclibs/NOC_5_11_SoftStringPendulum/Chain.pde
+++ /dev/null
@@ -1,103 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// A soft pendulum (series of connected springs)
-
-class Chain {
-
- // Chain properties
- float totalLength; // How long
- int numPoints; // How many points
- float strength; // Strength of springs
- float radius; // Radius of ball at tail
-
- // This list is redundant since we can ask for physics.particles, but in case we have many of these
- // it's a convenient to keep track of our own list
- ArrayList particles;
-
- // Let's keep an extra reference to the tail particle
- // This is just the last particle in the ArrayList
- Particle tail;
-
- // Some variables for mouse dragging
- PVector offset = new PVector();
- boolean dragged = false;
-
- // Chain constructor
- Chain(float l, int n, float r, float s) {
- particles = new ArrayList();
-
- totalLength = l;
- numPoints = n;
- radius = r;
- strength = s;
-
- float len = totalLength / numPoints;
-
- // Here is the real work, go through and add particles to the chain itself
- for(int i=0; i < numPoints; i++) {
- // Make a new particle with an initial starting location
- Particle particle=new Particle(width/2,i*len);
-
- // Redundancy, we put the particles both in physics and in our own ArrayList
- physics.addParticle(particle);
- particles.add(particle);
-
- // Connect the particles with a Spring (except for the head)
- if (i != 0) {
- Particle previous = particles.get(i-1);
- VerletSpring2D spring = new VerletSpring2D(particle,previous,len,strength);
- // Add the spring to the physics world
- physics.addSpring(spring);
- }
- }
-
- // Keep the top fixed
- Particle head=particles.get(0);
- head.lock();
-
- // Store reference to the tail
- tail = particles.get(numPoints-1);
- tail.radius = radius;
- }
-
- // Check if a point is within the ball at the end of the chain
- // If so, set dragged = true;
- void contains(int x, int y) {
- float d = dist(x,y,tail.x,tail.y);
- if (d < radius) {
- offset.x = tail.x - x;
- offset.y = tail.y - y;
- tail.lock();
- dragged = true;
- }
- }
-
- // Release the ball
- void release() {
- tail.unlock();
- dragged = false;
- }
-
- // Update tail location if being dragged
- void updateTail(int x, int y) {
- if (dragged) {
- tail.set(x+offset.x,y+offset.y);
- }
- }
-
- // Draw the chain
- void display() {
- // Draw line connecting all points
- beginShape();
- stroke(0);
- strokeWeight(2);
- noFill();
- for (Particle p : particles) {
- vertex(p.x,p.y);
- }
- endShape();
- tail.display();
- }
-}
diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/toxiclibs/NOC_5_11_SoftStringPendulum/NOC_5_11_SoftStringPendulum.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/toxiclibs/NOC_5_11_SoftStringPendulum/NOC_5_11_SoftStringPendulum.pde
deleted file mode 100644
index 1e9b6aa25..000000000
--- a/java/examples/Books/Nature of Code/chp5_physicslibraries/toxiclibs/NOC_5_11_SoftStringPendulum/NOC_5_11_SoftStringPendulum.pde
+++ /dev/null
@@ -1,68 +0,0 @@
-/**
- *
A soft pendulum (series of connected springs)
- * The Nature of Code
- * Spring 2010
- */
-
-/*
- * Copyright (c) 2010 Daniel Shiffman
- *
- * This demo & library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * http://creativecommons.org/licenses/LGPL/2.1/
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-import toxi.physics2d.*;
-import toxi.physics2d.behaviors.*;
-import toxi.geom.*;
-
-// Reference to physics "world" (2D)
-VerletPhysics2D physics;
-
-// Our "Chain" object
-Chain chain;
-
-void setup() {
- size(640, 360);
- // Initialize the physics world
- physics=new VerletPhysics2D();
- physics.addBehavior(new GravityBehavior(new Vec2D(0, 0.1)));
- physics.setWorldBounds(new Rect(0, 0, width, height));
-
- // Initialize the chain
- chain = new Chain(180, 20, 16, 0.2);
-}
-
-void draw() {
- background(255);
-
- // Update physics
- physics.update();
- // Update chain's tail according to mouse location
- chain.updateTail(mouseX, mouseY);
- // Display chain
- chain.display();
-}
-
-void mousePressed() {
- // Check to see if we're grabbing the chain
- chain.contains(mouseX, mouseY);
-}
-
-void mouseReleased() {
- // Release the chain
- chain.release();
-}
-
diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/toxiclibs/NOC_5_11_SoftStringPendulum/Particle.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/toxiclibs/NOC_5_11_SoftStringPendulum/Particle.pde
deleted file mode 100644
index 99ca7dac3..000000000
--- a/java/examples/Books/Nature of Code/chp5_physicslibraries/toxiclibs/NOC_5_11_SoftStringPendulum/Particle.pde
+++ /dev/null
@@ -1,24 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Notice how we are using inheritance here!
-// We could have just stored a reference to a VerletParticle object
-// inside the Particle class, but inheritance is a nice alternative
-
-class Particle extends VerletParticle2D {
-
- float radius = 4; // Adding a radius for each particle
-
- Particle(float x, float y) {
- super(x,y);
- }
-
- // All we're doing really is adding a display() function to a VerletParticle
- void display() {
- fill(127);
- stroke(0);
- strokeWeight(2);
- ellipse(x,y,radius*2,radius*2);
- }
-}
diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/toxiclibs/NOC_5_12_SimpleCluster/Cluster.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/toxiclibs/NOC_5_12_SimpleCluster/Cluster.pde
deleted file mode 100644
index 241520f2b..000000000
--- a/java/examples/Books/Nature of Code/chp5_physicslibraries/toxiclibs/NOC_5_12_SimpleCluster/Cluster.pde
+++ /dev/null
@@ -1,64 +0,0 @@
-// The Nature of Code
-//
-// Spring 2010
-// Toxiclibs example: http://toxiclibs.org/
-
-// Force directed graph
-// Heavily based on: http://code.google.com/p/fidgen/
-
-class Cluster {
-
- // A cluster is a grouping of nodes
- ArrayList nodes;
-
- float diameter;
-
- // We initialize a Cluster with a number of nodes, a diameter, and centerpoint
- Cluster(int n, float d, Vec2D center) {
-
- // Initialize the ArrayList
- nodes = new ArrayList();
-
- // Set the diameter
- diameter = d;
-
- // Create the nodes
- for (int i = 0; i < n; i++) {
- // We can't put them right on top of each other
- nodes.add(new Node(center.add(Vec2D.randomVector())));
- }
-
- // Connect all the nodes with a Spring
- for (int i = 0; i < nodes.size()-1; i++) {
- VerletParticle2D ni = nodes.get(i);
- for (int j = i+1; j < nodes.size(); j++) {
- VerletParticle2D nj = nodes.get(j);
- // A Spring needs two particles, a resting length, and a strength
- physics.addSpring(new VerletSpring2D(ni, nj, diameter, 0.01));
- }
- }
- }
-
- void display() {
- // Show all the nodes
- for (Node n : nodes) {
- n.display();
- }
- }
-
-
- // Draw all the internal connections
- void showConnections() {
- stroke(0, 150);
- strokeWeight(2);
- for (int i = 0; i < nodes.size()-1; i++) {
- VerletParticle2D pi = (VerletParticle2D) nodes.get(i);
- for (int j = i+1; j < nodes.size(); j++) {
- VerletParticle2D pj = (VerletParticle2D) nodes.get(j);
-
- line(pi.x, pi.y, pj.x, pj.y);
- }
- }
- }
-}
-
diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/toxiclibs/NOC_5_12_SimpleCluster/NOC_5_12_SimpleCluster.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/toxiclibs/NOC_5_12_SimpleCluster/NOC_5_12_SimpleCluster.pde
deleted file mode 100644
index 043803d67..000000000
--- a/java/examples/Books/Nature of Code/chp5_physicslibraries/toxiclibs/NOC_5_12_SimpleCluster/NOC_5_12_SimpleCluster.pde
+++ /dev/null
@@ -1,74 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Force directed graph,
-// heavily based on: http://code.google.com/p/fidgen/
-
-import toxi.geom.*;
-import toxi.physics2d.*;
-
-// Reference to physics world
-VerletPhysics2D physics;
-
-// A list of cluster objects
-Cluster cluster;
-
-// Boolean that indicates whether we draw connections or not
-boolean showPhysics = true;
-boolean showParticles = true;
-
-// Font
-PFont f;
-
-void setup() {
- size(640, 360);
- f = createFont("Georgia", 12, true);
-
- // Initialize the physics
- physics=new VerletPhysics2D();
- physics.setWorldBounds(new Rect(10, 10, width-20, height-20));
-
- // Spawn a new random graph
- cluster = new Cluster(8, 100, new Vec2D(width/2, height/2));
-}
-
-void draw() {
-
- // Update the physics world
- physics.update();
-
- background(255);
-
- // Display all points
- if (showParticles) {
- cluster.display();
- }
-
- // If we want to see the physics
- if (showPhysics) {
- cluster.showConnections();
- }
-
- // Instructions
- fill(0);
- textFont(f);
- text("'p' to display or hide particles\n'c' to display or hide connections\n'n' for new graph",10,20);
-}
-
-// Key press commands
-void keyPressed() {
- if (key == 'c') {
- showPhysics = !showPhysics;
- if (!showPhysics) showParticles = true;
- }
- else if (key == 'p') {
- showParticles = !showParticles;
- if (!showParticles) showPhysics = true;
- }
- else if (key == 'n') {
- physics.clear();
- cluster = new Cluster(int(random(2, 20)), random(10, width/2), new Vec2D(width/2, height/2));
- }
-}
-
diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/toxiclibs/NOC_5_12_SimpleCluster/Node.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/toxiclibs/NOC_5_12_SimpleCluster/Node.pde
deleted file mode 100644
index 6fe3b5144..000000000
--- a/java/examples/Books/Nature of Code/chp5_physicslibraries/toxiclibs/NOC_5_12_SimpleCluster/Node.pde
+++ /dev/null
@@ -1,27 +0,0 @@
-// The Nature of Code
-//
-// Spring 2010
-// Toxiclibs example: http://toxiclibs.org/
-
-// Force directed graph
-// Heavily based on: http://code.google.com/p/fidgen/
-
-// Notice how we are using inheritance here!
-// We could have just stored a reference to a VerletParticle object
-// inside the Node class, but inheritance is a nice alternative
-
-class Node extends VerletParticle2D {
-
- Node(Vec2D pos) {
- super(pos);
- }
-
- // All we're doing really is adding a display() function to a VerletParticle
- void display() {
- fill(0,150);
- stroke(0);
- strokeWeight(2);
- ellipse(x,y,16,16);
- }
-}
-
diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/toxiclibs/NOC_5_13_AttractRepel/Attractor.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/toxiclibs/NOC_5_13_AttractRepel/Attractor.pde
deleted file mode 100644
index 69e7ecb1d..000000000
--- a/java/examples/Books/Nature of Code/chp5_physicslibraries/toxiclibs/NOC_5_13_AttractRepel/Attractor.pde
+++ /dev/null
@@ -1,21 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-class Attractor extends VerletParticle2D {
-
- float r;
-
- Attractor (Vec2D loc) {
- super (loc);
- r = 24;
- physics.addParticle(this);
- physics.addBehavior(new AttractionBehavior(this, width, 0.1));
- }
-
- void display () {
- fill(0);
- ellipse (x, y, r*2, r*2);
- }
-}
-
diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/toxiclibs/NOC_5_13_AttractRepel/NOC_5_13_AttractRepel.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/toxiclibs/NOC_5_13_AttractRepel/NOC_5_13_AttractRepel.pde
deleted file mode 100644
index 4359d202c..000000000
--- a/java/examples/Books/Nature of Code/chp5_physicslibraries/toxiclibs/NOC_5_13_AttractRepel/NOC_5_13_AttractRepel.pde
+++ /dev/null
@@ -1,40 +0,0 @@
-import toxi.geom.*;
-import toxi.physics2d.*;
-import toxi.physics2d.behaviors.*;
-
-ArrayList particles;
-Attractor attractor;
-
-VerletPhysics2D physics;
-
-void setup () {
- size (640, 360);
- physics = new VerletPhysics2D ();
- physics.setDrag (0.01);
-
- particles = new ArrayList();
- for (int i = 0; i < 50; i++) {
- particles.add(new Particle(new Vec2D(random(width),random(height))));
- }
-
- attractor = new Attractor(new Vec2D(width/2,height/2));
-}
-
-
-void draw () {
- background (255);
- physics.update ();
-
- attractor.display();
- for (Particle p: particles) {
- p.display();
- }
-
- if (mousePressed) {
- attractor.lock();
- attractor.set(mouseX,mouseY);
- } else {
- attractor.unlock();
- }
-}
-
diff --git a/java/examples/Books/Nature of Code/chp5_physicslibraries/toxiclibs/NOC_5_13_AttractRepel/Particle.pde b/java/examples/Books/Nature of Code/chp5_physicslibraries/toxiclibs/NOC_5_13_AttractRepel/Particle.pde
deleted file mode 100644
index 8096405d4..000000000
--- a/java/examples/Books/Nature of Code/chp5_physicslibraries/toxiclibs/NOC_5_13_AttractRepel/Particle.pde
+++ /dev/null
@@ -1,24 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// class Spore extends the class "VerletParticle2D"
-class Particle extends VerletParticle2D {
-
- float r;
-
- Particle (Vec2D loc) {
- super(loc);
- r = 8;
- physics.addParticle(this);
- physics.addBehavior(new AttractionBehavior(this, r*4, -1));
- }
-
- void display () {
- fill (127);
- stroke (0);
- strokeWeight(2);
- ellipse (x, y, r*2, r*2);
- }
-}
-
diff --git a/java/examples/Books/Nature of Code/chp6_agents/Alignment/Alignment.pde b/java/examples/Books/Nature of Code/chp6_agents/Alignment/Alignment.pde
deleted file mode 100644
index 09404bbe5..000000000
--- a/java/examples/Books/Nature of Code/chp6_agents/Alignment/Alignment.pde
+++ /dev/null
@@ -1,44 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Separation
-// Via Reynolds: http://www.red3d.com/cwr/steer/
-
-// A list of vehicles
-ArrayList vehicles;
-
-void setup() {
- size(640,360);
- // We are now making random vehicles and storing them in an ArrayList
- vehicles = new ArrayList();
- for (int i = 0; i < 100; i++) {
- vehicles.add(new Vehicle(random(width),random(height)));
- }
-}
-
-void draw() {
- background(255);
-
- for (Vehicle v : vehicles) {
- // Path following and separation are worked on in this function
- v.align(vehicles);
- // Call the generic run method (update, borders, display, etc.)
- v.update();
- v.borders();
- v.display();
- }
-
- // Instructions
- fill(0);
- text("Drag the mouse to generate new vehicles.",10,height-16);
-}
-
-
-void mouseDragged() {
- vehicles.add(new Vehicle(mouseX,mouseY));
-}
-
-
-
-
diff --git a/java/examples/Books/Nature of Code/chp6_agents/Alignment/Vehicle.pde b/java/examples/Books/Nature of Code/chp6_agents/Alignment/Vehicle.pde
deleted file mode 100644
index 43e3f8bbc..000000000
--- a/java/examples/Books/Nature of Code/chp6_agents/Alignment/Vehicle.pde
+++ /dev/null
@@ -1,89 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Vehicle class
-
-class Vehicle {
-
- // All the usual stuff
- PVector location;
- PVector velocity;
- PVector acceleration;
- float r;
- float maxforce; // Maximum steering force
- float maxspeed; // Maximum speed
-
- // Constructor initialize all values
- Vehicle(float x, float y) {
- location = new PVector(x, y);
- r = 12;
- maxspeed = 3;
- maxforce = 0.2;
- acceleration = new PVector(0, 0);
- velocity = PVector.random2D();
- velocity.mult(random(1,4));
- }
-
- void applyForce(PVector force) {
- // We could add mass here if we want A = F / M
- acceleration.add(force);
- }
-
- // Alignment
- // For every nearby boid in the system, calculate the average velocity
- void align (ArrayList boids) {
- float neighbordist = 30;
- PVector sum = new PVector(0, 0);
- int count = 0;
- for (Vehicle other : vehicles) {
- float d = PVector.dist(location, other.location);
- if ((d > 0) && (d < neighbordist)) {
- sum.add(other.velocity);
- count++;
- }
- }
- if (count > 0) {
- sum.div((float)count);
- sum.normalize();
- sum.mult(maxspeed);
- PVector steer = PVector.sub(sum, velocity);
- steer.limit(maxforce);
- applyForce(steer);
- }
- }
-
-
- // Method to update location
- void update() {
- // Update velocity
- velocity.add(acceleration);
- // Limit speed
- velocity.limit(maxspeed);
- location.add(velocity);
- // Reset accelertion to 0 each cycle
- acceleration.mult(0);
- }
-
- void display() {
- fill(175);
- stroke(0);
- pushMatrix();
- translate(location.x, location.y);
- ellipse(0, 0, r, r);
- popMatrix();
- }
-
- // Wraparound
- void borders() {
- if (location.x < -r) location.x = width+r;
- if (location.y < -r) location.y = height+r;
- if (location.x > width+r) location.x = -r;
- if (location.y > height+r) location.y = -r;
- }
-}
-
-
-
-
-
diff --git a/java/examples/Books/Nature of Code/chp6_agents/Exercise_6_04_Wander/Exercise_6_04_Wander.pde b/java/examples/Books/Nature of Code/chp6_agents/Exercise_6_04_Wander/Exercise_6_04_Wander.pde
deleted file mode 100644
index daeda1da7..000000000
--- a/java/examples/Books/Nature of Code/chp6_agents/Exercise_6_04_Wander/Exercise_6_04_Wander.pde
+++ /dev/null
@@ -1,28 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Demonstration of Craig Reynolds' "Wandering" behavior
-// See: http://www.red3d.com/cwr/
-
-// Click mouse to turn on and off rendering of the wander circle
-
-Vehicle wanderer;
-boolean debug = true;
-
-void setup() {
- size(640,360);
- wanderer = new Vehicle(width/2,height/2);
-}
-
-void draw() {
- background(255);
- wanderer.wander();
- wanderer.run();
-}
-
-void mousePressed() {
- debug = !debug;
-}
-
-
diff --git a/java/examples/Books/Nature of Code/chp6_agents/Exercise_6_04_Wander/Vehicle.pde b/java/examples/Books/Nature of Code/chp6_agents/Exercise_6_04_Wander/Vehicle.pde
deleted file mode 100644
index fb979e8c5..000000000
--- a/java/examples/Books/Nature of Code/chp6_agents/Exercise_6_04_Wander/Vehicle.pde
+++ /dev/null
@@ -1,123 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// The "Vehicle" class (for wandering)
-
-class Vehicle {
-
- PVector location;
- PVector velocity;
- PVector acceleration;
- float r;
- float wandertheta;
- float maxforce; // Maximum steering force
- float maxspeed; // Maximum speed
-
- Vehicle(float x, float y) {
- acceleration = new PVector(0,0);
- velocity = new PVector(0,0);
- location = new PVector(x,y);
- r = 6;
- wandertheta = 0;
- maxspeed = 2;
- maxforce = 0.05;
- }
-
- void run() {
- update();
- borders();
- display();
- }
-
- // Method to update location
- void update() {
- // Update velocity
- velocity.add(acceleration);
- // Limit speed
- velocity.limit(maxspeed);
- location.add(velocity);
- // Reset accelertion to 0 each cycle
- acceleration.mult(0);
- }
-
- void wander() {
- float wanderR = 25; // Radius for our "wander circle"
- float wanderD = 80; // Distance for our "wander circle"
- float change = 0.3;
- wandertheta += random(-change,change); // Randomly change wander theta
-
- // Now we have to calculate the new location to steer towards on the wander circle
- PVector circleloc = velocity.get(); // Start with velocity
- circleloc.normalize(); // Normalize to get heading
- circleloc.mult(wanderD); // Multiply by distance
- circleloc.add(location); // Make it relative to boid's location
-
- float h = velocity.heading2D(); // We need to know the heading to offset wandertheta
-
- PVector circleOffSet = new PVector(wanderR*cos(wandertheta+h),wanderR*sin(wandertheta+h));
- PVector target = PVector.add(circleloc,circleOffSet);
- seek(target);
-
- // Render wandering circle, etc.
- if (debug) drawWanderStuff(location,circleloc,target,wanderR);
- }
-
- void applyForce(PVector force) {
- // We could add mass here if we want A = F / M
- acceleration.add(force);
- }
-
-
- // A method that calculates and applies a steering force towards a target
- // STEER = DESIRED MINUS VELOCITY
- void seek(PVector target) {
- PVector desired = PVector.sub(target,location); // A vector pointing from the location to the target
-
- // Normalize desired and scale to maximum speed
- desired.normalize();
- desired.mult(maxspeed);
- // Steering = Desired minus Velocity
- PVector steer = PVector.sub(desired,velocity);
- steer.limit(maxforce); // Limit to maximum steering force
-
- applyForce(steer);
- }
-
- void display() {
- // Draw a triangle rotated in the direction of velocity
- float theta = velocity.heading2D() + radians(90);
- fill(127);
- stroke(0);
- pushMatrix();
- translate(location.x,location.y);
- rotate(theta);
- beginShape(TRIANGLES);
- vertex(0, -r*2);
- vertex(-r, r*2);
- vertex(r, r*2);
- endShape();
- popMatrix();
- }
-
- // Wraparound
- void borders() {
- if (location.x < -r) location.x = width+r;
- if (location.y < -r) location.y = height+r;
- if (location.x > width+r) location.x = -r;
- if (location.y > height+r) location.y = -r;
- }
-}
-
-
-// A method just to draw the circle associated with wandering
-void drawWanderStuff(PVector location, PVector circle, PVector target, float rad) {
- stroke(0);
- noFill();
- ellipseMode(CENTER);
- ellipse(circle.x,circle.y,rad*2,rad*2);
- ellipse(target.x,target.y,4,4);
- line(location.x,location.y,circle.x,circle.y);
- line(circle.x,circle.y,target.x,target.y);
-}
-
diff --git a/java/examples/Books/Nature of Code/chp6_agents/Exercise_6_08_FlowField3DNoise/Exercise_6_08_FlowField3DNoise.pde b/java/examples/Books/Nature of Code/chp6_agents/Exercise_6_08_FlowField3DNoise/Exercise_6_08_FlowField3DNoise.pde
deleted file mode 100644
index 88a6b3bf6..000000000
--- a/java/examples/Books/Nature of Code/chp6_agents/Exercise_6_08_FlowField3DNoise/Exercise_6_08_FlowField3DNoise.pde
+++ /dev/null
@@ -1,52 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Flow Field Following
-// Via Reynolds: http://www.red3d.com/cwr/steer/FlowFollow.html
-
-// Using this variable to decide whether to draw all the stuff
-boolean debug = true;
-
-// Flowfield object
-FlowField flowfield;
-// An ArrayList of vehicles
-ArrayList vehicles;
-
-void setup() {
- size(640, 360);
- // Make a new flow field with "resolution" of 16
- flowfield = new FlowField(20);
- vehicles = new ArrayList();
- // Make a whole bunch of vehicles with random maxspeed and maxforce values
- for (int i = 0; i < 120; i++) {
- vehicles.add(new Vehicle(new PVector(random(width), random(height)), random(2, 5), random(0.1, 0.5)));
- }
-}
-
-void draw() {
- background(255);
- flowfield.update();
-
- // Display the flowfield in "debug" mode
- if (debug) flowfield.display();
- // Tell all the vehicles to follow the flow field
- for (Vehicle v : vehicles) {
- v.follow(flowfield);
- v.run();
- }
-
- // Instructions
- fill(0);
- text("Hit space bar to toggle debugging lines.\nClick the mouse to generate a new flow field.",10,height-20);
-}
-
-
-void keyPressed() {
- if (key == ' ') {
- debug = !debug;
- }
-}
-
-
-
diff --git a/java/examples/Books/Nature of Code/chp6_agents/Exercise_6_08_FlowField3DNoise/FlowField.pde b/java/examples/Books/Nature of Code/chp6_agents/Exercise_6_08_FlowField3DNoise/FlowField.pde
deleted file mode 100644
index f10539eb6..000000000
--- a/java/examples/Books/Nature of Code/chp6_agents/Exercise_6_08_FlowField3DNoise/FlowField.pde
+++ /dev/null
@@ -1,81 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Flow Field Following
-
-class FlowField {
-
- // A flow field is a two dimensional array of PVectors
- PVector[][] field;
- int cols, rows; // Columns and Rows
- int resolution; // How large is each "cell" of the flow field
-
- float zoff = 0.0; // 3rd dimension of noise
-
- FlowField(int r) {
- resolution = r;
- // Determine the number of columns and rows based on sketch's width and height
- cols = width/resolution;
- rows = height/resolution;
- field = new PVector[cols][rows];
- update();
- }
-
- void update() {
- float xoff = 0;
- for (int i = 0; i < cols; i++) {
- float yoff = 0;
- for (int j = 0; j < rows; j++) {
- float theta = map(noise(xoff,yoff,zoff),0,1,0,TWO_PI);
- // Make a vector from an angle
- field[i][j] = PVector.fromAngle(theta);
- yoff += 0.1;
- }
- xoff += 0.1;
- }
- // Animate by changing 3rd dimension of noise every frame
- zoff += 0.01;
- }
-
- // Draw every vector
- void display() {
- for (int i = 0; i < cols; i++) {
- for (int j = 0; j < rows; j++) {
- drawVector(field[i][j],i*resolution,j*resolution,resolution-2);
- }
- }
-
- }
-
- // Renders a vector object 'v' as an arrow and a location 'x,y'
- void drawVector(PVector v, float x, float y, float scayl) {
- pushMatrix();
- float arrowsize = 4;
- // Translate to location to render vector
- translate(x,y);
- stroke(0,150);
- // Call vector heading function to get direction (note that pointing up is a heading of 0) and rotate
- rotate(v.heading2D());
- // Calculate length of vector & scale it to be bigger or smaller if necessary
- float len = v.mag()*scayl;
- // Draw three lines to make an arrow (draw pointing up since we've rotate to the proper direction)
- line(0,0,len,0);
- //line(len,0,len-arrowsize,+arrowsize/2);
- //line(len,0,len-arrowsize,-arrowsize/2);
- popMatrix();
- }
-
- PVector lookup(PVector lookup) {
- int column = int(constrain(lookup.x/resolution,0,cols-1));
- int row = int(constrain(lookup.y/resolution,0,rows-1));
- return field[column][row].get();
- }
-
-
-}
-
-
-
-
-
diff --git a/java/examples/Books/Nature of Code/chp6_agents/Exercise_6_08_FlowField3DNoise/Vehicle.pde b/java/examples/Books/Nature of Code/chp6_agents/Exercise_6_08_FlowField3DNoise/Vehicle.pde
deleted file mode 100644
index 2326a1e7c..000000000
--- a/java/examples/Books/Nature of Code/chp6_agents/Exercise_6_08_FlowField3DNoise/Vehicle.pde
+++ /dev/null
@@ -1,87 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Flow Field Following
-
-class Vehicle {
-
- // The usual stuff
- PVector location;
- PVector velocity;
- PVector acceleration;
- float r;
- float maxforce; // Maximum steering force
- float maxspeed; // Maximum speed
-
- Vehicle(PVector l, float ms, float mf) {
- location = l.get();
- r = 3.0;
- maxspeed = ms;
- maxforce = mf;
- acceleration = new PVector(0,0);
- velocity = new PVector(0,0);
- }
-
- public void run() {
- update();
- borders();
- display();
- }
-
-
- // Implementing Reynolds' flow field following algorithm
- // http://www.red3d.com/cwr/steer/FlowFollow.html
- void follow(FlowField flow) {
- // What is the vector at that spot in the flow field?
- PVector desired = flow.lookup(location);
- // Scale it up by maxspeed
- desired.mult(maxspeed);
- // Steering is desired minus velocity
- PVector steer = PVector.sub(desired, velocity);
- steer.limit(maxforce); // Limit to maximum steering force
- applyForce(steer);
- }
-
- void applyForce(PVector force) {
- // We could add mass here if we want A = F / M
- acceleration.add(force);
- }
-
- // Method to update location
- void update() {
- // Update velocity
- velocity.add(acceleration);
- // Limit speed
- velocity.limit(maxspeed);
- location.add(velocity);
- // Reset accelertion to 0 each cycle
- acceleration.mult(0);
- }
-
- void display() {
- // Draw a triangle rotated in the direction of velocity
- float theta = velocity.heading2D() + radians(90);
- fill(175);
- stroke(0);
- pushMatrix();
- translate(location.x,location.y);
- rotate(theta);
- beginShape(TRIANGLES);
- vertex(0, -r*2);
- vertex(-r, r*2);
- vertex(r, r*2);
- endShape();
- popMatrix();
- }
-
- // Wraparound
- void borders() {
- if (location.x < -r) location.x = width+r;
- if (location.y < -r) location.y = height+r;
- if (location.x > width+r) location.x = -r;
- if (location.y > height+r) location.y = -r;
- }
-}
-
-
diff --git a/java/examples/Books/Nature of Code/chp6_agents/Exercise_6_09_AngleBetween/Exercise_6_09_AngleBetween.pde b/java/examples/Books/Nature of Code/chp6_agents/Exercise_6_09_AngleBetween/Exercise_6_09_AngleBetween.pde
deleted file mode 100644
index b5f145f6b..000000000
--- a/java/examples/Books/Nature of Code/chp6_agents/Exercise_6_09_AngleBetween/Exercise_6_09_AngleBetween.pde
+++ /dev/null
@@ -1,54 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Angle Between Two Vectors
-// Using the dot product to compute the angle between two vectors
-
-void setup() {
- size(640, 360);
-}
-
-void draw() {
- background(255);
-
- // A "vector" (really a point) to store the mouse location and screen center location
- PVector mouseLoc = new PVector(mouseX, mouseY);
- PVector centerLoc = new PVector(width/2, height/2);
-
- // Aha, a vector to store the displacement between the mouse and center
- PVector v = PVector.sub(mouseLoc, centerLoc);
- v.normalize();
- v.mult(75);
-
- PVector xaxis = new PVector(75, 0);
- // Render the vector
- drawVector(v, centerLoc, 1.0);
- drawVector(xaxis, centerLoc, 1.0);
-
-
- float theta = PVector.angleBetween(v, xaxis);
-
- fill(0);
- text(int(degrees(theta)) + " degrees\n" + theta + " radians", 10, 160);
-}
-
-// Renders a vector object 'v' as an arrow and a location 'loc'
-void drawVector(PVector v, PVector loc, float scayl) {
- pushMatrix();
- float arrowsize = 6;
- // Translate to location to render vector
- translate(loc.x, loc.y);
- stroke(0);
- strokeWeight(2);
- // Call vector heading function to get direction (pointing up is a heading of 0)
- rotate(v.heading2D());
- // Calculate length of vector & scale it to be bigger or smaller if necessary
- float len = v.mag()*scayl;
- // Draw three lines to make an arrow
- line(0, 0, len, 0);
- line(len, 0, len-arrowsize, +arrowsize/2);
- line(len, 0, len-arrowsize, -arrowsize/2);
- popMatrix();
-}
-
diff --git a/java/examples/Books/Nature of Code/chp6_agents/Exercise_6_13_CrowdPathFollowing/Exercise_6_13_CrowdPathFollowing.pde b/java/examples/Books/Nature of Code/chp6_agents/Exercise_6_13_CrowdPathFollowing/Exercise_6_13_CrowdPathFollowing.pde
deleted file mode 100644
index 43be58653..000000000
--- a/java/examples/Books/Nature of Code/chp6_agents/Exercise_6_13_CrowdPathFollowing/Exercise_6_13_CrowdPathFollowing.pde
+++ /dev/null
@@ -1,77 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Crowd Path Following
-// Via Reynolds: http://www.red3d.com/cwr/steer/CrowdPath.html
-
-// Using this variable to decide whether to draw all the stuff
-boolean debug = false;
-
-
-// A path object (series of connected points)
-Path path;
-
-// Two vehicles
-ArrayList vehicles;
-
-void setup() {
- size(640,360);
- // Call a function to generate new Path object
- newPath();
-
- // We are now making random vehicles and storing them in an ArrayList
- vehicles = new ArrayList();
- for (int i = 0; i < 120; i++) {
- newVehicle(random(width),random(height));
- }
-}
-
-void draw() {
- background(255);
- // Display the path
- path.display();
-
- for (Vehicle v : vehicles) {
- // Path following and separation are worked on in this function
- v.applyBehaviors(vehicles,path);
- // Call the generic run method (update, borders, display, etc.)
- v.run();
- }
-
- // Instructions
- fill(0);
- textAlign(CENTER);
- text("Hit 'd' to toggle debugging lines.\nClick the mouse to generate new vehicles.",width/2,height-20);
-}
-
-void newPath() {
- // A path is a series of connected points
- // A more sophisticated path might be a curve
- path = new Path();
- float offset = 30;
- path.addPoint(offset,offset);
- path.addPoint(width-offset,offset);
- path.addPoint(width-offset,height-offset);
- path.addPoint(width/2,height-offset*3);
- path.addPoint(offset,height-offset);
-}
-
-void newVehicle(float x, float y) {
- float maxspeed = random(2,4);
- float maxforce = 0.3;
- vehicles.add(new Vehicle(new PVector(x,y),maxspeed,maxforce));
-}
-
-void keyPressed() {
- if (key == 'd') {
- debug = !debug;
- }
-}
-
-void mousePressed() {
- newVehicle(mouseX,mouseY);
-}
-
-
-
diff --git a/java/examples/Books/Nature of Code/chp6_agents/Exercise_6_13_CrowdPathFollowing/Path.pde b/java/examples/Books/Nature of Code/chp6_agents/Exercise_6_13_CrowdPathFollowing/Path.pde
deleted file mode 100644
index 755be5b1f..000000000
--- a/java/examples/Books/Nature of Code/chp6_agents/Exercise_6_13_CrowdPathFollowing/Path.pde
+++ /dev/null
@@ -1,52 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Path Following
-
-class Path {
-
- // A Path is an arraylist of points (PVector objects)
- ArrayList points;
- // A path has a radius, i.e how far is it ok for the boid to wander off
- float radius;
-
- Path() {
- // Arbitrary radius of 20
- radius = 20;
- points = new ArrayList();
- }
-
- // Add a point to the path
- void addPoint(float x, float y) {
- PVector point = new PVector(x, y);
- points.add(point);
- }
-
- // Draw the path
- void display() {
- strokeJoin(ROUND);
-
- // Draw thick line for radius
- stroke(175);
- strokeWeight(radius*2);
- noFill();
- beginShape();
- for (PVector v : points) {
- vertex(v.x, v.y);
- }
- endShape(CLOSE);
- // Draw thin line for center of path
- stroke(0);
- strokeWeight(1);
- noFill();
- beginShape();
- for (PVector v : points) {
- vertex(v.x, v.y);
- }
- endShape(CLOSE);
- }
-}
-
-
-
diff --git a/java/examples/Books/Nature of Code/chp6_agents/Exercise_6_13_CrowdPathFollowing/Vehicle.pde b/java/examples/Books/Nature of Code/chp6_agents/Exercise_6_13_CrowdPathFollowing/Vehicle.pde
deleted file mode 100644
index 14a2947e7..000000000
--- a/java/examples/Books/Nature of Code/chp6_agents/Exercise_6_13_CrowdPathFollowing/Vehicle.pde
+++ /dev/null
@@ -1,240 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Path Following
-// Vehicle class
-
-class Vehicle {
-
- // All the usual stuff
- PVector location;
- PVector velocity;
- PVector acceleration;
- float r;
- float maxforce; // Maximum steering force
- float maxspeed; // Maximum speed
-
- // Constructor initialize all values
- Vehicle( PVector l, float ms, float mf) {
- location = l.get();
- r = 12;
- maxspeed = ms;
- maxforce = mf;
- acceleration = new PVector(0, 0);
- velocity = new PVector(maxspeed, 0);
- }
-
- // A function to deal with path following and separation
- void applyBehaviors(ArrayList vehicles, Path path) {
- // Follow path force
- PVector f = follow(path);
- // Separate from other boids force
- PVector s = separate(vehicles);
- // Arbitrary weighting
- f.mult(3);
- s.mult(1);
- // Accumulate in acceleration
- applyForce(f);
- applyForce(s);
- }
-
- void applyForce(PVector force) {
- // We could add mass here if we want A = F / M
- acceleration.add(force);
- }
-
-
-
- // Main "run" function
- public void run() {
- update();
- borders();
- render();
- }
-
-
- // This function implements Craig Reynolds' path following algorithm
- // http://www.red3d.com/cwr/steer/PathFollow.html
- PVector follow(Path p) {
-
- // Predict location 25 (arbitrary choice) frames ahead
- PVector predict = velocity.get();
- predict.normalize();
- predict.mult(25);
- PVector predictLoc = PVector.add(location, predict);
-
- // Now we must find the normal to the path from the predicted location
- // We look at the normal for each line segment and pick out the closest one
- PVector normal = null;
- PVector target = null;
- float worldRecord = 1000000; // Start with a very high worldRecord distance that can easily be beaten
-
- // Loop through all points of the path
- for (int i = 0; i < p.points.size(); i++) {
-
- // Look at a line segment
- PVector a = p.points.get(i);
- PVector b = p.points.get((i+1)%p.points.size()); // Note Path has to wraparound
-
- // Get the normal point to that line
- PVector normalPoint = getNormalPoint(predictLoc, a, b);
-
- // Check if normal is on line segment
- PVector dir = PVector.sub(b, a);
- // If it's not within the line segment, consider the normal to just be the end of the line segment (point b)
- //if (da + db > line.mag()+1) {
- if (normalPoint.x < min(a.x,b.x) || normalPoint.x > max(a.x,b.x) || normalPoint.y < min(a.y,b.y) || normalPoint.y > max(a.y,b.y)) {
- normalPoint = b.get();
- // If we're at the end we really want the next line segment for looking ahead
- a = p.points.get((i+1)%p.points.size());
- b = p.points.get((i+2)%p.points.size()); // Path wraps around
- dir = PVector.sub(b, a);
- }
-
- // How far away are we from the path?
- float d = PVector.dist(predictLoc, normalPoint);
- // Did we beat the worldRecord and find the closest line segment?
- if (d < worldRecord) {
- worldRecord = d;
- normal = normalPoint;
-
- // Look at the direction of the line segment so we can seek a little bit ahead of the normal
- dir.normalize();
- // This is an oversimplification
- // Should be based on distance to path & velocity
- dir.mult(25);
- target = normal.get();
- target.add(dir);
-
- }
- }
-
- // Draw the debugging stuff
- if (debug) {
- // Draw predicted future location
- stroke(0);
- fill(0);
- line(location.x, location.y, predictLoc.x, predictLoc.y);
- ellipse(predictLoc.x, predictLoc.y, 4, 4);
-
- // Draw normal location
- stroke(0);
- fill(0);
- ellipse(normal.x, normal.y, 4, 4);
- // Draw actual target (red if steering towards it)
- line(predictLoc.x, predictLoc.y, target.x, target.y);
- if (worldRecord > p.radius) fill(255, 0, 0);
- noStroke();
- ellipse(target.x, target.y, 8, 8);
- }
-
- // Only if the distance is greater than the path's radius do we bother to steer
- if (worldRecord > p.radius) {
- return seek(target);
- }
- else {
- return new PVector(0, 0);
- }
- }
-
-
- // A function to get the normal point from a point (p) to a line segment (a-b)
- // This function could be optimized to make fewer new Vector objects
- PVector getNormalPoint(PVector p, PVector a, PVector b) {
- // Vector from a to p
- PVector ap = PVector.sub(p, a);
- // Vector from a to b
- PVector ab = PVector.sub(b, a);
- ab.normalize(); // Normalize the line
- // Project vector "diff" onto line by using the dot product
- ab.mult(ap.dot(ab));
- PVector normalPoint = PVector.add(a, ab);
- return normalPoint;
- }
-
- // Separation
- // Method checks for nearby boids and steers away
- PVector separate (ArrayList boids) {
- float desiredseparation = r*2;
- PVector steer = new PVector(0, 0, 0);
- int count = 0;
- // For every boid in the system, check if it's too close
- for (int i = 0 ; i < boids.size(); i++) {
- Vehicle other = (Vehicle) boids.get(i);
- float d = PVector.dist(location, other.location);
- // If the distance is greater than 0 and less than an arbitrary amount (0 when you are yourself)
- if ((d > 0) && (d < desiredseparation)) {
- // Calculate vector pointing away from neighbor
- PVector diff = PVector.sub(location, other.location);
- diff.normalize();
- diff.div(d); // Weight by distance
- steer.add(diff);
- count++; // Keep track of how many
- }
- }
- // Average -- divide by how many
- if (count > 0) {
- steer.div((float)count);
- }
-
- // As long as the vector is greater than 0
- if (steer.mag() > 0) {
- // Implement Reynolds: Steering = Desired - Velocity
- steer.normalize();
- steer.mult(maxspeed);
- steer.sub(velocity);
- steer.limit(maxforce);
- }
- return steer;
- }
-
-
- // Method to update location
- void update() {
- // Update velocity
- velocity.add(acceleration);
- // Limit speed
- velocity.limit(maxspeed);
- location.add(velocity);
- // Reset accelertion to 0 each cycle
- acceleration.mult(0);
- }
-
- // A method that calculates and applies a steering force towards a target
- // STEER = DESIRED MINUS VELOCITY
- PVector seek(PVector target) {
- PVector desired = PVector.sub(target, location); // A vector pointing from the location to the target
-
- // Normalize desired and scale to maximum speed
- desired.normalize();
- desired.mult(maxspeed);
- // Steering = Desired minus Velocationity
- PVector steer = PVector.sub(desired, velocity);
- steer.limit(maxforce); // Limit to maximum steering force
-
- return steer;
- }
-
-
- void render() {
- // Simpler boid is just a circle
- fill(75);
- stroke(0);
- pushMatrix();
- translate(location.x, location.y);
- ellipse(0, 0, r, r);
- popMatrix();
- }
-
- // Wraparound
- void borders() {
- if (location.x < -r) location.x = width+r;
- //if (location.y < -r) location.y = height+r;
- if (location.x > width+r) location.x = -r;
- //if (location.y > height+r) location.y = -r;
- }
-}
-
-
-
diff --git a/java/examples/Books/Nature of Code/chp6_agents/Exercise_6_17_View/Boid.pde b/java/examples/Books/Nature of Code/chp6_agents/Exercise_6_17_View/Boid.pde
deleted file mode 100644
index e5ba60546..000000000
--- a/java/examples/Books/Nature of Code/chp6_agents/Exercise_6_17_View/Boid.pde
+++ /dev/null
@@ -1,242 +0,0 @@
-// Flocking
-// Daniel Shiffman
-// The Nature of Code, Spring 2009
-
-// Boid class
-// Methods for Separation, Cohesion, Alignment added
-
-class Boid {
-
- PVector location;
- PVector velocity;
- PVector acceleration;
- float r;
- float maxforce; // Maximum steering force
- float maxspeed; // Maximum speed
-
-
- color col;
- Boid(float x, float y) {
- acceleration = new PVector(0, 0);
- velocity = new PVector(random(-1, 1), random(-1, 1));
- location = new PVector(x, y);
- r = 5.0;
- maxspeed = 3;
- maxforce = 0.05;
-
- col = color(175);
- }
-
- void run(ArrayList boids) {
- //flock(boids);
- update();
- borders();
- render();
- }
-
- void applyForce(PVector force) {
- // We could add mass here if we want A = F / M
- acceleration.add(force);
- }
-
- // We accumulate a new acceleration each time based on three rules
- void flock(ArrayList boids) {
- PVector sep = separate(boids); // Separation
- PVector ali = align(boids); // Alignment
- PVector coh = cohesion(boids); // Cohesion
-
- // Not for every boid yet
- // PVector view = view(boids); // view
-
- // Arbitrarily weight these forces
- sep.mult(1.5);
- ali.mult(1.0);
- coh.mult(1.0);
-
- // Not for every boid yet
- // view.mult(1.0);
-
- // Add the force vectors to acceleration
- applyForce(sep);
- applyForce(ali);
- applyForce(coh);
-
- // Not for every boid yet
- // applyForce(view);
- }
-
- // Method to update location
- void update() {
- // Update velocity
- velocity.add(acceleration);
- // Limit speed
- velocity.limit(maxspeed);
- location.add(velocity);
- // Reset accelertion to 0 each cycle
- acceleration.mult(0);
- }
-
- // A method that calculates and applies a steering force towards a target
- // STEER = DESIRED MINUS VELOCITY
- PVector seek(PVector target) {
- PVector desired = PVector.sub(target, location); // A vector pointing from the location to the target
- // Normalize desired and scale to maximum speed
- desired.normalize();
- desired.mult(maxspeed);
- // Steering = Desired minus Velocity
- PVector steer = PVector.sub(desired, velocity);
- steer.limit(maxforce); // Limit to maximum steering force
- return steer;
- }
-
- void render() {
- // Draw a triangle rotated in the direction of velocity
- float theta = velocity.heading() + radians(90);
- fill(col);
- stroke(0);
- pushMatrix();
- translate(location.x, location.y);
- rotate(theta);
- beginShape(TRIANGLES);
- vertex(0, -r*2);
- vertex(-r, r*2);
- vertex(r, r*2);
- endShape();
- popMatrix();
- }
-
- // Wraparound
- void borders() {
- if (location.x < -r) location.x = width+r;
- if (location.y < -r) location.y = height+r;
- if (location.x > width+r) location.x = -r;
- if (location.y > height+r) location.y = -r;
- }
-
- // Separation
- // Method checks for nearby boids and steers away
- PVector separate (ArrayList boids) {
- float desiredseparation = 25.0f;
- PVector steer = new PVector(0, 0, 0);
- int count = 0;
- // For every boid in the system, check if it's too close
- for (Boid other : boids) {
- float d = PVector.dist(location, other.location);
- // If the distance is greater than 0 and less than an arbitrary amount (0 when you are yourself)
- if ((d > 0) && (d < desiredseparation)) {
- // Calculate vector pointing away from neighbor
- PVector diff = PVector.sub(location, other.location);
- diff.normalize();
- diff.div(d); // Weight by distance
- steer.add(diff);
- count++; // Keep track of how many
- }
- }
- // Average -- divide by how many
- if (count > 0) {
- steer.div((float)count);
- }
-
- // As long as the vector is greater than 0
- if (steer.mag() > 0) {
- // Implement Reynolds: Steering = Desired - Velocity
- steer.normalize();
- steer.mult(maxspeed);
- steer.sub(velocity);
- steer.limit(maxforce);
- }
- return steer;
- }
-
- // Alignment
- // For every nearby boid in the system, calculate the average velocity
- PVector align (ArrayList boids) {
- float neighbordist = 50;
- PVector sum = new PVector(0, 0);
- int count = 0;
- for (Boid other : boids) {
- float d = PVector.dist(location, other.location);
- if ((d > 0) && (d < neighbordist)) {
- sum.add(other.velocity);
- count++;
- }
- }
- if (count > 0) {
- sum.div((float)count);
- sum.normalize();
- sum.mult(maxspeed);
- PVector steer = PVector.sub(sum, velocity);
- steer.limit(maxforce);
- return steer;
- }
- else {
- return new PVector(0, 0);
- }
- }
-
- // Cohesion
- // For the average location (i.e. center) of all nearby boids, calculate steering vector towards that location
- PVector cohesion (ArrayList boids) {
- float neighbordist = 50;
- PVector sum = new PVector(0, 0); // Start with empty vector to accumulate all locations
- int count = 0;
- for (Boid other : boids) {
- float d = PVector.dist(location, other.location);
- if ((d > 0) && (d < neighbordist)) {
- sum.add(other.location); // Add location
- count++;
- }
- }
- if (count > 0) {
- sum.div(count);
- return seek(sum); // Steer towards the location
- }
- else {
- return new PVector(0, 0);
- }
- }
-
- // View
- // move laterally away from any boid that blocks the view
- // Right now we are just drawing the view and highlighting boids
- PVector view (ArrayList boids) {
-
- // How far can it see?
- float sightDistance = 100;
- float periphery = PI/4;
-
- for (Boid other : boids) {
- // A vector that points to another boid and that angle
- PVector comparison = PVector.sub(other.location, location);
-
- // How far is it
- float d = PVector.dist(location, other.location);
-
- // What is the angle between the other boid and this one's current direction
- float diff = PVector.angleBetween(comparison, velocity);
-
- // If it's within the periphery and close enough to see it
- if (diff < periphery && d > 0 && d < sightDistance) {
- // Just change its color
- other.highlight();
- }
- }
-
-
- // Debug Drawing
- float currentHeading = velocity.heading();
- pushMatrix();
- translate(location.x, location.y);
- rotate(currentHeading);
- fill(0, 100);
- arc(0, 0, sightDistance*2, sightDistance*2, -periphery, periphery);
- popMatrix();
-
- return new PVector();
- }
-
- void highlight() {
- col = color(255, 0, 0);
- }
-}
-
diff --git a/java/examples/Books/Nature of Code/chp6_agents/Exercise_6_17_View/Exercise_6_17_View.pde b/java/examples/Books/Nature of Code/chp6_agents/Exercise_6_17_View/Exercise_6_17_View.pde
deleted file mode 100644
index 8aa3f5011..000000000
--- a/java/examples/Books/Nature of Code/chp6_agents/Exercise_6_17_View/Exercise_6_17_View.pde
+++ /dev/null
@@ -1,31 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Exercise 6.17: Implement Flake's "View" rule
-
-// This answer doesn't implement the rule, but rather demonstrates how a boid can
-// detect what is "in front" of it based on peripheral vision
-
-Flock flock;
-
-void setup() {
- size(640,360);
- flock = new Flock();
- // Add an initial set of boids into the system
- for (int i = 0; i < 25; i++) {
- Boid b = new Boid(width/2+random(0,75),height/2+random(0,75));
- flock.addBoid(b);
- }
-}
-
-void draw() {
- background(255);
-
- flock.run();
-}
-
-// Add a new boid into the System
-void mouseDragged() {
- flock.addBoid(new Boid(mouseX,mouseY));
-}
diff --git a/java/examples/Books/Nature of Code/chp6_agents/Exercise_6_17_View/Flock.pde b/java/examples/Books/Nature of Code/chp6_agents/Exercise_6_17_View/Flock.pde
deleted file mode 100644
index 6b7b1c9e0..000000000
--- a/java/examples/Books/Nature of Code/chp6_agents/Exercise_6_17_View/Flock.pde
+++ /dev/null
@@ -1,37 +0,0 @@
-// Flocking
-// Daniel Shiffman
-// The Nature of Code, Spring 2011
-
-// Flock class
-// Does very little, simply manages the ArrayList of all the boids
-
-class Flock {
- ArrayList boids; // An ArrayList for all the boids
-
- Flock() {
- boids = new ArrayList(); // Initialize the ArrayList
- }
-
- void run() {
- for (Boid b : boids) {
- b.col = color(175);
- }
-
- Boid b1 = boids.get(0);
- b1.col = color(0, 0, 255);
- b1.view(boids);
-
- for (Boid b : boids) {
- b.flock(boids); // Passing the entire list of boids to each boid individually
- }
-
- for (Boid b : boids) {
- b.run(boids); // Passing the entire list of boids to each boid individually
- }
- }
-
- void addBoid(Boid b) {
- boids.add(b);
- }
-}
-
diff --git a/java/examples/Books/Nature of Code/chp6_agents/FlowfieldImage/FlowField.pde b/java/examples/Books/Nature of Code/chp6_agents/FlowfieldImage/FlowField.pde
deleted file mode 100644
index 370c83f47..000000000
--- a/java/examples/Books/Nature of Code/chp6_agents/FlowfieldImage/FlowField.pde
+++ /dev/null
@@ -1,85 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Flow Field Following
-
-class FlowField {
-
- // A flow field is a two dimensional array of PVectors
- PVector[][] field;
- int cols, rows; // Columns and Rows
- int resolution; // How large is each "cell" of the flow field
-
- FlowField(int r) {
- resolution = r;
- // Determine the number of columns and rows based on sketch's width and height
- cols = width/resolution;
- rows = height/resolution;
- field = new PVector[cols][rows];
- init();
- }
-
- void init() {
- // Reseed noise so we get a new flow field every time
- for (int i = 0; i < cols; i++) {
- for (int j = 0; j < rows; j++) {
-
- int x = i*resolution;
- int y = j*resolution;
- int c = img.pixels[x + y * img.width];
-
- // Map brightness to an angle
- float theta = 0;//map(brightness(c),0,255,0,PI/2);
- // Polar to cartesian coordinate transformation to get x and y components of the vector
- field[i][j] = PVector.fromAngle(theta);
-
- // Map magnitude to an angle (how fast is the desired velocity in the flow field)
- float m = map(brightness(c),0,255,0,1);
- field[i][j].mult(m);
- }
- }
- }
-
- // Draw every vector
- void display() {
- for (int i = 0; i < cols; i++) {
- for (int j = 0; j < rows; j++) {
- drawVector(field[i][j],i*resolution,j*resolution,resolution-2);
- }
- }
-
- }
-
- // Renders a vector object 'v' as an arrow and a location 'x,y'
- void drawVector(PVector v, float x, float y, float scayl) {
- pushMatrix();
- float arrowsize = 4;
- // Translate to location to render vector
- translate(x,y);
- strokeWeight(2);
- stroke(255,0,0);
- // Call vector heading function to get direction (note that pointing up is a heading of 0) and rotate
- rotate(v.heading2D());
- // Calculate length of vector & scale it to be bigger or smaller if necessary
- float len = v.mag()*scayl;
- // Draw three lines to make an arrow (draw pointing up since we've rotate to the proper direction)
- line(0,0,len,0);
- //line(len,0,len-arrowsize,+arrowsize/2);
- //line(len,0,len-arrowsize,-arrowsize/2);
- popMatrix();
- }
-
- PVector lookup(PVector lookup) {
- int column = int(constrain(lookup.x/resolution,0,cols-1));
- int row = int(constrain(lookup.y/resolution,0,rows-1));
- return field[column][row].get();
- }
-
-
-}
-
-
-
-
-
diff --git a/java/examples/Books/Nature of Code/chp6_agents/FlowfieldImage/FlowfieldImage.pde b/java/examples/Books/Nature of Code/chp6_agents/FlowfieldImage/FlowfieldImage.pde
deleted file mode 100644
index b023de6d6..000000000
--- a/java/examples/Books/Nature of Code/chp6_agents/FlowfieldImage/FlowfieldImage.pde
+++ /dev/null
@@ -1,59 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Flow Field Following
-// Via Reynolds: http://www.red3d.com/cwr/steer/FlowFollow.html
-
-// Using this variable to decide whether to draw all the stuff
-boolean debug = true;
-
-PImage img;
-
-// Flowfield object
-FlowField flowfield;
-// An ArrayList of vehicles
-ArrayList vehicles;
-
-void setup() {
- size(600, 568);
- img = loadImage("sil.jpg");
- // Make a new flow field with "resolution" of 16
- flowfield = new FlowField(20);
- vehicles = new ArrayList();
- // Make a whole bunch of vehicles with random maxspeed and maxforce values
- for (int i = 0; i < 120; i++) {
- vehicles.add(new Vehicle(new PVector(random(width), random(height)), random(2, 5), random(0.1, 0.5)));
- }
-}
-
-void draw() {
- background(255);
- image(img,0,0);
- // Display the flowfield in "debug" mode
- if (debug) flowfield.display();
- // Tell all the vehicles to follow the flow field
- for (Vehicle v : vehicles) {
- v.follow(flowfield);
- v.run();
- }
-
- // Instructions
- fill(0);
- text("Hit space bar to toggle debugging lines.\nClick the mouse to generate a new flow field.",10,height-20);
-}
-
-
-void keyPressed() {
- if (key == ' ') {
- debug = !debug;
- }
-}
-
-// Make a new flowfield
-void mousePressed() {
- flowfield.init();
-}
-
-
-
diff --git a/java/examples/Books/Nature of Code/chp6_agents/FlowfieldImage/Vehicle.pde b/java/examples/Books/Nature of Code/chp6_agents/FlowfieldImage/Vehicle.pde
deleted file mode 100644
index 2326a1e7c..000000000
--- a/java/examples/Books/Nature of Code/chp6_agents/FlowfieldImage/Vehicle.pde
+++ /dev/null
@@ -1,87 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Flow Field Following
-
-class Vehicle {
-
- // The usual stuff
- PVector location;
- PVector velocity;
- PVector acceleration;
- float r;
- float maxforce; // Maximum steering force
- float maxspeed; // Maximum speed
-
- Vehicle(PVector l, float ms, float mf) {
- location = l.get();
- r = 3.0;
- maxspeed = ms;
- maxforce = mf;
- acceleration = new PVector(0,0);
- velocity = new PVector(0,0);
- }
-
- public void run() {
- update();
- borders();
- display();
- }
-
-
- // Implementing Reynolds' flow field following algorithm
- // http://www.red3d.com/cwr/steer/FlowFollow.html
- void follow(FlowField flow) {
- // What is the vector at that spot in the flow field?
- PVector desired = flow.lookup(location);
- // Scale it up by maxspeed
- desired.mult(maxspeed);
- // Steering is desired minus velocity
- PVector steer = PVector.sub(desired, velocity);
- steer.limit(maxforce); // Limit to maximum steering force
- applyForce(steer);
- }
-
- void applyForce(PVector force) {
- // We could add mass here if we want A = F / M
- acceleration.add(force);
- }
-
- // Method to update location
- void update() {
- // Update velocity
- velocity.add(acceleration);
- // Limit speed
- velocity.limit(maxspeed);
- location.add(velocity);
- // Reset accelertion to 0 each cycle
- acceleration.mult(0);
- }
-
- void display() {
- // Draw a triangle rotated in the direction of velocity
- float theta = velocity.heading2D() + radians(90);
- fill(175);
- stroke(0);
- pushMatrix();
- translate(location.x,location.y);
- rotate(theta);
- beginShape(TRIANGLES);
- vertex(0, -r*2);
- vertex(-r, r*2);
- vertex(r, r*2);
- endShape();
- popMatrix();
- }
-
- // Wraparound
- void borders() {
- if (location.x < -r) location.x = width+r;
- if (location.y < -r) location.y = height+r;
- if (location.x > width+r) location.x = -r;
- if (location.y > height+r) location.y = -r;
- }
-}
-
-
diff --git a/java/examples/Books/Nature of Code/chp6_agents/NOC_6_01_Seek/NOC_6_01_Seek.pde b/java/examples/Books/Nature of Code/chp6_agents/NOC_6_01_Seek/NOC_6_01_Seek.pde
deleted file mode 100644
index f06b2d10f..000000000
--- a/java/examples/Books/Nature of Code/chp6_agents/NOC_6_01_Seek/NOC_6_01_Seek.pde
+++ /dev/null
@@ -1,35 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Two "vehicles" follow the mouse position
-
-// Implements Craig Reynold's autonomous steering behaviors
-// One vehicle "seeks"
-// One vehicle "arrives"
-// See: http://www.red3d.com/cwr/
-
-Vehicle v;
-
-void setup() {
- size(640, 360);
- v = new Vehicle(width/2, height/2);
-}
-
-void draw() {
- background(255);
-
- PVector mouse = new PVector(mouseX, mouseY);
-
- // Draw an ellipse at the mouse location
- fill(200);
- stroke(0);
- strokeWeight(2);
- ellipse(mouse.x, mouse.y, 48, 48);
-
- // Call the appropriate steering behaviors for our agents
- v.seek(mouse);
- v.update();
- v.display();
-}
-
diff --git a/java/examples/Books/Nature of Code/chp6_agents/NOC_6_01_Seek/Vehicle.pde b/java/examples/Books/Nature of Code/chp6_agents/NOC_6_01_Seek/Vehicle.pde
deleted file mode 100644
index 8c469b5d5..000000000
--- a/java/examples/Books/Nature of Code/chp6_agents/NOC_6_01_Seek/Vehicle.pde
+++ /dev/null
@@ -1,77 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Seek_Arrive
-
-// The "Vehicle" class
-
-class Vehicle {
-
- PVector location;
- PVector velocity;
- PVector acceleration;
- float r;
- float maxforce; // Maximum steering force
- float maxspeed; // Maximum speed
-
- Vehicle(float x, float y) {
- acceleration = new PVector(0,0);
- velocity = new PVector(0,-2);
- location = new PVector(x,y);
- r = 6;
- maxspeed = 4;
- maxforce = 0.1;
- }
-
- // Method to update location
- void update() {
- // Update velocity
- velocity.add(acceleration);
- // Limit speed
- velocity.limit(maxspeed);
- location.add(velocity);
- // Reset accelerationelertion to 0 each cycle
- acceleration.mult(0);
- }
-
- void applyForce(PVector force) {
- // We could add mass here if we want A = F / M
- acceleration.add(force);
- }
-
- // A method that calculates a steering force towards a target
- // STEER = DESIRED MINUS VELOCITY
- void seek(PVector target) {
- PVector desired = PVector.sub(target,location); // A vector pointing from the location to the target
-
- // Scale to maximum speed
- desired.setMag(maxspeed);
-
- // Steering = Desired minus velocity
- PVector steer = PVector.sub(desired,velocity);
- steer.limit(maxforce); // Limit to maximum steering force
-
- applyForce(steer);
- }
-
- void display() {
- // Draw a triangle rotated in the direction of velocity
- float theta = velocity.heading2D() + PI/2;
- fill(127);
- stroke(0);
- strokeWeight(1);
- pushMatrix();
- translate(location.x,location.y);
- rotate(theta);
- beginShape();
- vertex(0, -r*2);
- vertex(-r, r*2);
- vertex(r, r*2);
- endShape(CLOSE);
- popMatrix();
-
-
- }
-}
-
diff --git a/java/examples/Books/Nature of Code/chp6_agents/NOC_6_01_Seek_trail/NOC_6_01_Seek_trail.pde b/java/examples/Books/Nature of Code/chp6_agents/NOC_6_01_Seek_trail/NOC_6_01_Seek_trail.pde
deleted file mode 100644
index 5ec2d5091..000000000
--- a/java/examples/Books/Nature of Code/chp6_agents/NOC_6_01_Seek_trail/NOC_6_01_Seek_trail.pde
+++ /dev/null
@@ -1,33 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Implements Craig Reynold's autonomous steering behaviors
-// One vehicle "seeks"
-// See: http://www.red3d.com/cwr/
-
-Vehicle v;
-
-void setup() {
- size(800, 200);
- v = new Vehicle(width/2, height/2);
-}
-
-void draw() {
-
- background(255);
-
- PVector mouse = new PVector(mouseX, mouseY);
-
- // Draw an ellipse at the mouse location
- fill(200);
- stroke(0);
- strokeWeight(2);
- ellipse(mouse.x, mouse.y, 48, 48);
-
- // Call the appropriate steering behaviors for our agents
- v.seek(mouse);
- v.update();
- v.display();
-}
-
diff --git a/java/examples/Books/Nature of Code/chp6_agents/NOC_6_01_Seek_trail/Vehicle.pde b/java/examples/Books/Nature of Code/chp6_agents/NOC_6_01_Seek_trail/Vehicle.pde
deleted file mode 100644
index d0b33d652..000000000
--- a/java/examples/Books/Nature of Code/chp6_agents/NOC_6_01_Seek_trail/Vehicle.pde
+++ /dev/null
@@ -1,91 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// The "Vehicle" class
-
-class Vehicle {
- ArrayList history = new ArrayList();
-
- PVector location;
- PVector velocity;
- PVector acceleration;
- float r;
- float maxforce; // Maximum steering force
- float maxspeed; // Maximum speed
-
- Vehicle(float x, float y) {
- acceleration = new PVector(0,0);
- velocity = new PVector(0,-2);
- location = new PVector(x,y);
- r = 6;
- maxspeed = 4;
- maxforce = 0.1;
- }
-
- // Method to update location
- void update() {
- // Update velocity
- velocity.add(acceleration);
- // Limit speed
- velocity.limit(maxspeed);
- location.add(velocity);
- // Reset accelerationelertion to 0 each cycle
- acceleration.mult(0);
-
- history.add(location.get());
- if (history.size() > 100) {
- history.remove(0);
- }
- }
-
- void applyForce(PVector force) {
- // We could add mass here if we want A = F / M
- acceleration.add(force);
- }
-
- // A method that calculates a steering force towards a target
- // STEER = DESIRED MINUS VELOCITY
- void seek(PVector target) {
- PVector desired = PVector.sub(target,location); // A vector pointing from the location to the target
-
- // Normalize desired and scale to maximum speed
- desired.normalize();
- desired.mult(maxspeed);
- // Steering = Desired minus velocity
- PVector steer = PVector.sub(desired,velocity);
- steer.limit(maxforce); // Limit to maximum steering force
-
- applyForce(steer);
- }
-
- void display() {
- beginShape();
- stroke(0);
- strokeWeight(1);
- noFill();
- for(PVector v: history) {
- vertex(v.x,v.y);
- }
- endShape();
-
-
- // Draw a triangle rotated in the direction of velocity
- float theta = velocity.heading2D() + PI/2;
- fill(127);
- stroke(0);
- strokeWeight(1);
- pushMatrix();
- translate(location.x,location.y);
- rotate(theta);
- beginShape();
- vertex(0, -r*2);
- vertex(-r, r*2);
- vertex(r, r*2);
- endShape(CLOSE);
- popMatrix();
-
-
- }
-}
-
diff --git a/java/examples/Books/Nature of Code/chp6_agents/NOC_6_02_Arrive/NOC_6_02_Arrive.pde b/java/examples/Books/Nature of Code/chp6_agents/NOC_6_02_Arrive/NOC_6_02_Arrive.pde
deleted file mode 100644
index bd445d818..000000000
--- a/java/examples/Books/Nature of Code/chp6_agents/NOC_6_02_Arrive/NOC_6_02_Arrive.pde
+++ /dev/null
@@ -1,30 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// One vehicle "arrives"
-// See: http://www.red3d.com/cwr/
-
-Vehicle v;
-
-void setup() {
- size(640, 360);
- v = new Vehicle(width/2, height/2);
-}
-
-void draw() {
- background(255);
-
- PVector mouse = new PVector(mouseX, mouseY);
-
- // Draw an ellipse at the mouse location
- fill(200);
- stroke(0);
- strokeWeight(2);
- ellipse(mouse.x, mouse.y, 48, 48);
-
- // Call the appropriate steering behaviors for our agents
- v.arrive(mouse);
- v.update();
- v.display();
-}
diff --git a/java/examples/Books/Nature of Code/chp6_agents/NOC_6_02_Arrive/Vehicle.pde b/java/examples/Books/Nature of Code/chp6_agents/NOC_6_02_Arrive/Vehicle.pde
deleted file mode 100644
index a00eb9c4f..000000000
--- a/java/examples/Books/Nature of Code/chp6_agents/NOC_6_02_Arrive/Vehicle.pde
+++ /dev/null
@@ -1,80 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// The "Vehicle" class
-
-class Vehicle {
-
- PVector location;
- PVector velocity;
- PVector acceleration;
- float r;
- float maxforce; // Maximum steering force
- float maxspeed; // Maximum speed
-
- Vehicle(float x, float y) {
- acceleration = new PVector(0,0);
- velocity = new PVector(0,0);
- location = new PVector(x,y);
- r = 6;
- maxspeed = 4;
- maxforce = 0.1;
- }
-
- // Method to update location
- void update() {
- // Update velocity
- velocity.add(acceleration);
- // Limit speed
- velocity.limit(maxspeed);
- location.add(velocity);
- // Reset accelerationelertion to 0 each cycle
- acceleration.mult(0);
- }
-
- void applyForce(PVector force) {
- // We could add mass here if we want A = F / M
- acceleration.add(force);
- }
-
- // A method that calculates a steering force towards a target
- // STEER = DESIRED MINUS VELOCITY
- void arrive(PVector target) {
- PVector desired = PVector.sub(target,location); // A vector pointing from the location to the target
- float d = desired.mag();
- // Scale with arbitrary damping within 100 pixels
- if (d < 100) {
- float m = map(d,0,100,0,maxspeed);
- desired.setMag(m);
- } else {
- desired.setMag(maxspeed);
- }
-
- // Steering = Desired minus Velocity
- PVector steer = PVector.sub(desired,velocity);
- steer.limit(maxforce); // Limit to maximum steering force
- applyForce(steer);
- }
-
- void display() {
-
- // Draw a triangle rotated in the direction of velocity
- float theta = velocity.heading2D() + PI/2;
- fill(127);
- stroke(0);
- strokeWeight(1);
- pushMatrix();
- translate(location.x,location.y);
- rotate(theta);
- beginShape();
- vertex(0, -r*2);
- vertex(-r, r*2);
- vertex(r, r*2);
- endShape(CLOSE);
- popMatrix();
-
-
- }
-}
-
diff --git a/java/examples/Books/Nature of Code/chp6_agents/NOC_6_03_StayWithinWalls/NOC_6_03_StayWithinWalls.pde b/java/examples/Books/Nature of Code/chp6_agents/NOC_6_03_StayWithinWalls/NOC_6_03_StayWithinWalls.pde
deleted file mode 100644
index dbc5d3a5a..000000000
--- a/java/examples/Books/Nature of Code/chp6_agents/NOC_6_03_StayWithinWalls/NOC_6_03_StayWithinWalls.pde
+++ /dev/null
@@ -1,36 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Stay Within Walls
-// "Made-up" Steering behavior to stay within walls
-
-
-Vehicle v;
-boolean debug = true;
-
-float d = 25;
-
-void setup() {
- size(640, 360);
- v = new Vehicle(width/2, height/2);
-}
-
-void draw() {
- background(255);
-
- if (debug) {
- stroke(175);
- noFill();
- rectMode(CENTER);
- rect(width/2, height/2, width-d*2, height-d*2);
- }
-
- v.boundaries();
- v.run();
-}
-
-void mousePressed() {
- debug = !debug;
-}
-
diff --git a/java/examples/Books/Nature of Code/chp6_agents/NOC_6_03_StayWithinWalls/Vehicle.pde b/java/examples/Books/Nature of Code/chp6_agents/NOC_6_03_StayWithinWalls/Vehicle.pde
deleted file mode 100644
index 9a507181c..000000000
--- a/java/examples/Books/Nature of Code/chp6_agents/NOC_6_03_StayWithinWalls/Vehicle.pde
+++ /dev/null
@@ -1,92 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// The "Vehicle" class
-
-class Vehicle {
-
- PVector location;
- PVector velocity;
- PVector acceleration;
- float r;
-
- float maxspeed;
- float maxforce;
-
- Vehicle(float x, float y) {
- acceleration = new PVector(0, 0);
- velocity = new PVector(3, -2);
- velocity.mult(5);
- location = new PVector(x, y);
- r = 6;
- maxspeed = 3;
- maxforce = 0.15;
- }
-
- void run() {
- update();
- display();
- }
-
- // Method to update location
- void update() {
- // Update velocity
- velocity.add(acceleration);
- // Limit speed
- velocity.limit(maxspeed);
- location.add(velocity);
- // Reset accelertion to 0 each cycle
- acceleration.mult(0);
- }
-
- void boundaries() {
-
- PVector desired = null;
-
- if (location.x < d) {
- desired = new PVector(maxspeed, velocity.y);
- }
- else if (location.x > width -d) {
- desired = new PVector(-maxspeed, velocity.y);
- }
-
- if (location.y < d) {
- desired = new PVector(velocity.x, maxspeed);
- }
- else if (location.y > height-d) {
- desired = new PVector(velocity.x, -maxspeed);
- }
-
- if (desired != null) {
- desired.normalize();
- desired.mult(maxspeed);
- PVector steer = PVector.sub(desired, velocity);
- steer.limit(maxforce);
- applyForce(steer);
- }
- }
-
- void applyForce(PVector force) {
- // We could add mass here if we want A = F / M
- acceleration.add(force);
- }
-
-
- void display() {
- // Draw a triangle rotated in the direction of velocity
- float theta = velocity.heading2D() + radians(90);
- fill(127);
- stroke(0);
- pushMatrix();
- translate(location.x, location.y);
- rotate(theta);
- beginShape(TRIANGLES);
- vertex(0, -r*2);
- vertex(-r, r*2);
- vertex(r, r*2);
- endShape();
- popMatrix();
- }
-}
-
diff --git a/java/examples/Books/Nature of Code/chp6_agents/NOC_6_03_StayWithinWalls_trail/NOC_6_03_StayWithinWalls_trail.pde b/java/examples/Books/Nature of Code/chp6_agents/NOC_6_03_StayWithinWalls_trail/NOC_6_03_StayWithinWalls_trail.pde
deleted file mode 100644
index c260f716a..000000000
--- a/java/examples/Books/Nature of Code/chp6_agents/NOC_6_03_StayWithinWalls_trail/NOC_6_03_StayWithinWalls_trail.pde
+++ /dev/null
@@ -1,37 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Stay Within Walls
-// "Made-up" Steering behavior to stay within walls
-
-
-Vehicle v;
-boolean debug = true;
-
-float d = 25;
-
-
-void setup() {
- size(640, 360);
- v = new Vehicle(width/2, height/2);
-}
-
-void draw() {
- background(255);
-
- if (debug) {
- stroke(175);
- noFill();
- rectMode(CENTER);
- rect(width/2, height/2, width-d*2, height-d*2);
- }
-
- v.boundaries();
- v.run();
-}
-
-void mousePressed() {
- debug = !debug;
-}
-
diff --git a/java/examples/Books/Nature of Code/chp6_agents/NOC_6_03_StayWithinWalls_trail/Vehicle.pde b/java/examples/Books/Nature of Code/chp6_agents/NOC_6_03_StayWithinWalls_trail/Vehicle.pde
deleted file mode 100644
index 0d94054a4..000000000
--- a/java/examples/Books/Nature of Code/chp6_agents/NOC_6_03_StayWithinWalls_trail/Vehicle.pde
+++ /dev/null
@@ -1,108 +0,0 @@
-// Wander
-// Daniel Shiffman
-// The Nature of Code
-
-// The "Vehicle" class
-
-class Vehicle {
- ArrayList history = new ArrayList();
-
- PVector location;
- PVector velocity;
- PVector acceleration;
- float r;
-
- float maxspeed;
- float maxforce;
-
- Vehicle(float x, float y) {
- acceleration = new PVector(0, 0);
- velocity = new PVector(3, -2);
- velocity.mult(5);
- location = new PVector(x, y);
- r = 6;
- maxspeed = 3;
- maxforce = 0.15;
- }
-
- void run() {
- update();
- display();
- }
-
- // Method to update location
- void update() {
- // Update velocity
- velocity.add(acceleration);
- // Limit speed
- velocity.limit(maxspeed);
- location.add(velocity);
- // Reset accelertion to 0 each cycle
- acceleration.mult(0);
-
- history.add(location.get());
- if (history.size() > 500) {
- history.remove(0);
- }
- }
-
- void boundaries() {
-
- PVector desired = null;
-
- if (location.x < d) {
- desired = new PVector(maxspeed, velocity.y);
- }
- else if (location.x > width -d) {
- desired = new PVector(-maxspeed, velocity.y);
- }
-
- if (location.y < d) {
- desired = new PVector(velocity.x, maxspeed);
- }
- else if (location.y > height-d) {
- desired = new PVector(velocity.x, -maxspeed);
- }
-
- if (desired != null) {
- desired.normalize();
- desired.mult(maxspeed);
- PVector steer = PVector.sub(desired, velocity);
- steer.limit(maxforce);
- applyForce(steer);
- }
- }
-
- void applyForce(PVector force) {
- // We could add mass here if we want A = F / M
- acceleration.add(force);
- }
-
-
- void display() {
- beginShape();
- stroke(0);
- strokeWeight(1);
- noFill();
- for(PVector v: history) {
- vertex(v.x,v.y);
- }
- endShape();
-
-
- // Draw a triangle rotated in the direction of velocity
- float theta = velocity.heading2D() + radians(90);
- fill(127);
- stroke(0);
- pushMatrix();
- translate(location.x, location.y);
- rotate(theta);
- beginShape(TRIANGLES);
- vertex(0, -r*2);
- vertex(-r, r*2);
- vertex(r, r*2);
- endShape();
- popMatrix();
- }
-}
-
diff --git a/java/examples/Books/Nature of Code/chp6_agents/NOC_6_04_Flow_Figures/FlowField.pde b/java/examples/Books/Nature of Code/chp6_agents/NOC_6_04_Flow_Figures/FlowField.pde
deleted file mode 100644
index 75b471b29..000000000
--- a/java/examples/Books/Nature of Code/chp6_agents/NOC_6_04_Flow_Figures/FlowField.pde
+++ /dev/null
@@ -1,94 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Flow Field Following
-
-class FlowField {
-
- // A flow field is a two dimensional array of PVectors
- PVector[][] field;
- int cols, rows; // Columns and Rows
- int resolution; // How large is each "cell" of the flow field
-
- FlowField(int r) {
- resolution = r;
- // Determine the number of columns and rows based on sketch's width and height
- cols = width/resolution;
- rows = height/resolution;
- field = new PVector[cols][rows];
- init();
- }
-
- void init() {
- // Reseed noise so we get a new flow field every time
- noiseSeed((int)random(10000));
- float xoff = 0;
- for (int i = 0; i < cols; i++) {
- float yoff = 0;
- for (int j = 0; j < rows; j++) {
- //float theta = random(TWO_PI);
- //float theta = map(noise(xoff,yoff),0,1,0,TWO_PI);
- float x = i*resolution;
- float y = j*resolution;
- PVector v = new PVector(width/2-x,-y);
- v.normalize();
- // Polar to cartesian coordinate transformation to get x and y components of the vector
- field[i][j] = v;// new PVector(cos(theta),sin(theta));
- yoff += 0.1;
- }
- xoff += 0.1;
- }
- }
-
- // Draw every vector
- void display() {
- for (int i = 0; i < cols; i++) {
- for (int j = 0; j < rows; j++) {
- //drawVector(field[i][j],i*resolution,j*resolution,resolution-2);
- pushMatrix();
- //translate(i*resolution+arrow.width/2,j*resolution+arrow.height/2);
- translate(i*resolution,j*resolution);
- rotate(field[i][j].heading2D());
- imageMode(CENTER);
- //scale(0.2);
- image(a,0,0);
- //shape(arrow,-arrow.width/2,-arrow.height/2);
- //ellipse(0,0,8,8);
- popMatrix();
- }
- }
-
- }
-
- // Renders a vector object 'v' as an arrow and a location 'x,y'
- void drawVector(PVector v, float x, float y, float scayl) {
- pushMatrix();
- float arrowsize = 4;
- // Translate to location to render vector
- translate(x,y);
- stroke(0,100);
- // Call vector heading function to get direction (note that pointing up is a heading of 0) and rotate
- rotate(v.heading2D());
- // Calculate length of vector & scale it to be bigger or smaller if necessary
- float len = v.mag()*scayl;
- // Draw three lines to make an arrow (draw pointing up since we've rotate to the proper direction)
- line(0,0,len,0);
- line(len,0,len-arrowsize,+arrowsize/2);
- line(len,0,len-arrowsize,-arrowsize/2);
- popMatrix();
- }
-
- PVector lookup(PVector lookup) {
- int column = int(constrain(lookup.x/resolution,0,cols-1));
- int row = int(constrain(lookup.y/resolution,0,rows-1));
- return field[column][row].get();
- }
-
-
-}
-
-
-
-
-
diff --git a/java/examples/Books/Nature of Code/chp6_agents/NOC_6_04_Flow_Figures/NOC_6_04_Flow_Figures.pde b/java/examples/Books/Nature of Code/chp6_agents/NOC_6_04_Flow_Figures/NOC_6_04_Flow_Figures.pde
deleted file mode 100644
index beb0642c9..000000000
--- a/java/examples/Books/Nature of Code/chp6_agents/NOC_6_04_Flow_Figures/NOC_6_04_Flow_Figures.pde
+++ /dev/null
@@ -1,35 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Flow Field Following
-
-// Via Reynolds: http://www.red3d.com/cwr/steer/FlowFollow.html
-
-// Flowfield object
-FlowField flowfield;
-PShape arrow;
-PImage a;
-
-void setup() {
- size(1800, 60*9);
- // Make a new flow field with "resolution" of 16
- flowfield = new FlowField(60);
- arrow = loadShape("arrow.svg");
- a = loadImage("arrow60.png");
-}
-
-void draw() {
- background(255);
- // Display the flowfield in "debug" mode
- translate(30,30);
- flowfield.display();
- saveFrame("ch6_exc6.png");
- noLoop();
-}
-// Make a new flowfield
-void mousePressed() {
- flowfield.init();
-}
-
-
diff --git a/java/examples/Books/Nature of Code/chp6_agents/NOC_6_04_Flow_Figures/Vehicle.pde b/java/examples/Books/Nature of Code/chp6_agents/NOC_6_04_Flow_Figures/Vehicle.pde
deleted file mode 100644
index 2326a1e7c..000000000
--- a/java/examples/Books/Nature of Code/chp6_agents/NOC_6_04_Flow_Figures/Vehicle.pde
+++ /dev/null
@@ -1,87 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Flow Field Following
-
-class Vehicle {
-
- // The usual stuff
- PVector location;
- PVector velocity;
- PVector acceleration;
- float r;
- float maxforce; // Maximum steering force
- float maxspeed; // Maximum speed
-
- Vehicle(PVector l, float ms, float mf) {
- location = l.get();
- r = 3.0;
- maxspeed = ms;
- maxforce = mf;
- acceleration = new PVector(0,0);
- velocity = new PVector(0,0);
- }
-
- public void run() {
- update();
- borders();
- display();
- }
-
-
- // Implementing Reynolds' flow field following algorithm
- // http://www.red3d.com/cwr/steer/FlowFollow.html
- void follow(FlowField flow) {
- // What is the vector at that spot in the flow field?
- PVector desired = flow.lookup(location);
- // Scale it up by maxspeed
- desired.mult(maxspeed);
- // Steering is desired minus velocity
- PVector steer = PVector.sub(desired, velocity);
- steer.limit(maxforce); // Limit to maximum steering force
- applyForce(steer);
- }
-
- void applyForce(PVector force) {
- // We could add mass here if we want A = F / M
- acceleration.add(force);
- }
-
- // Method to update location
- void update() {
- // Update velocity
- velocity.add(acceleration);
- // Limit speed
- velocity.limit(maxspeed);
- location.add(velocity);
- // Reset accelertion to 0 each cycle
- acceleration.mult(0);
- }
-
- void display() {
- // Draw a triangle rotated in the direction of velocity
- float theta = velocity.heading2D() + radians(90);
- fill(175);
- stroke(0);
- pushMatrix();
- translate(location.x,location.y);
- rotate(theta);
- beginShape(TRIANGLES);
- vertex(0, -r*2);
- vertex(-r, r*2);
- vertex(r, r*2);
- endShape();
- popMatrix();
- }
-
- // Wraparound
- void borders() {
- if (location.x < -r) location.x = width+r;
- if (location.y < -r) location.y = height+r;
- if (location.x > width+r) location.x = -r;
- if (location.y > height+r) location.y = -r;
- }
-}
-
-
diff --git a/java/examples/Books/Nature of Code/chp6_agents/NOC_6_04_Flow_Figures/data/arrow.svg b/java/examples/Books/Nature of Code/chp6_agents/NOC_6_04_Flow_Figures/data/arrow.svg
deleted file mode 100644
index 0f34115e7..000000000
--- a/java/examples/Books/Nature of Code/chp6_agents/NOC_6_04_Flow_Figures/data/arrow.svg
+++ /dev/null
@@ -1,5149 +0,0 @@
-
-
-
-
diff --git a/java/examples/Books/Nature of Code/chp6_agents/NOC_6_04_Flowfield/FlowField.pde b/java/examples/Books/Nature of Code/chp6_agents/NOC_6_04_Flowfield/FlowField.pde
deleted file mode 100644
index 08bf7eb23..000000000
--- a/java/examples/Books/Nature of Code/chp6_agents/NOC_6_04_Flowfield/FlowField.pde
+++ /dev/null
@@ -1,79 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Flow Field Following
-
-class FlowField {
-
- // A flow field is a two dimensional array of PVectors
- PVector[][] field;
- int cols, rows; // Columns and Rows
- int resolution; // How large is each "cell" of the flow field
-
- FlowField(int r) {
- resolution = r;
- // Determine the number of columns and rows based on sketch's width and height
- cols = width/resolution;
- rows = height/resolution;
- field = new PVector[cols][rows];
- init();
- }
-
- void init() {
- // Reseed noise so we get a new flow field every time
- noiseSeed((int)random(10000));
- float xoff = 0;
- for (int i = 0; i < cols; i++) {
- float yoff = 0;
- for (int j = 0; j < rows; j++) {
- float theta = map(noise(xoff,yoff),0,1,0,TWO_PI);
- // Polar to cartesian coordinate transformation to get x and y components of the vector
- field[i][j] = new PVector(cos(theta),sin(theta));
- yoff += 0.1;
- }
- xoff += 0.1;
- }
- }
-
- // Draw every vector
- void display() {
- for (int i = 0; i < cols; i++) {
- for (int j = 0; j < rows; j++) {
- drawVector(field[i][j],i*resolution,j*resolution,resolution-2);
- }
- }
-
- }
-
- // Renders a vector object 'v' as an arrow and a location 'x,y'
- void drawVector(PVector v, float x, float y, float scayl) {
- pushMatrix();
- float arrowsize = 4;
- // Translate to location to render vector
- translate(x,y);
- stroke(0,100);
- // Call vector heading function to get direction (note that pointing up is a heading of 0) and rotate
- rotate(v.heading2D());
- // Calculate length of vector & scale it to be bigger or smaller if necessary
- float len = v.mag()*scayl;
- // Draw three lines to make an arrow (draw pointing up since we've rotate to the proper direction)
- line(0,0,len,0);
- //line(len,0,len-arrowsize,+arrowsize/2);
- //line(len,0,len-arrowsize,-arrowsize/2);
- popMatrix();
- }
-
- PVector lookup(PVector lookup) {
- int column = int(constrain(lookup.x/resolution,0,cols-1));
- int row = int(constrain(lookup.y/resolution,0,rows-1));
- return field[column][row].get();
- }
-
-
-}
-
-
-
-
-
diff --git a/java/examples/Books/Nature of Code/chp6_agents/NOC_6_04_Flowfield/NOC_6_04_Flowfield.pde b/java/examples/Books/Nature of Code/chp6_agents/NOC_6_04_Flowfield/NOC_6_04_Flowfield.pde
deleted file mode 100644
index 86a2c4c29..000000000
--- a/java/examples/Books/Nature of Code/chp6_agents/NOC_6_04_Flowfield/NOC_6_04_Flowfield.pde
+++ /dev/null
@@ -1,55 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Flow Field Following
-// Via Reynolds: http://www.red3d.com/cwr/steer/FlowFollow.html
-
-// Using this variable to decide whether to draw all the stuff
-boolean debug = true;
-
-// Flowfield object
-FlowField flowfield;
-// An ArrayList of vehicles
-ArrayList vehicles;
-
-void setup() {
- size(640, 360);
- // Make a new flow field with "resolution" of 16
- flowfield = new FlowField(20);
- vehicles = new ArrayList();
- // Make a whole bunch of vehicles with random maxspeed and maxforce values
- for (int i = 0; i < 120; i++) {
- vehicles.add(new Vehicle(new PVector(random(width), random(height)), random(2, 5), random(0.1, 0.5)));
- }
-}
-
-void draw() {
- background(255);
- // Display the flowfield in "debug" mode
- if (debug) flowfield.display();
- // Tell all the vehicles to follow the flow field
- for (Vehicle v : vehicles) {
- v.follow(flowfield);
- v.run();
- }
-
- // Instructions
- fill(0);
- text("Hit space bar to toggle debugging lines.\nClick the mouse to generate a new flow field.",10,height-20);
-}
-
-
-void keyPressed() {
- if (key == ' ') {
- debug = !debug;
- }
-}
-
-// Make a new flowfield
-void mousePressed() {
- flowfield.init();
-}
-
-
-
diff --git a/java/examples/Books/Nature of Code/chp6_agents/NOC_6_04_Flowfield/Vehicle.pde b/java/examples/Books/Nature of Code/chp6_agents/NOC_6_04_Flowfield/Vehicle.pde
deleted file mode 100644
index 2326a1e7c..000000000
--- a/java/examples/Books/Nature of Code/chp6_agents/NOC_6_04_Flowfield/Vehicle.pde
+++ /dev/null
@@ -1,87 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Flow Field Following
-
-class Vehicle {
-
- // The usual stuff
- PVector location;
- PVector velocity;
- PVector acceleration;
- float r;
- float maxforce; // Maximum steering force
- float maxspeed; // Maximum speed
-
- Vehicle(PVector l, float ms, float mf) {
- location = l.get();
- r = 3.0;
- maxspeed = ms;
- maxforce = mf;
- acceleration = new PVector(0,0);
- velocity = new PVector(0,0);
- }
-
- public void run() {
- update();
- borders();
- display();
- }
-
-
- // Implementing Reynolds' flow field following algorithm
- // http://www.red3d.com/cwr/steer/FlowFollow.html
- void follow(FlowField flow) {
- // What is the vector at that spot in the flow field?
- PVector desired = flow.lookup(location);
- // Scale it up by maxspeed
- desired.mult(maxspeed);
- // Steering is desired minus velocity
- PVector steer = PVector.sub(desired, velocity);
- steer.limit(maxforce); // Limit to maximum steering force
- applyForce(steer);
- }
-
- void applyForce(PVector force) {
- // We could add mass here if we want A = F / M
- acceleration.add(force);
- }
-
- // Method to update location
- void update() {
- // Update velocity
- velocity.add(acceleration);
- // Limit speed
- velocity.limit(maxspeed);
- location.add(velocity);
- // Reset accelertion to 0 each cycle
- acceleration.mult(0);
- }
-
- void display() {
- // Draw a triangle rotated in the direction of velocity
- float theta = velocity.heading2D() + radians(90);
- fill(175);
- stroke(0);
- pushMatrix();
- translate(location.x,location.y);
- rotate(theta);
- beginShape(TRIANGLES);
- vertex(0, -r*2);
- vertex(-r, r*2);
- vertex(r, r*2);
- endShape();
- popMatrix();
- }
-
- // Wraparound
- void borders() {
- if (location.x < -r) location.x = width+r;
- if (location.y < -r) location.y = height+r;
- if (location.x > width+r) location.x = -r;
- if (location.y > height+r) location.y = -r;
- }
-}
-
-
diff --git a/java/examples/Books/Nature of Code/chp6_agents/NOC_6_05_PathFollowingSimple/NOC_6_05_PathFollowingSimple.pde b/java/examples/Books/Nature of Code/chp6_agents/NOC_6_05_PathFollowingSimple/NOC_6_05_PathFollowingSimple.pde
deleted file mode 100644
index abe2f5e9a..000000000
--- a/java/examples/Books/Nature of Code/chp6_agents/NOC_6_05_PathFollowingSimple/NOC_6_05_PathFollowingSimple.pde
+++ /dev/null
@@ -1,55 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Path Following
-// Path is a just a straight line in this example
-// Via Reynolds: // http://www.red3d.com/cwr/steer/PathFollow.html
-
-// Using this variable to decide whether to draw all the stuff
-boolean debug = true;
-
-// A path object (series of connected points)
-Path path;
-
-// Two vehicles
-Vehicle car1;
-Vehicle car2;
-
-void setup() {
- size(640, 360);
- path = new Path();
-
- // Each vehicle has different maxspeed and maxforce for demo purposes
- car1 = new Vehicle(new PVector(0, height/2), 2, 0.02);
- car2 = new Vehicle(new PVector(0, height/2), 3, 0.05);
-}
-
-void draw() {
- background(255);
- // Display the path
- path.display();
- // The boids follow the path
- car1.follow(path);
- car2.follow(path);
- // Call the generic run method (update, borders, display, etc.)
- car1.run();
- car2.run();
-
- // Check if it gets to the end of the path since it's not a loop
- car1.borders(path);
- car2.borders(path);
-
- // Instructions
- fill(0);
- text("Hit space bar to toggle debugging lines.", 10, height-30);
-}
-
-public void keyPressed() {
- if (key == ' ') {
- debug = !debug;
- }
-}
-
-
-
diff --git a/java/examples/Books/Nature of Code/chp6_agents/NOC_6_05_PathFollowingSimple/Path.pde b/java/examples/Books/Nature of Code/chp6_agents/NOC_6_05_PathFollowingSimple/Path.pde
deleted file mode 100644
index 3d222214d..000000000
--- a/java/examples/Books/Nature of Code/chp6_agents/NOC_6_05_PathFollowingSimple/Path.pde
+++ /dev/null
@@ -1,44 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Path Following
-
-class Path {
-
- // A Path is line between two points (PVector objects)
- PVector start;
- PVector end;
- // A path has a radius, i.e how far is it ok for the boid to wander off
- float radius;
-
- Path() {
- // Arbitrary radius of 20
- radius = 20;
- start = new PVector(0,height/3);
- end = new PVector(width,2*height/3);
- }
-
- // Draw the path
- void display() {
-
- strokeWeight(radius*2);
- stroke(0,100);
- line(start.x,start.y,end.x,end.y);
-
- strokeWeight(1);
- stroke(0);
- line(start.x,start.y,end.x,end.y);
- }
-}
-
-
-
-
-
-
-
-
-
-
-
diff --git a/java/examples/Books/Nature of Code/chp6_agents/NOC_6_05_PathFollowingSimple/Vehicle.pde b/java/examples/Books/Nature of Code/chp6_agents/NOC_6_05_PathFollowingSimple/Vehicle.pde
deleted file mode 100644
index 1fdbd172e..000000000
--- a/java/examples/Books/Nature of Code/chp6_agents/NOC_6_05_PathFollowingSimple/Vehicle.pde
+++ /dev/null
@@ -1,160 +0,0 @@
-// Path Following
-// Daniel Shiffman
-// The Nature of Code, Spring 2009
-
-// Vehicle class
-
-class Vehicle {
-
- // All the usual stuff
- PVector location;
- PVector velocity;
- PVector acceleration;
- float r;
- float maxforce; // Maximum steering force
- float maxspeed; // Maximum speed
-
- // Constructor initialize all values
- Vehicle( PVector l, float ms, float mf) {
- location = l.get();
- r = 4.0;
- maxspeed = ms;
- maxforce = mf;
- acceleration = new PVector(0, 0);
- velocity = new PVector(maxspeed, 0);
- }
-
- // Main "run" function
- void run() {
- update();
- display();
- }
-
-
- // This function implements Craig Reynolds' path following algorithm
- // http://www.red3d.com/cwr/steer/PathFollow.html
- void follow(Path p) {
-
- // Predict location 50 (arbitrary choice) frames ahead
- PVector predict = velocity.get();
- predict.normalize();
- predict.mult(50);
- PVector predictLoc = PVector.add(location, predict);
-
- // Look at the line segment
- PVector a = p.start;
- PVector b = p.end;
-
- // Get the normal point to that line
- PVector normalPoint = getNormalPoint(predictLoc, a, b);
-
- // Find target point a little further ahead of normal
- PVector dir = PVector.sub(b, a);
- dir.normalize();
- dir.mult(10); // This could be based on velocity instead of just an arbitrary 10 pixels
- PVector target = PVector.add(normalPoint, dir);
-
- // How far away are we from the path?
- float distance = PVector.dist(predictLoc, normalPoint);
- // Only if the distance is greater than the path's radius do we bother to steer
- if (distance > p.radius) {
- seek(target);
- }
-
-
- // Draw the debugging stuff
- if (debug) {
- fill(0);
- stroke(0);
- line(location.x, location.y, predictLoc.x, predictLoc.y);
- ellipse(predictLoc.x, predictLoc.y, 4, 4);
-
- // Draw normal location
- fill(0);
- stroke(0);
- line(predictLoc.x, predictLoc.y, normalPoint.x, normalPoint.y);
- ellipse(normalPoint.x, normalPoint.y, 4, 4);
- stroke(0);
- if (distance > p.radius) fill(255, 0, 0);
- noStroke();
- ellipse(target.x+dir.x, target.y+dir.y, 8, 8);
- }
- }
-
-
- // A function to get the normal point from a point (p) to a line segment (a-b)
- // This function could be optimized to make fewer new Vector objects
- PVector getNormalPoint(PVector p, PVector a, PVector b) {
- // Vector from a to p
- PVector ap = PVector.sub(p, a);
- // Vector from a to b
- PVector ab = PVector.sub(b, a);
- ab.normalize(); // Normalize the line
- // Project vector "diff" onto line by using the dot product
- ab.mult(ap.dot(ab));
- PVector normalPoint = PVector.add(a, ab);
- return normalPoint;
- }
-
-
- // Method to update location
- void update() {
- // Update velocity
- velocity.add(acceleration);
- // Limit speed
- velocity.limit(maxspeed);
- location.add(velocity);
- // Reset accelertion to 0 each cycle
- acceleration.mult(0);
- }
-
- void applyForce(PVector force) {
- // We could add mass here if we want A = F / M
- acceleration.add(force);
- }
-
-
- // A method that calculates and applies a steering force towards a target
- // STEER = DESIRED MINUS VELOCITY
- void seek(PVector target) {
- PVector desired = PVector.sub(target, location); // A vector pointing from the location to the target
-
- // If the magnitude of desired equals 0, skip out of here
- // (We could optimize this to check if x and y are 0 to avoid mag() square root
- if (desired.mag() == 0) return;
-
- // Normalize desired and scale to maximum speed
- desired.normalize();
- desired.mult(maxspeed);
- // Steering = Desired minus Velocity
- PVector steer = PVector.sub(desired, velocity);
- steer.limit(maxforce); // Limit to maximum steering force
-
- applyForce(steer);
- }
-
- void display() {
- // Draw a triangle rotated in the direction of velocity
- float theta = velocity.heading2D() + radians(90);
- fill(175);
- stroke(0);
- pushMatrix();
- translate(location.x, location.y);
- rotate(theta);
- beginShape(PConstants.TRIANGLES);
- vertex(0, -r*2);
- vertex(-r, r*2);
- vertex(r, r*2);
- endShape();
- popMatrix();
- }
-
- // Wraparound
- void borders(Path p) {
- if (location.x > p.end.x + r) {
- location.x = p.start.x - r;
- location.y = p.start.y + (location.y-p.end.y);
- }
- }
-}
-
diff --git a/java/examples/Books/Nature of Code/chp6_agents/NOC_6_06_PathFollowing/NOC_6_06_PathFollowing.pde b/java/examples/Books/Nature of Code/chp6_agents/NOC_6_06_PathFollowing/NOC_6_06_PathFollowing.pde
deleted file mode 100644
index b07b478dd..000000000
--- a/java/examples/Books/Nature of Code/chp6_agents/NOC_6_06_PathFollowing/NOC_6_06_PathFollowing.pde
+++ /dev/null
@@ -1,67 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Path Following
-// Via Reynolds: // http://www.red3d.com/cwr/steer/PathFollow.html
-
-// Using this variable to decide whether to draw all the stuff
-boolean debug = true;
-
-// A path object (series of connected points)
-Path path;
-
-// Two vehicles
-Vehicle car1;
-Vehicle car2;
-
-void setup() {
- size(640, 360);
- // Call a function to generate new Path object
- newPath();
-
- // Each vehicle has different maxspeed and maxforce for demo purposes
- car1 = new Vehicle(new PVector(0, height/2), 2, 0.04);
- car2 = new Vehicle(new PVector(0, height/2), 3, 0.1);
-}
-
-void draw() {
- background(255);
- // Display the path
- path.display();
- // The boids follow the path
- car1.follow(path);
- car2.follow(path);
- // Call the generic run method (update, borders, display, etc.)
- car1.run();
- car2.run();
-
- car1.borders(path);
- car2.borders(path);
-
- // Instructions
- fill(0);
- text("Hit space bar to toggle debugging lines.\nClick the mouse to generate a new path.", 10, height-30);
-}
-
-void newPath() {
- // A path is a series of connected points
- // A more sophisticated path might be a curve
- path = new Path();
- path.addPoint(-20, height/2);
- path.addPoint(random(0, width/2), random(0, height));
- path.addPoint(random(width/2, width), random(0, height));
- path.addPoint(width+20, height/2);
-}
-
-public void keyPressed() {
- if (key == ' ') {
- debug = !debug;
- }
-}
-
-public void mousePressed() {
- newPath();
-}
-
-
diff --git a/java/examples/Books/Nature of Code/chp6_agents/NOC_6_06_PathFollowing/Path.pde b/java/examples/Books/Nature of Code/chp6_agents/NOC_6_06_PathFollowing/Path.pde
deleted file mode 100644
index 8d28b73cb..000000000
--- a/java/examples/Books/Nature of Code/chp6_agents/NOC_6_06_PathFollowing/Path.pde
+++ /dev/null
@@ -1,59 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Path Following
-
-class Path {
-
- // A Path is an arraylist of points (PVector objects)
- ArrayList points;
- // A path has a radius, i.e how far is it ok for the boid to wander off
- float radius;
-
- Path() {
- // Arbitrary radius of 20
- radius = 20;
- points = new ArrayList();
- }
-
- // Add a point to the path
- void addPoint(float x, float y) {
- PVector point = new PVector(x, y);
- points.add(point);
- }
-
- PVector getStart() {
- return points.get(0);
- }
-
- PVector getEnd() {
- return points.get(points.size()-1);
- }
-
-
- // Draw the path
- void display() {
- // Draw thick line for radius
- stroke(175);
- strokeWeight(radius*2);
- noFill();
- beginShape();
- for (PVector v : points) {
- vertex(v.x, v.y);
- }
- endShape();
- // Draw thin line for center of path
- stroke(0);
- strokeWeight(1);
- noFill();
- beginShape();
- for (PVector v : points) {
- vertex(v.x, v.y);
- }
- endShape();
- }
-}
-
-
-
diff --git a/java/examples/Books/Nature of Code/chp6_agents/NOC_6_06_PathFollowing/Vehicle.pde b/java/examples/Books/Nature of Code/chp6_agents/NOC_6_06_PathFollowing/Vehicle.pde
deleted file mode 100644
index 72bd7d1fe..000000000
--- a/java/examples/Books/Nature of Code/chp6_agents/NOC_6_06_PathFollowing/Vehicle.pde
+++ /dev/null
@@ -1,192 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Path Following
-
-// Vehicle class
-
-class Vehicle {
-
- // All the usual stuff
- PVector location;
- PVector velocity;
- PVector acceleration;
- float r;
- float maxforce; // Maximum steering force
- float maxspeed; // Maximum speed
-
- // Constructor initialize all values
- Vehicle( PVector l, float ms, float mf) {
- location = l.get();
- r = 4.0;
- maxspeed = ms;
- maxforce = mf;
- acceleration = new PVector(0, 0);
- velocity = new PVector(maxspeed, 0);
- }
-
- // Main "run" function
- public void run() {
- update();
- display();
- }
-
-
- // This function implements Craig Reynolds' path following algorithm
- // http://www.red3d.com/cwr/steer/PathFollow.html
- void follow(Path p) {
-
- // Predict location 50 (arbitrary choice) frames ahead
- // This could be based on speed
- PVector predict = velocity.get();
- predict.normalize();
- predict.mult(50);
- PVector predictLoc = PVector.add(location, predict);
-
- // Now we must find the normal to the path from the predicted location
- // We look at the normal for each line segment and pick out the closest one
-
- PVector normal = null;
- PVector target = null;
- float worldRecord = 1000000; // Start with a very high record distance that can easily be beaten
-
- // Loop through all points of the path
- for (int i = 0; i < p.points.size()-1; i++) {
-
- // Look at a line segment
- PVector a = p.points.get(i);
- PVector b = p.points.get(i+1);
-
- // Get the normal point to that line
- PVector normalPoint = getNormalPoint(predictLoc, a, b);
- // This only works because we know our path goes from left to right
- // We could have a more sophisticated test to tell if the point is in the line segment or not
- if (normalPoint.x < a.x || normalPoint.x > b.x) {
- // This is something of a hacky solution, but if it's not within the line segment
- // consider the normal to just be the end of the line segment (point b)
- normalPoint = b.get();
- }
-
- // How far away are we from the path?
- float distance = PVector.dist(predictLoc, normalPoint);
- // Did we beat the record and find the closest line segment?
- if (distance < worldRecord) {
- worldRecord = distance;
- // If so the target we want to steer towards is the normal
- normal = normalPoint;
-
- // Look at the direction of the line segment so we can seek a little bit ahead of the normal
- PVector dir = PVector.sub(b, a);
- dir.normalize();
- // This is an oversimplification
- // Should be based on distance to path & velocity
- dir.mult(10);
- target = normalPoint.get();
- target.add(dir);
- }
- }
-
- // Only if the distance is greater than the path's radius do we bother to steer
- if (worldRecord > p.radius) {
- seek(target);
- }
-
-
- // Draw the debugging stuff
- if (debug) {
- // Draw predicted future location
- stroke(0);
- fill(0);
- line(location.x, location.y, predictLoc.x, predictLoc.y);
- ellipse(predictLoc.x, predictLoc.y, 4, 4);
-
- // Draw normal location
- stroke(0);
- fill(0);
- ellipse(normal.x, normal.y, 4, 4);
- // Draw actual target (red if steering towards it)
- line(predictLoc.x, predictLoc.y, normal.x, normal.y);
- if (worldRecord > p.radius) fill(255, 0, 0);
- noStroke();
- ellipse(target.x, target.y, 8, 8);
- }
- }
-
-
- // A function to get the normal point from a point (p) to a line segment (a-b)
- // This function could be optimized to make fewer new Vector objects
- PVector getNormalPoint(PVector p, PVector a, PVector b) {
- // Vector from a to p
- PVector ap = PVector.sub(p, a);
- // Vector from a to b
- PVector ab = PVector.sub(b, a);
- ab.normalize(); // Normalize the line
- // Project vector "diff" onto line by using the dot product
- ab.mult(ap.dot(ab));
- PVector normalPoint = PVector.add(a, ab);
- return normalPoint;
- }
-
-
- // Method to update location
- void update() {
- // Update velocity
- velocity.add(acceleration);
- // Limit speed
- velocity.limit(maxspeed);
- location.add(velocity);
- // Reset accelertion to 0 each cycle
- acceleration.mult(0);
- }
-
- void applyForce(PVector force) {
- // We could add mass here if we want A = F / M
- acceleration.add(force);
- }
-
-
- // A method that calculates and applies a steering force towards a target
- // STEER = DESIRED MINUS VELOCITY
- void seek(PVector target) {
- PVector desired = PVector.sub(target, location); // A vector pointing from the location to the target
-
- // If the magnitude of desired equals 0, skip out of here
- // (We could optimize this to check if x and y are 0 to avoid mag() square root
- if (desired.mag() == 0) return;
-
- // Normalize desired and scale to maximum speed
- desired.normalize();
- desired.mult(maxspeed);
- // Steering = Desired minus Velocity
- PVector steer = PVector.sub(desired, velocity);
- steer.limit(maxforce); // Limit to maximum steering force
-
- applyForce(steer);
- }
-
- void display() {
- // Draw a triangle rotated in the direction of velocity
- float theta = velocity.heading2D() + radians(90);
- fill(175);
- stroke(0);
- pushMatrix();
- translate(location.x, location.y);
- rotate(theta);
- beginShape(PConstants.TRIANGLES);
- vertex(0, -r*2);
- vertex(-r, r*2);
- vertex(r, r*2);
- endShape();
- popMatrix();
- }
-
- // Wraparound
- void borders(Path p) {
- if (location.x > p.getEnd().x + r) {
- location.x = p.getStart().x - r;
- location.y = p.getStart().y + (location.y-p.getEnd().y);
- }
- }
-}
-
diff --git a/java/examples/Books/Nature of Code/chp6_agents/NOC_6_07_Separation/NOC_6_07_Separation.pde b/java/examples/Books/Nature of Code/chp6_agents/NOC_6_07_Separation/NOC_6_07_Separation.pde
deleted file mode 100644
index d884461f2..000000000
--- a/java/examples/Books/Nature of Code/chp6_agents/NOC_6_07_Separation/NOC_6_07_Separation.pde
+++ /dev/null
@@ -1,44 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Separation
-// Via Reynolds: http://www.red3d.com/cwr/steer/
-
-// A list of vehicles
-ArrayList vehicles;
-
-void setup() {
- size(640,360);
- // We are now making random vehicles and storing them in an ArrayList
- vehicles = new ArrayList();
- for (int i = 0; i < 100; i++) {
- vehicles.add(new Vehicle(random(width),random(height)));
- }
-}
-
-void draw() {
- background(255);
-
- for (Vehicle v : vehicles) {
- // Path following and separation are worked on in this function
- v.separate(vehicles);
- // Call the generic run method (update, borders, display, etc.)
- v.update();
- v.borders();
- v.display();
- }
-
- // Instructions
- fill(0);
- text("Drag the mouse to generate new vehicles.",10,height-16);
-}
-
-
-void mouseDragged() {
- vehicles.add(new Vehicle(mouseX,mouseY));
-}
-
-
-
-
diff --git a/java/examples/Books/Nature of Code/chp6_agents/NOC_6_07_Separation/Vehicle.pde b/java/examples/Books/Nature of Code/chp6_agents/NOC_6_07_Separation/Vehicle.pde
deleted file mode 100644
index f0a5ddb96..000000000
--- a/java/examples/Books/Nature of Code/chp6_agents/NOC_6_07_Separation/Vehicle.pde
+++ /dev/null
@@ -1,99 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Vehicle class
-
-class Vehicle {
-
- // All the usual stuff
- PVector location;
- PVector velocity;
- PVector acceleration;
- float r;
- float maxforce; // Maximum steering force
- float maxspeed; // Maximum speed
-
- // Constructor initialize all values
- Vehicle(float x, float y) {
- location = new PVector(x, y);
- r = 12;
- maxspeed = 3;
- maxforce = 0.2;
- acceleration = new PVector(0, 0);
- velocity = new PVector(0, 0);
- }
-
- void applyForce(PVector force) {
- // We could add mass here if we want A = F / M
- acceleration.add(force);
- }
-
- // Separation
- // Method checks for nearby vehicles and steers away
- void separate (ArrayList vehicles) {
- float desiredseparation = r*2;
- PVector sum = new PVector();
- int count = 0;
- // For every boid in the system, check if it's too close
- for (Vehicle other : vehicles) {
- float d = PVector.dist(location, other.location);
- // If the distance is greater than 0 and less than an arbitrary amount (0 when you are yourself)
- if ((d > 0) && (d < desiredseparation)) {
- // Calculate vector pointing away from neighbor
- PVector diff = PVector.sub(location, other.location);
- diff.normalize();
- diff.div(d); // Weight by distance
- sum.add(diff);
- count++; // Keep track of how many
- }
- }
- // Average -- divide by how many
- if (count > 0) {
- sum.div(count);
- // Our desired vector is the average scaled to maximum speed
- sum.normalize();
- sum.mult(maxspeed);
- // Implement Reynolds: Steering = Desired - Velocity
- PVector steer = PVector.sub(sum, velocity);
- steer.limit(maxforce);
- applyForce(steer);
- }
- }
-
-
-
- // Method to update location
- void update() {
- // Update velocity
- velocity.add(acceleration);
- // Limit speed
- velocity.limit(maxspeed);
- location.add(velocity);
- // Reset accelertion to 0 each cycle
- acceleration.mult(0);
- }
-
- void display() {
- fill(175);
- stroke(0);
- pushMatrix();
- translate(location.x, location.y);
- ellipse(0, 0, r, r);
- popMatrix();
- }
-
- // Wraparound
- void borders() {
- if (location.x < -r) location.x = width+r;
- if (location.y < -r) location.y = height+r;
- if (location.x > width+r) location.x = -r;
- if (location.y > height+r) location.y = -r;
- }
-}
-
-
-
-
-
-
diff --git a/java/examples/Books/Nature of Code/chp6_agents/NOC_6_08_SeparationAndSeek/NOC_6_08_SeparationAndSeek.pde b/java/examples/Books/Nature of Code/chp6_agents/NOC_6_08_SeparationAndSeek/NOC_6_08_SeparationAndSeek.pde
deleted file mode 100644
index bc744a1b8..000000000
--- a/java/examples/Books/Nature of Code/chp6_agents/NOC_6_08_SeparationAndSeek/NOC_6_08_SeparationAndSeek.pde
+++ /dev/null
@@ -1,39 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// A list of vehicles
-ArrayList vehicles;
-
-void setup() {
- size(640,360);
- // We are now making random vehicles and storing them in an ArrayList
- vehicles = new ArrayList();
- for (int i = 0; i < 100; i++) {
- vehicles.add(new Vehicle(random(width),random(height)));
- }
-}
-
-void draw() {
- background(255);
-
- for (Vehicle v : vehicles) {
- // Path following and separation are worked on in this function
- v.applyBehaviors(vehicles);
- // Call the generic run method (update, borders, display, etc.)
- v.update();
- v.display();
- }
-
- // Instructions
- fill(0);
- text("Drag the mouse to generate new vehicles.",10,height-16);
-}
-
-
-void mouseDragged() {
- vehicles.add(new Vehicle(mouseX,mouseY));
-}
-
-
-
diff --git a/java/examples/Books/Nature of Code/chp6_agents/NOC_6_08_SeparationAndSeek/Vehicle.pde b/java/examples/Books/Nature of Code/chp6_agents/NOC_6_08_SeparationAndSeek/Vehicle.pde
deleted file mode 100644
index b4270972e..000000000
--- a/java/examples/Books/Nature of Code/chp6_agents/NOC_6_08_SeparationAndSeek/Vehicle.pde
+++ /dev/null
@@ -1,113 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-class Vehicle {
-
- // All the usual stuff
- PVector location;
- PVector velocity;
- PVector acceleration;
- float r;
- float maxforce; // Maximum steering force
- float maxspeed; // Maximum speed
-
- // Constructor initialize all values
- Vehicle(float x, float y) {
- location = new PVector(x, y);
- r = 12;
- maxspeed = 3;
- maxforce = 0.2;
- acceleration = new PVector(0, 0);
- velocity = new PVector(0, 0);
- }
-
- void applyForce(PVector force) {
- // We could add mass here if we want A = F / M
- acceleration.add(force);
- }
-
- void applyBehaviors(ArrayList vehicles) {
- PVector separateForce = separate(vehicles);
- PVector seekForce = seek(new PVector(mouseX,mouseY));
- separateForce.mult(2);
- seekForce.mult(1);
- applyForce(separateForce);
- applyForce(seekForce);
- }
-
- // A method that calculates a steering force towards a target
- // STEER = DESIRED MINUS VELOCITY
- PVector seek(PVector target) {
- PVector desired = PVector.sub(target,location); // A vector pointing from the location to the target
-
- // Normalize desired and scale to maximum speed
- desired.normalize();
- desired.mult(maxspeed);
- // Steering = Desired minus velocity
- PVector steer = PVector.sub(desired,velocity);
- steer.limit(maxforce); // Limit to maximum steering force
-
- return steer;
- }
-
- // Separation
- // Method checks for nearby vehicles and steers away
- PVector separate (ArrayList vehicles) {
- float desiredseparation = r*2;
- PVector sum = new PVector();
- int count = 0;
- // For every boid in the system, check if it's too close
- for (Vehicle other : vehicles) {
- float d = PVector.dist(location, other.location);
- // If the distance is greater than 0 and less than an arbitrary amount (0 when you are yourself)
- if ((d > 0) && (d < desiredseparation)) {
- // Calculate vector pointing away from neighbor
- PVector diff = PVector.sub(location, other.location);
- diff.normalize();
- diff.div(d); // Weight by distance
- sum.add(diff);
- count++; // Keep track of how many
- }
- }
- // Average -- divide by how many
- if (count > 0) {
- sum.div(count);
- // Our desired vector is the average scaled to maximum speed
- sum.normalize();
- sum.mult(maxspeed);
- // Implement Reynolds: Steering = Desired - Velocity
- sum.sub(velocity);
- sum.limit(maxforce);
- }
- return sum;
- }
-
-
- // Method to update location
- void update() {
- // Update velocity
- velocity.add(acceleration);
- // Limit speed
- velocity.limit(maxspeed);
- location.add(velocity);
- // Reset accelertion to 0 each cycle
- acceleration.mult(0);
- }
-
- void display() {
- fill(175);
- stroke(0);
- pushMatrix();
- translate(location.x, location.y);
- ellipse(0, 0, r, r);
- popMatrix();
- }
-
-}
-
-
-
-
-
-
diff --git a/java/examples/Books/Nature of Code/chp6_agents/NOC_6_09_Flocking/Boid.pde b/java/examples/Books/Nature of Code/chp6_agents/NOC_6_09_Flocking/Boid.pde
deleted file mode 100644
index 194dfc362..000000000
--- a/java/examples/Books/Nature of Code/chp6_agents/NOC_6_09_Flocking/Boid.pde
+++ /dev/null
@@ -1,182 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Boid class
-// Methods for Separation, Cohesion, Alignment added
-
-class Boid {
-
- PVector location;
- PVector velocity;
- PVector acceleration;
- float r;
- float maxforce; // Maximum steering force
- float maxspeed; // Maximum speed
-
- Boid(float x, float y) {
- acceleration = new PVector(0,0);
- velocity = new PVector(random(-1,1),random(-1,1));
- location = new PVector(x,y);
- r = 3.0;
- maxspeed = 3;
- maxforce = 0.05;
- }
-
- void run(ArrayList boids) {
- flock(boids);
- update();
- borders();
- render();
- }
-
- void applyForce(PVector force) {
- // We could add mass here if we want A = F / M
- acceleration.add(force);
- }
-
- // We accumulate a new acceleration each time based on three rules
- void flock(ArrayList boids) {
- PVector sep = separate(boids); // Separation
- PVector ali = align(boids); // Alignment
- PVector coh = cohesion(boids); // Cohesion
- // Arbitrarily weight these forces
- sep.mult(1.5);
- ali.mult(1.0);
- coh.mult(1.0);
- // Add the force vectors to acceleration
- applyForce(sep);
- applyForce(ali);
- applyForce(coh);
- }
-
- // Method to update location
- void update() {
- // Update velocity
- velocity.add(acceleration);
- // Limit speed
- velocity.limit(maxspeed);
- location.add(velocity);
- // Reset accelertion to 0 each cycle
- acceleration.mult(0);
- }
-
- // A method that calculates and applies a steering force towards a target
- // STEER = DESIRED MINUS VELOCITY
- PVector seek(PVector target) {
- PVector desired = PVector.sub(target,location); // A vector pointing from the location to the target
- // Normalize desired and scale to maximum speed
- desired.normalize();
- desired.mult(maxspeed);
- // Steering = Desired minus Velocity
- PVector steer = PVector.sub(desired,velocity);
- steer.limit(maxforce); // Limit to maximum steering force
- return steer;
- }
-
- void render() {
- // Draw a triangle rotated in the direction of velocity
- float theta = velocity.heading2D() + radians(90);
- fill(175);
- stroke(0);
- pushMatrix();
- translate(location.x,location.y);
- rotate(theta);
- beginShape(TRIANGLES);
- vertex(0, -r*2);
- vertex(-r, r*2);
- vertex(r, r*2);
- endShape();
- popMatrix();
- }
-
- // Wraparound
- void borders() {
- if (location.x < -r) location.x = width+r;
- if (location.y < -r) location.y = height+r;
- if (location.x > width+r) location.x = -r;
- if (location.y > height+r) location.y = -r;
- }
-
- // Separation
- // Method checks for nearby boids and steers away
- PVector separate (ArrayList boids) {
- float desiredseparation = 25.0f;
- PVector steer = new PVector(0,0,0);
- int count = 0;
- // For every boid in the system, check if it's too close
- for (Boid other : boids) {
- float d = PVector.dist(location,other.location);
- // If the distance is greater than 0 and less than an arbitrary amount (0 when you are yourself)
- if ((d > 0) && (d < desiredseparation)) {
- // Calculate vector pointing away from neighbor
- PVector diff = PVector.sub(location,other.location);
- diff.normalize();
- diff.div(d); // Weight by distance
- steer.add(diff);
- count++; // Keep track of how many
- }
- }
- // Average -- divide by how many
- if (count > 0) {
- steer.div((float)count);
- }
-
- // As long as the vector is greater than 0
- if (steer.mag() > 0) {
- // Implement Reynolds: Steering = Desired - Velocity
- steer.normalize();
- steer.mult(maxspeed);
- steer.sub(velocity);
- steer.limit(maxforce);
- }
- return steer;
- }
-
- // Alignment
- // For every nearby boid in the system, calculate the average velocity
- PVector align (ArrayList boids) {
- float neighbordist = 50;
- PVector sum = new PVector(0,0);
- int count = 0;
- for (Boid other : boids) {
- float d = PVector.dist(location,other.location);
- if ((d > 0) && (d < neighbordist)) {
- sum.add(other.velocity);
- count++;
- }
- }
- if (count > 0) {
- sum.div((float)count);
- sum.normalize();
- sum.mult(maxspeed);
- PVector steer = PVector.sub(sum,velocity);
- steer.limit(maxforce);
- return steer;
- } else {
- return new PVector(0,0);
- }
- }
-
- // Cohesion
- // For the average location (i.e. center) of all nearby boids, calculate steering vector towards that location
- PVector cohesion (ArrayList boids) {
- float neighbordist = 50;
- PVector sum = new PVector(0,0); // Start with empty vector to accumulate all locations
- int count = 0;
- for (Boid other : boids) {
- float d = PVector.dist(location,other.location);
- if ((d > 0) && (d < neighbordist)) {
- sum.add(other.location); // Add location
- count++;
- }
- }
- if (count > 0) {
- sum.div(count);
- return seek(sum); // Steer towards the location
- } else {
- return new PVector(0,0);
- }
- }
-}
-
diff --git a/java/examples/Books/Nature of Code/chp6_agents/NOC_6_09_Flocking/Flock.pde b/java/examples/Books/Nature of Code/chp6_agents/NOC_6_09_Flocking/Flock.pde
deleted file mode 100644
index b548b2469..000000000
--- a/java/examples/Books/Nature of Code/chp6_agents/NOC_6_09_Flocking/Flock.pde
+++ /dev/null
@@ -1,25 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Flock class
-// Does very little, simply manages the ArrayList of all the boids
-
-class Flock {
- ArrayList boids; // An ArrayList for all the boids
-
- Flock() {
- boids = new ArrayList(); // Initialize the ArrayList
- }
-
- void run() {
- for (Boid b : boids) {
- b.run(boids); // Passing the entire list of boids to each boid individually
- }
- }
-
- void addBoid(Boid b) {
- boids.add(b);
- }
-
-}
diff --git a/java/examples/Books/Nature of Code/chp6_agents/NOC_6_09_Flocking/NOC_6_09_Flocking.pde b/java/examples/Books/Nature of Code/chp6_agents/NOC_6_09_Flocking/NOC_6_09_Flocking.pde
deleted file mode 100644
index 921f0d250..000000000
--- a/java/examples/Books/Nature of Code/chp6_agents/NOC_6_09_Flocking/NOC_6_09_Flocking.pde
+++ /dev/null
@@ -1,38 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Demonstration of Craig Reynolds' "Flocking" behavior
-// See: http://www.red3d.com/cwr/
-// Rules: Cohesion, Separation, Alignment
-
-// Click mouse to add boids into the system
-
-Flock flock;
-
-void setup() {
- size(640,360);
- flock = new Flock();
- // Add an initial set of boids into the system
- for (int i = 0; i < 200; i++) {
- Boid b = new Boid(width/2,height/2);
- flock.addBoid(b);
- }
- smooth();
-}
-
-void draw() {
- background(255);
- flock.run();
-
- // Instructions
- fill(0);
- //text("Drag the mouse to generate new boids.",10,height-16);
-}
-
-// Add a new boid into the System
-void mouseDragged() {
- flock.addBoid(new Boid(mouseX,mouseY));
-}
-
-
diff --git a/java/examples/Books/Nature of Code/chp6_agents/SimpleScalarProjection/SimpleScalarProjection.pde b/java/examples/Books/Nature of Code/chp6_agents/SimpleScalarProjection/SimpleScalarProjection.pde
deleted file mode 100644
index dbd09f94e..000000000
--- a/java/examples/Books/Nature of Code/chp6_agents/SimpleScalarProjection/SimpleScalarProjection.pde
+++ /dev/null
@@ -1,41 +0,0 @@
-
-void setup() {
- size(600, 360);
-}
-
-void draw() {
- background(255);
-
- PVector a = new PVector(20,300);
- PVector b = new PVector(500,250);
- PVector mouse = new PVector(mouseX,mouseY);
-
- stroke(0);
- strokeWeight(2);
- line(a.x,a.y,b.x,b.y);
- line(a.x,a.y,mouse.x,mouse.y);
- fill(0);
- ellipse(a.x,a.y,8,8);
- ellipse(b.x,b.y,8,8);
- ellipse(mouse.x,mouse.y,8,8);
-
- PVector norm = scalarProjection(mouse,a,b);
- strokeWeight(1);
- stroke(50);
- line(mouse.x,mouse.y,norm.x,norm.y);
-
- noStroke();
- fill(255,0,0);
- ellipse(norm.x,norm.y,16,16);
-}
-
-
-PVector scalarProjection(PVector p, PVector a, PVector b) {
- PVector ap = PVector.sub(p, a);
- PVector ab = PVector.sub(b, a);
- ab.normalize(); // Normalize the line
- ab.mult(ap.dot(ab));
- PVector normalPoint = PVector.add(a, ab);
- return normalPoint;
-}
-
diff --git a/java/examples/Books/Nature of Code/chp6_agents/StayWithinCircle/StayWithinCircle.pde b/java/examples/Books/Nature of Code/chp6_agents/StayWithinCircle/StayWithinCircle.pde
deleted file mode 100644
index 0c2d43c86..000000000
--- a/java/examples/Books/Nature of Code/chp6_agents/StayWithinCircle/StayWithinCircle.pde
+++ /dev/null
@@ -1,41 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Stay Within Circle
-// "Made-up" Steering behavior to stay within walls
-
-Vehicle v;
-boolean debug = true;
-
-
-PVector circleLocation;
-float circleRadius;
-
-
-
-void setup() {
- size(640, 360);
- v = new Vehicle(width/2, height/4);
-
- circleLocation = new PVector(width/2,height/2);
- circleRadius = height/2-25;
-}
-
-void draw() {
- background(255);
-
- if (debug) {
- stroke(175);
- noFill();
- ellipse(circleLocation.x,circleLocation.y, circleRadius*2,circleRadius*2);
- }
-
- v.boundaries();
- v.run();
-}
-
-void mousePressed() {
- debug = !debug;
-}
-
diff --git a/java/examples/Books/Nature of Code/chp6_agents/StayWithinCircle/Vehicle.pde b/java/examples/Books/Nature of Code/chp6_agents/StayWithinCircle/Vehicle.pde
deleted file mode 100644
index 7bc96d2fa..000000000
--- a/java/examples/Books/Nature of Code/chp6_agents/StayWithinCircle/Vehicle.pde
+++ /dev/null
@@ -1,93 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-class Vehicle {
-
- PVector location;
- PVector velocity;
- PVector acceleration;
- float r;
-
- float maxspeed;
- float maxforce;
-
- Vehicle(float x, float y) {
- acceleration = new PVector(0, 0);
- velocity = new PVector(1,0);
- velocity.mult(5);
- location = new PVector(x, y);
- r = 3;
- maxspeed = 3;
- maxforce = 0.15;
- }
-
- void run() {
- update();
- display();
- }
-
- // Method to update location
- void update() {
- // Update velocity
- velocity.add(acceleration);
- // Limit speed
- velocity.limit(maxspeed);
- location.add(velocity);
- // Reset accelertion to 0 each cycle
- acceleration.mult(0);
- }
-
- void boundaries() {
-
- PVector desired = null;
-
- // Predict location 25 (arbitrary choice) frames ahead
- PVector predict = velocity.get();
- predict.mult(25);
- PVector futureLocation = PVector.add(location, predict);
- float distance = PVector.dist(futureLocation,circleLocation);
-
- if (distance > circleRadius) {
- PVector toCenter = PVector.sub(circleLocation,location);
- toCenter.normalize();
- toCenter.mult(velocity.mag());
- desired = PVector.add(velocity,toCenter);
- desired.normalize();
- desired.mult(maxspeed);
- }
-
- if (desired != null) {
- PVector steer = PVector.sub(desired, velocity);
- steer.limit(maxforce);
- applyForce(steer);
- }
-
- fill(255,0,0);
- ellipse(futureLocation.x,futureLocation.y,4,4);
-
- }
-
- void applyForce(PVector force) {
- // We could add mass here if we want A = F / M
- acceleration.add(force);
- }
-
-
- void display() {
- // Draw a triangle rotated in the direction of velocity
- float theta = velocity.heading2D() + radians(90);
- fill(175);
- stroke(0);
- pushMatrix();
- translate(location.x, location.y);
- rotate(theta);
- beginShape(TRIANGLES);
- vertex(0, -r*2);
- vertex(-r, r*2);
- vertex(r, r*2);
- endShape();
- popMatrix();
- }
-}
-
diff --git a/java/examples/Books/Nature of Code/chp6_agents/binlatticespatialsubdivision/intersection/intersection/Thing.pde b/java/examples/Books/Nature of Code/chp6_agents/binlatticespatialsubdivision/intersection/intersection/Thing.pde
deleted file mode 100644
index 7a739186b..000000000
--- a/java/examples/Books/Nature of Code/chp6_agents/binlatticespatialsubdivision/intersection/intersection/Thing.pde
+++ /dev/null
@@ -1,33 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-// Daniel Shiffman
-
-// Simple class describing an ellipse living on our screen
-
-class Thing {
-
- float x,y;
- boolean highlight;
- float r;
-
- Thing (float x_, float y_) {
- x = x_;
- y = y_;
- highlight = false;
- r = random(8) + 1;
- }
-
- void move() {
- x += random(-1,1);
- y += random(-1,1);
- }
-
- void render() {
- noStroke();
- if (highlight) fill(255);
- else fill(100);
- ellipse(x,y,r,r);
- }
-
-}
diff --git a/java/examples/Books/Nature of Code/chp6_agents/binlatticespatialsubdivision/intersection/intersection/intersection.pde b/java/examples/Books/Nature of Code/chp6_agents/binlatticespatialsubdivision/intersection/intersection/intersection.pde
deleted file mode 100644
index a8474b9c3..000000000
--- a/java/examples/Books/Nature of Code/chp6_agents/binlatticespatialsubdivision/intersection/intersection/intersection.pde
+++ /dev/null
@@ -1,105 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Bin-Lattice Spatial Subdivision
-// http://www.red3d.com/cwr/papers/2000/pip.pdf
-
-// Example demonstrating optimized intersection test for large # of objects
-// Each object registers its location in a virtual grid
-// Only the objects in neighboring cells on the grid are tested against each other
-
-int totalThings = 2000;
-
-ArrayList a; // ArrayList for all "things"
-ArrayList[][] grid; // Grid of ArrayLists for intersection test
-int scl = 4; // Size of each grid cell
-int cols, rows; // Total coluns and rows
-
-void setup() {
- size(640,360);
- a = new ArrayList(); // Create the list
- cols = width/scl; // Calculate cols & rows
- rows = height/scl;
-
- // Initialize grid as 2D array of empty ArrayLists
- grid = new ArrayList[cols][rows];
- for (int i = 0; i < cols; i++) {
- for (int j = 0; j < rows; j++) {
- grid[i][j] = new ArrayList();
- }
- }
-
- // Put 2000 Things in the system
- for (int i = 0; i < totalThings; i++) {
- a.add(new Thing(random(width),random(height)));
- }
-
-}
-
-void draw() {
- background(0);
-
- // Every time through draw clear all the lists
- for (int i = 0; i < cols; i++) {
- for (int j = 0; j < rows; j++) {
- grid[i][j].clear();
- }
- }
-
- // Register every Thing object in the grid according to it's location
- for (Thing t : a) {
- t.highlight = false;
- int x = int(t.x) / scl;
- int y = int (t.y) /scl;
- // It goes in 9 cells, i.e. every Thing is tested against other Things in its cell
- // as well as its 8 neighbors
- for (int n = -1; n <= 1; n++) {
- for (int m = -1; m <= 1; m++) {
- if (x+n >= 0 && x+n < cols && y+m >= 0 && y+m< rows) grid[x+n][y+m].add(t);
- }
- }
- }
-
- // Run through the Grid
- stroke(255);
- for (int i = 0; i < cols; i++) {
- //line(i*scl,0,i*scl,height);
- for (int j = 0; j < rows; j++) {
- //line(0,j*scl,width,j*scl);
-
- // For every list in the grid
- ArrayList temp = grid[i][j];
- // Check every Thing
- for (Thing t : temp) {
- // Against every other Thing
- for (Thing other : temp) {
- // As long as its not the same one
- if (other != t) {
- // Check to see if they are touching
- // (We could do many other things here besides just intersection tests, such
- // as apply forces, etc.)
- float d = dist(t.x,t.y,other.x,other.y);
- if (d < t.r/2 + other.r/2) {
- t.highlight = true;
- }
- }
- }
- }
- }
- }
-
- // Display and move all Things
- for (Thing t : a) {
- t.render();
- t.move();
- }
-
- fill(0);
- rect(0,height-20,width,20);
- fill(255);
- text("Framerate: " + int(frameRate),10,height-6);
-
-
-
-}
diff --git a/java/examples/Books/Nature of Code/chp6_agents/binlatticespatialsubdivision/intersection/intersection_slow/Thing.pde b/java/examples/Books/Nature of Code/chp6_agents/binlatticespatialsubdivision/intersection/intersection_slow/Thing.pde
deleted file mode 100644
index 7a739186b..000000000
--- a/java/examples/Books/Nature of Code/chp6_agents/binlatticespatialsubdivision/intersection/intersection_slow/Thing.pde
+++ /dev/null
@@ -1,33 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-// Daniel Shiffman
-
-// Simple class describing an ellipse living on our screen
-
-class Thing {
-
- float x,y;
- boolean highlight;
- float r;
-
- Thing (float x_, float y_) {
- x = x_;
- y = y_;
- highlight = false;
- r = random(8) + 1;
- }
-
- void move() {
- x += random(-1,1);
- y += random(-1,1);
- }
-
- void render() {
- noStroke();
- if (highlight) fill(255);
- else fill(100);
- ellipse(x,y,r,r);
- }
-
-}
diff --git a/java/examples/Books/Nature of Code/chp6_agents/binlatticespatialsubdivision/intersection/intersection_slow/intersection_slow.pde b/java/examples/Books/Nature of Code/chp6_agents/binlatticespatialsubdivision/intersection/intersection_slow/intersection_slow.pde
deleted file mode 100644
index f8303c06e..000000000
--- a/java/examples/Books/Nature of Code/chp6_agents/binlatticespatialsubdivision/intersection/intersection_slow/intersection_slow.pde
+++ /dev/null
@@ -1,57 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// The old way to do intersection tests, look how slow!!
-
-int totalThings = 2000;
-
-ArrayList a; // ArrayList for all "things"
-
-void setup() {
- size(640,360);
- a = new ArrayList(); // Create the list
-
- // Put 2000 Things in the system
- for (int i = 0; i < totalThings; i++) {
- a.add(new Thing(random(width),random(height)));
- }
-
-}
-
-void draw() {
- background(0);
- fill(255);
- noStroke();
- // Run through the Grid
- stroke(255);
- for (Thing t : a) {
- t.highlight = false;
- for (Thing other : a) {
- // As long as its not the same one
- if (t != other) {
- // Check to see if they are touching
- // (We could do many other things here besides just intersection tests, such
- // as apply forces, etc.)
- float d = dist(t.x,t.y,other.x,other.y);
- if (d < t.r/2 + other.r/2) {
- t.highlight = true;
- }
- }
- }
- }
-
- // Display and move all Things
- for (Thing t : a) {
- t.render();
- t.move();
- }
-
- fill(0);
- rect(0,height-20,width,20);
- fill(255);
- text("Framerate: " + int(frameRate),10,height-6);
-
-
-
-}
diff --git a/java/examples/Books/Nature of Code/chp6_agents/box2d/Flocking_box2d/Boid.pde b/java/examples/Books/Nature of Code/chp6_agents/box2d/Flocking_box2d/Boid.pde
deleted file mode 100644
index 85150e404..000000000
--- a/java/examples/Books/Nature of Code/chp6_agents/box2d/Flocking_box2d/Boid.pde
+++ /dev/null
@@ -1,257 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Flocking
-
-// Boid class
-// Methods for Separation, Cohesion, Alignment added
-
-class Boid {
-
- // We need to keep track of a Body and a width and height
- Body body;
- float w;
- float h;
-
- float maxforce; // Maximum steering force
- float maxspeed; // Maximum speed
-
- Boid(PVector loc) {
- w = 12;
- h = 12;
- // Add the box to the box2d world
- makeBody(new Vec2(loc.x,loc.y),w,h,new Vec2(0,0),0);
- maxspeed = 20;
- maxforce = 10;
- }
-
- // This function removes the particle from the box2d world
- void killBody() {
- box2d.destroyBody(body);
- }
-
- void run(ArrayList boids) {
- flock(boids);
- borders();
- display();
- }
-
- // We accumulate a new acceleration each time based on three rules
- void flock(ArrayList boids) {
- Vec2 sep = separate(boids); // Separation
- Vec2 ali = align(boids); // Alignment
- Vec2 coh = cohesion(boids); // Cohesion
- // Arbitrarily weight these forces
- sep.mulLocal(1.5);
- ali.mulLocal(1);
- coh.mulLocal(1);
- // Add the force vectors to acceleration
- Vec2 loc = body.getWorldCenter();
- body.applyForce(sep,loc);
- body.applyForce(ali,loc);
- body.applyForce(coh,loc);
- }
-
- // A method that calculates and applies a steering force towards a target
- // STEER = DESIRED MINUS VELOCITY
- Vec2 seek(Vec2 target) {
- Vec2 loc = body.getWorldCenter();
- Vec2 desired = target.sub(loc); // A vector pointing from the location to the target
-
- // If the magnitude of desired equals 0, skip out of here
- // (We could optimize this to check if x and y are 0 to avoid mag() square root
- if (desired.length() == 0) return new Vec2(0,0);
-
- // Normalize desired and scale to maximum speed
- desired.normalize();
- desired.mulLocal(maxspeed);
- // Steering = Desired minus Velocity
-
- Vec2 vel = body.getLinearVelocity();
- Vec2 steer = desired.sub(vel);
-
- float len = steer.length();
- if (len > maxforce) {
- steer.normalize();
- steer.mulLocal(maxforce);
- }
- return steer;
- }
-
-
-
- // Drawing the box
- void display() {
- // We look at each body and get its screen position
- Vec2 pos = box2d.getBodyPixelCoord(body);
-
- // Get its angle of rotation
- float a = body.getAngle();
-
- rectMode(CENTER);
- pushMatrix();
- translate(pos.x,pos.y);
- rotate(-a);
- fill(175);
- strokeWeight(2);
- stroke(0);
- rect(0,0,w,h);
- popMatrix();
- }
-
- // Wraparound
- void borders() {
- Vec2 loc = box2d.getBodyPixelCoord(body);
- Vec2 vel = body.getLinearVelocity();
- float a = body.getAngularVelocity();
- if (loc.x < -w) {
- killBody();
- makeBody(new Vec2(width+w,loc.y),w,h,vel,a);
- } else if (loc.y < -w) {
- killBody();
- makeBody(new Vec2(loc.x,height+w),w,h,vel,a);
- } else if (loc.x > width+w) {
- killBody();
- makeBody(new Vec2(-w,loc.y),w,h,vel,a);
- } else if (loc.y > height+w) {
- killBody();
- makeBody(new Vec2(loc.x,-w),w,h,vel,a);
- }
- }
-
- // Separation
- // Method checks for nearby boids and steers away
- Vec2 separate (ArrayList boids) {
- float desiredseparation = box2d.scalarPixelsToWorld(30);
-
- Vec2 steer = new Vec2(0,0);
- int count = 0;
- // For every boid in the system, check if it's too close
- Vec2 locA = body.getWorldCenter();
- for (Boid other : boids) {
- Vec2 locB = other.body.getWorldCenter();
- float d = dist(locA.x,locA.y,locB.x,locB.y);
- // If the distance is greater than 0 and less than an arbitrary amount (0 when you are yourself)
- if ((d > 0) && (d < desiredseparation)) {
- // Calculate vector pointing away from neighbor
- Vec2 diff = locA.sub(locB);
- diff.normalize();
- diff.mulLocal(1.0/d); // Weight by distance
- steer.addLocal(diff);
- count++; // Keep track of how many
- }
- }
- // Average -- divide by how many
- if (count > 0) {
- steer.mulLocal(1.0/count);
- }
-
- // As long as the vector is greater than 0
- if (steer.length() > 0) {
- // Implement Reynolds: Steering = Desired - Velocity
- steer.normalize();
- steer.mulLocal(maxspeed);
- Vec2 vel = body.getLinearVelocity();
- steer.subLocal(vel);
- float len = steer.length();
- if (len > maxforce) {
- steer.normalize();
- steer.mulLocal(maxforce);
- }
- }
- return steer;
- }
-
- // Alignment
- // For every nearby boid in the system, calculate the average velocity
- Vec2 align (ArrayList boids) {
- float neighbordist = box2d.scalarPixelsToWorld(50);
- Vec2 steer = new Vec2(0,0);
- int count = 0;
- Vec2 locA = body.getWorldCenter();
- for (Boid other : boids) {
- Vec2 locB = other.body.getWorldCenter();
- float d = dist(locA.x,locA.y,locB.x,locB.y);
- if ((d > 0) && (d < neighbordist)) {
- Vec2 vel = other.body.getLinearVelocity();
- steer.addLocal(vel);
- count++;
- }
- }
- if (count > 0) {
- steer.mulLocal(1.0/count);
- }
-
- // As long as the vector is greater than 0
- if (steer.length() > 0) {
- // Implement Reynolds: Steering = Desired - Velocity
- steer.normalize();
- steer.mulLocal(maxspeed);
- Vec2 vel = body.getLinearVelocity();
- steer.subLocal(vel);
- float len = steer.length();
- if (len > maxforce) {
- steer.normalize();
- steer.mulLocal(maxforce);
- }
- }
- return steer;
- }
-
- // Cohesion
- // For the average location (i.e. center) of all nearby boids, calculate steering vector towards that location
- Vec2 cohesion (ArrayList boids) {
- float neighbordist = box2d.scalarPixelsToWorld(50);
- Vec2 sum = new Vec2(0,0); // Start with empty vector to accumulate all locations
- int count = 0;
- Vec2 locA = body.getWorldCenter();
- for (Boid other : boids) {
- Vec2 locB = other.body.getWorldCenter();
-
- float d = dist(locA.x,locA.y,locB.x,locB.y);
- if ((d > 0) && (d < neighbordist)) {
- sum.addLocal(locB); // Add location
- count++;
- }
- }
- if (count > 0) {
- sum.mulLocal(1.0/count);
- return seek(sum); // Steer towards the location
- }
- return sum;
- }
-
- // This function adds the rectangle to the box2d world
- void makeBody(Vec2 center, float w_, float h_, Vec2 vel, float avel) {
-
- // Define a polygon (this is what we use for a rectangle)
- PolygonShape sd = new PolygonShape();
- float box2dW = box2d.scalarPixelsToWorld(w_/2);
- float box2dH = box2d.scalarPixelsToWorld(h_/2);
- sd.setAsBox(box2dW, box2dH);
-
- // Define a fixture
- FixtureDef fd = new FixtureDef();
- fd.shape = sd;
- // Parameters that affect physics
- fd.density = 1;
- fd.friction = 0.3;
- fd.restitution = 0.5;
-
- // Define the body and make it from the shape
- BodyDef bd = new BodyDef();
- bd.type = BodyType.DYNAMIC;
- bd.position.set(box2d.coordPixelsToWorld(center));
-
- body = box2d.createBody(bd);
- body.createFixture(fd);
-
- body.setLinearVelocity(vel);
- body.setAngularVelocity(avel);
-
- }
-
-
-}
-
diff --git a/java/examples/Books/Nature of Code/chp6_agents/box2d/Flocking_box2d/Flock.pde b/java/examples/Books/Nature of Code/chp6_agents/box2d/Flocking_box2d/Flock.pde
deleted file mode 100644
index 47b0e7b16..000000000
--- a/java/examples/Books/Nature of Code/chp6_agents/box2d/Flocking_box2d/Flock.pde
+++ /dev/null
@@ -1,27 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Flocking
-
-// Flock class
-// Does very little, simply manages the ArrayList of all the boids
-
-class Flock {
- ArrayList boids; // An arraylist for all the boids
-
- Flock() {
- boids = new ArrayList(); // Initialize the arraylist
- }
-
- void run() {
- for (Boid b : boids) {
- b.run(boids); // Passing the entire list of boids to each boid individually
- }
- }
-
- void addBoid(Boid b) {
- boids.add(b);
- }
-
-}
diff --git a/java/examples/Books/Nature of Code/chp6_agents/box2d/Flocking_box2d/Flocking_box2d.pde b/java/examples/Books/Nature of Code/chp6_agents/box2d/Flocking_box2d/Flocking_box2d.pde
deleted file mode 100644
index e037a4db9..000000000
--- a/java/examples/Books/Nature of Code/chp6_agents/box2d/Flocking_box2d/Flocking_box2d.pde
+++ /dev/null
@@ -1,54 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Flocking
-
-// Demonstration of Craig Reynolds' "Flocking" behavior
-// See: http://www.red3d.com/cwr/
-// Rules: Cohesion, Separation, Alignment
-
-// Click mouse to add boids into the system
-
-import pbox2d.*;
-import org.jbox2d.collision.shapes.*;
-import org.jbox2d.common.*;
-import org.jbox2d.dynamics.*;
-
-// A reference to our box2d world
-PBox2D box2d;
-
-Flock flock;
-
-void setup() {
- size(640,360);
- // Initialize box2d physics and create the world
- box2d = new PBox2D(this);
- box2d.createWorld();
- // We are setting a custom gravity
- box2d.setGravity(0,0);
-
- flock = new Flock();
- // Add an initial set of boids into the system
- for (int i = 0; i < 50; i++) {
- flock.addBoid(new Boid(new PVector(random(width),random(height))));
- }
-}
-
-void draw() {
- // We must always step through time!
- box2d.step();
-
- background(255);
- flock.run();
-}
-
-void mousePressed() {
- flock.addBoid(new Boid(new PVector(mouseX,mouseY)));
-}
-
-void mouseDragged() {
- flock.addBoid(new Boid(new PVector(mouseX,mouseY)));
-}
-
-
diff --git a/java/examples/Books/Nature of Code/chp6_agents/flocking_sliders/Boid.pde b/java/examples/Books/Nature of Code/chp6_agents/flocking_sliders/Boid.pde
deleted file mode 100644
index 808b7c6d5..000000000
--- a/java/examples/Books/Nature of Code/chp6_agents/flocking_sliders/Boid.pde
+++ /dev/null
@@ -1,185 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-float swt = 25.0; //sep.mult(25.0f);
-float awt = 4.0; //ali.mult(4.0f);
-float cwt = 5.0; //coh.mult(5.0f);
-float maxspeed = 1;
-float maxforce = 0.025;
-
-
-// Flocking
-// Daniel Shiffman
-// The Nature of Code, Spring 2009
-
-// Boid class
-// Methods for Separation, Cohesion, Alignment added
-
-class Boid {
-
- PVector loc;
- PVector vel;
- PVector acc;
- float r;
-
- Boid(float x, float y) {
- acc = new PVector(0,0);
- vel = new PVector(random(-1,1),random(-1,1));
- loc = new PVector(x,y);
- r = 2.0;
- }
-
- void run(ArrayList boids) {
- flock(boids);
- update();
- borders();
- render();
- }
-
- void applyForce(PVector force) {
- // We could add mass here if we want A = F / M
- acc.add(force);
- }
-
- // We accumulate a new acceleration each time based on three rules
- void flock(ArrayList boids) {
- PVector sep = separate(boids); // Separation
- PVector ali = align(boids); // Alignment
- PVector coh = cohesion(boids); // Cohesion
- // Arbitrarily weight these forces
- sep.mult(swt);
- ali.mult(awt);
- coh.mult(cwt);
- // Add the force vectors to acceleration
- applyForce(sep);
- applyForce(ali);
- applyForce(coh);
- }
-
- // Method to update location
- void update() {
- // Update velocity
- vel.add(acc);
- // Limit speed
- vel.limit(maxspeed);
- loc.add(vel);
- // Reset accelertion to 0 each cycle
- acc.mult(0);
- }
-
- // A method that calculates and applies a steering force towards a target
- // STEER = DESIRED MINUS VELOCITY
- PVector seek(PVector target) {
- PVector desired = PVector.sub(target,loc); // A vector pointing from the location to the target
-
- // Normalize desired and scale to maximum speed
- desired.normalize();
- desired.mult(maxspeed);
- // Steering = Desired minus Velocity
- PVector steer = PVector.sub(desired,vel);
- steer.limit(maxforce); // Limit to maximum steering force
-
- return steer;
- }
-
- void render() {
- // Draw a triangle rotated in the direction of velocity
- float theta = vel.heading2D() + radians(90);
- fill(175);
- stroke(0);
- pushMatrix();
- translate(loc.x,loc.y);
- rotate(theta);
- beginShape(TRIANGLES);
- vertex(0, -r*2);
- vertex(-r, r*2);
- vertex(r, r*2);
- endShape();
- popMatrix();
- }
-
- // Wraparound
- void borders() {
- if (loc.x < -r) loc.x = width+r;
- if (loc.y < -r) loc.y = height+r;
- if (loc.x > width+r) loc.x = -r;
- if (loc.y > height+r) loc.y = -r;
- }
-
- // Separation
- // Method checks for nearby boids and steers away
- PVector separate (ArrayList boids) {
- float desiredseparation = 25.0;
- PVector steer = new PVector(0,0);
- int count = 0;
- // For every boid in the system, check if it's too close
- for (Boid other : boids) {
- float d = PVector.dist(loc,other.loc);
- // If the distance is greater than 0 and less than an arbitrary amount (0 when you are yourself)
- if ((d > 0) && (d < desiredseparation)) {
- // Calculate vector pointing away from neighbor
- PVector diff = PVector.sub(loc,other.loc);
- diff.normalize();
- diff.div(d); // Weight by distance
- steer.add(diff);
- count++; // Keep track of how many
- }
- }
- // Average -- divide by how many
- if (count > 0) {
- steer.div((float)count);
- // Implement Reynolds: Steering = Desired - Velocity
- steer.normalize();
- steer.mult(maxspeed);
- steer.sub(vel);
- steer.limit(maxforce);
- }
- return steer;
- }
-
- // Alignment
- // For every nearby boid in the system, calculate the average velocity
- PVector align (ArrayList boids) {
- float neighbordist = 50.0;
- PVector steer = new PVector();
- int count = 0;
- for (Boid other : boids) {
- float d = PVector.dist(loc,other.loc);
- if ((d > 0) && (d < neighbordist)) {
- steer.add(other.vel);
- count++;
- }
- }
- if (count > 0) {
- steer.div((float)count);
- // Implement Reynolds: Steering = Desired - Velocity
- steer.normalize();
- steer.mult(maxspeed);
- steer.sub(vel);
- steer.limit(maxforce);
- }
- return steer;
- }
-
- // Cohesion
- // For the average location (i.e. center) of all nearby boids, calculate steering vector towards that location
- PVector cohesion (ArrayList boids) {
- float neighbordist = 50.0;
- PVector sum = new PVector(0,0); // Start with empty vector to accumulate all locations
- int count = 0;
- for (Boid other : boids) {
- float d = PVector.dist(loc,other.loc);
- if ((d > 0) && (d < neighbordist)) {
- sum.add(other.loc); // Add location
- count++;
- }
- }
- if (count > 0) {
- sum.div((float)count);
- return seek(sum); // Steer towards the location
- }
- return sum;
- }
-}
-
diff --git a/java/examples/Books/Nature of Code/chp6_agents/flocking_sliders/Flock.pde b/java/examples/Books/Nature of Code/chp6_agents/flocking_sliders/Flock.pde
deleted file mode 100644
index b548b2469..000000000
--- a/java/examples/Books/Nature of Code/chp6_agents/flocking_sliders/Flock.pde
+++ /dev/null
@@ -1,25 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Flock class
-// Does very little, simply manages the ArrayList of all the boids
-
-class Flock {
- ArrayList boids; // An ArrayList for all the boids
-
- Flock() {
- boids = new ArrayList(); // Initialize the ArrayList
- }
-
- void run() {
- for (Boid b : boids) {
- b.run(boids); // Passing the entire list of boids to each boid individually
- }
- }
-
- void addBoid(Boid b) {
- boids.add(b);
- }
-
-}
diff --git a/java/examples/Books/Nature of Code/chp6_agents/flocking_sliders/flocking_sliders.pde b/java/examples/Books/Nature of Code/chp6_agents/flocking_sliders/flocking_sliders.pde
deleted file mode 100644
index afbf53ec4..000000000
--- a/java/examples/Books/Nature of Code/chp6_agents/flocking_sliders/flocking_sliders.pde
+++ /dev/null
@@ -1,57 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-
-// Flocking
-// Demonstration of Craig Reynolds' "Flocking" behavior
-// See: http://www.red3d.com/cwr/
-// Rules: Cohesion, Separation, Alignment
-
-// Click mouse to add boids into the system
-Flock flock;
-PVector center;
-
-boolean showvalues = true;
-boolean scrollbar = false;
-
-
-void setup() {
- size(displayWidth,displayHeight,P2D);
- setupScrollbars();
- center = new PVector(width/2,height/2);
- colorMode(RGB,255,255,255,100);
- flock = new Flock();
- // Add an initial set of boids into the system
- for (int i = 0; i < 120; i++) {
- flock.addBoid(new Boid(width/2,height/2));
- }
- smooth();
-}
-
-
-void draw() {
-
- background(255);
- flock.run();
- drawScrollbars();
-
- if (mousePressed && !scrollbar) {
- flock.addBoid(new Boid(mouseX,mouseY));
- }
-
-
- if (showvalues) {
- fill(0);
- textAlign(LEFT);
- text("Total boids: " + flock.boids.size() + "\n" + "Framerate: " + round(frameRate) + "\nPress any key to show/hide sliders and text\nClick mouse to add more boids",5,100);
- }
-}
-
-void keyPressed() {
- showvalues = !showvalues;
-}
-
-void mousePressed() {
-}
-
diff --git a/java/examples/Books/Nature of Code/chp6_agents/flocking_sliders/keyPressed.pde b/java/examples/Books/Nature of Code/chp6_agents/flocking_sliders/keyPressed.pde
deleted file mode 100644
index b28b04f64..000000000
--- a/java/examples/Books/Nature of Code/chp6_agents/flocking_sliders/keyPressed.pde
+++ /dev/null
@@ -1,3 +0,0 @@
-
-
-
diff --git a/java/examples/Books/Nature of Code/chp6_agents/flocking_sliders/scrollbar.pde b/java/examples/Books/Nature of Code/chp6_agents/flocking_sliders/scrollbar.pde
deleted file mode 100644
index 3a6bc39be..000000000
--- a/java/examples/Books/Nature of Code/chp6_agents/flocking_sliders/scrollbar.pde
+++ /dev/null
@@ -1,137 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Code based on "Scrollbar" by Casey Reas
-
-HScrollbar[] hs = new HScrollbar[5];//
-String[] labels = {"separation", "alignment","cohesion","maxspeed","maxforce"};
-
-int x = 5;
-int y = 20;
-int w = 50;
-int h = 8;
-int l = 2;
-int spacing = 4;
-
-void setupScrollbars() {
- for (int i = 0; i < hs.length; i++) {
- hs[i] = new HScrollbar(x, y + i*(h+spacing), w, h, l);
- }
-
- hs[0].setPos(0.5);
- hs[1].setPos(0.5);
- hs[2].setPos(0.5);
- hs[3].setPos(0.5);
- hs[4].setPos(0.05);
-
-}
-
-void drawScrollbars() {
- //if (showvalues) {
- swt = hs[0].getPos()*10.0f; //sep.mult(25.0f);
- awt = hs[1].getPos()*2.0f; //sep.mult(25.0f);
- cwt = hs[2].getPos()*2.0f; //sep.mult(25.0f);
- maxspeed = hs[3].getPos()*10.0f;
- maxforce = hs[4].getPos()*0.5;
-
-
- if (showvalues) {
- for (int i = 0; i < hs.length; i++) {
- hs[i].update();
- hs[i].draw();
- fill(0);
- textAlign(LEFT);
- text(labels[i],x+w+spacing,y+i*(h+spacing)+spacing);
- //text(hs[i].getPos(),x+w+spacing+75,y+i*(h+spacing)+spacing);
- }
- }
-}
-
-
-class HScrollbar
-{
- int swidth, sheight; // width and height of bar
- int xpos, ypos; // x and y position of bar
- float spos, newspos; // x position of slider
- int sposMin, sposMax; // max and min values of slider
- int loose; // how loose/heavy
- boolean over; // is the mouse over the slider?
- boolean locked;
- float ratio;
-
- HScrollbar (int xp, int yp, int sw, int sh, int l) {
- swidth = sw;
- sheight = sh;
- int widthtoheight = sw - sh;
- ratio = (float)sw / (float)widthtoheight;
- xpos = xp;
- ypos = yp-sheight/2;
- spos = xpos;
- newspos = spos;
- sposMin = xpos;
- sposMax = xpos + swidth - sheight;
- loose = l;
- }
-
- void update() {
- if(over()) {
- over = true;
- }
- else {
- over = false;
- }
- if(mousePressed && over) {
- scrollbar = true;
- locked = true;
- }
- if(!mousePressed) {
- locked = false;
- scrollbar = false;
- }
- if(locked) {
- newspos = constrain(mouseX-sheight/2, sposMin, sposMax);
- }
- if(abs(newspos - spos) > 0) {
- spos = spos + (newspos-spos)/loose;
- }
- }
-
- int constrain(int val, int minv, int maxv) {
- return min(max(val, minv), maxv);
- }
-
- boolean over() {
- if(mouseX > xpos && mouseX < xpos+swidth &&
- mouseY > ypos && mouseY < ypos+sheight) {
- return true;
- }
- else {
- return false;
- }
- }
-
- void draw() {
- fill(255);
- rectMode(CORNER);
- rect(xpos, ypos, swidth, sheight);
- if(over || locked) {
- fill(153, 102, 0);
- }
- else {
- fill(102, 102, 102);
- }
- rect(spos, ypos, sheight, sheight);
- }
-
- void setPos(float s) {
- spos = xpos + s*(sposMax-sposMin);
- newspos = spos;
- }
-
- float getPos() {
- // convert spos to be values between
- // 0 and the total width of the scrollbar
- return ((spos-xpos))/(sposMax-sposMin);// * ratio;
- }
-}
diff --git a/java/examples/Books/Nature of Code/chp7_CA/Exercise_7_01_WolframCA_randomizedrules/CA.pde b/java/examples/Books/Nature of Code/chp7_CA/Exercise_7_01_WolframCA_randomizedrules/CA.pde
deleted file mode 100644
index 57f208c2c..000000000
--- a/java/examples/Books/Nature of Code/chp7_CA/Exercise_7_01_WolframCA_randomizedrules/CA.pde
+++ /dev/null
@@ -1,98 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Wolfram Cellular Automata
-
-// A class to manage the CA
-
-class CA {
-
- int[] cells; // An array of 0s and 1s
- int generation; // How many generations?
-
- int[] ruleset; // An array to store the ruleset, for example {0,1,1,0,1,1,0,1}
-
- int w = 5;
-
- CA(int[] r) {
- ruleset = r;
- cells = new int[width/w];
- restart();
- }
-
- // Make a random ruleset
- void randomize() {
- for (int i = 0; i < 8; i++) {
- ruleset[i] = int(random(2));
- }
- }
-
- // Reset to generation 0
- void restart() {
- for (int i = 0; i < cells.length; i++) {
- cells[i] = 0;
- }
- cells[cells.length/2] = 1; // We arbitrarily start with just the middle cell having a state of "1"
- generation = 0;
- }
-
-
- // The process of creating the new generation
- void generate() {
- // First we create an empty array for the new values
- int[] nextgen = new int[cells.length];
- // For every spot, determine new state by examing current state, and neighbor states
- // Ignore edges that only have one neighor
- for (int i = 1; i < cells.length-1; i++) {
- int left = cells[i-1]; // Left neighbor state
- int me = cells[i]; // Current state
- int right = cells[i+1]; // Right neighbor state
- nextgen[i] = rules(left, me, right); // Compute next generation state based on ruleset
- }
- // The current generation is the new generation
- cells = nextgen;
- generation++;
- }
-
- // This is the easy part, just draw the cells, fill 255 for '1', fill 0 for '0'
- void display() {
- for (int i = 0; i < cells.length; i++) {
- if (cells[i] == 1) fill(0);
- else fill(255);
- noStroke();
- rect(i*w, generation*w, w, w);
- }
- }
-
- // Implementing the Wolfram rules
- // This is the concise conversion to binary way
- /*int rules (int a, int b, int c) {
- String s = "" + a + b + c;
- int index = Integer.parseInt(s, 2);
- return ruleset[index];
- }*/
- // For JavaScript Mode
- int rules (int a, int b, int c) {
- if (a == 1 && b == 1 && c == 1) return ruleset[0];
- if (a == 1 && b == 1 && c == 0) return ruleset[1];
- if (a == 1 && b == 0 && c == 1) return ruleset[2];
- if (a == 1 && b == 0 && c == 0) return ruleset[3];
- if (a == 0 && b == 1 && c == 1) return ruleset[4];
- if (a == 0 && b == 1 && c == 0) return ruleset[5];
- if (a == 0 && b == 0 && c == 1) return ruleset[6];
- if (a == 0 && b == 0 && c == 0) return ruleset[7];
- return 0;
- }
-
- // The CA is done if it reaches the bottom of the screen
- boolean finished() {
- if (generation > height/w) {
- return true;
- }
- else {
- return false;
- }
- }
-}
-
diff --git a/java/examples/Books/Nature of Code/chp7_CA/Exercise_7_01_WolframCA_randomizedrules/Exercise_7_01_WolframCA_randomizedrules.pde b/java/examples/Books/Nature of Code/chp7_CA/Exercise_7_01_WolframCA_randomizedrules/Exercise_7_01_WolframCA_randomizedrules.pde
deleted file mode 100644
index f39ae6b7f..000000000
--- a/java/examples/Books/Nature of Code/chp7_CA/Exercise_7_01_WolframCA_randomizedrules/Exercise_7_01_WolframCA_randomizedrules.pde
+++ /dev/null
@@ -1,45 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Wolfram Cellular Automata
-
-// Simple demonstration of a Wolfram 1-dimensional cellular automata
-// When the system reaches bottom of the window, it restarts with a new ruleset
-// Mouse click restarts as well
-
-CA ca; // An object to describe a Wolfram elementary Cellular Automata
-
-int delay = 0;
-
-void setup() {
- size(800, 200);
- background(255);
- int[] ruleset = {
- 0, 1, 0, 1, 1, 0, 1, 0
- }; // An initial rule system
- ca = new CA(ruleset); // Initialize CA
- frameRate(30);
-}
-
-void draw() {
- ca.display(); // Draw the CA
- ca.generate();
-
- if (ca.finished()) { // If we're done, clear the screen, pick a new ruleset and restart
- delay++;
- if (delay > 30) {
- background(255);
- ca.randomize();
- ca.restart();
- delay = 0;
- }
- }
-}
-
-void mousePressed() {
- background(255);
- ca.randomize();
- ca.restart();
-}
-
diff --git a/java/examples/Books/Nature of Code/chp7_CA/Exercise_7_04_WolframCA_scrolling/CA.pde b/java/examples/Books/Nature of Code/chp7_CA/Exercise_7_04_WolframCA_scrolling/CA.pde
deleted file mode 100644
index aadb60528..000000000
--- a/java/examples/Books/Nature of Code/chp7_CA/Exercise_7_04_WolframCA_scrolling/CA.pde
+++ /dev/null
@@ -1,97 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Wolfram Cellular Automata
-
-// A class to manage the CA
-
-class CA {
-
- int generation; // How many generations?
- int[] ruleset; // An array to store the ruleset, for example {0,1,1,0,1,1,0,1}
- int w = 4;
- int[][] matrix; // Store a history of generations in 2D array, not just one
-
- int cols;
- int rows;
-
-
- CA(int[] r) {
- ruleset = r;
- cols = width/w;
- rows = height/w;
- matrix = new int[cols][rows];
- restart();
- }
-
- // Make a random ruleset
- void randomize() {
- for (int i = 0; i < 8; i++) {
- ruleset[i] = int(random(2));
- }
- }
-
- // Reset to generation 0
- void restart() {
- for (int i = 0; i < cols; i++) {
- for (int j = 0; j < rows; j++) {
- matrix[i][j] = 0;
- }
- }
- matrix[cols/2][0] = 1; // We arbitrarily start with just the middle cell having a state of "1"
- generation = 0;
- }
-
-
- // The process of creating the new generation
- void generate() {
-
- // For every spot, determine new state by examing current state, and neighbor states
- // Ignore edges that only have one neighor
- for (int i = 0; i < cols; i++) {
- int left = matrix[(i+cols-1)%cols][generation%rows]; // Left neighbor state
- int me = matrix[i][generation%rows]; // Current state
- int right = matrix[(i+1)%cols][generation%rows]; // Right neighbor state
- matrix[i][(generation+1)%rows] = rules(left, me, right); // Compute next generation state based on ruleset
- }
- generation++;
- }
-
- // This is the easy part, just draw the cells, fill 255 for '1', fill 0 for '0'
- void display() {
- int offset = generation%rows;
-
- for (int i = 0; i < cols; i++) {
- for (int j = 0; j < rows; j++) {
- int y = j - offset;
- if (y <= 0) y = rows + y;
- // Only draw if cell state is 1
- if (matrix[i][j] == 1) {
- fill(0);
- noStroke();
- rect(i*w, (y-1)*w, w, w);
- }
- }
- }
- }
-
- // Implementing the Wolfram rules
- // This is the concise conversion to binary way
- int rules (int a, int b, int c) {
- String s = "" + a + b + c;
- int index = Integer.parseInt(s, 2);
- return ruleset[index];
- }
-
- // The CA is done if it reaches the bottom of the screen
- boolean finished() {
- if (generation > height/w) {
- return true;
- }
- else {
- return false;
- }
- }
-}
-
diff --git a/java/examples/Books/Nature of Code/chp7_CA/Exercise_7_04_WolframCA_scrolling/Exercise_7_04_WolframCA_scrolling.pde b/java/examples/Books/Nature of Code/chp7_CA/Exercise_7_04_WolframCA_scrolling/Exercise_7_04_WolframCA_scrolling.pde
deleted file mode 100644
index 4107ec882..000000000
--- a/java/examples/Books/Nature of Code/chp7_CA/Exercise_7_04_WolframCA_scrolling/Exercise_7_04_WolframCA_scrolling.pde
+++ /dev/null
@@ -1,31 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Wolfram Cellular Automata
-
-// Simple demonstration of a Wolfram 1-dimensional cellular automata
-// with the system scrolling by
-// Also implements wrap around
-
-CA ca; // An object to describe a Wolfram elementary Cellular Automata
-
-
-void setup() {
- size(640, 800);
- frameRate(24);
- background(255);
- //int[] ruleset = {0,1,1,1,1,0,1,1}; // Rule 222
- //int[] ruleset = {0,1,1,1,1,1,0,1}; // Rule 190
- //int[] ruleset = {0,1,1,1,1,0,0,0}; // Rule 30
- //int[] ruleset = {0,1,1,1,0,1,1,0}; // Rule 110
- int[] ruleset = {0,1,0,1,1,0,1,0}; // Rule 90
-
- ca = new CA(ruleset); // Initialize CA
-}
-
-void draw() {
- background(255);
- ca.display(); // Draw the CA
- ca.generate();
-}
diff --git a/java/examples/Books/Nature of Code/chp7_CA/Exercise_7_04_WolframCA_scrolling_110/CA.pde b/java/examples/Books/Nature of Code/chp7_CA/Exercise_7_04_WolframCA_scrolling_110/CA.pde
deleted file mode 100644
index fa62c817f..000000000
--- a/java/examples/Books/Nature of Code/chp7_CA/Exercise_7_04_WolframCA_scrolling_110/CA.pde
+++ /dev/null
@@ -1,107 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Wolfram Cellular Automata
-
-// A class to manage the CA
-
-class CA {
-
- int generation; // How many generations?
- int[] ruleset; // An array to store the ruleset, for example {0,1,1,0,1,1,0,1}
- int w = 5;
- int[][] matrix; // Store a history of generations in 2D array, not just one
-
- int cols;
- int rows;
-
-
- CA(int[] r) {
- ruleset = r;
- cols = width/w;
- rows = height/w;
- matrix = new int[cols][rows];
- restart();
- }
-
- // Make a random ruleset
- void randomize() {
- for (int i = 0; i < 8; i++) {
- ruleset[i] = int(random(2));
- }
- }
-
- // Reset to generation 0
- void restart() {
- for (int i = 0; i < cols; i++) {
- for (int j = 0; j < rows; j++) {
- matrix[i][j] = 0;
- }
- }
- matrix[cols/2][0] = 1; // We arbitrarily start with just the middle cell having a state of "1"
- generation = 0;
- }
-
-
- // The process of creating the new generation
- void generate() {
-
- // For every spot, determine new state by examing current state, and neighbor states
- // Ignore edges that only have one neighor
- for (int i = 0; i < cols; i++) {
- int left = matrix[(i+cols-1)%cols][generation%rows]; // Left neighbor state
- int me = matrix[i][generation%rows]; // Current state
- int right = matrix[(i+1)%cols][generation%rows]; // Right neighbor state
- matrix[i][(generation+1)%rows] = rules(left, me, right); // Compute next generation state based on ruleset
- }
- generation++;
- }
-
- // This is the easy part, just draw the cells, fill 255 for '1', fill 0 for '0'
- void display() {
- int offset = generation%rows;
-
- for (int i = 0; i < cols; i++) {
- for (int j = 0; j < rows; j++) {
- int y = j - offset;
- if (y <= 0) y = rows + y;
- if (matrix[i][j] == 1) fill(0);
- else fill(255);
- noStroke();
- rect(i*w, (y-1)*w, w, w);
- }
- }
- }
-
- // Implementing the Wolfram rules
- // This is the concise conversion to binary way
- /*int rules (int a, int b, int c) {
- String s = "" + a + b + c;
- int index = Integer.parseInt(s, 2);
- return ruleset[index];
- }*/
- // For JavaScript Mode
- int rules (int a, int b, int c) {
- if (a == 1 && b == 1 && c == 1) return ruleset[7];
- if (a == 1 && b == 1 && c == 0) return ruleset[6];
- if (a == 1 && b == 0 && c == 1) return ruleset[5];
- if (a == 1 && b == 0 && c == 0) return ruleset[4];
- if (a == 0 && b == 1 && c == 1) return ruleset[3];
- if (a == 0 && b == 1 && c == 0) return ruleset[2];
- if (a == 0 && b == 0 && c == 1) return ruleset[1];
- if (a == 0 && b == 0 && c == 0) return ruleset[0];
- return 0;
- }
-
- // The CA is done if it reaches the bottom of the screen
- boolean finished() {
- if (generation > height/w) {
- return true;
- }
- else {
- return false;
- }
- }
-}
-
diff --git a/java/examples/Books/Nature of Code/chp7_CA/Exercise_7_04_WolframCA_scrolling_110/Exercise_7_04_WolframCA_scrolling_110.pde b/java/examples/Books/Nature of Code/chp7_CA/Exercise_7_04_WolframCA_scrolling_110/Exercise_7_04_WolframCA_scrolling_110.pde
deleted file mode 100644
index fbf426702..000000000
--- a/java/examples/Books/Nature of Code/chp7_CA/Exercise_7_04_WolframCA_scrolling_110/Exercise_7_04_WolframCA_scrolling_110.pde
+++ /dev/null
@@ -1,29 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Wolfram Cellular Automata
-
-// Simple demonstration of a Wolfram 1-dimensional cellular automata
-// with the system scrolling by
-// Also implements wrap around
-
-CA ca; // An object to describe a Wolfram elementary Cellular Automata
-
-
-void setup() {
- size(800, 100);
- frameRate(30);
- background(255);
- //int[] ruleset = {0,1,1,1,1,0,1,1}; // Rule 222
- //int[] ruleset = {0,1,1,1,1,1,0,1}; // Rule 190
- //int[] ruleset = {0,1,1,1,1,0,0,0}; // Rule 30
- int[] ruleset = {0,1,1,1,0,1,1,0}; // Rule 110
-
- ca = new CA(ruleset); // Initialize CA
-}
-
-void draw() {
- ca.display(); // Draw the CA
- ca.generate();
-}
diff --git a/java/examples/Books/Nature of Code/chp7_CA/Exercise_7_04_WolframCA_scrolling_190/CA.pde b/java/examples/Books/Nature of Code/chp7_CA/Exercise_7_04_WolframCA_scrolling_190/CA.pde
deleted file mode 100644
index fa62c817f..000000000
--- a/java/examples/Books/Nature of Code/chp7_CA/Exercise_7_04_WolframCA_scrolling_190/CA.pde
+++ /dev/null
@@ -1,107 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Wolfram Cellular Automata
-
-// A class to manage the CA
-
-class CA {
-
- int generation; // How many generations?
- int[] ruleset; // An array to store the ruleset, for example {0,1,1,0,1,1,0,1}
- int w = 5;
- int[][] matrix; // Store a history of generations in 2D array, not just one
-
- int cols;
- int rows;
-
-
- CA(int[] r) {
- ruleset = r;
- cols = width/w;
- rows = height/w;
- matrix = new int[cols][rows];
- restart();
- }
-
- // Make a random ruleset
- void randomize() {
- for (int i = 0; i < 8; i++) {
- ruleset[i] = int(random(2));
- }
- }
-
- // Reset to generation 0
- void restart() {
- for (int i = 0; i < cols; i++) {
- for (int j = 0; j < rows; j++) {
- matrix[i][j] = 0;
- }
- }
- matrix[cols/2][0] = 1; // We arbitrarily start with just the middle cell having a state of "1"
- generation = 0;
- }
-
-
- // The process of creating the new generation
- void generate() {
-
- // For every spot, determine new state by examing current state, and neighbor states
- // Ignore edges that only have one neighor
- for (int i = 0; i < cols; i++) {
- int left = matrix[(i+cols-1)%cols][generation%rows]; // Left neighbor state
- int me = matrix[i][generation%rows]; // Current state
- int right = matrix[(i+1)%cols][generation%rows]; // Right neighbor state
- matrix[i][(generation+1)%rows] = rules(left, me, right); // Compute next generation state based on ruleset
- }
- generation++;
- }
-
- // This is the easy part, just draw the cells, fill 255 for '1', fill 0 for '0'
- void display() {
- int offset = generation%rows;
-
- for (int i = 0; i < cols; i++) {
- for (int j = 0; j < rows; j++) {
- int y = j - offset;
- if (y <= 0) y = rows + y;
- if (matrix[i][j] == 1) fill(0);
- else fill(255);
- noStroke();
- rect(i*w, (y-1)*w, w, w);
- }
- }
- }
-
- // Implementing the Wolfram rules
- // This is the concise conversion to binary way
- /*int rules (int a, int b, int c) {
- String s = "" + a + b + c;
- int index = Integer.parseInt(s, 2);
- return ruleset[index];
- }*/
- // For JavaScript Mode
- int rules (int a, int b, int c) {
- if (a == 1 && b == 1 && c == 1) return ruleset[7];
- if (a == 1 && b == 1 && c == 0) return ruleset[6];
- if (a == 1 && b == 0 && c == 1) return ruleset[5];
- if (a == 1 && b == 0 && c == 0) return ruleset[4];
- if (a == 0 && b == 1 && c == 1) return ruleset[3];
- if (a == 0 && b == 1 && c == 0) return ruleset[2];
- if (a == 0 && b == 0 && c == 1) return ruleset[1];
- if (a == 0 && b == 0 && c == 0) return ruleset[0];
- return 0;
- }
-
- // The CA is done if it reaches the bottom of the screen
- boolean finished() {
- if (generation > height/w) {
- return true;
- }
- else {
- return false;
- }
- }
-}
-
diff --git a/java/examples/Books/Nature of Code/chp7_CA/Exercise_7_04_WolframCA_scrolling_190/Exercise_7_04_WolframCA_scrolling_190.pde b/java/examples/Books/Nature of Code/chp7_CA/Exercise_7_04_WolframCA_scrolling_190/Exercise_7_04_WolframCA_scrolling_190.pde
deleted file mode 100644
index bf9542216..000000000
--- a/java/examples/Books/Nature of Code/chp7_CA/Exercise_7_04_WolframCA_scrolling_190/Exercise_7_04_WolframCA_scrolling_190.pde
+++ /dev/null
@@ -1,30 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Wolfram Cellular Automata
-
-// Simple demonstration of a Wolfram 1-dimensional cellular automata
-// with the system scrolling by
-// Also implements wrap around
-
-CA ca; // An object to describe a Wolfram elementary Cellular Automata
-
-
-void setup() {
- size(800, 100);
- frameRate(30);
- background(255);
- //int[] ruleset = {0,1,1,1,1,0,1,1}; // Rule 222
- int[] ruleset = {0,1,1,1,1,1,0,1}; // Rule 190
- //int[] ruleset = {0,1,1,1,1,0,0,0}; // Rule 30
- //int[] ruleset = {0,1,1,1,0,1,1,0}; // Rule 110
-
- ca = new CA(ruleset); // Initialize CA
-}
-
-void draw() {
- ca.display(); // Draw the CA
- ca.generate();
-}
-
diff --git a/java/examples/Books/Nature of Code/chp7_CA/Exercise_7_04_WolframCA_scrolling_222/CA.pde b/java/examples/Books/Nature of Code/chp7_CA/Exercise_7_04_WolframCA_scrolling_222/CA.pde
deleted file mode 100644
index fa62c817f..000000000
--- a/java/examples/Books/Nature of Code/chp7_CA/Exercise_7_04_WolframCA_scrolling_222/CA.pde
+++ /dev/null
@@ -1,107 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Wolfram Cellular Automata
-
-// A class to manage the CA
-
-class CA {
-
- int generation; // How many generations?
- int[] ruleset; // An array to store the ruleset, for example {0,1,1,0,1,1,0,1}
- int w = 5;
- int[][] matrix; // Store a history of generations in 2D array, not just one
-
- int cols;
- int rows;
-
-
- CA(int[] r) {
- ruleset = r;
- cols = width/w;
- rows = height/w;
- matrix = new int[cols][rows];
- restart();
- }
-
- // Make a random ruleset
- void randomize() {
- for (int i = 0; i < 8; i++) {
- ruleset[i] = int(random(2));
- }
- }
-
- // Reset to generation 0
- void restart() {
- for (int i = 0; i < cols; i++) {
- for (int j = 0; j < rows; j++) {
- matrix[i][j] = 0;
- }
- }
- matrix[cols/2][0] = 1; // We arbitrarily start with just the middle cell having a state of "1"
- generation = 0;
- }
-
-
- // The process of creating the new generation
- void generate() {
-
- // For every spot, determine new state by examing current state, and neighbor states
- // Ignore edges that only have one neighor
- for (int i = 0; i < cols; i++) {
- int left = matrix[(i+cols-1)%cols][generation%rows]; // Left neighbor state
- int me = matrix[i][generation%rows]; // Current state
- int right = matrix[(i+1)%cols][generation%rows]; // Right neighbor state
- matrix[i][(generation+1)%rows] = rules(left, me, right); // Compute next generation state based on ruleset
- }
- generation++;
- }
-
- // This is the easy part, just draw the cells, fill 255 for '1', fill 0 for '0'
- void display() {
- int offset = generation%rows;
-
- for (int i = 0; i < cols; i++) {
- for (int j = 0; j < rows; j++) {
- int y = j - offset;
- if (y <= 0) y = rows + y;
- if (matrix[i][j] == 1) fill(0);
- else fill(255);
- noStroke();
- rect(i*w, (y-1)*w, w, w);
- }
- }
- }
-
- // Implementing the Wolfram rules
- // This is the concise conversion to binary way
- /*int rules (int a, int b, int c) {
- String s = "" + a + b + c;
- int index = Integer.parseInt(s, 2);
- return ruleset[index];
- }*/
- // For JavaScript Mode
- int rules (int a, int b, int c) {
- if (a == 1 && b == 1 && c == 1) return ruleset[7];
- if (a == 1 && b == 1 && c == 0) return ruleset[6];
- if (a == 1 && b == 0 && c == 1) return ruleset[5];
- if (a == 1 && b == 0 && c == 0) return ruleset[4];
- if (a == 0 && b == 1 && c == 1) return ruleset[3];
- if (a == 0 && b == 1 && c == 0) return ruleset[2];
- if (a == 0 && b == 0 && c == 1) return ruleset[1];
- if (a == 0 && b == 0 && c == 0) return ruleset[0];
- return 0;
- }
-
- // The CA is done if it reaches the bottom of the screen
- boolean finished() {
- if (generation > height/w) {
- return true;
- }
- else {
- return false;
- }
- }
-}
-
diff --git a/java/examples/Books/Nature of Code/chp7_CA/Exercise_7_04_WolframCA_scrolling_222/Exercise_7_04_WolframCA_scrolling_222.pde b/java/examples/Books/Nature of Code/chp7_CA/Exercise_7_04_WolframCA_scrolling_222/Exercise_7_04_WolframCA_scrolling_222.pde
deleted file mode 100644
index 24f356e7e..000000000
--- a/java/examples/Books/Nature of Code/chp7_CA/Exercise_7_04_WolframCA_scrolling_222/Exercise_7_04_WolframCA_scrolling_222.pde
+++ /dev/null
@@ -1,30 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Wolfram Cellular Automata
-
-// Simple demonstration of a Wolfram 1-dimensional cellular automata
-// with the system scrolling by
-// Also implements wrap around
-
-CA ca; // An object to describe a Wolfram elementary Cellular Automata
-
-
-void setup() {
- size(800, 100);
- frameRate(30);
- background(255);
- int[] ruleset = {0,1,1,1,1,0,1,1}; // Rule 222
- //int[] ruleset = {0,1,1,1,1,1,0,1}; // Rule 190
- //int[] ruleset = {0,1,1,1,1,0,0,0}; // Rule 30
- //int[] ruleset = {0,1,1,1,0,1,1,0}; // Rule 110
-
- ca = new CA(ruleset); // Initialize CA
-}
-
-void draw() {
- ca.display(); // Draw the CA
- ca.generate();
-}
-
diff --git a/java/examples/Books/Nature of Code/chp7_CA/Exercise_7_04_WolframCA_scrolling_30/CA.pde b/java/examples/Books/Nature of Code/chp7_CA/Exercise_7_04_WolframCA_scrolling_30/CA.pde
deleted file mode 100644
index 2353dcb9b..000000000
--- a/java/examples/Books/Nature of Code/chp7_CA/Exercise_7_04_WolframCA_scrolling_30/CA.pde
+++ /dev/null
@@ -1,106 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Wolfram Cellular Automata
-
-// A class to manage the CA
-
-class CA {
-
- int generation; // How many generations?
- int[] ruleset; // An array to store the ruleset, for example {0,1,1,0,1,1,0,1}
- int w = 5;
- int[][] matrix; // Store a history of generations in 2D array, not just one
-
- int cols;
- int rows;
-
-
- CA(int[] r) {
- ruleset = r;
- cols = width/w;
- rows = height/w;
- matrix = new int[cols][rows];
- restart();
- }
-
- // Make a random ruleset
- void randomize() {
- for (int i = 0; i < 8; i++) {
- ruleset[i] = int(random(2));
- }
- }
-
- // Reset to generation 0
- void restart() {
- for (int i = 0; i < cols; i++) {
- for (int j = 0; j < rows; j++) {
- matrix[i][j] = 0;
- }
- }
- matrix[cols/2][0] = 1; // We arbitrarily start with just the middle cell having a state of "1"
- generation = 0;
- }
-
-
- // The process of creating the new generation
- void generate() {
-
- // For every spot, determine new state by examing current state, and neighbor states
- // Ignore edges that only have one neighor
- for (int i = 0; i < cols; i++) {
- int left = matrix[(i+cols-1)%cols][generation%rows]; // Left neighbor state
- int me = matrix[i][generation%rows]; // Current state
- int right = matrix[(i+1)%cols][generation%rows]; // Right neighbor state
- matrix[i][(generation+1)%rows] = rules(left, me, right); // Compute next generation state based on ruleset
- }
- generation++;
- }
-
- // This is the easy part, just draw the cells, fill 255 for '1', fill 0 for '0'
- void display() {
- int offset = generation%rows;
-
- for (int i = 0; i < cols; i++) {
- for (int j = 0; j < rows; j++) {
- int y = j - offset;
- if (y <= 0) y = rows + y;
- if (matrix[i][j] == 1) fill(0);
- else fill(255);
- noStroke();
- rect(i*w, (y-1)*w, w, w);
- }
- }
- }
- // Implementing the Wolfram rules
- // This is the concise conversion to binary way
- /*int rules (int a, int b, int c) {
- String s = "" + a + b + c;
- int index = Integer.parseInt(s, 2);
- return ruleset[index];
- }*/
- // For JavaScript Mode
- int rules (int a, int b, int c) {
- if (a == 1 && b == 1 && c == 1) return ruleset[7];
- if (a == 1 && b == 1 && c == 0) return ruleset[6];
- if (a == 1 && b == 0 && c == 1) return ruleset[5];
- if (a == 1 && b == 0 && c == 0) return ruleset[4];
- if (a == 0 && b == 1 && c == 1) return ruleset[3];
- if (a == 0 && b == 1 && c == 0) return ruleset[2];
- if (a == 0 && b == 0 && c == 1) return ruleset[1];
- if (a == 0 && b == 0 && c == 0) return ruleset[0];
- return 0;
- }
-
- // The CA is done if it reaches the bottom of the screen
- boolean finished() {
- if (generation > height/w) {
- return true;
- }
- else {
- return false;
- }
- }
-}
-
diff --git a/java/examples/Books/Nature of Code/chp7_CA/Exercise_7_04_WolframCA_scrolling_30/Exercise_7_04_WolframCA_scrolling_30.pde b/java/examples/Books/Nature of Code/chp7_CA/Exercise_7_04_WolframCA_scrolling_30/Exercise_7_04_WolframCA_scrolling_30.pde
deleted file mode 100644
index f77d59cb1..000000000
--- a/java/examples/Books/Nature of Code/chp7_CA/Exercise_7_04_WolframCA_scrolling_30/Exercise_7_04_WolframCA_scrolling_30.pde
+++ /dev/null
@@ -1,30 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Wolfram Cellular Automata
-
-// Simple demonstration of a Wolfram 1-dimensional cellular automata
-// with the system scrolling by
-// Also implements wrap around
-
-CA ca; // An object to describe a Wolfram elementary Cellular Automata
-
-
-void setup() {
- size(800, 100);
- frameRate(30);
- background(255);
- //int[] ruleset = {0,1,1,1,1,0,1,1}; // Rule 222
- //int[] ruleset = {0,1,1,1,1,1,0,1}; // Rule 190
- int[] ruleset = {0,1,1,1,1,0,0,0}; // Rule 30
- //int[] ruleset = {0,1,1,1,0,1,1,0}; // Rule 110
-
- ca = new CA(ruleset); // Initialize CA
-}
-
-void draw() {
- ca.display(); // Draw the CA
- ca.generate();
-}
-
diff --git a/java/examples/Books/Nature of Code/chp7_CA/Exercise_7_09_HexagonCells/Cell.pde b/java/examples/Books/Nature of Code/chp7_CA/Exercise_7_09_HexagonCells/Cell.pde
deleted file mode 100644
index 13acf5b88..000000000
--- a/java/examples/Books/Nature of Code/chp7_CA/Exercise_7_09_HexagonCells/Cell.pde
+++ /dev/null
@@ -1,42 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-class Cell {
-
- float x, y;
- float w;
- float xoff;
- float yoff;
-
- int state;
-
- Cell(float x_, float y_, float w_) {
- x = x_;
- y = y_;
- w = w_;
- xoff = w/2;
- yoff = sin(radians(60))*w;
- state = int(random(2));
- }
-
-
- void display() {
-
- fill(state*255);
- stroke(0);
- pushMatrix();
- translate(x,y);
- beginShape();
- vertex(0, yoff);
- vertex(xoff, 0);
- vertex(xoff+w, 0);
- vertex(2*w, yoff);
- vertex(xoff+w, 2*yoff);
- vertex(xoff, 2*yoff);
- vertex(0, yoff);
- endShape();
- popMatrix();
- }
-}
-
diff --git a/java/examples/Books/Nature of Code/chp7_CA/Exercise_7_09_HexagonCells/Exercise_7_09_HexagonCells.pde b/java/examples/Books/Nature of Code/chp7_CA/Exercise_7_09_HexagonCells/Exercise_7_09_HexagonCells.pde
deleted file mode 100644
index 38b7e4e27..000000000
--- a/java/examples/Books/Nature of Code/chp7_CA/Exercise_7_09_HexagonCells/Exercise_7_09_HexagonCells.pde
+++ /dev/null
@@ -1,24 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Outline for game of life
-// This is just a grid of hexagons right now
-
-GOL gol;
-
-void setup() {
- size(640, 360);
- gol = new GOL();
-}
-
-void draw() {
- background(255);
- gol.display();
-}
-
-// reset board when mouse is pressed
-void mousePressed() {
- gol.init();
-}
-
diff --git a/java/examples/Books/Nature of Code/chp7_CA/Exercise_7_09_HexagonCells/GOL.pde b/java/examples/Books/Nature of Code/chp7_CA/Exercise_7_09_HexagonCells/GOL.pde
deleted file mode 100644
index 1f1491abe..000000000
--- a/java/examples/Books/Nature of Code/chp7_CA/Exercise_7_09_HexagonCells/GOL.pde
+++ /dev/null
@@ -1,44 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-class GOL {
-
- float w = 20;
- float h = sin(radians(60))*w;
- int columns, rows;
-
- // Game of life board
- Cell[][] board;
-
-
- GOL() {
- // Initialize rows, columns and set-up arrays
- columns = width/int(w*3);
- rows = height/int(h);
- board = new Cell[columns][rows];
- init();
- }
-
- void init() {
- float h = sin(radians(60))*w;
- for (int i = 0; i < columns; i++) {
- for (int j = 0; j < rows; j++) {
- if (j % 2 == 0) board[i][j] = new Cell(i*w*3, j*h,w);
- else board[i][j] = new Cell(i*w*3+w+h/2, j*h, w);
- }
- }
- }
-
-
-
- // This is the easy part, just draw the cells, fill 255 for '1', fill 0 for '0'
- void display() {
- for ( int i = 0; i < columns;i++) {
- for ( int j = 0; j < rows;j++) {
- board[i][j].display();
- }
- }
- }
-}
-
diff --git a/java/examples/Books/Nature of Code/chp7_CA/Figure_7_17_cells/Figure_7_17_cells.pde b/java/examples/Books/Nature of Code/chp7_CA/Figure_7_17_cells/Figure_7_17_cells.pde
deleted file mode 100644
index ef16d1b06..000000000
--- a/java/examples/Books/Nature of Code/chp7_CA/Figure_7_17_cells/Figure_7_17_cells.pde
+++ /dev/null
@@ -1,31 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-size(1800,90);
-
-int w = 90;
-
-int total = width/w;
-
-int[] cells = {1,0,1,0,0,0,0,1,0,1,1,1,0,0,0,1,1,1,0,0};
-
-
-print("int[] cells = {");
-for (int i = 0; i < cells.length; i++) {
- if (cells[i] == 0) fill(255);
- else fill(64);
- stroke(0);
- rect(i*w,0,w-1,w-1);
- print(cells[i] +",");
-}
-
-saveFrame("cells.png");
-
-
-
-
-
-
-
-
diff --git a/java/examples/Books/Nature of Code/chp7_CA/Figure_7_17_cells/cells.tif b/java/examples/Books/Nature of Code/chp7_CA/Figure_7_17_cells/cells.tif
deleted file mode 100644
index 38ef13501..000000000
Binary files a/java/examples/Books/Nature of Code/chp7_CA/Figure_7_17_cells/cells.tif and /dev/null differ
diff --git a/java/examples/Books/Nature of Code/chp7_CA/GameOfLifeWrapAround/GOL.pde b/java/examples/Books/Nature of Code/chp7_CA/GameOfLifeWrapAround/GOL.pde
deleted file mode 100644
index 3fd3a82d5..000000000
--- a/java/examples/Books/Nature of Code/chp7_CA/GameOfLifeWrapAround/GOL.pde
+++ /dev/null
@@ -1,77 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-class GOL {
-
- int w = 8;
- int columns, rows;
-
- // Game of life board
- int[][] board;
-
-
- GOL() {
- // Initialize rows, columns and set-up arrays
- columns = width/w;
- rows = height/w;
- board = new int[columns][rows];
- //next = new int[columns][rows];
- // Call function to fill array with random values 0 or 1
- init();
- }
-
- void init() {
- for (int i =1;i < columns-1;i++) {
- for (int j =1;j < rows-1;j++) {
- board[i][j] = int(random(2));
- }
- }
- }
-
- // The process of creating the new generation
- void generate() {
-
- int[][] next = new int[columns][rows];
-
- // Loop through every spot in our 2D array and check spots neighbors
- for (int x = 0; x < columns; x++) {
- for (int y = 0; y < rows; y++) {
-
- // Add up all the states in a 3x3 surrounding grid
- int neighbors = 0;
- for (int i = -1; i <= 1; i++) {
- for (int j = -1; j <= 1; j++) {
- neighbors += board[(x+i+columns)%columns][(y+j+rows)%rows];
- }
- }
-
- // A little trick to subtract the current cell's state since
- // we added it in the above loop
- neighbors -= board[x][y];
-
- // Rules of Life
- if ((board[x][y] == 1) && (neighbors < 2)) next[x][y] = 0; // Loneliness
- else if ((board[x][y] == 1) && (neighbors > 3)) next[x][y] = 0; // Overpopulation
- else if ((board[x][y] == 0) && (neighbors == 3)) next[x][y] = 1; // Reproduction
- else next[x][y] = board[x][y]; // Stasis
- }
- }
-
- // Next is now our board
- board = next;
- }
-
- // This is the easy part, just draw the cells, fill 255 for '1', fill 0 for '0'
- void display() {
- for ( int i = 0; i < columns;i++) {
- for ( int j = 0; j < rows;j++) {
- if ((board[i][j] == 1)) fill(0);
- else fill(255);
- stroke(0);
- rect(i*w, j*w, w, w);
- }
- }
- }
-}
-
diff --git a/java/examples/Books/Nature of Code/chp7_CA/GameOfLifeWrapAround/GameOfLifeWrapAround.pde b/java/examples/Books/Nature of Code/chp7_CA/GameOfLifeWrapAround/GameOfLifeWrapAround.pde
deleted file mode 100644
index f807dbebc..000000000
--- a/java/examples/Books/Nature of Code/chp7_CA/GameOfLifeWrapAround/GameOfLifeWrapAround.pde
+++ /dev/null
@@ -1,33 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Daniel Shiffman, Nature of Code
-
-// A basic implementation of John Conway's Game of Life CA
-// how could this be improved to use object oriented programming?
-// think of it as similar to our particle system, with a "cell" class
-// to describe each individual cell and a "cellular automata" class
-// to describe a collection of cells
-
-// Cells wrap around
-
-GOL gol;
-
-void setup() {
- size(400, 400);
- gol = new GOL();
-}
-
-void draw() {
- background(255);
-
- gol.generate();
- gol.display();
-}
-
-// reset board when mouse is pressed
-void mousePressed() {
- gol.init();
-}
-
diff --git a/java/examples/Books/Nature of Code/chp7_CA/HexagonCells/Cell.pde b/java/examples/Books/Nature of Code/chp7_CA/HexagonCells/Cell.pde
deleted file mode 100644
index 13acf5b88..000000000
--- a/java/examples/Books/Nature of Code/chp7_CA/HexagonCells/Cell.pde
+++ /dev/null
@@ -1,42 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-class Cell {
-
- float x, y;
- float w;
- float xoff;
- float yoff;
-
- int state;
-
- Cell(float x_, float y_, float w_) {
- x = x_;
- y = y_;
- w = w_;
- xoff = w/2;
- yoff = sin(radians(60))*w;
- state = int(random(2));
- }
-
-
- void display() {
-
- fill(state*255);
- stroke(0);
- pushMatrix();
- translate(x,y);
- beginShape();
- vertex(0, yoff);
- vertex(xoff, 0);
- vertex(xoff+w, 0);
- vertex(2*w, yoff);
- vertex(xoff+w, 2*yoff);
- vertex(xoff, 2*yoff);
- vertex(0, yoff);
- endShape();
- popMatrix();
- }
-}
-
diff --git a/java/examples/Books/Nature of Code/chp7_CA/HexagonCells/GOL.pde b/java/examples/Books/Nature of Code/chp7_CA/HexagonCells/GOL.pde
deleted file mode 100644
index 1f1491abe..000000000
--- a/java/examples/Books/Nature of Code/chp7_CA/HexagonCells/GOL.pde
+++ /dev/null
@@ -1,44 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-class GOL {
-
- float w = 20;
- float h = sin(radians(60))*w;
- int columns, rows;
-
- // Game of life board
- Cell[][] board;
-
-
- GOL() {
- // Initialize rows, columns and set-up arrays
- columns = width/int(w*3);
- rows = height/int(h);
- board = new Cell[columns][rows];
- init();
- }
-
- void init() {
- float h = sin(radians(60))*w;
- for (int i = 0; i < columns; i++) {
- for (int j = 0; j < rows; j++) {
- if (j % 2 == 0) board[i][j] = new Cell(i*w*3, j*h,w);
- else board[i][j] = new Cell(i*w*3+w+h/2, j*h, w);
- }
- }
- }
-
-
-
- // This is the easy part, just draw the cells, fill 255 for '1', fill 0 for '0'
- void display() {
- for ( int i = 0; i < columns;i++) {
- for ( int j = 0; j < rows;j++) {
- board[i][j].display();
- }
- }
- }
-}
-
diff --git a/java/examples/Books/Nature of Code/chp7_CA/HexagonCells/HexagonCells.pde b/java/examples/Books/Nature of Code/chp7_CA/HexagonCells/HexagonCells.pde
deleted file mode 100644
index 6bd52053b..000000000
--- a/java/examples/Books/Nature of Code/chp7_CA/HexagonCells/HexagonCells.pde
+++ /dev/null
@@ -1,24 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Outline for game of life
-// This is just a grid of hexagons right now
-
-GOL gol;
-
-void setup() {
- size(600, 600);
- gol = new GOL();
-}
-
-void draw() {
- background(255);
- gol.display();
-}
-
-// reset board when mouse is pressed
-void mousePressed() {
- gol.init();
-}
-
diff --git a/java/examples/Books/Nature of Code/chp7_CA/NOC_7_01_WolframCA_figures/CA.pde b/java/examples/Books/Nature of Code/chp7_CA/NOC_7_01_WolframCA_figures/CA.pde
deleted file mode 100644
index b0309e63b..000000000
--- a/java/examples/Books/Nature of Code/chp7_CA/NOC_7_01_WolframCA_figures/CA.pde
+++ /dev/null
@@ -1,95 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Wolfram Cellular Automata
-
-// A class to manage the CA
-
-class CA {
-
- int[] cells; // An array of 0s and 1s
- int generation; // How many generations?
-
- int[] ruleset; // An array to store the ruleset, for example {0,1,1,0,1,1,0,1}
-
- CA(int[] r) {
- ruleset = r;
- cells = new int[width/scl];
- restart();
- }
-
- CA() {
- scl = 1;
- cells = new int[width/scl];
- randomize();
- restart();
- }
-
- // Set the rules of the CA
- void setRules(int[] r) {
- ruleset = r;
- }
-
- // Make a random ruleset
- void randomize() {
- for (int i = 0; i < 8; i++) {
- ruleset[i] = int(random(2));
- }
- }
-
- // Reset to generation 0
- void restart() {
- for (int i = 0; i < cells.length; i++) {
- cells[i] = 0;
- }
- cells[cells.length/2] = 1; // We arbitrarily start with just the middle cell having a state of "1"
- generation = 0;
- }
-
- // The process of creating the new generation
- void generate() {
- // First we create an empty array for the new values
- int[] nextgen = new int[cells.length];
- // For every spot, determine new state by examing current state, and neighbor states
- // Ignore edges that only have one neighor
- for (int i = 1; i < cells.length-1; i++) {
- int left = cells[i-1]; // Left neighbor state
- int me = cells[i]; // Current state
- int right = cells[i+1]; // Right neighbor state
- nextgen[i] = rules(left, me, right); // Compute next generation state based on ruleset
- }
- // The current generation is the new generation
- cells = nextgen;
- generation++;
- }
-
- // This is the easy part, just draw the cells, fill 255 for '1', fill 0 for '0'
- void render() {
- for (int i = 0; i < cells.length; i++) {
- if (cells[i] == 1) fill(0);
- else fill(255);
- stroke(0);
- rect(i*scl, generation*scl, scl, scl);
- }
- }
-
- // Implementing the Wolfram rules
- // Could be improved and made more concise, but here we can explicitly see what is going on for each case
- int rules (int a, int b, int c) {
- String s = "" + a + b + c;
- int index = Integer.parseInt(s,2);
- return ruleset[index];
- }
-
- // The CA is done if it reaches the bottom of the screen
- boolean finished() {
- if (generation > height/scl) {
- return true;
- }
- else {
- return false;
- }
- }
-}
-
diff --git a/java/examples/Books/Nature of Code/chp7_CA/NOC_7_01_WolframCA_figures/NOC_7_01_WolframCA_figures.pde b/java/examples/Books/Nature of Code/chp7_CA/NOC_7_01_WolframCA_figures/NOC_7_01_WolframCA_figures.pde
deleted file mode 100644
index 8e7ea3f4c..000000000
--- a/java/examples/Books/Nature of Code/chp7_CA/NOC_7_01_WolframCA_figures/NOC_7_01_WolframCA_figures.pde
+++ /dev/null
@@ -1,38 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Wolfram Cellular Automata
-
-// Simple demonstration of a Wolfram 1-dimensional cellular automata
-// When the system reaches bottom of the window, it restarts with a new ruleset
-// Mouse click restarts as well
-
-
-CA ca; // An instance object to describe the Wolfram basic Cellular Automata
-
-int scl = 20;
-
-void setup() {
- size(1800,600);
- background(255);
- //int[] ruleset = {0,1,0,1,1,0,1,0}; // 90
- int[] ruleset = {0,1,1,1,1,0,1,1}; // An initial rule system
- ca = new CA(ruleset); // Initialize CA
-}
-
-void draw() {
- ca.render(); // Draw the CA
- ca.generate(); // Generate the next level
-
- if (ca.finished()) { // If we're done, clear the screen, pick a new ruleset and restart
- saveFrame("rule222.png");
- noLoop();
- }
-}
-
-void mousePressed() {
- background(255);
- ca.randomize();
- ca.restart();
-}
diff --git a/java/examples/Books/Nature of Code/chp7_CA/NOC_7_01_WolframCA_simple/CA.pde b/java/examples/Books/Nature of Code/chp7_CA/NOC_7_01_WolframCA_simple/CA.pde
deleted file mode 100644
index a6e158470..000000000
--- a/java/examples/Books/Nature of Code/chp7_CA/NOC_7_01_WolframCA_simple/CA.pde
+++ /dev/null
@@ -1,70 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-// Wolfram Cellular Automata
-
-// A class to manage the CA
-
-class CA {
-
- int[] cells; // An array of 0s and 1s
- int generation; // How many generations?
-
- int[] ruleset = {0, 1, 0, 1, 1, 0, 1, 0}; // An array to store the ruleset, for example {0,1,1,0,1,1,0,1}
-
- int w = 10;
-
- CA() {
- cells = new int[width/w];
- for (int i = 0; i < cells.length; i++) {
- cells[i] = 0;
- }
- cells[cells.length/2] = 1; // We arbitrarily start with just the middle cell having a state of "1"
- generation = 0;
- }
-
- // The process of creating the new generation
- void generate() {
- // First we create an empty array for the new values
- int[] nextgen = new int[cells.length];
- // For every spot, determine new state by examing current state, and neighbor states
- // Ignore edges that only have one neighor
- for (int i = 1; i < cells.length-1; i++) {
- int left = cells[i-1]; // Left neighbor state
- int me = cells[i]; // Current state
- int right = cells[i+1]; // Right neighbor state
- nextgen[i] = rules(left, me, right); // Compute next generation state based on ruleset
- }
- // The current generation is the new generation
- cells = nextgen;
- generation++;
-
- }
-
- // This is the easy part, just draw the cells, fill 255 for '1', fill 0 for '0'
- void display() {
- for (int i = 0; i < cells.length; i++) {
- if (cells[i] == 1) fill(0);
- else fill(255);
- noStroke();
- rect(i*w, generation*w, w, w);
- }
- }
-
-
-
- // Implementing the Wolfram rules
- // Could be improved and made more concise, but here we can explicitly see what is going on for each case
- int rules (int a, int b, int c) {
- if (a == 1 && b == 1 && c == 1) return ruleset[0];
- if (a == 1 && b == 1 && c == 0) return ruleset[1];
- if (a == 1 && b == 0 && c == 1) return ruleset[2];
- if (a == 1 && b == 0 && c == 0) return ruleset[3];
- if (a == 0 && b == 1 && c == 1) return ruleset[4];
- if (a == 0 && b == 1 && c == 0) return ruleset[5];
- if (a == 0 && b == 0 && c == 1) return ruleset[6];
- if (a == 0 && b == 0 && c == 0) return ruleset[7];
- return 0;
- }
-}
-
diff --git a/java/examples/Books/Nature of Code/chp7_CA/NOC_7_01_WolframCA_simple/NOC_7_01_WolframCA_simple.pde b/java/examples/Books/Nature of Code/chp7_CA/NOC_7_01_WolframCA_simple/NOC_7_01_WolframCA_simple.pde
deleted file mode 100644
index e26b35453..000000000
--- a/java/examples/Books/Nature of Code/chp7_CA/NOC_7_01_WolframCA_simple/NOC_7_01_WolframCA_simple.pde
+++ /dev/null
@@ -1,24 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-// Wolfram Cellular Automata
-
-// Simple demonstration of a Wolfram 1-dimensional cellular automata
-
-CA ca; // An instance object to describe the Wolfram basic Cellular Automata
-
-
-void setup() {
- size(800, 400);
- background(255);
- ca = new CA(); // Initialize CA
-}
-
-void draw() {
- ca.display(); // Draw the CA
- if (ca.generation < height/ca.w) {
- ca.generate();
- }
-
-}
-
diff --git a/java/examples/Books/Nature of Code/chp7_CA/NOC_7_02_GameOfLifeSimple/GOL.pde b/java/examples/Books/Nature of Code/chp7_CA/NOC_7_02_GameOfLifeSimple/GOL.pde
deleted file mode 100644
index 413318d9d..000000000
--- a/java/examples/Books/Nature of Code/chp7_CA/NOC_7_02_GameOfLifeSimple/GOL.pde
+++ /dev/null
@@ -1,77 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-class GOL {
-
- int w = 8;
- int columns, rows;
-
- // Game of life board
- int[][] board;
-
-
- GOL() {
- // Initialize rows, columns and set-up arrays
- columns = width/w;
- rows = height/w;
- board = new int[columns][rows];
- //next = new int[columns][rows];
- // Call function to fill array with random values 0 or 1
- init();
- }
-
- void init() {
- for (int i =1;i < columns-1;i++) {
- for (int j =1;j < rows-1;j++) {
- board[i][j] = int(random(2));
- }
- }
- }
-
- // The process of creating the new generation
- void generate() {
-
- int[][] next = new int[columns][rows];
-
- // Loop through every spot in our 2D array and check spots neighbors
- for (int x = 1; x < columns-1; x++) {
- for (int y = 1; y < rows-1; y++) {
-
- // Add up all the states in a 3x3 surrounding grid
- int neighbors = 0;
- for (int i = -1; i <= 1; i++) {
- for (int j = -1; j <= 1; j++) {
- neighbors += board[x+i][y+j];
- }
- }
-
- // A little trick to subtract the current cell's state since
- // we added it in the above loop
- neighbors -= board[x][y];
-
- // Rules of Life
- if ((board[x][y] == 1) && (neighbors < 2)) next[x][y] = 0; // Loneliness
- else if ((board[x][y] == 1) && (neighbors > 3)) next[x][y] = 0; // Overpopulation
- else if ((board[x][y] == 0) && (neighbors == 3)) next[x][y] = 1; // Reproduction
- else next[x][y] = board[x][y]; // Stasis
- }
- }
-
- // Next is now our board
- board = next;
- }
-
- // This is the easy part, just draw the cells, fill 255 for '1', fill 0 for '0'
- void display() {
- for ( int i = 0; i < columns;i++) {
- for ( int j = 0; j < rows;j++) {
- if ((board[i][j] == 1)) fill(0);
- else fill(255);
- stroke(0);
- rect(i*w, j*w, w, w);
- }
- }
- }
-}
-
diff --git a/java/examples/Books/Nature of Code/chp7_CA/NOC_7_02_GameOfLifeSimple/NOC_7_02_GameOfLifeSimple.pde b/java/examples/Books/Nature of Code/chp7_CA/NOC_7_02_GameOfLifeSimple/NOC_7_02_GameOfLifeSimple.pde
deleted file mode 100644
index 4526630f8..000000000
--- a/java/examples/Books/Nature of Code/chp7_CA/NOC_7_02_GameOfLifeSimple/NOC_7_02_GameOfLifeSimple.pde
+++ /dev/null
@@ -1,30 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// A basic implementation of John Conway's Game of Life CA
-// how could this be improved to use object oriented programming?
-// think of it as similar to our particle system, with a "cell" class
-// to describe each individual cell and a "cellular automata" class
-// to describe a collection of cells
-
-GOL gol;
-
-void setup() {
- size(640, 360);
- frameRate(24);
- gol = new GOL();
-}
-
-void draw() {
- background(255);
-
- gol.generate();
- gol.display();
-}
-
-// reset board when mouse is pressed
-void mousePressed() {
- gol.init();
-}
-
diff --git a/java/examples/Books/Nature of Code/chp7_CA/NOC_7_03_GameOfLifeOOP/Cell.pde b/java/examples/Books/Nature of Code/chp7_CA/NOC_7_03_GameOfLifeOOP/Cell.pde
deleted file mode 100644
index d18e16933..000000000
--- a/java/examples/Books/Nature of Code/chp7_CA/NOC_7_03_GameOfLifeOOP/Cell.pde
+++ /dev/null
@@ -1,40 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-class Cell {
-
- float x, y;
- float w;
-
- int state;
- int previous;
-
- Cell(float x_, float y_, float w_) {
- x = x_;
- y = y_;
- w = w_;
-
- state = int(random(2));
- previous = state;
- }
-
- void savePrevious() {
- previous = state;
- }
-
- void newState(int s) {
- state = s;
- }
-
- void display() {
- if (previous == 0 && state == 1) fill(0,0,255);
- else if (state == 1) fill(0);
- else if (previous == 1 && state == 0) fill(255,0,0);
- else fill(255);
- stroke(0);
- rect(x, y, w, w);
- }
-}
-
-
diff --git a/java/examples/Books/Nature of Code/chp7_CA/NOC_7_03_GameOfLifeOOP/GOL.pde b/java/examples/Books/Nature of Code/chp7_CA/NOC_7_03_GameOfLifeOOP/GOL.pde
deleted file mode 100644
index cdf3f3ad2..000000000
--- a/java/examples/Books/Nature of Code/chp7_CA/NOC_7_03_GameOfLifeOOP/GOL.pde
+++ /dev/null
@@ -1,73 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-class GOL {
-
- int w = 8;
- int columns, rows;
-
- // Game of life board
- Cell[][] board;
-
-
- GOL() {
- // Initialize rows, columns and set-up arrays
- columns = width/w;
- rows = height/w;
- board = new Cell[columns][rows];
- init();
- }
-
- void init() {
- for (int i = 0; i < columns; i++) {
- for (int j = 0; j < rows; j++) {
- board[i][j] = new Cell(i*w, j*w, w);
- }
- }
- }
-
- // The process of creating the new generation
- void generate() {
- for ( int i = 0; i < columns;i++) {
- for ( int j = 0; j < rows;j++) {
- board[i][j].savePrevious();
- }
- }
-
-
- // Loop through every spot in our 2D array and check spots neighbors
- for (int x = 0; x < columns; x++) {
- for (int y = 0; y < rows; y++) {
-
- // Add up all the states in a 3x3 surrounding grid
- int neighbors = 0;
- for (int i = -1; i <= 1; i++) {
- for (int j = -1; j <= 1; j++) {
- neighbors += board[(x+i+columns)%columns][(y+j+rows)%rows].previous;
- }
- }
-
- // A little trick to subtract the current cell's state since
- // we added it in the above loop
- neighbors -= board[x][y].previous;
-
- // Rules of Life
- if ((board[x][y].state == 1) && (neighbors < 2)) board[x][y].newState(0); // Loneliness
- else if ((board[x][y].state == 1) && (neighbors > 3)) board[x][y].newState(0); // Overpopulation
- else if ((board[x][y].state == 0) && (neighbors == 3)) board[x][y].newState(1); // Reproduction
- // else do nothing!
- }
- }
- }
-
- // This is the easy part, just draw the cells, fill 255 for '1', fill 0 for '0'
- void display() {
- for ( int i = 0; i < columns;i++) {
- for ( int j = 0; j < rows;j++) {
- board[i][j].display();
- }
- }
- }
-}
-
diff --git a/java/examples/Books/Nature of Code/chp7_CA/NOC_7_03_GameOfLifeOOP/NOC_7_03_GameOfLifeOOP.pde b/java/examples/Books/Nature of Code/chp7_CA/NOC_7_03_GameOfLifeOOP/NOC_7_03_GameOfLifeOOP.pde
deleted file mode 100644
index 32227dd01..000000000
--- a/java/examples/Books/Nature of Code/chp7_CA/NOC_7_03_GameOfLifeOOP/NOC_7_03_GameOfLifeOOP.pde
+++ /dev/null
@@ -1,27 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// A basic implementation of John Conway's Game of Life CA
-
-// Each cell is now an object!
-
-GOL gol;
-
-void setup() {
- size(640, 360);
- gol = new GOL();
-}
-
-void draw() {
- background(255);
-
- gol.generate();
- gol.display();
-}
-
-// reset board when mouse is pressed
-void mousePressed() {
- gol.init();
-}
-
diff --git a/java/examples/Books/Nature of Code/chp8_fractals/CantorSetArrayList/CantorSetArrayList.pde b/java/examples/Books/Nature of Code/chp8_fractals/CantorSetArrayList/CantorSetArrayList.pde
deleted file mode 100644
index 3c3d86023..000000000
--- a/java/examples/Books/Nature of Code/chp8_fractals/CantorSetArrayList/CantorSetArrayList.pde
+++ /dev/null
@@ -1,48 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Cantor Set
-// Renders a simple fractal, the Cantor Set
-// Uses an ArrayList to store list of objects
-// Generates when mouse is pressed
-
-float h = 30;
-
-// List of line objects
-ArrayList cantor;
-
-void setup() {
- size(729, 200);
-
- // Start with one line
- cantor = new ArrayList();
- cantor.add(new CantorLine(0, 100, width));
-}
-
-// Click the mouse to advance the sequence
-void mousePressed() {
- generate();
-}
-
-void draw() {
- background(255);
- // Always show all the lines
- for (CantorLine cl : cantor) {
- cl.display();
- }
-
- fill(0);
- text("Click mouse to generate",10,height-20);
-}
-
-void generate() {
- // Generate the next set of lines
- ArrayList next = new ArrayList();
- for (CantorLine cl : cantor) {
- next.add(new CantorLine(cl.x,cl.y,cl.len/3));
- next.add(new CantorLine(cl.x+cl.len*2/3,cl.y,cl.len/3));
- }
- cantor = next;
-}
-
diff --git a/java/examples/Books/Nature of Code/chp8_fractals/CantorSetArrayList/Line.pde b/java/examples/Books/Nature of Code/chp8_fractals/CantorSetArrayList/Line.pde
deleted file mode 100644
index 2677ac37b..000000000
--- a/java/examples/Books/Nature of Code/chp8_fractals/CantorSetArrayList/Line.pde
+++ /dev/null
@@ -1,23 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Cantor line is a simple horizontal line with a starting point
-// and length
-
-class CantorLine {
- float x,y;
- float len;
-
- CantorLine(float x_, float y_, float len_) {
- x = x_;
- y = y_;
- len = len_;
- }
-
- void display() {
- stroke(0);
- line(x,y,x+len,y);
- }
-
-}
diff --git a/java/examples/Books/Nature of Code/chp8_fractals/Exercise_8_01_RecursionLines/Exercise_8_01_RecursionLines.pde b/java/examples/Books/Nature of Code/chp8_fractals/Exercise_8_01_RecursionLines/Exercise_8_01_RecursionLines.pde
deleted file mode 100644
index e90258a0b..000000000
--- a/java/examples/Books/Nature of Code/chp8_fractals/Exercise_8_01_RecursionLines/Exercise_8_01_RecursionLines.pde
+++ /dev/null
@@ -1,36 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Simple Recursion
-
-void setup() {
- size(800, 200);
-}
-
-void draw() {
- background(255);
- drawLines(100,100,700,100);
- noLoop();
-}
-
-void drawLines(float x1, float y1, float x2, float y2) {
-
- line(x1,y1,x2,y2);
-
- float dx = x2-x1;
- float dy = y2-y1;
-
- //println(dx + " " + dy);
-
- if (dx == 0 && dy > 4) {
- //println(dy);
- drawLines(x1-dy/3,y1,x1+dy/3,y1);
- drawLines(x1-dy/3,y2,x1+dy/3,y2);
- } else if (dy == 0 && dx > 4) {
- //println(dx);
- drawLines(x1,y1-dx/3,x1,y1+dx/3);
- drawLines(x2,y1-dx/3,x2,y1+dx/3);
- }
-}
-
diff --git a/java/examples/Books/Nature of Code/chp8_fractals/Exercise_8_02_KochSnowFlake/Exercise_8_02_KochSnowFlake.pde b/java/examples/Books/Nature of Code/chp8_fractals/Exercise_8_02_KochSnowFlake/Exercise_8_02_KochSnowFlake.pde
deleted file mode 100644
index c5e5f6b86..000000000
--- a/java/examples/Books/Nature of Code/chp8_fractals/Exercise_8_02_KochSnowFlake/Exercise_8_02_KochSnowFlake.pde
+++ /dev/null
@@ -1,55 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Koch Snowflake
-
-// Renders a simple fractal, the Koch snowflake
-// Each recursive level drawn in sequence
-
-ArrayList lines ; // A list to keep track of all the lines
-
-void setup() {
- size(600, 692);
- background(255);
- lines = new ArrayList();
- PVector a = new PVector(0, 173);
- PVector b = new PVector(width, 173);
- PVector c = new PVector(width/2, 173+width*cos(radians(30)));
-
- // Starting with additional lines
- lines.add(new KochLine(a, b));
- lines.add(new KochLine(b, c));
- lines.add(new KochLine(c, a));
-
- for (int i = 0; i < 5; i++) {
- generate();
- }
-}
-
-void draw() {
- background(255);
- for (KochLine l : lines) {
- l.display();
- }
-}
-
-void generate() {
- ArrayList next = new ArrayList(); // Create emtpy list
- for (KochLine l : lines) {
- // Calculate 5 koch PVectors (done for us by the line object)
- PVector a = l.kochA();
- PVector b = l.kochB();
- PVector c = l.kochC();
- PVector d = l.kochD();
- PVector e = l.kochE();
- // Make line segments between all the PVectors and add them
- next.add(new KochLine(a, b));
- next.add(new KochLine(b, c));
- next.add(new KochLine(c, d));
- next.add(new KochLine(d, e));
- }
- lines = next;
-}
-
-
diff --git a/java/examples/Books/Nature of Code/chp8_fractals/Exercise_8_02_KochSnowFlake/KochLine.pde b/java/examples/Books/Nature of Code/chp8_fractals/Exercise_8_02_KochSnowFlake/KochLine.pde
deleted file mode 100644
index 8b2b5aab9..000000000
--- a/java/examples/Books/Nature of Code/chp8_fractals/Exercise_8_02_KochSnowFlake/KochLine.pde
+++ /dev/null
@@ -1,75 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Koch Curve
-
-// A class to describe one line segment in the fractal
-// Includes methods to calculate midPVectors along the line according to the Koch algorithm
-
-class KochLine {
-
- // Two PVectors,
- // a is the "left" PVector and
- // b is the "right PVector
- PVector start;
- PVector end;
-
- KochLine(PVector a, PVector b) {
- start = a.get();
- end = b.get();
- }
-
- void display() {
- stroke(0);
- strokeWeight(2);
- line(start.x, start.y, end.x, end.y);
- }
-
- PVector kochA() {
- return start.get();
- }
-
-
- // This is easy, just 1/3 of the way
- PVector kochB() {
- PVector v = PVector.sub(end, start);
- v.div(3);
- v.add(start);
- return v;
- }
-
- // More complicated, have to use a little trig to figure out where this PVector is!
- PVector kochC() {
- PVector a = start.get(); // Start at the beginning
-
- PVector v = PVector.sub(end, start);
- v.div(3);
- a.add(v); // Move to point B
-
- rotate(v, -radians(60)); // Rotate 60 degrees
- a.add(v); // Move to point C
-
- return a;
- }
-
- // Easy, just 2/3 of the way
- PVector kochD() {
- PVector v = PVector.sub(end, start);
- v.mult(2/3.0);
- v.add(start);
- return v;
- }
-
- PVector kochE() {
- return end.get();
- }
-}
-
-public void rotate(PVector v, float theta) {
- float xTemp = v.x;
- // Might need to check for rounding errors like with angleBetween function?
- v.x = v.x*PApplet.cos(theta) - v.y*PApplet.sin(theta);
- v.y = xTemp*PApplet.sin(theta) + v.y*PApplet.cos(theta);
-}
-
diff --git a/java/examples/Books/Nature of Code/chp8_fractals/Exercise_8_06_Tree/Exercise_8_06_Tree.pde b/java/examples/Books/Nature of Code/chp8_fractals/Exercise_8_06_Tree/Exercise_8_06_Tree.pde
deleted file mode 100644
index ced569b79..000000000
--- a/java/examples/Books/Nature of Code/chp8_fractals/Exercise_8_06_Tree/Exercise_8_06_Tree.pde
+++ /dev/null
@@ -1,58 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Recursive Tree
-
-// Renders a simple tree-like structure via recursion
-// Branching angle calculated as a function of horizontal mouse location
-
-float theta;
-
-void setup() {
- size(1800, 500);
- smooth();
-}
-
-void draw() {
- background(255);
- // Let's pick an angle 0 to 90 degrees based on the mouse position
- theta = PI/6;//map(mouseX,0,width,0,PI/2);
-
- // Start the tree from the bottom of the screen
- translate(width/2, height);
- stroke(0);
- branch(200,0);
- save("chapter08_exc06.png");
- noLoop();
-}
-
-void branch(float len, int level) {
- // Each branch will be 2/3rds the size of the previous one
-
- //float sw = map(len,2,120,1,10);
- //strokeWeight(sw);
- strokeWeight(2);
-
- line(0, 0, 0, -len);
- // Move to the end of that line
- translate(0, -len);
-
- len *= 0.66;
- level++;
- // All recursive functions must have an exit condition!!!!
- // Here, ours is when the length of the branch is 2 pixels or less
- if (level < 5) {
- pushMatrix(); // Save the current state of transformation (i.e. where are we now)
- rotate(theta); // Rotate by theta
- branch(len,level); // Ok, now call myself to draw two new branches!!
- popMatrix(); // Whenever we get back here, we "pop" in order to restore the previous matrix state
-
- // Repeat the same thing, only branch off to the "left" this time!
- pushMatrix();
- rotate(-theta);
- branch(len,level);
- popMatrix();
- }
-}
-
diff --git a/java/examples/Books/Nature of Code/chp8_fractals/Exercise_8_07_Tree/Exercise_8_07_Tree.pde b/java/examples/Books/Nature of Code/chp8_fractals/Exercise_8_07_Tree/Exercise_8_07_Tree.pde
deleted file mode 100644
index 3019d44ca..000000000
--- a/java/examples/Books/Nature of Code/chp8_fractals/Exercise_8_07_Tree/Exercise_8_07_Tree.pde
+++ /dev/null
@@ -1,51 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Recursive Tree
-// Renders a simple tree-like structure via recursion
-// Branching angle calculated as a function of horizontal mouse location
-
-float theta;
-
-void setup() {
- size(640, 360);
-}
-
-void draw() {
- background(255);
- // Let's pick an angle 0 to 90 degrees based on the mouse position
- theta = map(mouseX,0,width,0,PI/2);
-
- // Start the tree from the bottom of the screen
- translate(width/2, height);
- stroke(0);
- branch(60);
-}
-
-void branch(float len) {
- // Each branch will be 2/3rds the size of the previous one
- float sw = map(len,2,120,1,10);
- strokeWeight(sw);
-
- line(0, 0, 0, -len);
- // Move to the end of that line
- translate(0, -len);
-
- len *= 0.66;
- // All recursive functions must have an exit condition!!!!
- // Here, ours is when the length of the branch is 2 pixels or less
- if (len > 2) {
- pushMatrix(); // Save the current state of transformation (i.e. where are we now)
- rotate(theta); // Rotate by theta
- branch(len); // Ok, now call myself to draw two new branches!!
- popMatrix(); // Whenever we get back here, we "pop" in order to restore the previous matrix state
-
- // Repeat the same thing, only branch off to the "left" this time!
- pushMatrix();
- rotate(-theta);
- branch(len);
- popMatrix();
- }
-}
-
diff --git a/java/examples/Books/Nature of Code/chp8_fractals/Exercise_8_08_09_TreeArrayListLeaves/Branch.pde b/java/examples/Books/Nature of Code/chp8_fractals/Exercise_8_08_09_TreeArrayListLeaves/Branch.pde
deleted file mode 100644
index 7c5e8b9c8..000000000
--- a/java/examples/Books/Nature of Code/chp8_fractals/Exercise_8_08_09_TreeArrayListLeaves/Branch.pde
+++ /dev/null
@@ -1,68 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Recursive Tree (w/ ArrayList)
-
-// A class for one branch in the system
-
-class Branch {
- // Each has a location, velocity, and timer
- // We could implement this same idea with different data
- PVector start;
- PVector end;
- PVector vel;
- float timer;
- float timerstart;
-
- boolean growing = true;
-
- Branch(PVector l, PVector v, float n) {
- start = l.get();
- end = l.get();
- vel = v.get();
- timerstart = n;
- timer = timerstart;
- }
-
- // Move location
- void update() {
- if (growing) {
- end.add(vel);
- }
- }
-
- // Draw a dot at location
- void render() {
- stroke(0);
- line(start.x,start.y,end.x,end.y);
- }
-
- // Did the timer run out?
- boolean timeToBranch() {
- timer--;
- if (timer < 0 && growing) {
- growing = false;
- return true;
- }
- else {
- return false;
- }
- }
-
- // Create a new branch at the current location, but change direction by a given angle
- Branch branch(float angle) {
- // What is my current heading
- float theta = vel.heading2D();
- // What is my current speed
- float mag = vel.mag();
- // Turn me
- theta += radians(angle);
- // Look, polar coordinates to cartesian!!
- PVector newvel = new PVector(mag*cos(theta),mag*sin(theta));
- // Return a new Branch
- return new Branch(end,newvel,timerstart*0.66f);
- }
-
-}
-
diff --git a/java/examples/Books/Nature of Code/chp8_fractals/Exercise_8_08_09_TreeArrayListLeaves/Exercise_8_08_09_TreeArrayListLeaves.pde b/java/examples/Books/Nature of Code/chp8_fractals/Exercise_8_08_09_TreeArrayListLeaves/Exercise_8_08_09_TreeArrayListLeaves.pde
deleted file mode 100644
index 2900307cf..000000000
--- a/java/examples/Books/Nature of Code/chp8_fractals/Exercise_8_08_09_TreeArrayListLeaves/Exercise_8_08_09_TreeArrayListLeaves.pde
+++ /dev/null
@@ -1,59 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Recursive Tree (w/ ArrayList)
-// Nature of Code, Chapter 8
-
-// Recursive branching "structure" without an explicitly recursive function
-// Instead we have an ArrayList to hold onto N number of elements
-// For every element in the ArrayList, we add 2 more elements, etc. (this is the recursion)
-
-// An arraylist that will keep track of all current branches
-ArrayList tree;
-ArrayList leaves;
-
-void setup() {
- size(640,360);
- background(255);
- // Setup the arraylist and add one branch to it
- tree = new ArrayList();
- leaves = new ArrayList();
- // A branch has a starting location, a starting "velocity", and a starting "timer"
- Branch b = new Branch(new PVector(width/2,height),new PVector(0,-1),100);
- // Add to arraylist
- tree.add(b);
-}
-
-void draw() {
- background(255);
-
- // Let's stop when the arraylist gets too big
- // For every branch in the arraylist
- for (int i = tree.size()-1; i >= 0; i--) {
- // Get the branch, update and draw it
- Branch b = tree.get(i);
- b.update();
- b.render();
- // If it's ready to split
- if (b.timeToBranch()) {
- if (tree.size() < 1024) {
- //tree.remove(i); // Delete it
- tree.add(b.branch( 30)); // Add one going right
- tree.add(b.branch(-25)); // Add one going left
- }
- else {
- leaves.add(new Leaf(b.end));
- }
- }
- }
-
- for (Leaf leaf : leaves) {
- leaf.display();
- }
-
-}
-
-
-
-
diff --git a/java/examples/Books/Nature of Code/chp8_fractals/Exercise_8_08_09_TreeArrayListLeaves/Leaf.pde b/java/examples/Books/Nature of Code/chp8_fractals/Exercise_8_08_09_TreeArrayListLeaves/Leaf.pde
deleted file mode 100644
index 94ffd407e..000000000
--- a/java/examples/Books/Nature of Code/chp8_fractals/Exercise_8_08_09_TreeArrayListLeaves/Leaf.pde
+++ /dev/null
@@ -1,23 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Recursive Tree (w/ ArrayList)
-
-// A class for a leaf that gets placed at the end of
-// the last branches
-
-class Leaf {
- PVector loc;
-
- Leaf(PVector l) {
- loc = l.get();
- }
-
- void display() {
- noStroke();
- fill(50,100);
- ellipse(loc.x,loc.y,4,4);
- }
-}
-
diff --git a/java/examples/Books/Nature of Code/chp8_fractals/Exercise_8_10_TreeStochasticNoise/Exercise_8_10_TreeStochasticNoise.pde b/java/examples/Books/Nature of Code/chp8_fractals/Exercise_8_10_TreeStochasticNoise/Exercise_8_10_TreeStochasticNoise.pde
deleted file mode 100644
index 5a0bf3792..000000000
--- a/java/examples/Books/Nature of Code/chp8_fractals/Exercise_8_10_TreeStochasticNoise/Exercise_8_10_TreeStochasticNoise.pde
+++ /dev/null
@@ -1,74 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Stochastic Tree with angles fluctuating with Perlin noise
-// Nature of Code, Chapter 8
-
-// Perlin noise offset
-float yoff = 0;
-// Random seed to control randomness while drawing the tree
-int seed = 5;
-
-
-void setup() {
- size(800, 200);
- smooth();
-}
-
-void draw() {
- background(255);
- fill(0);
- //text("Click mouse to generate a new tree", 10, height-20);
-
- stroke(0);
- // Start the tree from the bottom of the screen
- translate(width/2, height);
- // Move alogn through noise
- yoff += 0.005;
- randomSeed(seed);
- // Start the recursive branching!
- branch(60, 0);
-}
-
-
-void mousePressed() {
- // New tree starts with new noise offset and new random seed
- yoff = random(1000);
- seed = millis();
-}
-
-
-void branch(float h, float xoff) {
- // thickness of the branch is mapped to its length
- float sw = map(h, 2, 100, 1, 5);
- strokeWeight(sw);
- // Draw the branch
- line(0, 0, 0, -h);
- // Move along to end
- translate(0, -h);
-
- // Each branch will be 2/3rds the size of the previous one
- h *= 0.7f;
-
- // Move along through noise space
- xoff += 0.1;
-
- if (h > 4) {
- // Random number of branches
- int n = int(random(0, 5));
- for (int i = 0; i < n; i++) {
-
- // Here the angle is controlled by perlin noise
- // This is a totally arbitrary way to do it, try others!
- float theta = map(noise(xoff+i, yoff), 0, 1, -PI/3, PI/3);
- if (n%2==0) theta *= -1;
-
- pushMatrix(); // Save the current state of transformation (i.e. where are we now)
- rotate(theta); // Rotate by theta
- branch(h, xoff); // Ok, now call myself to branch again
- popMatrix(); // Whenever we get back here, we "pop" in order to restore the previous matrix state
- }
- }
-}
-
diff --git a/java/examples/Books/Nature of Code/chp8_fractals/Figure_8_02_Mandelbrot/Figure_8_02_Mandelbrot.pde b/java/examples/Books/Nature of Code/chp8_fractals/Figure_8_02_Mandelbrot/Figure_8_02_Mandelbrot.pde
deleted file mode 100644
index 6883037b6..000000000
--- a/java/examples/Books/Nature of Code/chp8_fractals/Figure_8_02_Mandelbrot/Figure_8_02_Mandelbrot.pde
+++ /dev/null
@@ -1,80 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// The Mandelbrot Set
-
-// Simple rendering of the Mandelbrot set
-// c = a + bi
-// Iterate z = z^2 + c, i.e.
-// z(0) = 0
-// z(1) = 0*0 + c
-// z(2) = c*c + c
-// z(3) = (c*c + c) * (c*c + c) + c
-// etc.
-
-// c*c = (a+bi) * (a+bi) = a^2 - b^2 + 2abi
-
-// Establish a range of values on the complex plane
-double xmin = -2.5; double ymin = -1; double w = 4; double h = 2;
-// A different range will allow us to "zoom" in or out on the fractal
-// double xmin = -1.5; double ymin = -.1; double wh = 0.15;
-
-void setup() {
- size(863,863/2);
-}
-
-void draw() {
-
- loadPixels();
-
- // Maximum number of iterations for each point on the complex plane
- int maxiterations = 200;
-
- // x goes from xmin to xmax
- double xmax = xmin + w;
- // y goes from ymin to ymax
- double ymax = ymin + h;
-
- // Calculate amount we increment x,y for each pixel
- double dx = (xmax - xmin) / (width);
- double dy = (ymax - ymin) / (height);
-
- // Start y
- double y = ymin;
- for(int j = 0; j < height; j++) {
- // Start x
- double x = xmin;
- for(int i = 0; i < width; i++) {
-
- // Now we test, as we iterate z = z^2 + cm does z tend towards infinity?
- double a = x;
- double b = y;
- int n = 0;
- while (n < maxiterations) {
- double aa = a * a;
- double bb = b * b;
- double twoab = 2.0 * a * b;
- a = aa - bb + x;
- b = twoab + y;
- // Infinty in our finite world is simple, let's just consider it 16
- if(aa + bb > 16.0f) {
- break; // Bail
- }
- n++;
- }
-
- // We color each pixel based on how long it takes to get to infinity
- // If we never got there, let's pick the color black
- if (n == maxiterations) pixels[i+j*width] = color(0);
- else pixels[i+j*width] = color(n*16 % 255); // Gosh, we could make fancy colors here if we wanted
- x += dx;
- }
- y += dy;
- }
- updatePixels();
-
- save("chapter08_02.png");
- noLoop();
-}
-
diff --git a/java/examples/Books/Nature of Code/chp8_fractals/Figure_8_14_Koch/Figure_8_14_Koch.pde b/java/examples/Books/Nature of Code/chp8_fractals/Figure_8_14_Koch/Figure_8_14_Koch.pde
deleted file mode 100644
index d9d8b0bee..000000000
--- a/java/examples/Books/Nature of Code/chp8_fractals/Figure_8_14_Koch/Figure_8_14_Koch.pde
+++ /dev/null
@@ -1,67 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Koch Curve
-
-// Renders a simple fractal, the Koch snowflake
-// Each recursive level drawn in sequence
-
-ArrayList lines ; // A list to keep track of all the lines
-
-void setup() {
- size(1820, 200);
-
-
- smooth();
-}
-
-
-
-void draw() {
- translate(10,0);
- int spacing = 10;
- int total = 5;
-
- background(255);
- float w = (1800-spacing*(total-1))/5;
- for (int n = 0; n < total; n++) {
- lines = new ArrayList();
- PVector start = new PVector(0, height*2/3);
- PVector end = new PVector(w, height*2/3);
- lines.add(new KochLine(start, end));
- for (int i = 0; i < n; i++) {
- generate();
- }
- strokeWeight(2);
- for (KochLine l : lines) {
- l.display();
- }
- noFill();
- strokeWeight(1);
- stroke(127);
- rect(0, 10, w,height-20);
- translate(w+spacing, 0);
- }
- save("chapter08_14.png");
- noLoop();
-}
-
-void generate() {
- ArrayList next = new ArrayList(); // Create emtpy list
- for (KochLine l : lines) {
- // Calculate 5 koch PVectors (done for us by the line object)
- PVector a = l.kochA();
- PVector b = l.kochB();
- PVector c = l.kochC();
- PVector d = l.kochD();
- PVector e = l.kochE();
- // Make line segments between all the PVectors and add them
- next.add(new KochLine(a, b));
- next.add(new KochLine(b, c));
- next.add(new KochLine(c, d));
- next.add(new KochLine(d, e));
- }
- lines = next;
-}
-
diff --git a/java/examples/Books/Nature of Code/chp8_fractals/Figure_8_14_Koch/KochLine.pde b/java/examples/Books/Nature of Code/chp8_fractals/Figure_8_14_Koch/KochLine.pde
deleted file mode 100644
index 54ed28120..000000000
--- a/java/examples/Books/Nature of Code/chp8_fractals/Figure_8_14_Koch/KochLine.pde
+++ /dev/null
@@ -1,74 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Koch Curve
-
-// A class to describe one line segment in the fractal
-// Includes methods to calculate midPVectors along the line according to the Koch algorithm
-
-class KochLine {
-
- // Two PVectors,
- // a is the "left" PVector and
- // b is the "right PVector
- PVector start;
- PVector end;
-
- KochLine(PVector a, PVector b) {
- start = a.get();
- end = b.get();
- }
-
- void display() {
- stroke(0);
- line(start.x, start.y, end.x, end.y);
- }
-
- PVector kochA() {
- return start.get();
- }
-
-
- // This is easy, just 1/3 of the way
- PVector kochB() {
- PVector v = PVector.sub(end, start);
- v.div(3);
- v.add(start);
- return v;
- }
-
- // More complicated, have to use a little trig to figure out where this PVector is!
- PVector kochC() {
- PVector a = start.get(); // Start at the beginning
-
- PVector v = PVector.sub(end, start);
- v.div(3);
- a.add(v); // Move to point B
-
- rotate(v, -radians(60)); // Rotate 60 degrees
- a.add(v); // Move to point C
-
- return a;
- }
-
- // Easy, just 2/3 of the way
- PVector kochD() {
- PVector v = PVector.sub(end, start);
- v.mult(2/3.0);
- v.add(start);
- return v;
- }
-
- PVector kochE() {
- return end.get();
- }
-}
-
-public void rotate(PVector v, float theta) {
- float xTemp = v.x;
- // Might need to check for rounding errors like with angleBetween function?
- v.x = v.x*PApplet.cos(theta) - v.y*PApplet.sin(theta);
- v.y = xTemp*PApplet.sin(theta) + v.y*PApplet.cos(theta);
-}
-
diff --git a/java/examples/Books/Nature of Code/chp8_fractals/Figure_8_20_Tree/Figure_8_20_Tree.pde b/java/examples/Books/Nature of Code/chp8_fractals/Figure_8_20_Tree/Figure_8_20_Tree.pde
deleted file mode 100644
index a81bd3fe8..000000000
--- a/java/examples/Books/Nature of Code/chp8_fractals/Figure_8_20_Tree/Figure_8_20_Tree.pde
+++ /dev/null
@@ -1,55 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Recursive Tree
-
-// Renders a simple tree-like structure via recursion
-// Branching angle calculated as a function of horizontal mouse location
-
-float theta;
-
-void setup() {
- size(800, 200);
- smooth();
-}
-
-void draw() {
- background(255);
- // Let's pick an angle 0 to 90 degrees based on the mouse position
- theta = map(mouseX,0,width,0,PI/2);
-
- // Start the tree from the bottom of the screen
- translate(width/2, height);
- stroke(0);
- branch(60);
-}
-
-void branch(float len) {
- // Each branch will be 2/3rds the size of the previous one
-
- //float sw = map(len,2,120,1,10);
- //strokeWeight(sw);
- strokeWeight(2);
-
- line(0, 0, 0, -len);
- // Move to the end of that line
- translate(0, -len);
-
- len *= 0.66;
- // All recursive functions must have an exit condition!!!!
- // Here, ours is when the length of the branch is 2 pixels or less
- if (len > 2) {
- pushMatrix(); // Save the current state of transformation (i.e. where are we now)
- rotate(theta); // Rotate by theta
- branch(len); // Ok, now call myself to draw two new branches!!
- popMatrix(); // Whenever we get back here, we "pop" in order to restore the previous matrix state
-
- // Repeat the same thing, only branch off to the "left" this time!
- pushMatrix();
- rotate(-theta);
- branch(len);
- popMatrix();
- }
-}
-
diff --git a/java/examples/Books/Nature of Code/chp8_fractals/Figure_8_CantorLine/Figure_8_CantorLine.pde b/java/examples/Books/Nature of Code/chp8_fractals/Figure_8_CantorLine/Figure_8_CantorLine.pde
deleted file mode 100644
index 135d12ac9..000000000
--- a/java/examples/Books/Nature of Code/chp8_fractals/Figure_8_CantorLine/Figure_8_CantorLine.pde
+++ /dev/null
@@ -1,23 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-void setup() {
- size(800, 60);
- background(255);
-}
-
-void cantor(float x, float y, float len) {
- line(x, y, x+len, y);
-
- y += 20;
- line(x,y,x+len/3,y); //[bold]
- line(x+len*2/3,y,x+len,y); //[bold]
-}
-
-void draw() {
- cantor(10, 20, width-20);
- save("chapter08_12.png");
- noLoop();
-}
-
diff --git a/java/examples/Books/Nature of Code/chp8_fractals/NOC_8_01_Recursion/NOC_8_01_Recursion.pde b/java/examples/Books/Nature of Code/chp8_fractals/NOC_8_01_Recursion/NOC_8_01_Recursion.pde
deleted file mode 100644
index 84b600182..000000000
--- a/java/examples/Books/Nature of Code/chp8_fractals/NOC_8_01_Recursion/NOC_8_01_Recursion.pde
+++ /dev/null
@@ -1,27 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Simple Recursion
-
-void setup() {
- size(640,360);
-}
-
-void draw() {
- background(255);
- drawCircle(width/2,height/2,width);
- noLoop();
-}
-
-// Very simple function that draws one circle
-// and recursively calls itself
-void drawCircle(int x, int y, float r) {
- ellipse(x, y, r, r);
- // Exit condition, stop when radius is too small
- if(r > 2) {
- r *= 0.75f;
- // Call the function inside the function! (recursion!)
- drawCircle(x, y, r);
- }
-}
diff --git a/java/examples/Books/Nature of Code/chp8_fractals/NOC_8_02_Recursion/NOC_8_02_Recursion.pde b/java/examples/Books/Nature of Code/chp8_fractals/NOC_8_02_Recursion/NOC_8_02_Recursion.pde
deleted file mode 100644
index b02eda5fe..000000000
--- a/java/examples/Books/Nature of Code/chp8_fractals/NOC_8_02_Recursion/NOC_8_02_Recursion.pde
+++ /dev/null
@@ -1,28 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Simple Recursion
-
-void setup() {
- size(640,360);
-}
-
-void draw() {
- background(255);
- drawCircle(width/2,height/2,400);
- noLoop();
-}
-
-// Recursive function
-void drawCircle(float x, float y, float r) {
- stroke(0);
- noFill();
- ellipse(x, y, r, r);
- if(r > 2) {
- // Now we draw two more circles, one to the left
- // and one to the right
- drawCircle(x + r/2, y, r/2);
- drawCircle(x - r/2, y, r/2);
- }
-}
diff --git a/java/examples/Books/Nature of Code/chp8_fractals/NOC_8_03_Recursion/NOC_8_03_Recursion.pde b/java/examples/Books/Nature of Code/chp8_fractals/NOC_8_03_Recursion/NOC_8_03_Recursion.pde
deleted file mode 100644
index c7257d242..000000000
--- a/java/examples/Books/Nature of Code/chp8_fractals/NOC_8_03_Recursion/NOC_8_03_Recursion.pde
+++ /dev/null
@@ -1,29 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Simple Recursion
-
-void setup() {
- size(640, 360);
-}
-
-void draw() {
- background(255);
- drawCircle(width/2, height/2, 400);
- noLoop();
-}
-
-void drawCircle(float x, float y, float radius) {
- noFill();
- stroke(0);
- ellipse(x, y, radius, radius);
- if (radius > 8) {
- // Four circles! left right, up and down
- drawCircle(x + radius/2, y, radius/2);
- drawCircle(x - radius/2, y, radius/2);
- drawCircle(x, y + radius/2, radius/2);
- drawCircle(x, y - radius/2, radius/2);
- }
-}
-
diff --git a/java/examples/Books/Nature of Code/chp8_fractals/NOC_8_04_CantorSet/NOC_8_04_CantorSet.pde b/java/examples/Books/Nature of Code/chp8_fractals/NOC_8_04_CantorSet/NOC_8_04_CantorSet.pde
deleted file mode 100644
index 47da39851..000000000
--- a/java/examples/Books/Nature of Code/chp8_fractals/NOC_8_04_CantorSet/NOC_8_04_CantorSet.pde
+++ /dev/null
@@ -1,39 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Cantor Set
-// Renders a simple fractal, the Cantor Set
-
-void setup() {
- size(800, 200);
- background(255);
-
- // Call the recursive function
- cantor(35, 0, 730);
-}
-
-void draw() {
- // No need to loop
- noLoop();
-}
-
-
-void cantor(float x, float y, float len) {
-
- float h = 30;
-
- // recursive exit condition
- if (len >= 1) {
- // Draw line (as rectangle to make it easier to see)
- noStroke();
- fill(0);
- rect(x, y, len, h/3);
- // Go down to next y position
- y += h;
- // Draw 2 more lines 1/3rd the length (without the middle section)
- cantor(x, y, len/3);
- cantor(x+len*2/3, y, len/3);
- }
-}
-
diff --git a/java/examples/Books/Nature of Code/chp8_fractals/NOC_8_04_Tree/NOC_8_04_Tree.pde b/java/examples/Books/Nature of Code/chp8_fractals/NOC_8_04_Tree/NOC_8_04_Tree.pde
deleted file mode 100644
index cb35ab15f..000000000
--- a/java/examples/Books/Nature of Code/chp8_fractals/NOC_8_04_Tree/NOC_8_04_Tree.pde
+++ /dev/null
@@ -1,53 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Recursive Tree
-// Renders a simple tree-like structure via recursion
-// Branching angle calculated as a function of horizontal mouse location
-
-float theta;
-
-void setup() {
- size(300, 200);
- smooth();
-}
-
-void draw() {
- background(255);
- // Let's pick an angle 0 to 90 degrees based on the mouse position
- theta = map(mouseX,0,width,0,PI/2);
-
- // Start the tree from the bottom of the screen
- translate(width/2, height);
- stroke(0);
- branch(60);
-}
-
-void branch(float len) {
- // Each branch will be 2/3rds the size of the previous one
-
- float sw = map(len,2,120,1,10);
- strokeWeight(sw);
-
- line(0, 0, 0, -len);
- // Move to the end of that line
- translate(0, -len);
-
- len *= 0.66;
- // All recursive functions must have an exit condition!!!!
- // Here, ours is when the length of the branch is 2 pixels or less
- if (len > 2) {
- pushMatrix(); // Save the current state of transformation (i.e. where are we now)
- rotate(theta); // Rotate by theta
- branch(len); // Ok, now call myself to draw two new branches!!
- popMatrix(); // Whenever we get back here, we "pop" in order to restore the previous matrix state
-
- // Repeat the same thing, only branch off to the "left" this time!
- pushMatrix();
- rotate(-theta);
- branch(len);
- popMatrix();
- }
-}
-
diff --git a/java/examples/Books/Nature of Code/chp8_fractals/NOC_8_05_Koch/KochFractal.pde b/java/examples/Books/Nature of Code/chp8_fractals/NOC_8_05_Koch/KochFractal.pde
deleted file mode 100644
index 76a8f1cd7..000000000
--- a/java/examples/Books/Nature of Code/chp8_fractals/NOC_8_05_Koch/KochFractal.pde
+++ /dev/null
@@ -1,71 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Koch Curve
-// A class to manage the list of line segments in the snowflake pattern
-
-class KochFractal {
- PVector start; // A PVector for the start
- PVector end; // A PVector for the end
- ArrayList lines; // A list to keep track of all the lines
- int count;
-
- public KochFractal() {
- start = new PVector(0,height-20);
- end = new PVector(width,height-20);
- lines = new ArrayList();
- restart();
- }
-
- void nextLevel() {
- // For every line that is in the arraylist
- // create 4 more lines in a new arraylist
- lines = iterate(lines);
- count++;
- }
-
- void restart() {
- count = 0; // Reset count
- lines.clear(); // Empty the array list
- lines.add(new KochLine(start,end)); // Add the initial line (from one end PVector to the other)
- }
-
- int getCount() {
- return count;
- }
-
- // This is easy, just draw all the lines
- void render() {
- for(KochLine l : lines) {
- l.display();
- }
- }
-
- // This is where the **MAGIC** happens
- // Step 1: Create an empty arraylist
- // Step 2: For every line currently in the arraylist
- // - calculate 4 line segments based on Koch algorithm
- // - add all 4 line segments into the new arraylist
- // Step 3: Return the new arraylist and it becomes the list of line segments for the structure
-
- // As we do this over and over again, each line gets broken into 4 lines, which gets broken into 4 lines, and so on. . .
- ArrayList iterate(ArrayList before) {
- ArrayList now = new ArrayList(); // Create emtpy list
- for(KochLine l : before) {
- // Calculate 5 koch PVectors (done for us by the line object)
- PVector a = l.start();
- PVector b = l.kochleft();
- PVector c = l.kochmiddle();
- PVector d = l.kochright();
- PVector e = l.end();
- // Make line segments between all the PVectors and add them
- now.add(new KochLine(a,b));
- now.add(new KochLine(b,c));
- now.add(new KochLine(c,d));
- now.add(new KochLine(d,e));
- }
- return now;
- }
-
-}
diff --git a/java/examples/Books/Nature of Code/chp8_fractals/NOC_8_05_Koch/KochLine.pde b/java/examples/Books/Nature of Code/chp8_fractals/NOC_8_05_Koch/KochLine.pde
deleted file mode 100644
index 6f3ff6913..000000000
--- a/java/examples/Books/Nature of Code/chp8_fractals/NOC_8_05_Koch/KochLine.pde
+++ /dev/null
@@ -1,74 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Koch Curve
-// A class to describe one line segment in the fractal
-// Includes methods to calculate midPVectors along the line according to the Koch algorithm
-
-class KochLine {
-
- // Two PVectors,
- // a is the "left" PVector and
- // b is the "right PVector
- PVector a;
- PVector b;
-
- KochLine(PVector start, PVector end) {
- a = start.get();
- b = end.get();
- }
-
- void display() {
- stroke(0);
- line(a.x, a.y, b.x, b.y);
- }
-
- PVector start() {
- return a.get();
- }
-
- PVector end() {
- return b.get();
- }
-
- // This is easy, just 1/3 of the way
- PVector kochleft() {
- PVector v = PVector.sub(b, a);
- v.div(3);
- v.add(a);
- return v;
- }
-
- // More complicated, have to use a little trig to figure out where this PVector is!
- PVector kochmiddle() {
- PVector v = PVector.sub(b, a);
- v.div(3);
-
- PVector p = a.get();
- p.add(v);
-
- rotate(v,-radians(60));
- p.add(v);
-
- return p;
- }
-
-
- // Easy, just 2/3 of the way
- PVector kochright() {
- PVector v = PVector.sub(a, b);
- v.div(3);
- v.add(b);
- return v;
- }
-}
-
- public void rotate(PVector v, float theta) {
- float xTemp = v.x;
- // Might need to check for rounding errors like with angleBetween function?
- v.x = v.x*cos(theta) - v.y*sin(theta);
- v.y = xTemp*sin(theta) + v.y*cos(theta);
- }
-
-
diff --git a/java/examples/Books/Nature of Code/chp8_fractals/NOC_8_05_Koch/NOC_8_05_Koch.pde b/java/examples/Books/Nature of Code/chp8_fractals/NOC_8_05_Koch/NOC_8_05_Koch.pde
deleted file mode 100644
index f61293171..000000000
--- a/java/examples/Books/Nature of Code/chp8_fractals/NOC_8_05_Koch/NOC_8_05_Koch.pde
+++ /dev/null
@@ -1,30 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-// Koch Curve
-
-// Renders a simple fractal, the Koch snowflake
-// Each recursive level drawn in sequence
-
-KochFractal k;
-
-void setup() {
- size(800,250);
- background(255);
- frameRate(1); // Animate slowly
- k = new KochFractal();
- smooth();
-}
-
-void draw() {
- background(255);
- // Draws the snowflake!
- k.render();
- // Iterate
- k.nextLevel();
- // Let's not do it more than 5 times. . .
- if (k.getCount() > 5) {
- k.restart();
- }
-}
-
diff --git a/java/examples/Books/Nature of Code/chp8_fractals/NOC_8_05_KochSimple/KochLine.pde b/java/examples/Books/Nature of Code/chp8_fractals/NOC_8_05_KochSimple/KochLine.pde
deleted file mode 100644
index f66510428..000000000
--- a/java/examples/Books/Nature of Code/chp8_fractals/NOC_8_05_KochSimple/KochLine.pde
+++ /dev/null
@@ -1,73 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Koch Curve
-// A class to describe one line segment in the fractal
-// Includes methods to calculate midPVectors along the line according to the Koch algorithm
-
-class KochLine {
-
- // Two PVectors,
- // a is the "left" PVector and
- // b is the "right PVector
- PVector start;
- PVector end;
-
- KochLine(PVector a, PVector b) {
- start = a.get();
- end = b.get();
- }
-
- void display() {
- stroke(0);
- line(start.x, start.y, end.x, end.y);
- }
-
- PVector kochA() {
- return start.get();
- }
-
-
- // This is easy, just 1/3 of the way
- PVector kochB() {
- PVector v = PVector.sub(end, start);
- v.div(3);
- v.add(start);
- return v;
- }
-
- // More complicated, have to use a little trig to figure out where this PVector is!
- PVector kochC() {
- PVector a = start.get(); // Start at the beginning
-
- PVector v = PVector.sub(end, start);
- v.div(3);
- a.add(v); // Move to point B
-
- rotate(v, -radians(60)); // Rotate 60 degrees
- a.add(v); // Move to point C
-
- return a;
- }
-
- // Easy, just 2/3 of the way
- PVector kochD() {
- PVector v = PVector.sub(end, start);
- v.mult(2/3.0);
- v.add(start);
- return v;
- }
-
- PVector kochE() {
- return end.get();
- }
-}
-
-public void rotate(PVector v, float theta) {
- float xTemp = v.x;
- // Might need to check for rounding errors like with angleBetween function?
- v.x = v.x*PApplet.cos(theta) - v.y*PApplet.sin(theta);
- v.y = xTemp*PApplet.sin(theta) + v.y*PApplet.cos(theta);
-}
-
diff --git a/java/examples/Books/Nature of Code/chp8_fractals/NOC_8_05_KochSimple/NOC_8_05_KochSimple.pde b/java/examples/Books/Nature of Code/chp8_fractals/NOC_8_05_KochSimple/NOC_8_05_KochSimple.pde
deleted file mode 100644
index b8268ee9f..000000000
--- a/java/examples/Books/Nature of Code/chp8_fractals/NOC_8_05_KochSimple/NOC_8_05_KochSimple.pde
+++ /dev/null
@@ -1,51 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Koch Curve
-// Renders a simple fractal, the Koch snowflake
-// Each recursive level drawn in sequence
-
-ArrayList lines ; // A list to keep track of all the lines
-
-void setup() {
- size(383, 200);
- background(255);
- lines = new ArrayList();
- PVector start = new PVector(0, 150);
- PVector end = new PVector(width, 150);
- lines.add(new KochLine(start, end));
-
- for (int i = 0; i < 5; i++) {
- generate();
- }
-
- smooth();
-}
-
-void draw() {
- background(255);
- for (KochLine l : lines) {
- l.display();
- }
-}
-
-void generate() {
- ArrayList next = new ArrayList(); // Create emtpy list
- for (KochLine l : lines) {
- // Calculate 5 koch PVectors (done for us by the line object)
- PVector a = l.kochA();
- PVector b = l.kochB();
- PVector c = l.kochC();
- PVector d = l.kochD();
- PVector e = l.kochE();
- // Make line segments between all the PVectors and add them
- next.add(new KochLine(a, b));
- next.add(new KochLine(b, c));
- next.add(new KochLine(c, d));
- next.add(new KochLine(d, e));
- }
- lines = next;
-}
-
-
diff --git a/java/examples/Books/Nature of Code/chp8_fractals/NOC_8_06_SimpleLSystem/NOC_8_06_SimpleLSystem.pde b/java/examples/Books/Nature of Code/chp8_fractals/NOC_8_06_SimpleLSystem/NOC_8_06_SimpleLSystem.pde
deleted file mode 100644
index b14d7b021..000000000
--- a/java/examples/Books/Nature of Code/chp8_fractals/NOC_8_06_SimpleLSystem/NOC_8_06_SimpleLSystem.pde
+++ /dev/null
@@ -1,48 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// L-System
-// Just demonstrating working with L-System strings
-// No drawing
-
-// Start with "A"
-String current = "A";
-// Number of generations
-int count = 0;
-
-void setup() {
- size(200, 200);
- println("Generation " + count + ": " + current);
-}
-
-void draw() {
- background(255);
- fill(0);
- text("Click mouse to generate", 10, height-20);
- noLoop();
-}
-
-void mousePressed() {
- // A new StringBuffer for the next generation
- StringBuffer next = new StringBuffer();
-
- // Look through the current String to replace according to L-System rules
- for (int i = 0; i < current.length(); i++) {
- char c = current.charAt(i);
- if (c == 'A') {
- // If we find A replace with AB
- next.append("AB");
- } else if (c == 'B') {
- // If we find B replace with A
- next.append("A");
- }
- }
- // The current String is now the next one
- current = next.toString();
- count++;
- // Print to message console
- println("Generation " + count + ": " + current);
- println(count + " " + current.length());
-}
-
diff --git a/java/examples/Books/Nature of Code/chp8_fractals/NOC_8_06_Tree/NOC_8_06_Tree.pde b/java/examples/Books/Nature of Code/chp8_fractals/NOC_8_06_Tree/NOC_8_06_Tree.pde
deleted file mode 100644
index f2853c124..000000000
--- a/java/examples/Books/Nature of Code/chp8_fractals/NOC_8_06_Tree/NOC_8_06_Tree.pde
+++ /dev/null
@@ -1,53 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Recursive Tree
-// Renders a simple tree-like structure via recursion
-// Branching angle calculated as a function of horizontal mouse location
-
-float theta;
-
-void setup() {
- size(640, 360);
-}
-
-void draw() {
- background(255);
- // Let's pick an angle 0 to 90 degrees based on the mouse position
- theta = map(mouseX,0,width,0,PI/2);
-
- // Start the tree from the bottom of the screen
- translate(width/2, height);
- stroke(0);
- branch(60);
-}
-
-void branch(float len) {
- // Each branch will be 2/3rds the size of the previous one
-
- //float sw = map(len,2,120,1,10);
- //strokeWeight(sw);
- strokeWeight(2);
-
- line(0, 0, 0, -len);
- // Move to the end of that line
- translate(0, -len);
-
- len *= 0.66;
- // All recursive functions must have an exit condition!!!!
- // Here, ours is when the length of the branch is 2 pixels or less
- if (len > 2) {
- pushMatrix(); // Save the current state of transformation (i.e. where are we now)
- rotate(theta); // Rotate by theta
- branch(len); // Ok, now call myself to draw two new branches!!
- popMatrix(); // Whenever we get back here, we "pop" in order to restore the previous matrix state
-
- // Repeat the same thing, only branch off to the "left" this time!
- pushMatrix();
- rotate(-theta);
- branch(len);
- popMatrix();
- }
-}
-
diff --git a/java/examples/Books/Nature of Code/chp8_fractals/NOC_8_06_Tree_static/NOC_8_06_Tree_static.pde b/java/examples/Books/Nature of Code/chp8_fractals/NOC_8_06_Tree_static/NOC_8_06_Tree_static.pde
deleted file mode 100644
index 92805fdb4..000000000
--- a/java/examples/Books/Nature of Code/chp8_fractals/NOC_8_06_Tree_static/NOC_8_06_Tree_static.pde
+++ /dev/null
@@ -1,45 +0,0 @@
-// Recursive Tree
-// Daniel Shiffman
-// Nature of Code, Chapter 8
-
-// Renders a simple tree-like structure via recursion
-// Branching angle calculated as a function of horizontal mouse location
-
-void setup() {
- size(800, 200);
- smooth();
-}
-
-void draw() {
- background(255);
- // Start the tree from the bottom of the screen
- translate(width/2, height);
- stroke(0);
- branch(60);
- noLoop();
-}
-
-void branch(float len) {
- strokeWeight(2);
-
- line(0, 0, 0, -len);
- // Move to the end of that line
- translate(0, -len);
-
- len *= 0.66;
- // All recursive functions must have an exit condition!!!!
- // Here, ours is when the length of the branch is 2 pixels or less
- if (len > 2) {
- pushMatrix(); // Save the current state of transformation (i.e. where are we now)
- rotate(PI/5); // Rotate by theta
- branch(len); // Ok, now call myself to draw two new branches!!
- popMatrix(); // Whenever we get back here, we "pop" in order to restore the previous matrix state
-
- // Repeat the same thing, only branch off to the "left" this time!
- pushMatrix();
- rotate(-PI/5);
- branch(len);
- popMatrix();
- }
-}
-
diff --git a/java/examples/Books/Nature of Code/chp8_fractals/NOC_8_07_TreeStochastic/NOC_8_07_TreeStochastic.pde b/java/examples/Books/Nature of Code/chp8_fractals/NOC_8_07_TreeStochastic/NOC_8_07_TreeStochastic.pde
deleted file mode 100644
index c0e22fb7b..000000000
--- a/java/examples/Books/Nature of Code/chp8_fractals/NOC_8_07_TreeStochastic/NOC_8_07_TreeStochastic.pde
+++ /dev/null
@@ -1,66 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Stochastic Tree
-// Renders a simple tree-like structure via recursion
-// Angles and number of branches are random
-
-void setup() {
- size(800, 200);
- newTree();
-}
-
-void draw() {
- noLoop();
-}
-
-void mousePressed() {
- newTree();
- redraw();
-}
-
-void newTree() {
- background(255);
- fill(0);
- text("Click mouse to generate a new tree", 10, height-10);
-
- stroke(0);
- pushMatrix();
- // Start the tree from the bottom of the screen
- translate(width/2, height);
- // Start the recursive branching!
- branch(80);
- popMatrix();
-}
-
-
-
-void branch(float h) {
- // thickness of the branch is mapped to its length
- float sw = map(h, 2, 120, 1, 5);
- strokeWeight(sw);
- // Draw the actual branch
- line(0, 0, 0, -h);
- // Move along to end
- translate(0, -h);
-
- // Each branch will be 2/3rds the size of the previous one
- h *= 0.66f;
-
- // All recursive functions must have an exit condition!!!!
- // Here, ours is when the length of the branch is 2 pixels or less
- if (h > 2) {
- // A random number of branches
- int n = int(random(1, 4));
- for (int i = 0; i < n; i++) {
- // Picking a random angle
- float theta = random(-PI/2, PI/2);
- pushMatrix(); // Save the current state of transformation (i.e. where are we now)
- rotate(theta); // Rotate by theta
- branch(h); // Ok, now call myself to branch again
- popMatrix(); // Whenever we get back here, we "pop" in order to restore the previous matrix state
- }
- }
-}
-
diff --git a/java/examples/Books/Nature of Code/chp8_fractals/NOC_8_07_TreeStochastic_angleonly/NOC_8_07_TreeStochastic_angleonly.pde b/java/examples/Books/Nature of Code/chp8_fractals/NOC_8_07_TreeStochastic_angleonly/NOC_8_07_TreeStochastic_angleonly.pde
deleted file mode 100644
index 5c73557a5..000000000
--- a/java/examples/Books/Nature of Code/chp8_fractals/NOC_8_07_TreeStochastic_angleonly/NOC_8_07_TreeStochastic_angleonly.pde
+++ /dev/null
@@ -1,59 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Stochastic Tree
-// Renders a simple tree-like structure via recursion
-// Angles and number of branches are random
-
-void setup() {
- size(800, 200);
- newTree();
-}
-
-void draw() {
- noLoop();
-}
-
-void mousePressed() {
- pushMatrix();
- newTree();
- popMatrix();
- redraw();
-}
-
-void newTree() {
- background(255);
- fill(0);
- text("Click mouse to generate a new tree", 10, height-10);
-
- stroke(0);
- // Start the tree from the bottom of the screen
- translate(width/2, height);
- // Start the recursive branching!
- branch(60);
-}
-
-
-
-void branch(float h) {
- // thickness of the branch is mapped to its length
- float sw = map(h, 2, 120, 1, 5);
- strokeWeight(sw);
- float theta = random(0,PI/3);
-
- line(0, 0, 0, -h);
- translate(0, -h);
- h *= 0.66;
- if (h > 2) {
- pushMatrix();
- rotate(theta);
- branch(h);
- popMatrix();
- pushMatrix();
- rotate(-theta);
- branch(h);
- popMatrix();
- }
-}
-
diff --git a/java/examples/Books/Nature of Code/chp8_fractals/NOC_8_08_SimpleLSystem/NOC_8_08_SimpleLSystem.pde b/java/examples/Books/Nature of Code/chp8_fractals/NOC_8_08_SimpleLSystem/NOC_8_08_SimpleLSystem.pde
deleted file mode 100644
index 9f1b0dac3..000000000
--- a/java/examples/Books/Nature of Code/chp8_fractals/NOC_8_08_SimpleLSystem/NOC_8_08_SimpleLSystem.pde
+++ /dev/null
@@ -1,48 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// L-System
-// Just demonstrating working with L-System strings
-// No drawing
-
-// Start with "A"
-String current = "A";
-// Number of generations
-int count = 0;
-
-void setup() {
- size(800, 200);
- println("Generation " + count + ": " + current);
-}
-
-void draw() {
- background(255);
- fill(0);
- text("Click mouse to generate", 10, height-20);
- noLoop();
-}
-
-void mousePressed() {
- // A new StringBuffer for the next generation
- StringBuffer next = new StringBuffer();
-
- // Look through the current String to replace according to L-System rules
- for (int i = 0; i < current.length(); i++) {
- char c = current.charAt(i);
- if (c == 'A') {
- // If we find A replace with AB
- next.append("AB");
- } else if (c == 'B') {
- // If we find B replace with A
- next.append("A");
- }
- }
- // The current String is now the next one
- current = next.toString();
- count++;
- // Print to message console
- println("Generation " + count + ": " + current);
- //println(count + " " + current.length());
-}
-
diff --git a/java/examples/Books/Nature of Code/chp8_fractals/NOC_8_09_LSystem/LSystem.pde b/java/examples/Books/Nature of Code/chp8_fractals/NOC_8_09_LSystem/LSystem.pde
deleted file mode 100644
index a51c255ee..000000000
--- a/java/examples/Books/Nature of Code/chp8_fractals/NOC_8_09_LSystem/LSystem.pde
+++ /dev/null
@@ -1,63 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// An LSystem has a starting sentence
-// An a ruleset
-// Each generation recursively replaces characteres in the sentence
-// Based on the rulset
-
-class LSystem {
-
- String sentence; // The sentence (a String)
- Rule[] ruleset; // The ruleset (an array of Rule objects)
- int generation; // Keeping track of the generation #
-
- // Construct an LSystem with a startin sentence and a ruleset
- LSystem(String axiom, Rule[] r) {
- sentence = axiom;
- ruleset = r;
- generation = 0;
- }
-
- // Generate the next generation
- void generate() {
- // An empty StringBuffer that we will fill
- StringBuffer nextgen = new StringBuffer();
- // For every character in the sentence
- for (int i = 0; i < sentence.length(); i++) {
- // What is the character
- char curr = sentence.charAt(i);
- // We will replace it with itself unless it matches one of our rules
- String replace = "" + curr;
- // Check every rule
- for (int j = 0; j < ruleset.length; j++) {
- char a = ruleset[j].getA();
- // if we match the Rule, get the replacement String out of the Rule
- if (a == curr) {
- replace = ruleset[j].getB();
- break;
- }
- }
- // Append replacement String
- nextgen.append(replace);
- }
- // Replace sentence
- sentence = nextgen.toString();
- // Increment generation
- generation++;
- }
-
- String getSentence() {
- return sentence;
- }
-
- int getGeneration() {
- return generation;
- }
-
-
-}
-
-
-
diff --git a/java/examples/Books/Nature of Code/chp8_fractals/NOC_8_09_LSystem/NOC_8_09_LSystem.pde b/java/examples/Books/Nature of Code/chp8_fractals/NOC_8_09_LSystem/NOC_8_09_LSystem.pde
deleted file mode 100644
index 94a960d42..000000000
--- a/java/examples/Books/Nature of Code/chp8_fractals/NOC_8_09_LSystem/NOC_8_09_LSystem.pde
+++ /dev/null
@@ -1,63 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-LSystem lsys;
-Turtle turtle;
-
-void setup() {
- size(600, 600);
- /*
- // Create an empty ruleset
- Rule[] ruleset = new Rule[2];
- // Fill with two rules (These are rules for the Sierpinksi Gasket Triangle)
- ruleset[0] = new Rule('F',"F--F--F--G");
- ruleset[1] = new Rule('G',"GG");
- // Create LSystem with axiom and ruleset
- lsys = new LSystem("F--F--F",ruleset);
- turtle = new Turtle(lsys.getSentence(),width*2,TWO_PI/3);
- */
-
- /*Rule[] ruleset = new Rule[1];
- //ruleset[0] = new Rule('F',"F[F]-F+F[--F]+F-F");
- ruleset[0] = new Rule['F',"FF+[+F-F-F]-[-F+F+F]");
- lsys = new LSystem("F-F-F-F",ruleset);
- turtle = new Turtle(lsys.getSentence(),width-1,PI/2);
- */
-
- Rule[] ruleset = new Rule[1];
- ruleset[0] = new Rule('F', "FF+[+F-F-F]-[-F+F+F]");
- lsys = new LSystem("F", ruleset);
- turtle = new Turtle(lsys.getSentence(), height/3, radians(25));
-
-
-
- smooth();
-}
-
-void draw() {
- background(255);
- fill(0);
- //text("Click mouse to generate", 10, height-10);
-
- translate(width/2, height);
- rotate(-PI/2);
- turtle.render();
- noLoop();
-}
-
-int counter = 0;
-
-void mousePressed() {
- if (counter < 5) {
- pushMatrix();
- lsys.generate();
- //println(lsys.getSentence());
- turtle.setToDo(lsys.getSentence());
- turtle.changeLen(0.5);
- popMatrix();
- redraw();
- counter++;
- }
-}
-
diff --git a/java/examples/Books/Nature of Code/chp8_fractals/NOC_8_09_LSystem/Rule.pde b/java/examples/Books/Nature of Code/chp8_fractals/NOC_8_09_LSystem/Rule.pde
deleted file mode 100644
index 49353e772..000000000
--- a/java/examples/Books/Nature of Code/chp8_fractals/NOC_8_09_LSystem/Rule.pde
+++ /dev/null
@@ -1,26 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// LSystem Rule class
-
-class Rule {
- char a;
- String b;
-
- Rule(char a_, String b_) {
- a = a_;
- b = b_;
- }
-
- char getA() {
- return a;
- }
-
- String getB() {
- return b;
- }
-
-}
-
-
diff --git a/java/examples/Books/Nature of Code/chp8_fractals/NOC_8_09_LSystem/Turtle.pde b/java/examples/Books/Nature of Code/chp8_fractals/NOC_8_09_LSystem/Turtle.pde
deleted file mode 100644
index cede7d5c7..000000000
--- a/java/examples/Books/Nature of Code/chp8_fractals/NOC_8_09_LSystem/Turtle.pde
+++ /dev/null
@@ -1,54 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-class Turtle {
-
- String todo;
- float len;
- float theta;
-
- Turtle(String s, float l, float t) {
- todo = s;
- len = l;
- theta = t;
- }
-
- void render() {
- stroke(0,175);
- for (int i = 0; i < todo.length(); i++) {
- char c = todo.charAt(i);
- if (c == 'F' || c == 'G') {
- line(0,0,len,0);
- translate(len,0);
- }
- else if (c == '+') {
- rotate(theta);
- }
- else if (c == '-') {
- rotate(-theta);
- }
- else if (c == '[') {
- pushMatrix();
- }
- else if (c == ']') {
- popMatrix();
- }
- }
- }
-
- void setLen(float l) {
- len = l;
- }
-
- void changeLen(float percent) {
- len *= percent;
- }
-
- void setToDo(String s) {
- todo = s;
- }
-
-}
-
-
diff --git a/java/examples/Books/Nature of Code/chp9_ga/EvolveFlowField/DNA.pde b/java/examples/Books/Nature of Code/chp9_ga/EvolveFlowField/DNA.pde
deleted file mode 100644
index 54d988426..000000000
--- a/java/examples/Books/Nature of Code/chp9_ga/EvolveFlowField/DNA.pde
+++ /dev/null
@@ -1,82 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Pathfinding w/ Genetic Algorithms
-
-// DNA is an array of vectors
-
-class DNA {
-
- // The genetic sequence
- PVector[] genes;
-
- // Constructor (makes a DNA of random PVectors)
- DNA(int num) {
- genes = new PVector[num];
- for (int i = 0; i < genes.length; i++) {
- genes[i] = PVector.random2D();
- }
- }
-
- // Constructor #2, creates the instance based on an existing array
- DNA(PVector[] newgenes) {
- // We could make a copy if necessary
- // genes = (PVector []) newgenes.clone();
- genes = newgenes;
- }
-
- // CROSSOVER
- // Creates new DNA sequence from two (this & and a partner)
- DNA crossover(DNA partner) {
- PVector[] child = new PVector[genes.length];
- // Pick a midpoint
- int crossover = int(random(genes.length));
- // Take "half" from one and "half" from the other
- for (int i = 0; i < genes.length; i++) {
- if (i > crossover) child[i] = genes[i];
- else child[i] = partner.genes[i];
- }
- DNA newgenes = new DNA(child);
- return newgenes;
- }
-
- // Based on a mutation probability, picks a new random Vector
- void mutate(float m) {
- for (int i = 0; i < genes.length; i++) {
- if (random(1) < m) {
- genes[i] = PVector.random2D();
- }
- }
- }
-
- void debugDraw() {
- int cols = width / gridscale;
- int rows = height / gridscale;
- for (int i = 0; i < cols; i++) {
- for (int j = 0; j < rows; j++) {
- drawVector(genes[i+j*cols],i*gridscale,j*gridscale,gridscale-2);
- }
- }
- }
-
- // Renders a vector object 'v' as an arrow and a location 'x,y'
- void drawVector(PVector v, float x, float y, float scayl) {
- pushMatrix();
- float arrowsize = 4;
- // Translate to location to render vector
- translate(x+gridscale/2,y);
- stroke(0,100);
- // Call vector heading function to get direction (note that pointing up is a heading of 0) and rotate
- rotate(v.heading());
- // Calculate length of vector & scale it to be bigger or smaller if necessary
- float len = v.mag()*scayl;
- // Draw three lines to make an arrow (draw pointing up since we've rotate to the proper direction)
- line(-len/2,0,len/2,0);
- //noFill();
- //ellipse(-len/2,0,2,2);
- popMatrix();
- }
-
-}
-
diff --git a/java/examples/Books/Nature of Code/chp9_ga/EvolveFlowField/EvolveFlowField.pde b/java/examples/Books/Nature of Code/chp9_ga/EvolveFlowField/EvolveFlowField.pde
deleted file mode 100644
index 433924997..000000000
--- a/java/examples/Books/Nature of Code/chp9_ga/EvolveFlowField/EvolveFlowField.pde
+++ /dev/null
@@ -1,121 +0,0 @@
- // The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Pathfinding Flowfield w/ Genetic Algorithms
-
-// This example produces an obstacle course with a start and finish
-// Virtual "creatures" are rewarded for making it closer to the finish
-
-// Each creature's DNA is a "flowfield" of PVectors that
-// determine steering vectors for each cell on the screen
-
-import java.awt.Rectangle;
-
-int gridscale = 10; // Scale of grid is 1/24 of screen size
-
-// DNA needs one vector for every spot on the grid
-// (it's like a pixel array, but with vectors instead of colors)
-int dnasize;
-
-int lifetime; // How long should each generation live
-
-
-Population population; // Population
-int lifecycle; // Timer for cycle of generation
-int recordtime; // Fastest time to target
-Obstacle target; // Target location
-Obstacle start; // Start location
-int diam = 24; // Size of target
-
-ArrayList obstacles; //an array list to keep track of all the obstacles!
-
-boolean debug = false;
-
-Rectangle newObstacle = null;
-
-void setup() {
- size(640,360);
- dnasize = (width / gridscale) * (height / gridscale);
- lifetime = width/3;
-
- // Initialize variables
- lifecycle = 0;
- recordtime = lifetime;
- target = new Obstacle(width-diam-diam/2,height/2-diam/2,diam,diam);
- start = new Obstacle(diam/2,height/2-diam/2,diam,diam);
-
- // Create a population with a mutation rate, and population max
- int popmax = 1000;
- float mutationRate = 0.02;
- population = new Population(mutationRate,popmax);
-
- // Create the obstacle course
- obstacles = new ArrayList();
-
-
- /*obstacles.add(new Obstacle(width/4,80,10,height-160));
- obstacles.add(new Obstacle(width/2,0,10,height/2-20));
- obstacles.add(new Obstacle(width/2,height-height/2+20,10,height/2-20));
- obstacles.add(new Obstacle(2*width/3,height/2-height/8,10,height/4));*/
-}
-
-void draw() {
- background(255);
-
- // Draw the target locations
- target.display();
-
- // Draw the obstacles
- for (Obstacle obs : obstacles) {
- obs.display();
- }
-
-
- // If the generation hasn't ended yet
- if (lifecycle < lifetime) {
- population.live(obstacles);
- if ((population.targetReached()) && (lifecycle < recordtime)) {
- recordtime = lifecycle;
- }
- lifecycle++;
- // Otherwise a new generation
- } else {
- lifecycle = 0;
- population.calcFitness();
- population.naturalSelection();
- population.generate();
- }
-
- // Display some info
- textAlign(RIGHT);
- fill(0);
- text("Generation #:" + population.getGenerations(),width-10,18);
- text("Cycles left:" + ((lifetime-lifecycle)),width-10,36);
- text("Record cycles: " + recordtime,width-10,54);
-
- if (newObstacle != null) {
- rect(newObstacle.x,newObstacle.y,newObstacle.width,newObstacle.height);
- }
-
-}
-
-void keyPressed() {
- if (key == 'd') {
- debug = !debug;
- }
-}
-
-void mousePressed() {
- newObstacle = new Rectangle(mouseX,mouseY,0,0);
-}
-
-void mouseDragged() {
- newObstacle.width = mouseX-newObstacle.x;
- newObstacle.height = mouseY-newObstacle.y;
-}
-
-void mouseReleased() {
- obstacles.add(new Obstacle(newObstacle));
- newObstacle = null;
-}
diff --git a/java/examples/Books/Nature of Code/chp9_ga/EvolveFlowField/Obstacle.pde b/java/examples/Books/Nature of Code/chp9_ga/EvolveFlowField/Obstacle.pde
deleted file mode 100644
index 2658d7bd5..000000000
--- a/java/examples/Books/Nature of Code/chp9_ga/EvolveFlowField/Obstacle.pde
+++ /dev/null
@@ -1,39 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Pathfinding w/ Genetic Algorithms
-
-// A class for an obstacle, just a simple rectangle that is drawn
-// and can check if a creature touches it
-
-// Also using this class for starting point and target location
-
-class Obstacle {
-
- Rectangle r;
-
- Obstacle(int x, int y, int w, int h) {
- r = new Rectangle(x,y,w,h);
- }
-
- Obstacle(Rectangle r_) {
- r = r_;
- }
-
- void display() {
- stroke(0);
- fill(175);
- rectMode(CORNER);
- rect(r.x,r.y,r.width,r.height);
- }
-
- boolean contains(PVector spot) {
- if (r.contains((int)spot.x,(int)spot.y)) {
- return true;
- } else {
- return false;
- }
- }
-
-}
diff --git a/java/examples/Books/Nature of Code/chp9_ga/EvolveFlowField/Population.pde b/java/examples/Books/Nature of Code/chp9_ga/EvolveFlowField/Population.pde
deleted file mode 100644
index baa32703a..000000000
--- a/java/examples/Books/Nature of Code/chp9_ga/EvolveFlowField/Population.pde
+++ /dev/null
@@ -1,142 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// A class to describe a population of "creatures"
-
-class Population {
-
- float mutationRate; // Mutation rate
- Rocket[] population; // Array to hold the current population
- ArrayList darwin; // ArrayList which we will use for our "mating pool"
- int generations; // Number of generations
-
- int order; // Keep track of the order of creature's finishing the maze
-
-
-
- // Initialize the population
- Population(float m, int num) {
- mutationRate = m;
- population = new Rocket[num];
- darwin = new ArrayList();
- generations = 0;
- //make a new set of creatures
- for (int i = 0; i < population.length; i++) {
- PVector location = new PVector(start.r.x+start.r.width/2, start.r.y+start.r.height/2);
- population[i] = new Rocket(location, new DNA(dnasize));
- }
- order = 1; // The first one to finish will be #1
- }
-
- void live (ArrayList o) {
- // For every creature
-
-
-
- float record = 100000;
- int closest = 0;
-
- for (int i = 0; i < population.length; i++) {
- // If it finishes, mark it down as done!
- if ((population[i].finished())) {
- population[i].setFinish(order);
- order++;
- }
- // Run it
- population[i].run(o);
-
- if (population[i].recordDist < record) {// && !population[i].dead) {
- record = population[i].recordDist;
- closest = i;
- }
- }
-
- population[closest].highlight();
- // Drawing one example of the DNA
- if (debug) {
- population[closest].dna.debugDraw();
- }
- }
-
- // Did anything finish?
- boolean targetReached() {
- for (int i = 0; i < population.length; i++) {
- if (population[i].finished()) return true;
- }
- return false;
- }
-
- // Calculate fitness for each creature
- void calcFitness() {
- for (int i = 0; i < population.length; i++) {
- population[i].calcFitness();
- }
- order = 1; // Hmmm, awkward place for this, we have to reset this for the next generation
- }
-
- // Generate a mating pool
- void naturalSelection() {
- // Clear the ArrayList
- darwin.clear();
-
- // Calculate total fitness of whole population
- float totalFitness = getTotalFitness();
- float avgFitness = totalFitness/population.length;
-
- // Calculate normalized fitness for each member of the population
- // Based on normalized fitness, each member will get added to the mating pool a certain number of times a la roulette wheel
- // A higher fitness = more entries to mating pool = more likely to be picked as a parent
- // A lower fitness = fewer entries to mating pool = less likely to be picked as a parent
- int count = 0;
- for (int i = 0; i < population.length; i++) {
- float fitness = population[i].getFitness();
- //if (fitness > avgFitness) {
- count++;
- float fitnessNormal = fitness / totalFitness;
- int n = (int) (fitnessNormal * 50000); // Arbitrary multiplier, consider mapping fix
- for (int j = 0; j < n; j++) {
- darwin.add(population[i]);
- }
- //}
- }
- //println("Total: " + count + " " + population.length);
- }
-
- // Making the next generation
- void generate() {
- // Refill the population with children from the mating pool
- for (int i = 0; i < population.length; i++) {
- int m = int(random(darwin.size()));
- int d = int(random(darwin.size()));
- // Pick two parents
- Rocket mom = darwin.get(m);
- Rocket dad = darwin.get(d);
- // Get their genes
- DNA momgenes = mom.getDNA();
- DNA dadgenes = dad.getDNA();
- // Mate their genes
- DNA child = momgenes.crossover(dadgenes);
- // Mutate their genes
- child.mutate(mutationRate);
- // Fill the new population with the new child
- PVector location = new PVector(start.r.x+start.r.width/2, start.r.y+start.r.height/2);
- population[i] = new Rocket(location, child);
- }
- generations++;
- }
-
- int getGenerations() {
- return generations;
- }
-
- //compute total fitness for the population
- float getTotalFitness() {
- float total = 0;
- for (int i = 0; i < population.length; i++) {
- total += population[i].getFitness();
- }
- return total;
- }
-}
-
diff --git a/java/examples/Books/Nature of Code/chp9_ga/EvolveFlowField/Rocket.pde b/java/examples/Books/Nature of Code/chp9_ga/EvolveFlowField/Rocket.pde
deleted file mode 100644
index dab8d959c..000000000
--- a/java/examples/Books/Nature of Code/chp9_ga/EvolveFlowField/Rocket.pde
+++ /dev/null
@@ -1,171 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Pathfinding w/ Genetic Algorithms
-
-// Rocket class -- this is just like our Boid / Particle class
-// the only difference is that it has DNA & fitness
-
-class Rocket {
-
- // All of our physics stuff
- PVector location;
- PVector velocity;
- PVector acceleration;
- float r;
- float recordDist;
-
- float fitness;
- DNA dna;
-
- // Could make this part of DNA??)
- float maxspeed = 6.0;
- float maxforce = 1.0;
-
- boolean stopped; // Am I stuck?
- boolean dead; // Did I hit an obstacle?
-
- int finish; // What was my finish? (first, second, etc. . . )
-
- //constructor
- Rocket(PVector l, DNA dna_) {
- acceleration = new PVector();
- velocity = new PVector();
- location = l.get();
- r = 2;
- dna = dna_;
- stopped = false;
- finish = 100000; // Some high number to begin with
- recordDist = width;
- }
-
- // FITNESS FUNCTION
- // distance = distance from target
- // finish = what order did i finish (first, second, etc. . .)
- // f(distance,finish) = (1.0f / finish^1.5) * (1.0f / distance^6);
- // a lower finish is rewarded (exponentially) and/or shorter distance to target (exponetially)
- void calcFitness() {
- float d = recordDist;
- if (d < diam/2) {
- d = 1.0;
- }
- // Reward finishing faster and getting closer
- fitness = (1.0f / pow(finish,1.5)) * (1 / (pow(d,6)));
-
- //if (dead) fitness = 0;
- }
-
- void setFinish(int f) {
- finish = f;
- }
-
- // Run in relation to all the obstacles
- // If I'm stuck, don't bother updating or checking for intersection
- void run(ArrayList o) {
- if (!stopped) {
- update();
- // If I hit an edge or an obstacle
- if ((borders()) || (obstacles(o))) {
- stopped = true;
- dead = true;
- }
- }
- // Draw me!
- display();
- }
-
- // Did I hit an edge?
- boolean borders() {
- if ((location.x < 0) || (location.y < 0) || (location.x > width) || (location.y > height)) {
- return true;
- } else {
- return false;
- }
- }
-
- // Did I make it to the target?
- boolean finished() {
- float d = dist(location.x,location.y,target.r.x,target.r.y);
- if (d < recordDist) {
- recordDist = d;
- }
- if (target.contains(location)) {
- stopped = true;
- return true;
- }
- return false;
- }
-
- // Did I hit an obstacle?
- boolean obstacles(ArrayList o) {
- for (Obstacle obs : o) {
- if (obs.contains(location)) {
- return true;
- }
- }
- return false;
- }
-
- void update() {
- if (!finished()) {
- // Where are we? Our location will tell us what steering vector to look up in our DNA;
- int x = (int) location.x/gridscale;
- int y = (int) location.y/gridscale;
- x = constrain(x,0,width/gridscale-1); // Make sure we are not off the edge
- y = constrain(y,0,height/gridscale-1); // Make sure we are not off the edge
-
- // Get the steering vector out of our genes in the right spot
- // A little Reynolds steering here
- PVector desired = dna.genes[x+y*(width/gridscale)].get();
- desired.mult(maxspeed);
- PVector steer = PVector.sub(desired,velocity);
- acceleration.add(steer);
- acceleration.limit(maxforce);
-
- velocity.add(acceleration);
- velocity.limit(maxspeed);
- location.add(velocity);
- acceleration.mult(0);
- }
- }
-
- void display() {
- //fill(0,150);
- //stroke(0);
- //ellipse(location.x,location.y,r,r);
- float theta = velocity.heading() + PI/2;
- fill(200,100);
- stroke(0);
- pushMatrix();
- translate(location.x,location.y);
- rotate(theta);
- beginShape(TRIANGLES);
- vertex(0, -r*2);
- vertex(-r, r*2);
- vertex(r, r*2);
- endShape();
- popMatrix();
- }
-
- void highlight() {
- stroke(0);
- line(location.x,location.y,target.r.x,target.r.y);
- fill(255,0,0,100);
- ellipse(location.x,location.y,16,16);
-
- }
-
- float getFitness() {
- return fitness;
- }
-
- DNA getDNA() {
- return dna;
- }
-
- boolean stopped() {
- return stopped;
- }
-
-}
diff --git a/java/examples/Books/Nature of Code/chp9_ga/GA_Shakespeare_fancyfitness/DNA.pde b/java/examples/Books/Nature of Code/chp9_ga/GA_Shakespeare_fancyfitness/DNA.pde
deleted file mode 100644
index 8286ab0c0..000000000
--- a/java/examples/Books/Nature of Code/chp9_ga/GA_Shakespeare_fancyfitness/DNA.pde
+++ /dev/null
@@ -1,70 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Genetic Algorithm, Evolving Shakespeare
-
-// A class to describe a psuedo-DNA, i.e. genotype
-// Here, a virtual organism's DNA is an array of character.
-// Functionality:
-// -- convert DNA into a string
-// -- calculate DNA's "fitness"
-// -- mate DNA with another set of DNA
-// -- mutate DNA
-
-
-class DNA {
-
- // The genetic sequence
- char[] genes;
-
- float fitness;
-
- // Constructor (makes a random DNA)
- DNA(int num) {
- genes = new char[num];
- for (int i = 0; i < genes.length; i++) {
- genes[i] = (char) random(32,128); // Pick from range of chars
- }
- }
-
- // Converts character array to a String
- String getPhrase() {
- return new String(genes);
- }
-
- // Fitness function (returns floating point % of "correct" characters)
- void fitness (String target) {
- int score = 0;
- for (int i = 0; i < genes.length; i++) {
- if (genes[i] == target.charAt(i)) {
- score++;
- }
- }
- fitness = pow(2,score);
- }
-
- // Crossover
- DNA crossover(DNA partner) {
- // A new child
- DNA child = new DNA(genes.length);
-
- int midpoint = int(random(genes.length)); // Pick a midpoint
-
- // Half from one, half from the other
- for (int i = 0; i < genes.length; i++) {
- if (i > midpoint) child.genes[i] = genes[i];
- else child.genes[i] = partner.genes[i];
- }
- return child;
- }
-
- // Based on a mutation probability, picks a new random character
- void mutate(float mutationRate) {
- for (int i = 0; i < genes.length; i++) {
- if (random(1) < mutationRate) {
- genes[i] = (char) random(32,128);
- }
- }
- }
-}
diff --git a/java/examples/Books/Nature of Code/chp9_ga/GA_Shakespeare_fancyfitness/GA_Shakespeare_fancyfitness.pde b/java/examples/Books/Nature of Code/chp9_ga/GA_Shakespeare_fancyfitness/GA_Shakespeare_fancyfitness.pde
deleted file mode 100644
index a50ef3319..000000000
--- a/java/examples/Books/Nature of Code/chp9_ga/GA_Shakespeare_fancyfitness/GA_Shakespeare_fancyfitness.pde
+++ /dev/null
@@ -1,89 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Genetic Algorithm, Evolving Shakespeare
-
-// Demonstration of using a genetic algorithm to perform a search
-
-// setup()
-// # Step 1: The populationation
-// # Create an empty populationation (an array or ArrayList)
-// # Fill it with DNA encoded objects (pick random values to start)
-
-// draw()
-// # Step 1: Selection
-// # Create an empty mating pool (an empty ArrayList)
-// # For every member of the populationation, evaluate its fitness based on some criteria / function,
-// and add it to the mating pool in a manner consistant with its fitness, i.e. the more fit it
-// is the more times it appears in the mating pool, in order to be more likely picked for reproduction.
-
-// # Step 2: Reproduction Create a new empty populationation
-// # Fill the new populationation by executing the following steps:
-// 1. Pick two "parent" objects from the mating pool.
-// 2. Crossover -- create a "child" object by mating these two parents.
-// 3. Mutation -- mutate the child's DNA based on a given probability.
-// 4. Add the child object to the new populationation.
-// # Replace the old populationation with the new populationation
-//
-// # Rinse and repeat
-
-
-PFont f;
-String target;
-int popmax;
-float mutationRate;
-Population population;
-
-void setup() {
- size(600, 200);
- f = createFont("Courier", 32, true);
- target = "To be or not to be.";
- popmax = 150;
- mutationRate = 0.01;
-
- // Create a populationation with a target phrase, mutation rate, and populationation max
- population = new Population(target, mutationRate, popmax);
-}
-
-void draw() {
- // Generate mating pool
- population.naturalSelection();
- //Create next generation
- population.generate();
- // Calculate fitness
- population.calcFitness();
- displayInfo();
-
- // If we found the target phrase, stop
- if (population.finished()) {
- println(millis()/1000.0);
- noLoop();
- }
-}
-
-void displayInfo() {
- background(255);
- // Display current status of populationation
- String answer = population.getBest();
- textFont(f);
- textAlign(LEFT);
- fill(0);
-
-
- textSize(16);
- text("Best phrase:",20,30);
- textSize(32);
- text(answer, 20, 75);
-
- textSize(12);
- text("total generations: " + population.getGenerations(), 20, 140);
- text("average fitness: " + nf(population.getAverageFitness(), 0, 2), 20, 155);
- text("total populationation: " + popmax, 20, 170);
- text("mutation rate: " + int(mutationRate * 100) + "%", 20, 185);
-
- textSize(10);
- text("All phrases:\n" + population.allPhrases(), 450, 10);
-}
-
-
diff --git a/java/examples/Books/Nature of Code/chp9_ga/GA_Shakespeare_fancyfitness/Population.pde b/java/examples/Books/Nature of Code/chp9_ga/GA_Shakespeare_fancyfitness/Population.pde
deleted file mode 100644
index 03630a706..000000000
--- a/java/examples/Books/Nature of Code/chp9_ga/GA_Shakespeare_fancyfitness/Population.pde
+++ /dev/null
@@ -1,127 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Genetic Algorithm, Evolving Shakespeare
-
-// A class to describe a population of virtual organisms
-// In this case, each organism is just an instance of a DNA object
-
-class Population {
-
- float mutationRate; // Mutation rate
- DNA[] population; // Array to hold the current population
- ArrayList matingPool; // ArrayList which we will use for our "mating pool"
- String target; // Target phrase
- int generations; // Number of generations
- boolean finished; // Are we finished evolving?
- int perfectScore;
-
- Population(String p, float m, int num) {
- target = p;
- mutationRate = m;
- population = new DNA[num];
- for (int i = 0; i < population.length; i++) {
- population[i] = new DNA(target.length());
- }
- calcFitness();
- matingPool = new ArrayList();
- finished = false;
- generations = 0;
-
- perfectScore = int(pow(2,target.length()));
- }
-
- // Fill our fitness array with a value for every member of the population
- void calcFitness() {
- for (int i = 0; i < population.length; i++) {
- population[i].fitness(target);
- }
- }
-
- // Generate a mating pool
- void naturalSelection() {
- // Clear the ArrayList
- matingPool.clear();
-
- float maxFitness = 0;
- for (int i = 0; i < population.length; i++) {
- if (population[i].fitness > maxFitness) {
- maxFitness = population[i].fitness;
- }
- }
-
- // Based on fitness, each member will get added to the mating pool a certain number of times
- // a higher fitness = more entries to mating pool = more likely to be picked as a parent
- // a lower fitness = fewer entries to mating pool = less likely to be picked as a parent
- for (int i = 0; i < population.length; i++) {
-
- float fitness = map(population[i].fitness,0,maxFitness,0,1);
- int n = int(fitness * 100); // Arbitrary multiplier, we can also use monte carlo method
- for (int j = 0; j < n; j++) { // and pick two random numbers
- matingPool.add(population[i]);
- }
- }
- }
-
- // Create a new generation
- void generate() {
- // Refill the population with children from the mating pool
- for (int i = 0; i < population.length; i++) {
- int a = int(random(matingPool.size()));
- int b = int(random(matingPool.size()));
- DNA partnerA = matingPool.get(a);
- DNA partnerB = matingPool.get(b);
- DNA child = partnerA.crossover(partnerB);
- child.mutate(mutationRate);
- population[i] = child;
- }
- generations++;
- }
-
-
- // Compute the current "most fit" member of the population
- String getBest() {
- float worldrecord = 0.0f;
- int index = 0;
- for (int i = 0; i < population.length; i++) {
- if (population[i].fitness > worldrecord) {
- index = i;
- worldrecord = population[i].fitness;
- }
- }
-
- if (worldrecord == perfectScore ) finished = true;
- return population[index].getPhrase();
- }
-
- boolean finished() {
- return finished;
- }
-
- int getGenerations() {
- return generations;
- }
-
- // Compute average fitness for the population
- float getAverageFitness() {
- float total = 0;
- for (int i = 0; i < population.length; i++) {
- total += population[i].fitness;
- }
- return total / (population.length);
- }
-
- String allPhrases() {
- String everything = "";
-
- int displayLimit = min(population.length,50);
-
-
- for (int i = 0; i < displayLimit; i++) {
- everything += population[i].getPhrase() + "\n";
- }
- return everything;
- }
-}
-
diff --git a/java/examples/Books/Nature of Code/chp9_ga/NOC_9_01_GA_Shakespeare/DNA.pde b/java/examples/Books/Nature of Code/chp9_ga/NOC_9_01_GA_Shakespeare/DNA.pde
deleted file mode 100644
index d3ceb1ce3..000000000
--- a/java/examples/Books/Nature of Code/chp9_ga/NOC_9_01_GA_Shakespeare/DNA.pde
+++ /dev/null
@@ -1,72 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Genetic Algorithm, Evolving Shakespeare
-
-// A class to describe a psuedo-DNA, i.e. genotype
-// Here, a virtual organism's DNA is an array of character.
-// Functionality:
-// -- convert DNA into a string
-// -- calculate DNA's "fitness"
-// -- mate DNA with another set of DNA
-// -- mutate DNA
-
-
-class DNA {
-
- // The genetic sequence
- char[] genes;
-
- float fitness;
-
- // Constructor (makes a random DNA)
- DNA(int num) {
- genes = new char[num];
- for (int i = 0; i < genes.length; i++) {
- genes[i] = (char) random(32,128); // Pick from range of chars
- }
- }
-
- // Converts character array to a String
- String getPhrase() {
- return new String(genes);
- }
-
- // Fitness function (returns floating point % of "correct" characters)
- void fitness (String target) {
- int score = 0;
- for (int i = 0; i < genes.length; i++) {
- if (genes[i] == target.charAt(i)) {
- score++;
- }
- }
-
-
- fitness = (float)score / (float)target.length();
- }
-
- // Crossover
- DNA crossover(DNA partner) {
- // A new child
- DNA child = new DNA(genes.length);
-
- int midpoint = int(random(genes.length)); // Pick a midpoint
-
- // Half from one, half from the other
- for (int i = 0; i < genes.length; i++) {
- if (i > midpoint) child.genes[i] = genes[i];
- else child.genes[i] = partner.genes[i];
- }
- return child;
- }
-
- // Based on a mutation probability, picks a new random character
- void mutate(float mutationRate) {
- for (int i = 0; i < genes.length; i++) {
- if (random(1) < mutationRate) {
- genes[i] = (char) random(32,128);
- }
- }
- }
-}
diff --git a/java/examples/Books/Nature of Code/chp9_ga/NOC_9_01_GA_Shakespeare/NOC_9_01_GA_Shakespeare.pde b/java/examples/Books/Nature of Code/chp9_ga/NOC_9_01_GA_Shakespeare/NOC_9_01_GA_Shakespeare.pde
deleted file mode 100644
index d4e72a1fc..000000000
--- a/java/examples/Books/Nature of Code/chp9_ga/NOC_9_01_GA_Shakespeare/NOC_9_01_GA_Shakespeare.pde
+++ /dev/null
@@ -1,90 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Genetic Algorithm, Evolving Shakespeare
-
-// Demonstration of using a genetic algorithm to perform a search
-
-// setup()
-// # Step 1: The Population
-// # Create an empty population (an array or ArrayList)
-// # Fill it with DNA encoded objects (pick random values to start)
-
-// draw()
-// # Step 1: Selection
-// # Create an empty mating pool (an empty ArrayList)
-// # For every member of the population, evaluate its fitness based on some criteria / function,
-// and add it to the mating pool in a manner consistant with its fitness, i.e. the more fit it
-// is the more times it appears in the mating pool, in order to be more likely picked for reproduction.
-
-// # Step 2: Reproduction Create a new empty population
-// # Fill the new population by executing the following steps:
-// 1. Pick two "parent" objects from the mating pool.
-// 2. Crossover -- create a "child" object by mating these two parents.
-// 3. Mutation -- mutate the child's DNA based on a given probability.
-// 4. Add the child object to the new population.
-// # Replace the old population with the new population
-//
-// # Rinse and repeat
-
-
-PFont f;
-String target;
-int popmax;
-float mutationRate;
-Population population;
-
-void setup() {
- size(640, 360);
- f = createFont("Courier", 32, true);
- target = "To be or not to be.";
- popmax = 150;
- mutationRate = 0.01;
-
- // Create a populationation with a target phrase, mutation rate, and populationation max
- population = new Population(target, mutationRate, popmax);
-}
-
-void draw() {
- // Generate mating pool
- population.naturalSelection();
- //Create next generation
- population.generate();
- // Calculate fitness
- population.calcFitness();
- displayInfo();
-
- // If we found the target phrase, stop
- if (population.finished()) {
- println(millis()/1000.0);
- noLoop();
- }
-}
-
-void displayInfo() {
- background(255);
- // Display current status of populationation
- String answer = population.getBest();
- textFont(f);
- textAlign(LEFT);
- fill(0);
-
-
- textSize(24);
- text("Best phrase:",20,30);
- textSize(40);
- text(answer, 20, 100);
-
- textSize(18);
- text("total generations: " + population.getGenerations(), 20, 160);
- text("average fitness: " + nf(population.getAverageFitness(), 0, 2), 20, 180);
- text("total population: " + popmax, 20, 200);
- text("mutation rate: " + int(mutationRate * 100) + "%", 20, 220);
-
- textSize(10);
- text("All phrases:\n" + population.allPhrases(), 500, 10);
-}
-
-
-
diff --git a/java/examples/Books/Nature of Code/chp9_ga/NOC_9_01_GA_Shakespeare/Population.pde b/java/examples/Books/Nature of Code/chp9_ga/NOC_9_01_GA_Shakespeare/Population.pde
deleted file mode 100644
index d48ac6c3f..000000000
--- a/java/examples/Books/Nature of Code/chp9_ga/NOC_9_01_GA_Shakespeare/Population.pde
+++ /dev/null
@@ -1,127 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Genetic Algorithm, Evolving Shakespeare
-
-// A class to describe a population of virtual organisms
-// In this case, each organism is just an instance of a DNA object
-
-class Population {
-
- float mutationRate; // Mutation rate
- DNA[] population; // Array to hold the current population
- ArrayList matingPool; // ArrayList which we will use for our "mating pool"
- String target; // Target phrase
- int generations; // Number of generations
- boolean finished; // Are we finished evolving?
- int perfectScore;
-
- Population(String p, float m, int num) {
- target = p;
- mutationRate = m;
- population = new DNA[num];
- for (int i = 0; i < population.length; i++) {
- population[i] = new DNA(target.length());
- }
- calcFitness();
- matingPool = new ArrayList();
- finished = false;
- generations = 0;
-
- perfectScore = 1;
- }
-
- // Fill our fitness array with a value for every member of the population
- void calcFitness() {
- for (int i = 0; i < population.length; i++) {
- population[i].fitness(target);
- }
- }
-
- // Generate a mating pool
- void naturalSelection() {
- // Clear the ArrayList
- matingPool.clear();
-
- float maxFitness = 0;
- for (int i = 0; i < population.length; i++) {
- if (population[i].fitness > maxFitness) {
- maxFitness = population[i].fitness;
- }
- }
-
- // Based on fitness, each member will get added to the mating pool a certain number of times
- // a higher fitness = more entries to mating pool = more likely to be picked as a parent
- // a lower fitness = fewer entries to mating pool = less likely to be picked as a parent
- for (int i = 0; i < population.length; i++) {
-
- float fitness = map(population[i].fitness,0,maxFitness,0,1);
- int n = int(fitness * 100); // Arbitrary multiplier, we can also use monte carlo method
- for (int j = 0; j < n; j++) { // and pick two random numbers
- matingPool.add(population[i]);
- }
- }
- }
-
- // Create a new generation
- void generate() {
- // Refill the population with children from the mating pool
- for (int i = 0; i < population.length; i++) {
- int a = int(random(matingPool.size()));
- int b = int(random(matingPool.size()));
- DNA partnerA = matingPool.get(a);
- DNA partnerB = matingPool.get(b);
- DNA child = partnerA.crossover(partnerB);
- child.mutate(mutationRate);
- population[i] = child;
- }
- generations++;
- }
-
-
- // Compute the current "most fit" member of the population
- String getBest() {
- float worldrecord = 0.0;
- int index = 0;
- for (int i = 0; i < population.length; i++) {
- if (population[i].fitness > worldrecord) {
- index = i;
- worldrecord = population[i].fitness;
- }
- }
-
- if (worldrecord == perfectScore ) finished = true;
- return population[index].getPhrase();
- }
-
- boolean finished() {
- return finished;
- }
-
- int getGenerations() {
- return generations;
- }
-
- // Compute average fitness for the population
- float getAverageFitness() {
- float total = 0;
- for (int i = 0; i < population.length; i++) {
- total += population[i].fitness;
- }
- return total / (population.length);
- }
-
- String allPhrases() {
- String everything = "";
-
- int displayLimit = min(population.length,50);
-
-
- for (int i = 0; i < displayLimit; i++) {
- everything += population[i].getPhrase() + "\n";
- }
- return everything;
- }
-}
-
diff --git a/java/examples/Books/Nature of Code/chp9_ga/NOC_9_01_GA_Shakespeare_simplified/DNA.pde b/java/examples/Books/Nature of Code/chp9_ga/NOC_9_01_GA_Shakespeare_simplified/DNA.pde
deleted file mode 100644
index e4ce06c31..000000000
--- a/java/examples/Books/Nature of Code/chp9_ga/NOC_9_01_GA_Shakespeare_simplified/DNA.pde
+++ /dev/null
@@ -1,70 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Genetic Algorithm, Evolving Shakespeare
-
-// A class to describe a psuedo-DNA, i.e. genotype
-// Here, a virtual organism's DNA is an array of character.
-// Functionality:
-// -- convert DNA into a string
-// -- calculate DNA's "fitness"
-// -- mate DNA with another set of DNA
-// -- mutate DNA
-
-
-class DNA {
-
- // The genetic sequence
- char[] genes;
-
- float fitness;
-
- // Constructor (makes a random DNA)
- DNA(int num) {
- genes = new char[num];
- for (int i = 0; i < genes.length; i++) {
- genes[i] = (char) random(32,128); // Pick from range of chars
- }
- }
-
- // Converts character array to a String
- String getPhrase() {
- return new String(genes);
- }
-
- // Fitness function (returns floating point % of "correct" characters)
- void calcFitness (String target) {
- int score = 0;
- for (int i = 0; i < genes.length; i++) {
- if (genes[i] == target.charAt(i)) {
- score++;
- }
- }
- fitness = (float)score / (float)target.length();
- }
-
- // Crossover
- DNA crossover(DNA partner) {
- // A new child
- DNA child = new DNA(genes.length);
-
- int midpoint = int(random(genes.length)); // Pick a midpoint
-
- // Half from one, half from the other
- for (int i = 0; i < genes.length; i++) {
- if (i > midpoint) child.genes[i] = genes[i];
- else child.genes[i] = partner.genes[i];
- }
- return child;
- }
-
- // Based on a mutation probability, picks a new random character
- void mutate(float mutationRate) {
- for (int i = 0; i < genes.length; i++) {
- if (random(1) < mutationRate) {
- genes[i] = (char) random(32,128);
- }
- }
- }
-}
diff --git a/java/examples/Books/Nature of Code/chp9_ga/NOC_9_01_GA_Shakespeare_simplified/NOC_9_01_GA_Shakespeare_simplified.pde b/java/examples/Books/Nature of Code/chp9_ga/NOC_9_01_GA_Shakespeare_simplified/NOC_9_01_GA_Shakespeare_simplified.pde
deleted file mode 100644
index a46d90a23..000000000
--- a/java/examples/Books/Nature of Code/chp9_ga/NOC_9_01_GA_Shakespeare_simplified/NOC_9_01_GA_Shakespeare_simplified.pde
+++ /dev/null
@@ -1,89 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Genetic Algorithm, Evolving Shakespeare
-
-// Demonstration of using a genetic algorithm to perform a search
-
-// setup()
-// # Step 1: The Population
-// # Create an empty population (an array or ArrayList)
-// # Fill it with DNA encoded objects (pick random values to start)
-
-// draw()
-// # Step 1: Selection
-// # Create an empty mating pool (an empty ArrayList)
-// # For every member of the population, evaluate its fitness based on some criteria / function,
-// and add it to the mating pool in a manner consistant with its fitness, i.e. the more fit it
-// is the more times it appears in the mating pool, in order to be more likely picked for reproduction.
-
-// # Step 2: Reproduction Create a new empty population
-// # Fill the new population by executing the following steps:
-// 1. Pick two "parent" objects from the mating pool.
-// 2. Crossover -- create a "child" object by mating these two parents.
-// 3. Mutation -- mutate the child's DNA based on a given probability.
-// 4. Add the child object to the new population.
-// # Replace the old population with the new population
-//
-// # Rinse and repeat
-
-
-float mutationRate = 0.01; // Mutation rate
-int totalPopulation = 150; // Total Population
-
-DNA[] population; // Array to hold the current population
-ArrayList matingPool; // ArrayList which we will use for our "mating pool"
-String target; // Target phrase
-
-PFont f;
-
-void setup() {
- size(800, 200);
- target = "to be or not to be";
-
- population = new DNA[totalPopulation];
-
- for (int i = 0; i < population.length; i++) {
- population[i] = new DNA(target.length());
- }
-
- f = createFont("Courier",12,true);
-}
-
-void draw() {
- for (int i = 0; i < population.length; i++) {
- population[i].calcFitness(target);
- }
-
- ArrayList matingPool = new ArrayList(); // ArrayList which we will use for our "mating pool"
-
- for (int i = 0; i < population.length; i++) {
- int nnnn = int(population[i].fitness * 100); // Arbitrary multiplier, we can also use monte carlo method
- for (int j = 0; j crossover) child[i] = genes[i];
- else child[i] = partner.genes[i];
- }
- DNA newgenes = new DNA(child);
- return newgenes;
- }
-
- // Based on a mutation probability, picks a new random Vector
- void mutate(float m) {
- for (int i = 0; i < genes.length; i++) {
- if (random(1) < m) {
- float angle = random(TWO_PI);
- genes[i] = new PVector(cos(angle), sin(angle));
- genes[i].mult(random(0, maxforce));
- }
- }
- }
-}
-
diff --git a/java/examples/Books/Nature of Code/chp9_ga/NOC_9_02_SmartRockets_superbasic/NOC_9_02_SmartRockets_superbasic.pde b/java/examples/Books/Nature of Code/chp9_ga/NOC_9_02_SmartRockets_superbasic/NOC_9_02_SmartRockets_superbasic.pde
deleted file mode 100644
index 3ae68e806..000000000
--- a/java/examples/Books/Nature of Code/chp9_ga/NOC_9_02_SmartRockets_superbasic/NOC_9_02_SmartRockets_superbasic.pde
+++ /dev/null
@@ -1,74 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Smart Rockets w/ Genetic Algorithms
-
-// Each Rocket's DNA is an array of PVectors
-// Each PVector acts as a force for each frame of animation
-// Imagine an booster on the end of the rocket that can point in any direction
-// and fire at any strength every frame
-
-// The Rocket's fitness is a function of how close it gets to the target as well as how fast it gets there
-
-// This example is inspired by Jer Thorp's Smart Rockets
-// http://www.blprnt.com/smartrockets/
-
-int lifetime; // How long should each generation live
-
-Population population; // Population
-
-int lifeCounter; // Timer for cycle of generation
-
-PVector target; // Target location
-
-void setup() {
- size(640, 360);
- // The number of cycles we will allow a generation to live
- lifetime = height;
-
- // Initialize variables
- lifeCounter = 0;
-
- target = new PVector(width/2, 24);
-
- // Create a population with a mutation rate, and population max
- float mutationRate = 0.01;
- population = new Population(mutationRate, 50);
-
-}
-
-void draw() {
- background(255);
-
- // Draw the start and target locations
- fill(0);
- ellipse(target.x,target.y,24,24);
-
-
- // If the generation hasn't ended yet
- if (lifeCounter < lifetime) {
- population.live();
- lifeCounter++;
- // Otherwise a new generation
- }
- else {
- lifeCounter = 0;
- population.fitness();
- population.selection();
- population.reproduction();
- }
-
- // Display some info
- fill(0);
- text("Generation #: " + population.getGenerations(), 10, 18);
- text("Cycles left: " + (lifetime-lifeCounter), 10, 36);
-}
-
-// Move the target if the mouse is pressed
-// System will adapt to new target
-void mousePressed() {
- target.x = mouseX;
- target.y = mouseY;
-}
-
diff --git a/java/examples/Books/Nature of Code/chp9_ga/NOC_9_02_SmartRockets_superbasic/Population.pde b/java/examples/Books/Nature of Code/chp9_ga/NOC_9_02_SmartRockets_superbasic/Population.pde
deleted file mode 100644
index 128d38636..000000000
--- a/java/examples/Books/Nature of Code/chp9_ga/NOC_9_02_SmartRockets_superbasic/Population.pde
+++ /dev/null
@@ -1,103 +0,0 @@
-// The Nature of Code
-// Daniel Shiffman
-// http://natureofcode.com
-
-// Pathfinding w/ Genetic Algorithms
-
-// A class to describe a population of "creatures"
-
-class Population {
-
- float mutationRate; // Mutation rate
- Rocket[] population; // Array to hold the current population
- ArrayList