Initial Commit

This commit is contained in:
plane000
2018-04-20 10:15:15 +01:00
parent 49150ccfe4
commit 62101e8e61
2870 changed files with 520122 additions and 0 deletions

View File

@@ -0,0 +1,30 @@
/**
* PolygonPShapeOOP.
*
* Wrapping a PShape inside a custom class
*/
// A Star object
Star s1, s2;
void setup() {
size(640, 360, P2D);
// Make a new Star
s1 = new Star();
s2 = new Star();
}
void draw() {
background(51);
s1.display(); // Display the first star
s1.move(); // Move the first star
s2.display(); // Display the second star
s2.move(); // Move the second star
}

View File

@@ -0,0 +1,52 @@
// A class to describe a Star shape
class Star {
// The PShape object
PShape s;
// The location where we will draw the shape
float x, y;
float speed;
Star() {
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(255, 204);
s.noStroke();
// Here, we are hardcoding a series of vertices
s.vertex(0, -50);
s.vertex(14, -20);
s.vertex(47, -15);
s.vertex(23, 7);
s.vertex(29, 40);
s.vertex(0, 25);
s.vertex(-29, 40);
s.vertex(-23, 7);
s.vertex(-47, -15);
s.vertex(-14, -20);
// The shape is complete
s.endShape(CLOSE);
}
void move() {
// Demonstrating some simple motion
x += speed;
if (x > width+100) {
x = -100;
}
}
void display() {
// Locating and drawing the shape
pushMatrix();
translate(x, y);
shape(s);
popMatrix();
}
}