2019年9月26日 星期四

紹軒的p語言之旅 - week03

一開始老師複習了上週的打卡機卡片的程式
可以到120.125.70.53 這個老師臨時開的網址去載入

打卡機程式碼:

void draw(){
  background(imgBG);
  int nowI=int((mouseX-33)/8.18);
  int nowJ=int((mouseY-107)/23);//index in table[][]
  if(mousePressed && mouseButton==LEFT && nowJ>=0 && nowI>=0 && nowJ<10&& nowI<80){
    table[nowI][nowJ]=1;
  }else if(mousePressed && mouseButton==RIGHT && nowJ>=0 && nowI>=0 && nowJ<10&& nowI<80){
    table[nowI][nowJ]=0;
  }
  for(int i=0;i<80;i++){
    for(int j=0;j<10;j++){
      fill(0);
      if( table[i][j]==1 ) rect( 33+i*8.18, 107+j*23, 4,9);
    }
  }
}

之後老師介紹了 One stroke drawing 他是一種一筆畫畫完的藝術
也試著將他用程式寫出來


上面的是滑鼠移動到哪就會跟著畫出線
下方是我們讓他變成滑鼠按下左建材繪畫出線來


使用鍵盤按鈕選擇顏色stroke(色碼);及粗細strokeWeight(粗度);


試著在左側畫出顏色按鈕利用滑數按下y值的位置來判斷案到哪個鈕
最下方利用插值來做出調整大小的軌道
strokeWeight((mouseY-250)/10);
畫完五個正方形後y值是250 


程式碼如下:

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); 
   }
  }
  if (mousePressed && mouseX>50) {
    line(mouseX, mouseY, pmouseX, pmouseY);
  }
}




沒有留言:

張貼留言

alanhc 互動技術-week17 [final]

回顧這學期的作品:  期中作業:LANDING:PLANET 賣點&特點: 炫麗的特效 物理(星球重力及降落)及粒子系統(噴射) 世界地圖可根據視角縮放 困難點: 重寫3次最終改寫成物件導向的CLASS寫法...