Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function Poly()
- {
- this.verts = [];
- this.pos = createVector(0, 0);
- this.col = color(255);
- this.colStroke = color(0);
- this.useFill = true;
- this.useStroke = false;
- this.weightStroke = 1;
- this.rot = 0;
- this.scl = createVector(1, 1);
- this.cnt = createVector(0, 0);
- this.draw = function()
- {
- if (this.verts.length == 0)
- return;
- var b = this.getBounds();
- var w = b.size.x;
- var h = b.size.y;
- push();
- translate(this.pos.x, this.pos.y);
- rotate (this.rot);
- scale (this.scl.x, this.scl.y);
- translate(w * -this.cnt.x, h * -this.cnt.y);
- if (this.useFill)
- fill(this.col);
- else
- noFill();
- if (this.useStroke)
- {
- strokeWeight(this.weightStroke);
- stroke(this.colStroke);
- }
- else
- noStroke();
- beginShape();
- for (var i = 0; i < this.verts.length; ++ i)
- vertex(this.verts[i].x, this.verts[i].y);
- endShape(CLOSE);
- pop();
- };
- this.getBounds = function()
- {
- var r = {pos: createVector(0, 0), size: createVector(0, 0)};
- if (this.verts.length == 0)
- return r;
- var xmin = this.verts[0].x;
- var ymin = this.verts[0].y;
- var xmax = this.verts[0].x;
- var ymax = this.verts[0].y;
- for (var i = 0; i < this.verts.length; ++ i)
- {
- if (this.verts[i].x < xmin) xmin = this.verts[i].x;
- if (this.verts[i].y < ymin) ymin = this.verts[i].y;
- if (this.verts[i].x > xmax) xmax = this.verts[i].x;
- if (this.verts[i].y > ymax) ymax = this.verts[i].y;
- }
- r.pos.x = xmin;
- r.pos.y = ymin;
- r.size.x = xmax - xmin;
- r.size.y = ymax - ymin;
- return r;
- };
- }
Add Comment
Please, Sign In to add comment