/** Shapes.pde (part of NoiseGrid) Dave Bollinger http://www.davebollinger.com note: there's not much difference between the wide/tall versions of some shapes (f.e.: rectangle, ellipse) since they're symmetric about z rotation, but they're still provided in case the transform doesn't include rotation. */ /** * shapes are responsible for drawing themselves in a (roughly) unit cube */ public class BaseShape { PApplet applet; public BaseShape(PApplet applet) { this.applet = applet; } public void draw() { rect(0,0,1,1); } } //--------- // POLYGONS //--------- public class TriangleShape extends BaseShape { public TriangleShape(PApplet applet) { super(applet); } public void draw() { triangle(-0.5f,0.5f, 0.5f,0.5f, 0f,-0.5f); } } public class WideTriangleShape extends BaseShape { public WideTriangleShape(PApplet applet) { super(applet); } public void draw() { triangle(-1f,0.5f, 1f,0.5f, 0f,-0.5f); } } public class TallTriangleShape extends BaseShape { public TallTriangleShape(PApplet applet) { super(applet); } public void draw() { triangle(-0.5f,1f, 0.5f,1f, 0f,-1f); } } public class RectangleShape extends BaseShape { public RectangleShape(PApplet applet) { super(applet); } public void draw() { rect(0f, 0, 1f, 1f); } } public class WideRectangleShape extends BaseShape { public WideRectangleShape(PApplet applet) { super(applet); } public void draw() { rect(0f, 0f, 2f, 1f); } } public class TallRectangleShape extends BaseShape { public TallRectangleShape(PApplet applet) { super(applet); } public void draw() { rect(0f, 0f, 1f, 2f); } } public class PentagonShape extends BaseShape { public PentagonShape(PApplet applet) { super(applet); } public void draw() { float radius = 0.5f; beginShape(); for (int i=0; i<5; i++) { float theta = HALF_PI + (float)(i) * TWO_PI/5f; vertex(radius*cos(theta), radius*sin(theta)); } endShape(CLOSE); } } public class WidePentagonShape extends BaseShape { public WidePentagonShape(PApplet applet) { super(applet); } public void draw() { float radius = 0.5f; beginShape(); for (int i=0; i<5; i++) { float theta = HALF_PI + (float)(i) * TWO_PI/5f; vertex(radius*2f*cos(theta), radius*sin(theta)); } endShape(CLOSE); } } public class TallPentagonShape extends BaseShape { public TallPentagonShape(PApplet applet) { super(applet); } public void draw() { float radius = 0.5f; beginShape(); for (int i=0; i<5; i++) { float theta = HALF_PI + (float)(i) * TWO_PI/5f; vertex(radius*cos(theta), radius*2f*sin(theta)); } endShape(CLOSE); } } public class HexagonShape extends BaseShape { public HexagonShape(PApplet applet) { super(applet); } public void draw() { float radius = 0.5f; beginShape(); for (int i=0; i<6; i++) { float theta = HALF_PI + (float)(i) * TWO_PI/6f; vertex(radius*cos(theta), radius*sin(theta)); } endShape(CLOSE); } } public class WideHexagonShape extends BaseShape { public WideHexagonShape(PApplet applet) { super(applet); } public void draw() { float radius = 0.5f; beginShape(); for (int i=0; i<6; i++) { float theta = HALF_PI + (float)(i) * TWO_PI/6f; vertex(radius*2f*cos(theta), radius*sin(theta)); } endShape(CLOSE); } } public class TallHexagonShape extends BaseShape { public TallHexagonShape(PApplet applet) { super(applet); } public void draw() { float radius = 0.5f; beginShape(); for (int i=0; i<6; i++) { float theta = HALF_PI + (float)(i) * TWO_PI/6f; vertex(radius*cos(theta), radius*2f*sin(theta)); } endShape(CLOSE); } } //--------- // ELLIPSES // (note: we draw our own polygons here because ellipse(0,0,1,1) // won't work - it won't have enough segments at that small scale) //--------- public class EllipseShape extends BaseShape { public EllipseShape(PApplet applet) { super(applet); } public void draw() { float radius = 0.5f; beginShape(); for (int i=0; i<16; i++) { float theta = HALF_PI + (float)(i) * TWO_PI/16f; vertex(radius*cos(theta), radius*sin(theta)); } endShape(CLOSE); } } public class WideEllipseShape extends BaseShape { public WideEllipseShape(PApplet applet) { super(applet); } public void draw() { float radius = 0.4f; beginShape(); for (int i=0; i<16; i++) { float theta = HALF_PI + (float)(i) * TWO_PI/16f; vertex(radius*2f*cos(theta), radius*sin(theta)); } endShape(CLOSE); } } public class TallEllipseShape extends BaseShape { public TallEllipseShape(PApplet applet) { super(applet); } public void draw() { float radius = 0.4f; beginShape(); for (int i=0; i<16; i++) { float theta = HALF_PI + (float)(i) * TWO_PI/16f; vertex(radius*cos(theta), radius*2f*sin(theta)); } endShape(CLOSE); } } //------ // STARS //------ public class Star3Shape extends BaseShape { // caltrop public Star3Shape(PApplet applet) { super(applet); } public void draw() { float baseradius = 0.6f; beginShape(); for (int i=0; i<6; i++) { float radius = ((i&1)==0) ? baseradius : baseradius/4f; float theta = HALF_PI + (float)(i) * TWO_PI/6f; vertex(radius*cos(theta), radius*sin(theta)); } endShape(CLOSE); } } public class Star4Shape extends BaseShape { // shuriken public Star4Shape(PApplet applet) { super(applet); } public void draw() { float baseradius = 0.6f; beginShape(); for (int i=0; i<8; i++) { float radius = ((i&1)==0) ? baseradius : baseradius/3f; float theta = HALF_PI + (float)(i) * TWO_PI/8f; vertex(radius*cos(theta), radius*sin(theta)); } endShape(CLOSE); } } public class Star5Shape extends BaseShape { // star public Star5Shape(PApplet applet) { super(applet); } public void draw() { float baseradius = 0.6f; beginShape(); for (int i=0; i<10; i++) { float radius = ((i&1)==0) ? baseradius : baseradius/2f; float theta = HALF_PI + (float)(i) * TWO_PI/10f; vertex(radius*cos(theta), radius*sin(theta)); } endShape(CLOSE); } } public class Star6Shape extends BaseShape { // snowflake public Star6Shape(PApplet applet) { super(applet); } public void draw() { float baseradius = 0.6f; beginShape(); for (int i=0; i<12; i++) { float radius = ((i&1)==0) ? baseradius : baseradius/2f; float theta = HALF_PI + (float)(i) * TWO_PI/12f; vertex(radius*cos(theta), radius*sin(theta)); } endShape(CLOSE); } } //--------- // ESOTERIC //--------- public class EllShape extends BaseShape { public EllShape(PApplet applet) { super(applet); } public void draw() { scale(0.6f); beginShape(); vertex(-1f,-1f); vertex(-0.5f,-1f); vertex(-0.5f,0.5f); vertex(1f, 0.5f); vertex(1f, 1f); vertex(-1f, 1f); endShape(CLOSE); } } public class TeeShape extends BaseShape { public TeeShape(PApplet applet) { super(applet); } public void draw() { scale(0.6f); beginShape(); vertex(-1f,-1f); vertex(1f, -1f); vertex(1f, -0.5f); vertex(0.25f, -0.5f); vertex(0.25f, 1f); vertex(-0.25f, 1f); vertex(-0.25f, -0.5f); vertex(-1f, -0.5f); endShape(CLOSE); } } public class ZeeShape extends BaseShape { public ZeeShape(PApplet applet) { super(applet); } public void draw() { scale(0.6f); beginShape(); vertex(-1f,-1f); vertex(1f, -1f); vertex(1f, -0.5f); vertex(-0.5f, 0.5f); vertex(1f, 0.5f); vertex(1f, 1f); vertex(-1f, 1f); vertex(-1f, 0.5f); vertex(0.5f, -0.5f); vertex(-1f, -0.5f); endShape(CLOSE); } } // and maybe: H, I, V, X, Y also? // ..etc..