#include <stdio.h>
#include <math.h>
#include "svg.h"

void star(double x, double y){  /* 星の描画関数star */
    beginShape();
    fill(0xffffff);
    vertex(1.56+x,0+y);     vertex(1.16+x,1.024+y); vertex(0+x,1.024+y);    vertex(0.96+x,1.664+y);
    vertex(0.56+x,2.784+y); vertex(1.56+x,2.048+y); vertex(2.56+x,2.784+y); vertex(2.16+x,1.664+y);
    vertex(3.12+x,1.024+y); vertex(1.96+x,1.024+y);
    endShape(1);
}

int main(void){ /* main関数 */
    int i,j,tmp=0,color;
    double usa_x=50,usa_y=50,jpn_x=150.5,jpn_y=114;

    start();
    fill(0x0042ff); noStroke();
    upperBar(8);
    lowerBar(8);

    /*****旗(USA)******/
    color=0xff0000;
    for (i=0; i<13; i++){
        fill(color);
        rect(usa_x,usa_y+i*4.5,90,4.5);
        if (tmp==0){                    /* 赤と白の入れ替え */
            color=0xffffff;
            tmp=1;
        } else if(tmp==1){
            color=0xff0000;
            tmp=0;
        }
    }
    fill(0x11005A);
    rect(usa_x,usa_y,37,27);

    /* 星の描画 */
    for (i=0; i<9; i++){
        if (i%2==0){
            for (j=0; j<6; j++){
                star(usa_x+0.8+j*6.4,usa_y+0.8+i*2.784);   /* star関数呼び出し */
            }
        } else if(i%2!=0){
            for (j=0; j<5; j++){
                star(usa_x+4.0+j*6.4,usa_y+0.8+i*2.784);    /* star関数呼び出し */
            }
        }
    }
    
    stroke(0x000000);  strokeWeight(0.15); noFill();
    rect(usa_x,usa_y,90,58.5);

    /***********旗(JPN)*************/
    rect(jpn_x,jpn_y,90,58.5);
    fill(0xff0000); noStroke();
    ellipse(jpn_x+90/2,jpn_y+58.5/2,35,35);

    /***********文字****************/
    fill(0x00ff00);
    textFont("Verdana", 12);
    text("Kagawa Lab @ Kagawa Univ", 20, 43);
    finish();
    return 0;
}
