1. 程式人生 > >Processing 教程(12)

Processing 教程(12)

/* - - - - - - - - - - -- - - - - - - - - - - - - - - - - - 
    程式功能:
    重點語句:
    1.宣告字型變數 ,
    PFont myFont;
    2.賦值
    myFont = createFont("Rajdhani Light",24);
    3.載入
    textFont(myFont);
    4.顯示模式
    textAlign(CENTER, CENTER);
    5.顯示文字;
    text("rect(50,50,400,100,5,10,20,40);",width/2,height - 50);
    
    - - - - - - - - - - -- - - - - - - - - - - - - - - - - - */

// 定義變數;
float circle_x, fast_circle_x;

PFont myFont;
void setup(){
    size(720,404);
    frameRate(30);
    background(20);
    stroke(#75F56F);
    strokeWeight(0.3);
    myFont = createFont("Rajdhani Light",24);
    textFont(myFont);
    textAlign(CENTER, CENTER);
    
    circle_x = 0;
    fast_circle_x = 0;
}

void draw(){
   background(20);
   noFill();
   stroke(#75F56F);
   ellipse(circle_x - 75,height/2,150,150);
   stroke(#FA8767);
   ellipse(fast_circle_x - 75,height/2,150,150);
   circle_x = (circle_x + 1) % (width + 150);
   fast_circle_x = (fast_circle_x + 4) % (width + 150);
   text("frameRate: " + str(int(frameRate)),width/2,height-50);
   
}

void keyPressed(){
   if(key == '1')frameRate(1);
   else if(key == '2')frameRate(10);
   else if(key == '3')frameRate(30);
   else if(key == '4')frameRate(60);
   else if(key == '5')frameRate(100);
}
void mouseClicked(){
   
    if(mouseButton == RIGHT){        
        String picName = "PDE_" + year()+ "_" + month()+"_" + day()+"_" + 
                                  hour()+"_" + minute()+"_" + second();
        save("D:\\myProcessingPics\\" + picName + ".png");
        println(picName + " ----> Picture saved.");
    }
}
void wheel(){
    // code here!
}