From 9775dedaad2f9315648ed40e8f882426ee46ced3 Mon Sep 17 00:00:00 2001 From: Casey Reas Date: Tue, 6 Sep 2011 05:22:47 +0000 Subject: [PATCH] --- .../PenroseSnowflake/PenroseSnowflake.pde | 2 +- .../PenroseTile/PenroseTile.pde | 2 +- .../Pentigree/Pentigree.pde | 5 +- java/examples/Topics/GUI/Buttons/Buttons.pde | 220 ------------------ java/examples/Topics/GUI/Handles/Handles.pde | 12 +- .../Topics/GUI/Scrollbar/Scrollbar.pde | 20 +- .../Topics/Interaction/Follow1/Follow1.pde | 6 +- .../Topics/Interaction/Follow2/Follow2.pde | 6 +- .../Topics/Interaction/Follow3/Follow3.pde | 10 +- .../Topics/Interaction/Reach1/Reach1.pde | 18 +- .../Topics/Interaction/Reach2/Reach2.pde | 10 +- .../Topics/Interaction/Reach3/Reach3.pde | 10 +- java/examples/Topics/Simulate/Chain/Chain.pde | 10 +- .../Topics/Simulate/Flocking/Boid.pde | 4 +- .../SmokeParticleSystem.pde | 2 +- .../Topics/Simulate/Spring/Spring.pde | 51 ++-- .../Topics/Simulate/Springs/Springs.pde | 12 +- 17 files changed, 89 insertions(+), 311 deletions(-) delete mode 100644 java/examples/Topics/GUI/Buttons/Buttons.pde diff --git a/java/examples/Topics/Fractals and L-Systems/PenroseSnowflake/PenroseSnowflake.pde b/java/examples/Topics/Fractals and L-Systems/PenroseSnowflake/PenroseSnowflake.pde index 8fe1c9393..e25b78966 100644 --- a/java/examples/Topics/Fractals and L-Systems/PenroseSnowflake/PenroseSnowflake.pde +++ b/java/examples/Topics/Fractals and L-Systems/PenroseSnowflake/PenroseSnowflake.pde @@ -1,6 +1,6 @@ /** * Penrose Snowflake L-System - * by Geraldine Sarmiento (NYU ITP). + * by Geraldine Sarmiento. * * This code was based on Patrick Dwyer's L-System class. */ diff --git a/java/examples/Topics/Fractals and L-Systems/PenroseTile/PenroseTile.pde b/java/examples/Topics/Fractals and L-Systems/PenroseTile/PenroseTile.pde index 1cbeb439c..35c6fbe2a 100644 --- a/java/examples/Topics/Fractals and L-Systems/PenroseTile/PenroseTile.pde +++ b/java/examples/Topics/Fractals and L-Systems/PenroseTile/PenroseTile.pde @@ -1,6 +1,6 @@ /** * Penrose Tile L-System - * by Geraldine Sarmiento (NYU ITP). + * by Geraldine Sarmiento. * * This code was based on Patrick Dwyer's L-System class. */ diff --git a/java/examples/Topics/Fractals and L-Systems/Pentigree/Pentigree.pde b/java/examples/Topics/Fractals and L-Systems/Pentigree/Pentigree.pde index be0d3fb77..0ce44d156 100644 --- a/java/examples/Topics/Fractals and L-Systems/Pentigree/Pentigree.pde +++ b/java/examples/Topics/Fractals and L-Systems/Pentigree/Pentigree.pde @@ -1,10 +1,10 @@ /** * Pentigree L-System - * by Geraldine Sarmiento (NYU ITP). + * by Geraldine Sarmiento. * * This code was based on Patrick Dwyer's L-System class. */ - + PentigreeLSystem ps; @@ -20,4 +20,3 @@ void draw() { ps.render(); } - diff --git a/java/examples/Topics/GUI/Buttons/Buttons.pde b/java/examples/Topics/GUI/Buttons/Buttons.pde deleted file mode 100644 index f060e4d39..000000000 --- a/java/examples/Topics/GUI/Buttons/Buttons.pde +++ /dev/null @@ -1,220 +0,0 @@ -/** - * Buttons. - * - * Click on one of the shapes to change - * the background color. This example - * demonstates a class for buttons. - */ - -color currentcolor; - -CircleButton circle1, circle2, circle3; -RectButton rect1, rect2; - -boolean locked = false; - -void setup() -{ - size(640, 360); - smooth(); - - color baseColor = color(102); - currentcolor = baseColor; - - // Define and create circle button - color buttoncolor = color(204); - color highlight = color(153); - ellipseMode(CENTER); - circle1 = new CircleButton(30, 100, 100, buttoncolor, highlight); - - // Define and create circle button - buttoncolor = color(204); - highlight = color(153); - circle2 = new CircleButton(130, 110, 24, buttoncolor, highlight); - - // Define and create circle button - buttoncolor = color(153); - highlight = color(102); - circle3 = new CircleButton(130, 140, 24, buttoncolor, highlight); - - // Define and create rectangle button - buttoncolor = color(102); - highlight = color(51); - rect1 = new RectButton(150, 20, 100, buttoncolor, highlight); - - // Define and create rectangle button - buttoncolor = color(51); - highlight = color(0); - rect2 = new RectButton(90, 20, 50, buttoncolor, highlight); -} - -void draw() -{ - background(currentcolor); - stroke(255); - update(mouseX, mouseY); - circle1.display(); - circle2.display(); - circle3.display(); - rect1.display(); - rect2.display(); -} - -void update(int x, int y) -{ - if(locked == false) { - circle1.update(); - circle2.update(); - circle3.update(); - rect1.update(); - rect2.update(); - } - else { - locked = false; - } - - if(mousePressed) { - if(circle1.pressed()) { - currentcolor = circle1.basecolor; - } - else if(circle2.pressed()) { - currentcolor = circle2.basecolor; - } - else if(circle3.pressed()) { - currentcolor = circle3.basecolor; - } - else if(rect1.pressed()) { - currentcolor = rect1.basecolor; - } - else if(rect2.pressed()) { - currentcolor = rect2.basecolor; - } - } -} - - -class Button -{ - int x, y; - int size; - color basecolor, highlightcolor; - color currentcolor; - boolean over = false; - boolean pressed = false; - - void update() - { - if(over()) { - currentcolor = highlightcolor; - } - else { - currentcolor = basecolor; - } - } - - boolean pressed() - { - if(over) { - locked = true; - return true; - } - else { - locked = false; - return false; - } - } - - boolean over() - { - return true; - } - - boolean overRect(int x, int y, int width, int height) - { - if (mouseX >= x && mouseX <= x+width && - mouseY >= y && mouseY <= y+height) { - return true; - } - else { - return false; - } - } - - boolean overCircle(int x, int y, int diameter) - { - float disX = x - mouseX; - float disY = y - mouseY; - if(sqrt(sq(disX) + sq(disY)) < diameter/2 ) { - return true; - } - else { - return false; - } - } - -} - -class CircleButton extends Button -{ - CircleButton(int ix, int iy, int isize, color icolor, color ihighlight) - { - x = ix; - y = iy; - size = isize; - basecolor = icolor; - highlightcolor = ihighlight; - currentcolor = basecolor; - } - - boolean over() - { - if( overCircle(x, y, size) ) { - over = true; - return true; - } - else { - over = false; - return false; - } - } - - void display() - { - stroke(255); - fill(currentcolor); - ellipse(x, y, size, size); - } -} - -class RectButton extends Button -{ - RectButton(int ix, int iy, int isize, color icolor, color ihighlight) - { - x = ix; - y = iy; - size = isize; - basecolor = icolor; - highlightcolor = ihighlight; - currentcolor = basecolor; - } - - boolean over() - { - if( overRect(x, y, size, size) ) { - over = true; - return true; - } - else { - over = false; - return false; - } - } - - void display() - { - stroke(255); - fill(currentcolor); - rect(x, y, size, size); - } -} - diff --git a/java/examples/Topics/GUI/Handles/Handles.pde b/java/examples/Topics/GUI/Handles/Handles.pde index 962f5f995..2a6d5f387 100644 --- a/java/examples/Topics/GUI/Handles/Handles.pde +++ b/java/examples/Topics/GUI/Handles/Handles.pde @@ -31,7 +31,7 @@ void draw() { void mouseReleased() { for(int i=0; i xpos && mouseX < xpos+swidth && mouseY > ypos && mouseY < ypos+sheight) { return true; @@ -101,10 +101,10 @@ class HScrollbar { } void display() { - fill(255); + fill(204); rect(xpos, ypos, swidth, sheight); if(over || locked) { - fill(153, 102, 0); + fill(0, 0, 0); } else { fill(102, 102, 102); } diff --git a/java/examples/Topics/Interaction/Follow1/Follow1.pde b/java/examples/Topics/Interaction/Follow1/Follow1.pde index f817d0f64..4ff2e5023 100644 --- a/java/examples/Topics/Interaction/Follow1/Follow1.pde +++ b/java/examples/Topics/Interaction/Follow1/Follow1.pde @@ -11,14 +11,14 @@ float angle1 = 0.0; float segLength = 50; void setup() { - size(200, 200); + size(640, 360); smooth(); strokeWeight(20.0); - stroke(0, 100); + stroke(255, 100); } void draw() { - background(226); + background(0); float dx = mouseX - x; float dy = mouseY - y; diff --git a/java/examples/Topics/Interaction/Follow2/Follow2.pde b/java/examples/Topics/Interaction/Follow2/Follow2.pde index a0a6f8516..711bd3e20 100644 --- a/java/examples/Topics/Interaction/Follow2/Follow2.pde +++ b/java/examples/Topics/Interaction/Follow2/Follow2.pde @@ -12,14 +12,14 @@ float[] y = new float[2]; float segLength = 50; void setup() { - size(200, 200); + size(640, 360); smooth(); strokeWeight(20.0); - stroke(0, 100); + stroke(255, 100); } void draw() { - background(226); + background(0); dragSegment(0, mouseX, mouseY); dragSegment(1, x[0], y[0]); } diff --git a/java/examples/Topics/Interaction/Follow3/Follow3.pde b/java/examples/Topics/Interaction/Follow3/Follow3.pde index 1a004ccc3..24fd44c5b 100644 --- a/java/examples/Topics/Interaction/Follow3/Follow3.pde +++ b/java/examples/Topics/Interaction/Follow3/Follow3.pde @@ -9,17 +9,17 @@ float[] x = new float[20]; float[] y = new float[20]; -float segLength = 9; +float segLength = 18; void setup() { - size(200, 200); + size(640, 360); smooth(); - strokeWeight(5); - stroke(0, 100); + strokeWeight(9); + stroke(255, 100); } void draw() { - background(226); + background(0); dragSegment(0, mouseX, mouseY); for(int i=0; i 0) { @@ -73,7 +73,7 @@ class Boid { if ((slowdown) && (d < 100.0)) desired.mult(maxspeed*(d/100.0)); // This damping is somewhat arbitrary else desired.mult(maxspeed); // Steering = Desired minus Velocity - steer = target.sub(desired,vel); + steer = PVector.sub(desired,vel); steer.limit(maxforce); // Limit to maximum steering force } else { diff --git a/java/examples/Topics/Simulate/SmokeParticleSystem/SmokeParticleSystem.pde b/java/examples/Topics/Simulate/SmokeParticleSystem/SmokeParticleSystem.pde index 98cb16da9..c499d83b0 100644 --- a/java/examples/Topics/Simulate/SmokeParticleSystem/SmokeParticleSystem.pde +++ b/java/examples/Topics/Simulate/SmokeParticleSystem/SmokeParticleSystem.pde @@ -11,7 +11,7 @@ Random generator; void setup() { - size(640, 200); + size(640, 360); colorMode(RGB, 255, 255, 255, 100); // Using a Java random number generator for Gaussian random numbers diff --git a/java/examples/Topics/Simulate/Spring/Spring.pde b/java/examples/Topics/Simulate/Spring/Spring.pde index e36286bd9..1310faae7 100644 --- a/java/examples/Topics/Simulate/Spring/Spring.pde +++ b/java/examples/Topics/Simulate/Spring/Spring.pde @@ -5,47 +5,47 @@ */ // Spring drawing constants for top bar -int s_height = 16; // Height -int left = 50; // Left position -int right = 150; // Right position -int max = 100; // Maximum Y value -int min = 20; // Minimum Y value -boolean over = false; // If mouse over -boolean move = false; // If mouse down and over +int springHeight = 16; // Height +int left; // Left position +int right; // Right position +int max = 200; // Maximum Y value +int min = 100; // Minimum Y value +boolean over = false; // If mouse over +boolean move = false; // If mouse down and over // Spring simulation constants float M = 0.8; // Mass float K = 0.2; // Spring constant float D = 0.92; // Damping -float R = 60; // Rest position +float R = 150; // Rest position // Spring simulation variables -float ps = 60.0; // Position +float ps = R; // Position float vs = 0.0; // Velocity float as = 0; // Acceleration float f = 0; // Force -void setup() -{ - size(200, 200); +void setup() { + size(640, 360); rectMode(CORNERS); noStroke(); + left = width/2 - 100; + right = width/2 + 100; } -void draw() -{ +void draw() { background(102); updateSpring(); drawSpring(); } -void drawSpring() -{ +void drawSpring() { + // Draw base fill(0.2); - float b_width = 0.5 * ps + -8; - rect(width/2 - b_width, ps + s_height, width/2 + b_width, 150); + float baseWidth = 0.5 * ps + -8; + rect(width/2 - baseWidth, ps + springHeight, width/2 + baseWidth, height); // Set color and draw top bar if(over || move) { @@ -53,12 +53,11 @@ void drawSpring() } else { fill(204); } - rect(left, ps, right, ps + s_height); + rect(left, ps, right, ps + springHeight); } -void updateSpring() -{ +void updateSpring() { // Update the spring position if(!move) { f = -K * (ps - R); // f=-ky @@ -71,7 +70,7 @@ void updateSpring() } // Test if mouse is over the top bar - if(mouseX > left && mouseX < right && mouseY > ps && mouseY < ps + s_height) { + if(mouseX > left && mouseX < right && mouseY > ps && mouseY < ps + springHeight) { over = true; } else { over = false; @@ -79,9 +78,8 @@ void updateSpring() // Set and constrain the position of top bar if(move) { - ps = mouseY - s_height/2; - if (ps < min) { ps = min; } - if (ps > max) { ps = max; } + ps = mouseY - springHeight/2; + ps = constrain(ps, min, max); } } @@ -91,7 +89,6 @@ void mousePressed() { } } -void mouseReleased() -{ +void mouseReleased() { move = false; } diff --git a/java/examples/Topics/Simulate/Springs/Springs.pde b/java/examples/Topics/Simulate/Springs/Springs.pde index c615d4819..7b638ba27 100644 --- a/java/examples/Topics/Simulate/Springs/Springs.pde +++ b/java/examples/Topics/Simulate/Springs/Springs.pde @@ -12,12 +12,12 @@ Spring[] springs = new Spring[num]; void setup() { - size(200, 200); + size(640, 360); noStroke(); smooth(); - springs[0] = new Spring( 70, 160, 20, 0.98, 8.0, 0.1, springs, 0); - springs[1] = new Spring(150, 110, 60, 0.95, 9.0, 0.1, springs, 1); - springs[2] = new Spring( 40, 70, 120, 0.90, 9.9, 0.1, springs, 2); + springs[0] = new Spring(240, 260, 40, 0.98, 8.0, 0.1, springs, 0); + springs[1] = new Spring(320, 210, 120, 0.95, 9.0, 0.1, springs, 1); + springs[2] = new Spring(180, 170, 200, 0.90, 9.9, 0.1, springs, 2); } void draw() @@ -104,7 +104,7 @@ class Spring tempxpos = tempxpos + velx; // Updated position - if ((over() || move) && !otherOver() ) { + if ((overEvent() || move) && !otherOver() ) { over = true; } else { over = false; @@ -112,7 +112,7 @@ class Spring } // Test to see if mouse is over this spring - boolean over() { + boolean overEvent() { float disX = tempxpos - mouseX; float disY = tempypos - mouseY; if (sqrt(sq(disX) + sq(disY)) < size/2 ) {