mirror of
https://github.com/processing/processing4.git
synced 2026-06-16 04:26:26 +02:00
Updated PShape android examples to use the latest API
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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<Polygon>();
|
||||
@@ -49,4 +50,4 @@ void draw() {
|
||||
poly.move();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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<Polygon>();
|
||||
@@ -60,4 +60,4 @@ void draw() {
|
||||
poly.move();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user