#include <stdio.h>
#include <math.h>
#include "svg.h"

// はがきサイズのガイドを描画  100*148
void hagakiRect(void);

// 香川大学キャラクターの描画
void kadaiChar(double x, double y, double size);

// 縦方向にグラデーションを行った矩形を描画
void gradationRect(double x, double y, double w, double h,
                   int r1, int g1, int b1, int r2, int g2, int b2);

int main(void){
    int i;
        
    start();
        
    //hagakiRect();
        
    gradationRect(
                  0, 0, 100, 148,
                  0x80, 0xff, 0x80,
                  0xff, 0x80, 0xff
                  );
        
    kadaiChar(10, 20, 30);
        
    textFont("ＭＳ ゴシック", 15);
    stroke(0x000000);
    fill(0x000000);
    text("agawa", 25, 50);
    text("University", 20, 70);
        
    noStroke();
    textFont("ＭＳ ゴシック", 8);
    text("Open Campus 2011", 32, 145);
        
    finish();
        
    return 0;
}


void kadaiChar(double x, double y, double size) {
        
    // 体部分
    stroke(0xff8080);
    line(x, y, x, y+size);
    // 尻尾
    line(x, y+size*0.5, x+size*0.35, y+size*0.35);
    go(x+size*0.35, y+size*0.35);
    turn(-70);
    forward(size*0.04);
    turn(120);
    forward(size*0.06);
    turn(-130);
    forward(size*0.05);
    turn(120);
    forward(size*0.04);
    turn(-130);
    forward(size*0.03);
        
    // なぞ部分
    arc360(x-size*0.95, y+size, size*2.5, size*2.5, 0, -27);
        
        
    // 顔部分
    fill(0x000000);
    noStroke();
    ellipse(x, y, size*0.1, size*0.1);
    // 目
    ellipse(x+size*0.15, y, size*0.05, size*0.05);
    ellipse(x-size*0.15, y, size*0.05, size*0.05);
    // 口
    stroke(0xff8080);
    noFill();
    arc360(x, y+size*0.07, size*0.3, size*0.2, 0, 180);
        
        
        
}

void gradationRect(double x, double y, double w, double h,
                   int r1, int g1, int b1, int r2, int g2, int b2) {
    const int grad = 50;  // 分割数
    int i;
        
    noStroke();
    for ( i = 0; i < grad; i++ ) {
        fill(rgb255(r2*((double)i/grad)+r1*(grad-i)/grad,
                    g2*((double)i/grad)+g1*(grad-i)/grad,
                    b2*((double)i/grad)+b1*(grad-i)/grad));
        rect(x, y+(h/grad)*i, w, 0.5+h/grad);
    }
        
}

void hagakiRect(void) {
    noFill();
    stroke(0x000000);
    rect(0, 0, 100, 148);
}
