Skip to content
This repository was archived by the owner on May 11, 2025. It is now read-only.

Commit a7ca5b7

Browse files
committed
Updated PShape android examples to use the latest API
1 parent 50c5947 commit a7ca5b7

11 files changed

Lines changed: 62 additions & 54 deletions

File tree

examples/Topics/Create Shapes/BeginEndContour/BeginEndContour.pde

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,29 +12,26 @@ void setup() {
1212
smooth();
1313
// Make a shape
1414
s = createShape();
15+
s.beginShape();
1516
s.fill(0);
1617
s.stroke(255);
1718
s.strokeWeight(2);
1819
// Exterior part of shape
19-
s.beginContour();
2020
s.vertex(-100,-100);
2121
s.vertex(100,-100);
2222
s.vertex(100,100);
2323
s.vertex(-100,100);
24-
s.vertex(-100,-100);
25-
s.endContour();
2624

2725
// Interior part of shape
2826
s.beginContour();
2927
s.vertex(-10,-10);
3028
s.vertex(10,-10);
3129
s.vertex(10,10);
3230
s.vertex(-10,10);
33-
s.vertex(-10,-10);
3431
s.endContour();
3532

3633
// Finishing off shape
37-
s.end();
34+
s.endShape(CLOSE);
3835
}
3936

4037
void draw() {
@@ -45,4 +42,4 @@ void draw() {
4542
s.rotate(0.01);
4643
shape(s);
4744
}
48-
45+

examples/Topics/Create Shapes/GroupPShape/GroupPShape.pde

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ void setup() {
1717

1818
// Make a polygon PShape
1919
PShape star = createShape();
20+
star.beginShape();
2021
star.noFill();
2122
star.stroke(255);
2223
star.vertex(0, -50);
@@ -29,29 +30,29 @@ void setup() {
2930
star.vertex(-23, 7);
3031
star.vertex(-47, -15);
3132
star.vertex(-14, -20);
32-
star.end(CLOSE);
33+
star.endShape(CLOSE);
3334

3435
// Make a path PShape
3536
PShape path = createShape();
36-
path = createShape();
37+
path.beginShape();
3738
path.noFill();
3839
path.stroke(255);
3940
for (float a = -PI; a < 0; a += 0.1) {
4041
float r = random(60, 70);
4142
path.vertex(r*cos(a), r*sin(a));
4243
}
43-
path.end();
44+
path.endShape();
4445

4546
// Make a primitive (Rectangle) PShape
4647
PShape rectangle = createShape(RECT,-10,-10,20,20);
47-
rectangle.noFill();
48-
rectangle.stroke(255);
48+
rectangle.setFill(false);
49+
rectangle.setStroke(255);
4950

5051
// Add them all to the group
5152
group.addChild(star);
5253
group.addChild(path);
5354
group.addChild(rectangle); // Rectangle is missing???
54-
55+
5556
}
5657

5758
void draw() {
@@ -66,4 +67,4 @@ void draw() {
6667
translate(mouseX, mouseY);
6768
shape(group);
6869
}
69-
70+

examples/Topics/Create Shapes/ParticleSystemPShape/Particle.pde

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,16 @@ class Particle {
1919
Particle() {
2020
partSize = random(10, 60);
2121
// The particle is a textured quad
22-
part = createShape(QUAD);
22+
part = createShape();
23+
part.beginShape(QUAD);
2324
part.noStroke();
2425
part.texture(sprite);
2526
part.normal(0, 0, 1);
2627
part.vertex(-partSize/2, -partSize/2, 0, 0);
2728
part.vertex(+partSize/2, -partSize/2, sprite.width, 0);
2829
part.vertex(+partSize/2, +partSize/2, sprite.width, sprite.height);
2930
part.vertex(-partSize/2, +partSize/2, 0, sprite.height);
30-
part.end();
31+
part.endShape();
3132

3233
// Initialize center vector
3334
center = new PVector();
@@ -72,7 +73,7 @@ class Particle {
7273
lifespan = lifespan - 1;
7374
// Apply gravity
7475
velocity.add(gravity);
75-
part.tint(255, lifespan);
76+
part.setTint(color(255, lifespan));
7677
// Move the particle according to its velocity
7778
part.translate(velocity.x, velocity.y);
7879
// and also update the center

examples/Topics/Create Shapes/PathPShape/PathPShape.pde

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ void setup() {
1212
orientation(LANDSCAPE);
1313
// Create the shape
1414
path = createShape();
15+
path.beginShape();
1516
// Set fill and stroke
1617
path.noFill();
1718
path.stroke(255);
@@ -24,7 +25,7 @@ void setup() {
2425
x+= 5;
2526
}
2627
// The path is complete
27-
path.end();
28+
path.endShape();
2829

2930
}
3031

@@ -34,4 +35,4 @@ void draw() {
3435
translate(mouseX, mouseY);
3536
shape(path);
3637
}
37-
38+

examples/Topics/Create Shapes/PolygonPShape/PolygonPShape.pde

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ void setup() {
1313
orientation(LANDSCAPE);
1414
// First create the shape
1515
star = createShape();
16+
star.beginShape();
1617
// You can set fill and stroke
1718
star.fill(102);
1819
star.stroke(255);
@@ -28,7 +29,7 @@ void setup() {
2829
star.vertex(-23, 7);
2930
star.vertex(-47, -15);
3031
star.vertex(-14, -20);
31-
star.end(CLOSE);
32+
star.endShape(CLOSE);
3233
}
3334

3435
void draw() {
@@ -38,4 +39,4 @@ void draw() {
3839
// Display the shape
3940
shape(star);
4041
}
41-
42+

examples/Topics/Create Shapes/PolygonPShapeOOP/PolygonPShapeOOP.pde

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,25 @@
66

77

88
// A Star object
9-
Star s;
9+
Star s1, s2;
1010

1111
void setup() {
1212
size(640, 360, P2D);
1313
orientation(LANDSCAPE);
1414
// Make a new Star
15-
s = new Star();
15+
s1 = new Star();
16+
s2 = new Star();
1617

1718
}
1819

1920
void draw() {
2021
background(51);
21-
// Display the star
22-
s.display();
23-
// Move the star
24-
s.move();
22+
23+
s1.display(); // Display the first star
24+
s1.move(); // Move the first star
25+
26+
s2.display(); // Display the second star
27+
s2.move(); // Move the second star
28+
2529
}
26-
30+

examples/Topics/Create Shapes/PolygonPShapeOOP/Star.pde

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,18 @@ class Star {
66
PShape s;
77
// The location where we will draw the shape
88
float x, y;
9+
float speed;
910

1011
Star() {
11-
x = 0;
12-
y = height/2;
12+
x = random(100, width-100);
13+
y = random(100, height-100);
14+
speed = random(0.5, 3);
1315
// First create the shape
1416
s = createShape();
17+
s.beginShape();
1518
// You can set fill and stroke
16-
s.fill(102);
17-
s.stroke(255);
18-
s.strokeWeight(2);
19+
s.fill(255, 204);
20+
s.noStroke();
1921
// Here, we are hardcoding a series of vertices
2022
s.vertex(0, -50);
2123
s.vertex(14, -20);
@@ -28,12 +30,12 @@ class Star {
2830
s.vertex(-47, -15);
2931
s.vertex(-14, -20);
3032
// The shape is complete
31-
s.end(CLOSE);
33+
s.endShape(CLOSE);
3234
}
3335

3436
void move() {
3537
// Demonstrating some simple motion
36-
x++;
38+
x += speed;
3739
if (x > width+100) {
3840
x = -100;
3941
}

examples/Topics/Create Shapes/PolygonPShapeOOP2/PolygonPShapeOOP2.pde

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ void setup() {
1515
orientation(LANDSCAPE);
1616
// Make a PShape
1717
PShape star = createShape();
18-
star.fill(0,127);
19-
star.stroke(0);
18+
star.beginShape();
19+
star.noStroke();
20+
star.fill(0, 127);
2021
star.vertex(0, -50);
2122
star.vertex(14, -20);
2223
star.vertex(47, -15);
@@ -27,7 +28,7 @@ void setup() {
2728
star.vertex(-23, 7);
2829
star.vertex(-47, -15);
2930
star.vertex(-14, -20);
30-
star.end(CLOSE);
31+
star.endShape(CLOSE);
3132

3233
// Make an ArrayList
3334
polygons = new ArrayList<Polygon>();
@@ -49,4 +50,4 @@ void draw() {
4950
poly.move();
5051
}
5152
}
52-
53+

examples/Topics/Create Shapes/PolygonPShapeOOP3/PolygonPShapeOOP3.pde

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,15 @@ void setup() {
1818
orientation(LANDSCAPE);
1919

2020
shapes[0] = createShape(ELLIPSE,0,0,100,100);
21-
shapes[0].fill(255,127);
22-
shapes[0].stroke(0);
21+
shapes[0].setFill(color(255, 127));
22+
shapes[0].setStroke(false);
2323
shapes[1] = createShape(RECT,0,0,100,100);
24-
shapes[1].fill(255,127);
25-
shapes[1].stroke(0);
26-
shapes[2] = createShape();
27-
shapes[2].fill(0,127);
28-
shapes[2].stroke(0);
24+
shapes[1].setFill(color(255, 127));
25+
shapes[1].setStroke(false);
26+
shapes[2] = createShape();
27+
shapes[2].beginShape();
28+
shapes[2].fill(0, 127);
29+
shapes[2].noStroke();
2930
shapes[2].vertex(0, -50);
3031
shapes[2].vertex(14, -20);
3132
shapes[2].vertex(47, -15);
@@ -36,8 +37,7 @@ void setup() {
3637
shapes[2].vertex(-23, 7);
3738
shapes[2].vertex(-47, -15);
3839
shapes[2].vertex(-14, -20);
39-
shapes[2].end(CLOSE);
40-
40+
shapes[2].endShape(CLOSE);
4141

4242
// Make an ArrayList
4343
polygons = new ArrayList<Polygon>();
@@ -60,4 +60,4 @@ void draw() {
6060
poly.move();
6161
}
6262
}
63-
63+

examples/Topics/Create Shapes/PrimitivePShape/PrimitivePShape.pde

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,17 @@ void setup() {
1313
orientation(LANDSCAPE);
1414
// Creating the PShape as an ellipse
1515
// The corner is -50,-50 so that the center is at 0,0
16-
circle = createShape(RECT, -50, -25, 100, 50);
16+
circle = createShape(ELLIPSE, -50, -25, 100, 50);
1717
}
1818

1919
void draw() {
2020
background(51);
2121
// We can dynamically set the stroke and fill of the shape
22-
circle.stroke(255);
23-
circle.strokeWeight(4);
24-
circle.fill(map(mouseX, 0, width, 0, 255));
22+
circle.setStroke(color(255));
23+
circle.setStrokeWeight(4);
24+
circle.setFill(color(map(mouseX, 0, width, 0, 255)));
2525
// We can use translate to move the PShape
2626
translate(mouseX, mouseY);
2727
// Drawing the PShape
2828
shape(circle);
2929
}
30-

0 commit comments

Comments
 (0)