2019年9月26日 星期四

喬現在才來上課日常Week3

用鼠標繪圖















有小點點 (這密集的有點噁心 
















其他功能
















void draw() {
  fill(0,255,0);   ///填充顏色
  stroke(255,0,0);  ///線的顏色
  if(mousePressed){   ///if 按下滑鼠
  line(mouseX, mouseY, pmouseX, pmouseY);  ///開始繪圖
  }

}
















void draw() {
  if(key=='1') stroke(255,0,0);  ///按下鍵盤 改變顏色
  if(key=='2') stroke(255,255,0);
  if(key=='3') stroke(0,255,0);
  if(mousePressed){
  line(mouseX, mouseY, pmouseX, pmouseY);
  }

}
































void setup() {
  size(600, 400);
  fill(255, 0, 0);
  rect(0, 0, 50, 50);
  fill(255, 255, 0);
  rect(0, 50, 50, 50);
  fill(0, 255, 0);
  rect(0, 100, 50, 50);
  fill(0, 255, 255);
  rect(0, 150, 50, 50);
  fill(0, 0, 255);
  rect(0, 200, 50, 50);
  line(25, 250, 25-7, 400);
  line(25, 250, 25+7, 400);
}
void draw() {
  if (mouseX<50 && mousePressed) {
    if (mouseY<50) stroke(255, 0, 0);
    else if (mouseY<100) stroke(255, 255, 0);
    else if (mouseY<150) stroke(0, 255, 0);
    else if (mouseY<200) stroke(0, 255, 255);
    else if (mouseY<250) stroke(0, 0, 255);
    else {
      strokeWeight((mouseY-250)/10);
    }
  }
}
void mouseDragged() {
  if (mouseX>50 && mousePressed) {
    line(mouseX, mouseY, pmouseX, pmouseY);
  }
}
void keyPressed() {
  if (key=='1') stroke(255, 0, 0);
  if (keyCode==UP) line(300, 200, 300, 0);
  if (keyCode==DOWN) line(300, 200, 300, 400);
  if (keyCode==LEFT) line(300, 200, 0, 200);
  if (keyCode==RIGHT) line(300, 200, 600, 200);
}