วันอังคารที่ 1 กันยายน พ.ศ. 2558

Lab2-SPYAIR(Function)

float spin = 0;
float speed = 0;
int textposX = 360;
int R = 255, G = 255, B = 255;

void setup() {
    size(700, 400);
}

void draw() {
    background(0);
    text_spyair(textposX, 350, 70);
    textposX = textposX - 2;
    if (textposX == -250) {
        textposX = 360;
    }
    howto(350, 20);
    spin = spin+speed;
    translate(200, 130);
    rotate(spin);
    stroke(R, G, B);
    logo(0, 0);
}

void logo(int x, int y) {
    int logosize = 220;
    noFill();
    strokeWeight(12);
    ellipse(x, y, logosize, logosize);
    line(x-105, y-30, x+60, y-90);
    line(x+5, y-65, x+80, y+70);
    line(x+5, y-65, x-20, y+105);
    line(x-105, y-30, x+60, y+35);
    line(x-70, y+80, x+60, y+35);
}

void text_spyair(int x, int y, int size) {
    fill(255);
    strokeWeight(12);
    textSize(size);
    text("SPYAIR", x, y);
}

void howto(int posX, int posY) {
    int howtoW = 330, howtoH = 360;
    int space = 30;
    fill(0);
    noStroke();
    rect(posX, posY, howtoW, howtoH);
    textSize(20);
    fill(#DD0000);
    text("Left Click = Left Spin", posX+space, posY+space);
    text("Right Click = Right Spin", posX+space, posY+space*2);
    text("Press 'Z' = Stop Spin", posX+space, posY+space*3);
    text("Press 'X' = Reset Position", posX+space, posY+space*4);
    text("Press 'C' = Change Color", posX+space, posY+space*5);
    text("Press 'V' = Reset Color", posX+space, posY+space*6);
}

void mouseClicked() {
    if (mouseButton == LEFT) {
        speed = 0.05;
    } else if (mouseButton == RIGHT) {
        speed = -0.05;
    }
}

void keyPressed() {
    if (key == 'z' || key == 'Z') {
        speed = 0;
    }
    if (key == 'x' || key == 'X') {
        spin = 0;
        speed = 0;
    }
    if (key == 'c' || key == 'C') {
        R = R-15;
        G = G-51;
        B = B-5;
        if (R == 0) {
            R = 255;
        }
        if (G == 0) {
            G = 255;
        }
        if (B == 0) {
            B = 255;
        }
    }
    if (key == 'v' || key == 'V') {
        R = 255;
        B = 255;
        G = 255;
    }
}


ไม่มีความคิดเห็น:

แสดงความคิดเห็น