Flag Of Australia


  // Australia
  
  // http://en.wikipedia.org/wiki/File:Flag_of_Australia_template.svg
  
  int kHeight = 250; // The only number that needs changing
  
  // The RGB red and blue specified in the Wikipedia entry are super saturated, and don't look
  // good to me, so I commented them out in favor of the Pantone equivalents listed here.
  // http://www.umsiko.co.za/links/color.html
  
  // color blueColor = color(0,0,139);     // RGB recommendation
  // color whiteColor = color(255,255,255); // RGB recommendation
  // color redColor = color(255,0,0);      // RGB recommendation
  
  color blueColor = color(0,38,127);     // Pantone 280C
  color whiteColor = color(255,255,255); // Pantone Safe
  color redColor = color(234,4,55);      // Pantone 185C
  
  PGraphics unionJack;
  
  void setup()
  {
    size(kHeight*2, kHeight);
    noStroke();
    smooth();
    noLoop();
  
    unionJack = createGraphics(width/2, height/2, P2D);
    unionJack.beginDraw();
    drawUnionJack(unionJack);
    unionJack.endDraw();
  }
  
  void drawUnionJack(PGraphics pg)
  {
    int w = pg.width;
    int h = pg.height;
  
    float fatRedCrossWidth= h/5.0;
    float thinRedCrossWidth = h/15.0;
    
    float whiteDiagonalCrossWidth = h/5.0;
    float fatWhiteCrossWidth = h/3;
  
    // Background blue field
    pg.smooth();
    pg.noStroke();
  
    pg.fill(blueColor);
    pg.rect(0,0, pg.width, pg.height);
    
    // White Diagonal Cross
    pg.stroke(whiteColor);
    pg.strokeCap(PROJECT);
    pg.noFill();
    pg.strokeWeight(whiteDiagonalCrossWidth);
    pg.line(0,0,w,h);
    pg.line(0,h,w,0);
    
    // Thin Red Diagonal Lines (the most complicated bit, because each one is offset)
    float yRatio = 1/sin(radians(90)-atan2(h,w));
  
    // This is the amount to move the (centered stripe) so it lines up with corner, creating pinwheel effect.
    float offsetY = thinRedCrossWidth*yRatio/2;  
  
    pg.stroke(redColor);
    pg.strokeWeight(thinRedCrossWidth);
    pg.line(0,0+offsetY,w/2,h/2+offsetY);           // top left stripe
    pg.line(w,0-offsetY,w/2,h/2-offsetY);       // top right stripe
    pg.line(w,h-offsetY,w/2,h/2-offsetY);  // bot right stripe
    pg.line(0,h+offsetY,w/2,h/2+offsetY);      // bot left stripe
    pg.strokeWeight(1);
    pg.noStroke();
    
    // Thin Red Diagonal Cross pinwheel segments...
    pg.fill(redColor);
    pg.beginShape();
    pg.vertex(0,0);
    pg.vertex(w/2, h/2);
    pg.vertex(w/2+cos(PI-PI/4)*thinRedCrossWidth,h/2+sin(PI-PI/4)*thinRedCrossWidth);
    pg.vertex(0+cos(PI-PI/4)*thinRedCrossWidth,0+sin(PI-PI/4)*thinRedCrossWidth);
    pg.endShape(CLOSE);
    
    pg.beginShape();
    pg.vertex(w,0);
    pg.vertex(w/2, h/2);
    pg.vertex(w/2+cos(PI+PI/4)*thinRedCrossWidth,h/2+sin(PI+PI/4)*thinRedCrossWidth);
    pg.vertex(w+cos(PI+PI/4)*thinRedCrossWidth,0+sin(PI+PI/4)*thinRedCrossWidth);
    pg.endShape(CLOSE);
    
    pg.beginShape();
    pg.vertex(0,h);
    pg.vertex(w/2, h/2);
    pg.vertex(w/2+cos(PI/4)*thinRedCrossWidth,h/2+sin(PI/4)*thinRedCrossWidth);
    pg.vertex(0+cos(PI/4)*thinRedCrossWidth,h+sin(PI/4)*thinRedCrossWidth);
    pg.endShape(CLOSE);
    
    pg.beginShape();
    pg.vertex(w,h);
    pg.vertex(w/2, h/2);
    pg.vertex(w/2+cos(-PI/4)*thinRedCrossWidth,h/2+sin(-PI/4)*thinRedCrossWidth);
    pg.vertex(w+cos(-PI/4)*thinRedCrossWidth,h+sin(-PI/4)*thinRedCrossWidth);
    pg.endShape(CLOSE);
    
    
    // Fat White Cross
    pg.fill(whiteColor);
    pg.rect(0,h/2-fatWhiteCrossWidth/2, w, fatWhiteCrossWidth);
    pg.rect(w/2-fatWhiteCrossWidth/2,0, fatWhiteCrossWidth, h);
    
    // Fat Red Cross
    pg.fill(redColor);
    pg.rect(0,h/2-fatRedCrossWidth/2, w, fatRedCrossWidth);
    pg.rect(w/2-fatRedCrossWidth/2,0, fatRedCrossWidth, h);
  }
  
  void drawAster(int nbrPoints, float cx, float cy, float odiam, float idiamRatio)
  {
    float orad = odiam / 2;
    float irad = orad * idiamRatio;
  
    pushMatrix();
    translate(cx, cy);
    rotate(radians(-90)); // Point upwards  
  
    float  a = TWO_PI / nbrPoints;
  
    beginShape();
    for (int i = 0; i < nbrPoints; ++i) {
      vertex( cos( a * i) * orad, sin( a * i) * orad);
      vertex( cos( a * (i+.5)) * irad, sin( a * (i+.5)) * irad);
    }
    endShape(CLOSE);
    popMatrix();
  }
  
  void draw()
  {
    background(blueColor);
    image(unionJack, 0, 0);
  
    fill(whiteColor);
  
    drawAster( 7, width/4.0, height*3/4.0, width*3/20.0, 4/9.0); // Commonwealth star
    drawAster( 7, width*3/4.0, height*5/6.0, width*1/14.0, 4/9.0); // Alpha Crucis
    drawAster( 7, width*5/8.0, height*7/16.0, width*1/14.0, 4/9.0); // Beta Crucis
    drawAster( 7, width*3/4.0, height*1/6.0, width*1/14.0, 4/9.0); // Gamma Crucis
    drawAster( 7, width*31/36.0, height*89/240.0, width*1/14.0, 4/9.0); // Delta Crucis
    drawAster( 5, width*4/5.0, height*13/24.0, width*1/24.0, 4/9.0); // Epsilon Crucis
  }