/* 6.914, Example 0.8 Some other parameters can be given to the custom shape tool, as arguments to beginShape. They are: -TRIANGLES, TRIANGLE_STRIP and TRIANGLE_FAN -QUADS and QUAD_STRIP. */ void setup(){ size(470, 420); background(255); fill(255); strokeWeight(2); } void draw(){ scale(1.3); // ignore this line - we'll cover it later. // using TRIANGLES with beginShape groups // vertices into sets of three, so that // each set of three forms a single triangle. // e.g. if you have 6 vertices, you get 2 triangles: // v1-v2-v3, v4-v5-v6. stroke(150); beginShape(TRIANGLES); vertex(10, 10); vertex(10, 50); vertex(40, 60); vertex(40, 10); vertex(80, 60); vertex(10, 10); endShape(); // using TRIANGLE_FAN with beginShape // means that your first and final vertices should be // in the same place. The intermediate vertices will give // the outer points of the "Fan". // e.g. if you have 6 vertices, you get 3 triangles: // v1-v2-v3, v1-v3-v4, v1-v4-v5. // (v1 and v6 must be at the same location.) stroke(100); beginShape(TRIANGLE_FAN); vertex(10, 110); vertex(10, 150); vertex(40, 160); vertex(40, 110); vertex(80, 160); vertex(10, 110); endShape(); // using TRIANGLE_STRIP with beginShape // every vertex after the second one // will be connected to the previous two. // e.g. if you have 6 vertices, you get 4 triangles: // v1-v2-v3, v2-v3-v4, v3-v4-v5, v4-v5-v6. stroke(50); beginShape(TRIANGLE_STRIP); vertex(10, 210); vertex(10, 250); vertex(40, 260); vertex(40, 210); vertex(80, 260); vertex(10, 210); endShape(); // giving QUADS argument groups your vertices into sets of 4. Each vertex // is connected to the next one in the order given, and the last one is // connected to the first one, in each set. stroke(60, 180, 60); // bright green beginShape(QUADS); vertex(200, 60); vertex(200, 30); vertex(240, 40); vertex(240, 60); // order matters! vertex(300, 60); vertex(340, 40); vertex(300, 30); vertex(340, 60); endShape(); stroke(40, 120, 40); // dark green beginShape(QUAD_STRIP); vertex(200, 160); vertex(200, 130); vertex(240, 160); vertex(240, 140); vertex(270, 160); vertex(270, 110); endShape(); }