/**
* PolygonPShapeOOP.
*
* Wrapping a PShape inside a custom class
* and demonstrating how we can have a multiple objects each
* using the same PShape.
*/
// A list of objects
ArrayList<Polygon> polygons;
PImage img1, img2, img3, img4, img5, img6, img7, img8, img9, img10, img11, img12, img13, img14, img15, img16, img17, img18, img19, img20, img21, img22, img23, img24, img25, img26, img27, img28, img29, img30, img31, img32, img33, img34, img35;
// Three possible shapes
PShape[] shapes = new PShape[3];
int size;
int dice;
void setup() {
size(1000, 600);
imageMode(CENTER);
img1 = loadImage("https://i.imgur.com/vH19idL.png");
img2 = loadImage("https://i.imgur.com/lGPZQyd.png");
img3 = loadImage("https://i.imgur.com/S6C0N0p.png");
img4 = loadImage("https://i.imgur.com/EUqg8SR.png");
img5 = loadImage("https://i.imgur.com/Y8cuVgV.png");
img6 = loadImage("https://i.imgur.com/nc13bhi.png");
img7 = loadImage("https://i.imgur.com/GRO4efd.png");
img8 = loadImage("https://i.imgur.com/it3TJ4a.png");
img9 = loadImage("https://i.imgur.com/rtsPlZI.png");
img10 = loadImage("https://i.imgur.com/h2HO2PC.png");
img11 = loadImage("https://i.imgur.com/LbBirzO.png");
img12 = loadImage("https://i.imgur.com/qpJsaFC.png");
img13 = loadImage("https://i.imgur.com/pYjBgkE.png");
img14 = loadImage("https://i.imgur.com/9D35V1o.png");
img15 = loadImage("https://i.imgur.com/WVjzEEA.png");
img16 = loadImage("https://i.imgur.com/WmmnuKb.png");
img17 = loadImage("https://i.imgur.com/HMvCmkn.png");
img18 = loadImage("https://i.imgur.com/RFpszse.png");
img19 = loadImage("https://i.imgur.com/c2nrTT6.png");
img20 = loadImage("https://i.imgur.com/XC1ftRi.png");
img21= loadImage("https://i.imgur.com/4WqDZfi.png");
img22 = loadImage("https://i.imgur.com/x4dE47c.png");
img23 = loadImage("https://i.imgur.com/lVLDD54.png");
img24 = loadImage("https://i.imgur.com/bRumJOi.png");
img25 = loadImage("https://i.imgur.com/V3zSAu9.png");
img26 = loadImage("https://i.imgur.com/UJvB8wk.png");
img27 = loadImage("https://i.imgur.com/kTBsqjW.png");
// img28 = loadImage("");
img29 = loadImage("https://i.imgur.com/HZ24hdV.png");
img30 = loadImage("https://i.imgur.com/0S4EbpH.png");
img31 = loadImage("https://i.imgur.com/mA4jh13.png");
img32 = loadImage("https://i.imgur.com/ijtM99I.png");
img33 = loadImage("https://i.imgur.com/wbFh5FV.png");
img34 = loadImage("https://i.imgur.com/d0XVxw6.png");
img35 = loadImage("https://i.imgur.com/ZQlXg2a.png");
/*
shapes[0] = createShape(ELLIPSE,0,0,100,100);
shapes[0].setFill(color(255, 127));
shapes[0].setStroke(false);
shapes[1] = createShape(RECT,0,0,100,100);
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);
shapes[2].vertex(23, 7);
shapes[2].vertex(29, 40);
shapes[2].vertex(0, 25);
shapes[2].vertex(-29, 40);
shapes[2].vertex(-23, 7);
shapes[2].vertex(-47, -15);
shapes[2].vertex(-14, -20);
shapes[2].endShape(CLOSE);
*/ // Make an ArrayList
polygons = new ArrayList<Polygon>();
for (int i = 0; i < 25; i++) {
int selection = int(random(shapes.length)); // Pick a random index
Polygon p = new Polygon(shapes[selection]); // Use corresponding PShape to create Polygon
polygons.add(p);
}
}
void draw() {
background(0,0);
// Display and move them all
for (Polygon poly : polygons) {
poly.display();
poly.move();
}
}
// A class to describe a Polygon (with a PShape)
class Polygon {
// The PShape object
PShape s;
// The location where we will draw the shape
float x, y;
// Variable for simple motion
float speed;
int size = int(random(50, 100));
int dice = int(random(1, 35));
Polygon(PShape s_) {
x = random(width);
y = random(-500, -100);
s = s_;
speed = random(2, 6);
}
// Simple motion
void move() {
y+=speed;
if (y > height+100) {
y = -100;
}
}
// Draw the object
void display() {
pushMatrix();
translate(x, y);
if (dice == 1) {
image(img1, x, y, size, size);
} else if (dice == 2) {
image(img2, x, y, size, size);
} else if (dice == 3) {
image(img3, x, y, size, size);
} else if (dice == 4) {
image(img4, x, y, size, size);
} else if (dice == 5) {
image(img5, x, y, size, size);
} else if (dice == 6) {
image(img6, x, y, size, size);
} else if (dice == 7) {
image(img7, x, y, size, size);
} else if (dice == 8) {
image(img8, x, y, size, size);
} else if (dice == 9) {
image(img9, x, y, size, size);
} else if (dice == 10) {
image(img10, x, y, size, size);
} else if (dice == 11) {
image(img11, x, y, size, size);
} else if (dice == 12) {
image(img12, x, y, size, size);
} else if (dice == 13) {
image(img13, x, y, size, size);
} else if (dice == 14) {
image(img14, x, y, size, size);
} else if (dice == 15) {
image(img15, x, y, size, size);
} else if (dice == 16) {
image(img16, x, y, size, size);
} else if (dice == 17) {
image(img17, x, y, size, size);
} else if (dice == 18) {
image(img18, x, y, size, size);
} else if (dice == 19) {
image(img19, x, y, size, size);
} else if (dice == 20) {
image(img20, x, y, size, size);
} else if (dice == 21) {
image(img21, x, y, size, size);
} else if (dice == 22) {
image(img22, x, y, size, size);
} else if (dice == 23) {
image(img23, x, y, size, size);
} else if (dice == 24) {
image(img24, x, y, size, size);
} else if (dice == 25) {
image(img25, x, y, size, size);
} else if (dice == 26) {
image(img26, x, y, size, size);
} else if (dice == 27) {
image(img27, x, y, size, size);
} else if (dice == 28) {
// image(img28, x, y, size, size);
} else if (dice == 29) {
image(img29, x, y, size, size);
} else if (dice == 30) {
image(img30, x, y, size, size);
} else if (dice == 31) {
image(img31, x, y, size, size);
} else if (dice == 32) {
image(img32, x, y, size, size);
} else if (dice == 33) {
image(img33, x, y, size, size);
} else if (dice == 34) {
image(img34, x, y, size, size);
} else if (dice == 35) {
image(img35, x, y, size, size);
}
// shape(s);
popMatrix();
};
}