close

2016/07/31玩電玩,學程式_暑期班 3.2常數與變數

 

float centerX,centerY;

void setup(){
   size(320,200);
   centerX=width/2;
   centerY=height/2;
 
   //nose
   ellipse(centerX,centerY,50,50);
   //mouth

   noFill();
   arc(centerX,centerY,height,height,0,PI);
   //eyes
   fill(255);
   ellipse(centerX+100,centerY-50,10,10);
   ellipse(centerX-100,centerY-50,10,10);
}
void draw(){
 line(centerX,0,mouseX,mouseY);
}

​​​​​​​​​​​​​​筆記

float centerX,centerY; 先設定常用數值

void setup(){           這裡放開始時啟用一次之後不會變更的東西
   size(320,200);       畫布大小
   centerX=width/2;    設定鼻子與微笑要使用的中心
   centerY=height/2;
 
   //nose
   ellipse(centerX,centerY,50,50);     圓形ellipse (中心X,中心Y,長.寬)
   //mouth

  noFill();
   arc(centerX,centerY,height,height,0,PI);     弧線arc(弧線圓心座標X,弧線圓心座標Y,寬,高,起點,結束點)
   //eyes
   fill(255);  顏色(白)
   ellipse(centerX+100,centerY-50,10,10);圓形ellipse (中心X,中心Y,長.寬)
   ellipse(centerX-100,centerY-50,10,10);圓形ellipse (中心X,中心Y,長.寬)
}
void draw(){
 line(centerX,0,mouseX,mouseY);  line(起點x,起點y,跟著滑鼠移動位子x,跟著滑鼠移動位子y)
 

 

3.3認識電腦超能力─判斷力if

 

void setup(){
  size(300,300);
  background(225);
}

void draw(){
  if(mousePressed){
    
    if(mouseButton==LEFT){
      stroke(266,0,0);
    }else{
      stroke(0);
    }
    
    line(pmouseX,pmouseY,mouseX,mouseY);
  }
}

 

筆記

 

void setup(){
  size(300,300);                    畫布大小
  background(225);            背景色
}

void draw(){
  if(mousePressed){               如果壓下滑鼠
    
    if(mouseButton==LEFT){              如果是左鍵
      stroke(266,0,0);                               就是紅色
    }else{                   不然的話
      stroke(0);          就是黑色
    }
    
    line(pmouseX,pmouseY,mouseX,mouseY);      

   line(上一秒滑鼠位置x,上一秒y,這一秒x,這一秒y)
  }
}

 

arrow
arrow

    wl02722691 發表在 痞客邦 留言(0) 人氣()