From f39e24e4f8f87c572ac5aae5b3205d8fcca87798 Mon Sep 17 00:00:00 2001 From: codeanticode Date: Wed, 13 Feb 2013 11:13:43 -0500 Subject: [PATCH] Updated PShape android examples to use the latest API --- .../BeginEndContour/BeginEndContour.pde | 9 +++------ .../Create Shapes/GroupPShape/GroupPShape.pde | 15 +++++++------- .../ParticleSystemPShape/Particle.pde | 7 ++++--- .../Create Shapes/PathPShape/PathPShape.pde | 5 +++-- .../PolygonPShape/PolygonPShape.pde | 5 +++-- .../PolygonPShapeOOP/PolygonPShapeOOP.pde | 18 ++++++++++------- .../Create Shapes/PolygonPShapeOOP/Star.pde | 16 ++++++++------- .../PolygonPShapeOOP2/PolygonPShapeOOP2.pde | 9 +++++---- .../PolygonPShapeOOP3/PolygonPShapeOOP3.pde | 20 +++++++++---------- .../PrimitivePShape/PrimitivePShape.pde | 9 ++++----- .../Create Shapes/WigglePShape/Wiggler.pde | 3 ++- 11 files changed, 62 insertions(+), 54 deletions(-) diff --git a/android/examples/Topics/Create Shapes/BeginEndContour/BeginEndContour.pde b/android/examples/Topics/Create Shapes/BeginEndContour/BeginEndContour.pde index 71a2b5801..2769397e1 100644 --- a/android/examples/Topics/Create Shapes/BeginEndContour/BeginEndContour.pde +++ b/android/examples/Topics/Create Shapes/BeginEndContour/BeginEndContour.pde @@ -12,17 +12,15 @@ void setup() { smooth(); // Make a shape s = createShape(); + s.beginShape(); s.fill(0); s.stroke(255); s.strokeWeight(2); // Exterior part of shape - s.beginContour(); s.vertex(-100,-100); s.vertex(100,-100); s.vertex(100,100); s.vertex(-100,100); - s.vertex(-100,-100); - s.endContour(); // Interior part of shape s.beginContour(); @@ -30,11 +28,10 @@ void setup() { s.vertex(10,-10); s.vertex(10,10); s.vertex(-10,10); - s.vertex(-10,-10); s.endContour(); // Finishing off shape - s.end(); + s.endShape(CLOSE); } void draw() { @@ -45,4 +42,4 @@ void draw() { s.rotate(0.01); shape(s); } - + diff --git a/android/examples/Topics/Create Shapes/GroupPShape/GroupPShape.pde b/android/examples/Topics/Create Shapes/GroupPShape/GroupPShape.pde index aa9133564..96f86b495 100644 --- a/android/examples/Topics/Create Shapes/GroupPShape/GroupPShape.pde +++ b/android/examples/Topics/Create Shapes/GroupPShape/GroupPShape.pde @@ -17,6 +17,7 @@ void setup() { // Make a polygon PShape PShape star = createShape(); + star.beginShape(); star.noFill(); star.stroke(255); star.vertex(0, -50); @@ -29,29 +30,29 @@ void setup() { star.vertex(-23, 7); star.vertex(-47, -15); star.vertex(-14, -20); - star.end(CLOSE); + star.endShape(CLOSE); // Make a path PShape PShape path = createShape(); - path = createShape(); + path.beginShape(); path.noFill(); path.stroke(255); for (float a = -PI; a < 0; a += 0.1) { float r = random(60, 70); path.vertex(r*cos(a), r*sin(a)); } - path.end(); + path.endShape(); // Make a primitive (Rectangle) PShape PShape rectangle = createShape(RECT,-10,-10,20,20); - rectangle.noFill(); - rectangle.stroke(255); + rectangle.setFill(false); + rectangle.setStroke(255); // Add them all to the group group.addChild(star); group.addChild(path); group.addChild(rectangle); // Rectangle is missing??? - + } void draw() { @@ -66,4 +67,4 @@ void draw() { translate(mouseX, mouseY); shape(group); } - + diff --git a/android/examples/Topics/Create Shapes/ParticleSystemPShape/Particle.pde b/android/examples/Topics/Create Shapes/ParticleSystemPShape/Particle.pde index 6034e52bb..ccccb6509 100644 --- a/android/examples/Topics/Create Shapes/ParticleSystemPShape/Particle.pde +++ b/android/examples/Topics/Create Shapes/ParticleSystemPShape/Particle.pde @@ -19,7 +19,8 @@ class Particle { Particle() { partSize = random(10, 60); // The particle is a textured quad - part = createShape(QUAD); + part = createShape(); + part.beginShape(QUAD); part.noStroke(); part.texture(sprite); part.normal(0, 0, 1); @@ -27,7 +28,7 @@ class Particle { part.vertex(+partSize/2, -partSize/2, sprite.width, 0); part.vertex(+partSize/2, +partSize/2, sprite.width, sprite.height); part.vertex(-partSize/2, +partSize/2, 0, sprite.height); - part.end(); + part.endShape(); // Initialize center vector center = new PVector(); @@ -72,7 +73,7 @@ class Particle { lifespan = lifespan - 1; // Apply gravity velocity.add(gravity); - part.tint(255, lifespan); + part.setTint(color(255, lifespan)); // Move the particle according to its velocity part.translate(velocity.x, velocity.y); // and also update the center diff --git a/android/examples/Topics/Create Shapes/PathPShape/PathPShape.pde b/android/examples/Topics/Create Shapes/PathPShape/PathPShape.pde index becab8e4c..7d650624e 100644 --- a/android/examples/Topics/Create Shapes/PathPShape/PathPShape.pde +++ b/android/examples/Topics/Create Shapes/PathPShape/PathPShape.pde @@ -12,6 +12,7 @@ void setup() { orientation(LANDSCAPE); // Create the shape path = createShape(); + path.beginShape(); // Set fill and stroke path.noFill(); path.stroke(255); @@ -24,7 +25,7 @@ void setup() { x+= 5; } // The path is complete - path.end(); + path.endShape(); } @@ -34,4 +35,4 @@ void draw() { translate(mouseX, mouseY); shape(path); } - + diff --git a/android/examples/Topics/Create Shapes/PolygonPShape/PolygonPShape.pde b/android/examples/Topics/Create Shapes/PolygonPShape/PolygonPShape.pde index c4c67340f..cb0b0aba2 100644 --- a/android/examples/Topics/Create Shapes/PolygonPShape/PolygonPShape.pde +++ b/android/examples/Topics/Create Shapes/PolygonPShape/PolygonPShape.pde @@ -13,6 +13,7 @@ void setup() { orientation(LANDSCAPE); // First create the shape star = createShape(); + star.beginShape(); // You can set fill and stroke star.fill(102); star.stroke(255); @@ -28,7 +29,7 @@ void setup() { star.vertex(-23, 7); star.vertex(-47, -15); star.vertex(-14, -20); - star.end(CLOSE); + star.endShape(CLOSE); } void draw() { @@ -38,4 +39,4 @@ void draw() { // Display the shape shape(star); } - + diff --git a/android/examples/Topics/Create Shapes/PolygonPShapeOOP/PolygonPShapeOOP.pde b/android/examples/Topics/Create Shapes/PolygonPShapeOOP/PolygonPShapeOOP.pde index e20dd90fd..4f040adc2 100644 --- a/android/examples/Topics/Create Shapes/PolygonPShapeOOP/PolygonPShapeOOP.pde +++ b/android/examples/Topics/Create Shapes/PolygonPShapeOOP/PolygonPShapeOOP.pde @@ -6,21 +6,25 @@ // A Star object -Star s; +Star s1, s2; void setup() { size(640, 360, P2D); orientation(LANDSCAPE); // Make a new Star - s = new Star(); + s1 = new Star(); + s2 = new Star(); } void draw() { background(51); - // Display the star - s.display(); - // Move the star - s.move(); + + s1.display(); // Display the first star + s1.move(); // Move the first star + + s2.display(); // Display the second star + s2.move(); // Move the second star + } - + diff --git a/android/examples/Topics/Create Shapes/PolygonPShapeOOP/Star.pde b/android/examples/Topics/Create Shapes/PolygonPShapeOOP/Star.pde index 9899910d1..d75d445eb 100644 --- a/android/examples/Topics/Create Shapes/PolygonPShapeOOP/Star.pde +++ b/android/examples/Topics/Create Shapes/PolygonPShapeOOP/Star.pde @@ -6,16 +6,18 @@ class Star { PShape s; // The location where we will draw the shape float x, y; + float speed; Star() { - x = 0; - y = height/2; + x = random(100, width-100); + y = random(100, height-100); + speed = random(0.5, 3); // First create the shape s = createShape(); + s.beginShape(); // You can set fill and stroke - s.fill(102); - s.stroke(255); - s.strokeWeight(2); + s.fill(255, 204); + s.noStroke(); // Here, we are hardcoding a series of vertices s.vertex(0, -50); s.vertex(14, -20); @@ -28,12 +30,12 @@ class Star { s.vertex(-47, -15); s.vertex(-14, -20); // The shape is complete - s.end(CLOSE); + s.endShape(CLOSE); } void move() { // Demonstrating some simple motion - x++; + x += speed; if (x > width+100) { x = -100; } diff --git a/android/examples/Topics/Create Shapes/PolygonPShapeOOP2/PolygonPShapeOOP2.pde b/android/examples/Topics/Create Shapes/PolygonPShapeOOP2/PolygonPShapeOOP2.pde index 6d8cb7ed5..b5223310f 100644 --- a/android/examples/Topics/Create Shapes/PolygonPShapeOOP2/PolygonPShapeOOP2.pde +++ b/android/examples/Topics/Create Shapes/PolygonPShapeOOP2/PolygonPShapeOOP2.pde @@ -15,8 +15,9 @@ void setup() { orientation(LANDSCAPE); // Make a PShape PShape star = createShape(); - star.fill(0,127); - star.stroke(0); + star.beginShape(); + star.noStroke(); + star.fill(0, 127); star.vertex(0, -50); star.vertex(14, -20); star.vertex(47, -15); @@ -27,7 +28,7 @@ void setup() { star.vertex(-23, 7); star.vertex(-47, -15); star.vertex(-14, -20); - star.end(CLOSE); + star.endShape(CLOSE); // Make an ArrayList polygons = new ArrayList(); @@ -49,4 +50,4 @@ void draw() { poly.move(); } } - + diff --git a/android/examples/Topics/Create Shapes/PolygonPShapeOOP3/PolygonPShapeOOP3.pde b/android/examples/Topics/Create Shapes/PolygonPShapeOOP3/PolygonPShapeOOP3.pde index 7a5c87bb3..5ea6acec1 100644 --- a/android/examples/Topics/Create Shapes/PolygonPShapeOOP3/PolygonPShapeOOP3.pde +++ b/android/examples/Topics/Create Shapes/PolygonPShapeOOP3/PolygonPShapeOOP3.pde @@ -18,14 +18,15 @@ void setup() { orientation(LANDSCAPE); shapes[0] = createShape(ELLIPSE,0,0,100,100); - shapes[0].fill(255,127); - shapes[0].stroke(0); + shapes[0].setFill(color(255, 127)); + shapes[0].setStroke(false); shapes[1] = createShape(RECT,0,0,100,100); - shapes[1].fill(255,127); - shapes[1].stroke(0); - shapes[2] = createShape(); - shapes[2].fill(0,127); - shapes[2].stroke(0); + shapes[1].setFill(color(255, 127)); + shapes[1].setStroke(false); + shapes[2] = createShape(); + shapes[2].beginShape(); + shapes[2].fill(0, 127); + shapes[2].noStroke(); shapes[2].vertex(0, -50); shapes[2].vertex(14, -20); shapes[2].vertex(47, -15); @@ -36,8 +37,7 @@ void setup() { shapes[2].vertex(-23, 7); shapes[2].vertex(-47, -15); shapes[2].vertex(-14, -20); - shapes[2].end(CLOSE); - + shapes[2].endShape(CLOSE); // Make an ArrayList polygons = new ArrayList(); @@ -60,4 +60,4 @@ void draw() { poly.move(); } } - + diff --git a/android/examples/Topics/Create Shapes/PrimitivePShape/PrimitivePShape.pde b/android/examples/Topics/Create Shapes/PrimitivePShape/PrimitivePShape.pde index c0b3f6091..0aa9f9610 100644 --- a/android/examples/Topics/Create Shapes/PrimitivePShape/PrimitivePShape.pde +++ b/android/examples/Topics/Create Shapes/PrimitivePShape/PrimitivePShape.pde @@ -13,18 +13,17 @@ void setup() { orientation(LANDSCAPE); // Creating the PShape as an ellipse // The corner is -50,-50 so that the center is at 0,0 - circle = createShape(RECT, -50, -25, 100, 50); + circle = createShape(ELLIPSE, -50, -25, 100, 50); } void draw() { background(51); // We can dynamically set the stroke and fill of the shape - circle.stroke(255); - circle.strokeWeight(4); - circle.fill(map(mouseX, 0, width, 0, 255)); + circle.setStroke(color(255)); + circle.setStrokeWeight(4); + circle.setFill(color(map(mouseX, 0, width, 0, 255))); // We can use translate to move the PShape translate(mouseX, mouseY); // Drawing the PShape shape(circle); } - diff --git a/android/examples/Topics/Create Shapes/WigglePShape/Wiggler.pde b/android/examples/Topics/Create Shapes/WigglePShape/Wiggler.pde index bb601dccd..be4d7981f 100644 --- a/android/examples/Topics/Create Shapes/WigglePShape/Wiggler.pde +++ b/android/examples/Topics/Create Shapes/WigglePShape/Wiggler.pde @@ -28,13 +28,14 @@ class Wiggler { // Now make the PShape with those vertices s = createShape(); + s.beginShape(); s.fill(127); s.stroke(0); s.strokeWeight(2); for (PVector v : original) { s.vertex(v.x, v.y); } - s.end(CLOSE); + s.endShape(CLOSE); } void wiggle() {