顯示具有 99161055陳重光 標籤的文章。 顯示所有文章
顯示具有 99161055陳重光 標籤的文章。 顯示所有文章

2013年1月18日 星期五

Week19, Final



期末DEMO
聲音不夠大聲,所以有後製補上聲音。
畫面稍嫌小,不過仔細看還是看的到音符落點。

這學期這堂課學到很多,
也感謝老師的獎品鼓勵,
未來將會用它做出更棒更完整的作品。

Week15, HW12

呃,正確來說,我們好像是這周就發表了。
因為主遊戲程式是用C#寫的,所以有點複雜,不知道怎麼解釋,
不過Arduino部分就很簡單,
一號按鈕有按,就送出1,反之則0
二號按鈕有按,就送出3,反之則2
以此類推,遊戲側的程式會判定傳來的值代表哪個按鈕。

另外補上幾張製作控制器時的圖:



Arduino的程式碼:

int switchPin1 = 2;
int switchPin2 = 3;
int switchPin3 = 4;
int switchPin4 = 5;
int switchPin5 = 6;
boolean oldStage1 = false;
boolean oldStage2 = false;
boolean oldStage3 = false;
boolean oldStage4 = false;
boolean oldStage5 = false;

void setup()
{
pinMode(switchPin1, INPUT);
pinMode(switchPin2, INPUT);
pinMode(switchPin3, INPUT);
pinMode(switchPin4, INPUT);
pinMode(switchPin5, INPUT);
Serial.begin(9600);
}

void loop()
{
    if (digitalRead(switchPin1) == LOW)
    {
      if(oldStage1)
      {
        Serial.print(0,DEC);
      }
      oldStage1 = false;
    }
    else
    {
      if(!oldStage1)
      {
        Serial.print(1,DEC);
      }
      oldStage1 = true;
    }
 
    if (digitalRead(switchPin2) == LOW)
    {
      if(oldStage2)
      {
        Serial.print(2,DEC);
      }
      oldStage2 = false;
    }
    else
    {
      if(!oldStage2)
      {
        Serial.print(3,DEC);
      }
      oldStage2 = true;
    }
 
    if (digitalRead(switchPin3) == LOW)
    {
      if(oldStage3)
      {
        Serial.print(4,DEC);
      }
      oldStage3 = false;
    }
    else
    {
      if(!oldStage3)
      {
        Serial.print(5,DEC);
      }
      oldStage3 = true;
    }
 
    if (digitalRead(switchPin4) == LOW)
    {
      if(oldStage4)
      {
        Serial.print(6,DEC);
      }
      oldStage4 = false;
    }
    else
    {
      if(!oldStage4)
      {
        Serial.print(7,DEC);
      }
      oldStage4 = true;
    }
 
    if (digitalRead(switchPin5) == LOW)
    {
      if(oldStage5)
      {
        Serial.print(8,DEC);
      }
      oldStage5 = false;
    }
    else
    {
      if(!oldStage5)
      {
        Serial.print(9,DEC);
      }
      oldStage5 = true;
    }
}

2012年11月27日 星期二

Week12,HW10

影片一








影片二








影片三









影片四






[程式碼]
int sensorPin = A0;    // select the input pin for the potentiometer
int ledPin = 13;      // select the pin for the LED
int sensorValue = 0;  // variable to store the value coming from the sensor
void setup() {
  // declare the ledPin as an OUTPUT:
  pinMode(13, OUTPUT); 
  pinMode(12, OUTPUT); 
  pinMode(11, OUTPUT); 
  pinMode(10, OUTPUT); 
  pinMode(9, OUTPUT); 
  pinMode(8, OUTPUT); 
  pinMode(7, OUTPUT); 
}
void loop() {
  // read the value from the sensor:
  sensorValue = analogRead(sensorPin);   
  // turn the ledPin on
 
  digitalWrite(13, HIGH); 
  delay(sensorValue/4);
  digitalWrite(11, LOW); 
  delay(sensorValue/4);
 
  digitalWrite(12, HIGH); 
  delay(sensorValue/4);
 
  digitalWrite(11, HIGH); 
  delay(sensorValue/4);
  digitalWrite(13, LOW); 
  delay(sensorValue/4);
 
  digitalWrite(10, HIGH); 
  delay(sensorValue/4);
  digitalWrite(12, LOW); 
  delay(sensorValue/4);
 
  digitalWrite(9, HIGH); 
  delay(sensorValue/4);
  digitalWrite(11, LOW); 
  delay(sensorValue/4);
 
  digitalWrite(8, HIGH); 
  delay(sensorValue/4);
  digitalWrite(10, LOW); 
  delay(sensorValue/4);
 
  digitalWrite(7, HIGH); 
  delay(sensorValue/4);
  digitalWrite(9, LOW); 
  delay(sensorValue/4);
 
  digitalWrite(9, HIGH); 
  delay(sensorValue/4);
  digitalWrite(7, LOW); 
  delay(sensorValue/4);
 
  digitalWrite(10, HIGH); 
  delay(sensorValue/4);
  digitalWrite(8, LOW); 
  delay(sensorValue/4);
 
  digitalWrite(11, HIGH); 
  delay(sensorValue/4);
  digitalWrite(9, LOW); 
  delay(sensorValue/4);
 
  digitalWrite(12, HIGH); 
  delay(sensorValue/4);
  digitalWrite(10, LOW); 
  delay(sensorValue/4);            
}

2012年11月20日 星期二

week11, hw9

媽勒踩地雷是要怎麼用Arduino玩ˊ_>ˋ

既然老師上課都一直推廣音Game了,那就來挑戰看看POP'n music好了



貼一個Arduino相關的影片:


看起來是用Arduino跑midi發聲的木(鐵?)琴

2012年11月13日 星期二

Midterm


踩地雷
左半邊是地圖區,很簡單就是地雷可以踩或是右鍵Mark為地雷,
右邊介面區顯示當前這局總共有多少顆地雷,
可以使用下面的+或-來增加減少,然後按下PLAY開始新一局,
總地雷數就會是新設定的地雷數。

中間是經過時間,從第一顆地雷被踩下去才開始記數,
做為計算排行榜之用。

最下是高分表,顯示了目前資料中記錄的前三名,
會有一個HighSore.txt的純文字文件用於記錄當前排行榜,
如果不存在就會跳出例外,前三名的成績就為預設的255
只有玩地雷為25顆的正規局,名次才會被計算。

開始玩

如同大家所知的踩地雷一樣,
當踩到一格是周圍完全沒有地雷的空格,
就會自動把周圍全部點開,所以如果運氣好,
點兩三下就可以開出一大片安全區。

踩爆
如果不幸踩到地雷,畫面上就會秀出失敗的訊息,
這個時候時間不再繼續記數,也不能夠再踩,
只能夠按下PLAY開始新的一局,當然也可以設定地雷數後再開始。

勝利(這裡為了節省時間把地雷數改為5顆,排行榜也會計算)
當地圖上應該要被踩下的位置都被踩下後
(剩下未踩,或被Mark都是地雷)
判定勝利,秀出勝利訊息。
如果很確定是地雷的位置,那不必標記也沒關係,不影響判定。

可以看到上一局的11秒刷新了新的紀錄,
所以被記錄在第一名的位置了。


我的專案資料夾結構
HighScore是個很單純的純文字文件,
所以任何有心人士(?)都可以輕易的竄改上面的排行榜...



Code

字很多,先直接說我的做法好了QQ
程式從按下PLAY開始,
首先生成n(地雷數)個隨機不重複0~143的亂數,設定為地雷,
建構一個boolean陣列,存放144格是否地雷的地圖;
然後再做一個int二維陣列(boolean陣列為配合亂數,是一維陣列)
根據boolean陣列的資料判定當前這格周圍有多少顆地雷(或根本就是雷)
這個int map做好以後,地雷的資料就算完成了。

當使用者開始踩地雷區,因為每一格是50像素,
所以直接把使用者的mouseX.Y除50就可以對應到int map上,
判定起來很方便;
我的圖片在遊戲一開始後就載入到一個Image陣列之中,
當Click事件發生,直接讓int map中的資料去當作Image陣列的Index,
然後貼圖就是對應的數字,省去很多不必要的記憶體浪費。

大致上就是這樣,其他的小功能基本上都是小函式,
copy來研究一下就貼上了沒什麼特別的QQ

以下為程式碼:
請搭配http://ppt.cc/z6ee
完整專案檔服用,不然圖都貼不出來(doh)
int intMap[][] = new int[12][12];
boolean check[][] = new boolean[12][12];
boolean mark[][] = new boolean[12][12];
PImage pic[] = new PImage[10];
int mines = 25;
int oldTime;
int time = 0;
boolean pause;
boolean begin;
int[] highScore = {255,255,255};
int winCount;

void setup()
{
  size(800,600);
  try
  {
    String lines[] = loadStrings("HighScore.txt");
    for (int i = 0; i < 3; i++)
      highScore[i] = Integer.parseInt(lines[i]);
  }
  catch(Exception ex)
  {
    println("There is no High Score Data!\nThe High Score are all 255");
  }
  
  pic[0] = loadImage("white.jpg");
  pic[1] = loadImage("one.jpg");
  pic[2] = loadImage("two.jpg");
  pic[3] = loadImage("three.jpg");
  pic[4] = loadImage("four.jpg");
  pic[5] = loadImage("five.jpg");
  pic[6] = loadImage("six.jpg");
  pic[7] = loadImage("seven.jpg");
  pic[8] = loadImage("eight.jpg");
  pic[9] = loadImage("red.jpg");
  
  
  background(255,255,255);
  //frameRate(24);
  
  gameZoom();
  IFset();
  Start();
  
}
void gameZoom()
{
  stroke(5);
  fill(200,200,200);
  rect(0,0,600,600);
  strokeWeight(5);
  line(0,0,600,0);
  line(0,50,600,50);
  line(0,100,600,100);
  line(0,150,600,150);
  line(0,200,600,200);
  line(0,250,600,250);
  line(0,300,600,300);
  line(0,350,600,350);
  line(0,400,600,400);
  line(0,450,600,450);
  line(0,500,600,500);
  line(0,550,600,550);
  line(0,600,600,600);
  
  line(0,0,0,600);
  line(50,0,50,600);
  line(100,0,100,600);
  line(150,0,150,600);
  line(200,0,200,600);
  line(250,0,250,600);
  line(300,0,300,600);
  line(350,0,350,600);
  line(400,0,400,600);
  line(450,0,450,600);
  line(500,0,500,600);
  line(550,0,550,600);
  line(600,0,600,600);
  strokeWeight(1);
}
void IFset()
{
  fill(0,0,0);
  PFont myFont;
  myFont = createFont("FFScala", 32);
  textFont(myFont);
  text(str(mines),630,10,100,100);
  
  text("經過時間",620, 350,170,100);
  text("High Score",620, 450,170,100);
  
  myFont = createFont("FFScala", 20);
  textFont(myFont);
  text("顆地雷",690,20,200,100);
  text("1.\n2.\n3.",630,490,50,100);
  noStroke();
  fill(255,255,255);
  rect(700,490,50,100);
  fill(0,0,0);
  text(str(highScore[0])+"\n"+str(highScore[1])+"\n"+str(highScore[2]),700,490,50,100);
  stroke(1);
  
  fill(0,255,0);
  rect(630,60,40,40);
  fill(0,0,255);
  rect(700,60,40,40);
  fill(255,0,0);
  rect(635,78,30,4);
  rect(648,65,4,30);
  rect(705,78,30,4);
  
  rect(625,160,150,150);
  fill(0,0,0);
  myFont = createFont("FFScala", 50);
  textFont(myFont);
  text("PLAY",635,200,200,100);
  myFont = createFont("FFScala", 40);
  textFont(myFont);
}

void Start()
{
  int mine[] = new int[mines];
  boolean boolMap[] = new boolean[144];
  check = new boolean[12][12];
  mark = new boolean[12][12];
  for (int i = 0; i < mines; i++)
  {
    boolean checker = true;
    while(checker)
    {
      mine[i] = int(random(144));
      for(int j = 0; j <= i; j++)
      {
        if (i == j)
        {
          checker = false;
          break;
        }
        else if (mine[i] == mine[j])
          break;
      }
    }
    boolMap[mine[i]] = true;
  }
  
  int count = 0;
  if (boolMap[0])
    count = 9;
  else
  {
    if(boolMap[1])
      count++;
    if(boolMap[12])
      count++;
    if(boolMap[13])
      count++;
  }
  intMap[0][0] = count;
  count = 0;
  
  if (boolMap[11])
    count = 9;
  else
  {
    if (boolMap[10])
      count++;
    if (boolMap[22])
      count++;
    if (boolMap[23])
      count++;
  }
  intMap[11][0] = count;
  count = 0;
  
  if (boolMap[132])
    count = 9;
  else
  {
    if (boolMap[120])
      count++;
    if (boolMap[121])
      count++;
    if (boolMap[133])
      count++;
  }
  intMap[0][11] = count;
  count = 0;
  
  if (boolMap[143])
    count = 9;
  else
  {
    if (boolMap[130])
      count++;
    if (boolMap[131])
      count++;
    if (boolMap[142])
      count++;
  }
  intMap[11][11] = count;
  count = 0;
  //上排
  for (int i = 1; i < 11; i++)
  {
    int couM = 0;
    if (boolMap[i])
      couM = 9;
    else
    {
      if (boolMap[i - 1])
        couM++;
      if (boolMap[i + 1])
        couM++;
      if (boolMap[i + 11])
        couM++;
      if (boolMap[i + 12])
        couM++;
      if (boolMap[i + 13])
        couM++;
    }
    intMap[i][0] = couM;
  }
  //左排
  for (int i = 1; i < 11; i++)
  {
    int couM = 0;
    if (boolMap[12 * i])
      couM = 9;
    else
    {
      if (boolMap[12 * (i - 1)])
        couM++;
      if (boolMap[12 * (i - 1) + 1])
        couM++;
      if (boolMap[12 * i + 1])
        couM++;
      if (boolMap[12 * (i + 1)])
        couM++;
      if (boolMap[12 * (i + 1) + 1])
        couM++;
    }
    intMap[0][i] = couM;
  }
  //右排
  for (int i = 1; i < 11; i++)
  {
    int couM = 0;
    if (boolMap[(i + 1) * 12 - 1])
      couM = 9;
    else
    {
      if (boolMap[i * 12 - 2])
        couM++;
      if (boolMap[i * 12 - 1])
        couM++;
      if (boolMap[(i + 1) * 12 - 2])
        couM++;
      if (boolMap[(i + 2) * 12 - 2])
        couM++;
      if (boolMap[(i + 2) * 12 - 1])
        couM++;
    }
    intMap[11][i] = couM;
  }
  //下排
  for (int i = 1; i < 11; i++)
  {
    int couM = 0;
    if (boolMap[132 + i])
      couM = 9;
    else
    {
      if (boolMap[120 + i - 1])
        couM++;
      if (boolMap[120 + i])
        couM++;
      if (boolMap[120 + i + 1])
        couM++;
      if (boolMap[132 + i - 1])
        couM++;
      if (boolMap[132 + i + 1])
        couM++;
    }
    intMap[i][11] = couM;
  }
  //中間
  for (int i = 1; i < 11; i++)
  {
    for (int j = 1; j < 11; j++)
    {
      int couM = 0;
      if (boolMap[i * 12 + j])
        couM = 9;
      else
      {
        if (boolMap[(i - 1) * 12 + j - 1])
          couM++;
        if (boolMap[(i - 1) * 12 + j])
          couM++;
        if (boolMap[(i - 1) * 12 + j + 1])
          couM++;
        if (boolMap[i * 12 + j - 1])
          couM++;
        if (boolMap[i * 12 + j + 1])
          couM++;
        if (boolMap[(i + 1) * 12 + j - 1])
          couM++;
        if (boolMap[(i + 1) * 12 + j])
          couM++;
        if (boolMap[(i + 1) * 12 + j + 1])
          couM++;
      }
      intMap[j][i] = couM;
    }
  }
}
void mousePressed()
{
  int a = mouseX / 50;
  int b = mouseY / 50;
  if (mouseButton == LEFT)
  {
    if(mouseX<600 && !pause)
    {
      image(pic[intMap[a][b]], a * 50 + 3, b * 50 + 3, 45, 45);
      check[a][b]=true;
      winCount++;
      if (intMap[a][b] == 9)
        endGame();
      else if (intMap[a][b] == 0)
        safe(a, b);
        
      if(!begin)
      {
        begin = true;
        oldTime = second();
      }
      
      if(winCount == 144 - mines)
        win();
    }
    else if(mouseY&rt;60 && mouseY<100)
    {
      PFont myFont;
      myFont = createFont("FFScala", 32);
      textFont(myFont);
      if(mouseX&rt;630 && mouseX<670)
      {
        mines++;
        fill(255,255,255);
        noStroke();
        rect(610,8,75,40);
        fill(0,0,0);
        text(str(mines),630,10,100,100);
      }
      else if(mouseX&rt;700 && mouseX<740)
      {
        mines--;
        fill(255,255,255);
        noStroke();
        rect(610,8,55,40);
        fill(0,0,0);
        text(str(mines),630,10,100,100);
      }
    }
    else if(mouseX&rt;625 && mouseX<775 && mouseY&rt;160 && mouseY<310)
    {
      gameZoom();
      Start();
      IFset();
      time = 0;
      begin = false;
      pause = false;
    }
  }
  else if (mouseButton == RIGHT)
  {
    if(!pause)
    {
      if (!check[a][b] && !mark[a][b])
      {
        mark[a][b] = true;
        PImage flag = loadImage("mark.jpg");
        image(flag, a * 50 + 3, b * 50 + 3, 45, 45);
      }
      else if (mark[a][b])
      {
        mark[a][b] = false;
        fill(200,200,200);
        rect(a * 50 + 2, b * 50 + 2,46,46);
      }
      
    }
  }
}

void endGame()
{
  PFont myFont;
  myFont = createFont("FFScala", 80);
  textFont(myFont);
  fill(255,0,0);
  text("爆了!GG!",100,200,500,200);
  myFont = createFont("FFScala", 40);
  textFont(myFont);
  pause = true;
  winCount = 0;
}

void win()
{
  PFont myFont;
  myFont = createFont("FFScala", 80);
  textFont(myFont);
  fill(255,0,0);
  text("YOU WIN!!",100,200,500,200);
  myFont = createFont("FFScala", 40);
  textFont(myFont);
  pause = true;
  winCount = 0;
  if(mines == 25)        //如果是25顆地雷才會記錄!!!!
  {
    for(int i = 0; i < 3; i++)
      if(time < highScore[i])
      {
        for(int j = 2; j &rt; i; j--)
          highScore[j] = highScore[j - 1];
        highScore[i] = time;
        String saveHC = "";
        for(int j = 0; j < 3; j++)
          saveHC += str(highScore[j]) + " ";
        String[] list = split(saveHC, ' ');
        saveStrings("HighScore.txt", list);
        break;
      }
  }
}

void safe(int a,int b)
{
  if (a &rt; 0 && b &rt; 0)
  {
    if (!check[a-1][b-1])
    {
      image(pic[intMap[a-1][b-1]], (a-1) * 50 + 3, (b-1) * 50 + 3, 45, 45);
      check[a-1][b-1]=true;
      winCount++;
      if (intMap[a-1][b-1] == 0)
        safe(a-1, b-1);
    }
  }
  if (b &rt; 0)
  {
    if (!check[a][b-1])
    {
      image(pic[intMap[a][b-1]], (a) * 50 + 3, (b-1) * 50 + 3, 45, 45);
      check[a][b-1]=true;
      winCount++;
      if(intMap[a][b-1] == 0)
        safe(a, b-1);
    }
  }
  if (a < 11 && b &rt; 0)
  {
    if (!check[a+1][b-1])
    {
      image(pic[intMap[a+1][b-1]], (a+1) * 50 + 3, (b-1) * 50 + 3, 45, 45);
      check[a+1][b-1]=true;
      winCount++;
      if(intMap[a+1][b-1] == 0)
        safe(a+1, b-1);
    }
  }
  if (a &rt; 0 )
  {
    if (!check[a-1][b])
    {
      image(pic[intMap[a-1][b]], (a-1) * 50 + 3, (b) * 50 + 3, 45, 45);
      check[a-1][b]=true;
      winCount++;
      if(intMap[a-1][b] == 0)
        safe(a-1, b);
    }
  }
  if (a < 11)
  {
    if (!check[a+1][b])
    {
      image(pic[intMap[a+1][b]], (a+1) * 50 + 3, (b) * 50 + 3, 45, 45);
      check[a+1][b]=true;
      winCount++;
      if(intMap[a+1][b] == 0)
        safe(a+1,b);
    }
  }
  if (a &rt; 0 && b < 11)
  {
    if (!check[a-1][b+1])
    {
      image(pic[intMap[a-1][b+1]], (a-1) * 50 + 3, (b+1) * 50 + 3, 45, 45);
      check[a-1][b+1]=true;
      winCount++;
      if(intMap[a-1][b+1] == 0)
        safe(a-1,b+1);
    }
  }
  if (b < 11)
  {
    if (!check[a][b+1])
    {
      image(pic[intMap[a][b+1]], (a) * 50 + 3, (b+1) * 50 + 3, 45, 45);
      check[a][b+1]=true;
      winCount++;
      if(intMap[a][b+1] == 0)
        safe(a, b+1);
    }
  }
  if (a < 11 && b < 11)
  {
    if (!check[a+1][b+1])
    {
      image(pic[intMap[a+1][b+1]], (a+1) * 50 + 3, (b+1) * 50 + 3, 45, 45);
      check[a+1][b+1]=true;
      winCount++;
      if(intMap[a+1][b+1] == 0)
        safe(a+1,b+1);
    }
  }
}

void draw()
{
  if(begin)
  {
    if (oldTime != second())
      time++;
    oldTime = second();
  }
  noStroke();
  if(!pause)
  {  
    fill(255,255,255);
    rect(700,400,200,50);
    fill(0,0,0);
    text(str(time),700,400,200,50);
  }
}




//媽勒為什麼大家都是Midtern害我以為我拼錯

2012年11月12日 星期一

Week08, HW08

1.1 你之前完成了什麼
呃...踩地雷的基本功能

1.2 你今天計畫完成什麼
我想做出排行榜的功能,會記錄前三位時間最短的時間

1.3可能會遇到的問題
檔案讀取和儲存的功能要踹一下才知道怎麼用

2012年10月23日 星期二

HW7 Week7

1. 期中作品 踩地雷

以Windows XP的踩地雷為範本,基本上已經做好了,
踩到空白的地方會自動把周圍全部點開,
踩到地雷會在螢幕上show出lose訊息,
介面方面,可以設定要玩多少顆地雷(但是不能選擇地圖大小),
按下PLAY會開始重新的一局,
如果有改過地雷數量,必須按過PLAY才有效(廢話)

2.視訊

我是用 會一直噴水很難用還一時找不到截圖在哪的MAC內建的攝像頭 錄的,
基本上沒什麼問題,不過在MAC上灌的Win7跑MAC攝像頭驅動實在有點蠢,
下次有要用會開OS X

2012年10月16日 星期二

Week06, HW06

看其他人的心得:

大部分人都是做一些小時候玩過的小遊戲,
感覺都快變成懷舊大會了.
只有發現有一個人跟我一樣想做踩地雷QQ

可以發現這些小遊戲雖然看似簡單,
但因為開發平台的不同,不一定適合移植在processing,
比如有些彈珠台、2D卷軸等等,都要用到碰撞判定,
個人覺得還蠻麻煩的.

所以最後還是選了個簡單跑資料的遊戲.

2012年10月9日 星期二

99161055 Week05 HW05

void setup()
{
  size(600,600);
}
float ang=0;
float speed=0.005;
void draw()
{
  background(0,255,255);
  translate(mouseX,mouseY);
  rotate(ang+=speed);
  for(int i=0;i<36;i++)
  {
    fill(255,255,0);
    rotate( PI/18);
    ellipse(100,40,200,30);
  }
  translate(0,0);
  fill(255,255,255);
  ellipse(0,0,100,100);
}
void mousePressed()
{
  if (mouseButton == LEFT)
  speed+=0.001;
  else if (mouseButton == RIGHT)
  speed-=0.001;
}

這次作業很基本的功能,再加上上禮拜教的滑鼠功能,花的中心點會跟著滑鼠跑,按左鍵轉的速度會變快,反之則變慢;不過可惜再怎麼快截圖也截不到殘影.


之前無聊有用C#練習做過踩地雷,這次想在Processing上實作看看.
C#上的Button或是PictureBox的類別很完整,很容易引用Click的函式,
Processing好像不行(?),老師上次的教法是偵測座標,我覺得這種做法,
按鈕一多,效率應該會變得很低.
希望老師可以介紹一下,Processing裡面有沒有類似Button的類別可以用.

2012年10月2日 星期二

Week04,HW04

void setup()
{
  size(600,400);
}
int w=1;
void draw()
{
  if(mousePressed&&mouseX<50)
  {
    if(mouseY<50)
      stroke(255,0,0);
    else if(mouseY<100)
      stroke(0,255,0);
    else if(mouseY<150)
      stroke(0,0,255);
    else if(mouseY&rt;350&&mouseY<400)
      save("light.png");
  }
  else if(mousePressed&&mouseX<100&&mouseY&rt;350&&mouseY<400)
  {
    PImage imaged=loadImage("light.png");
    image(imaged,0,0,600,400);
  }
  else if(mousePressed&&mouseX&rt;550&&mouseY<50)
    strokeWeight(++w);
  else if(mousePressed&&mouseX&rt;550&&mouseY<100)
  {
    strokeWeight(--w);
    if(w<1)w=1;
  }
  
  
  if(mousePressed)
  {
    line(mouseX,mouseY,pmouseX,pmouseY);
  }
  
  strokeWeight(1);
  
  fill(255,0,0);
  rect(0,0,50,50);
  fill(0,255,0);
  rect(0,50,50,50);
  fill(0,0,255);
  rect(0,100,50,50);
  
  fill(0,0,0);
  rect(0,350,50,50);
  fill(255,255,255);
  rect(50,350,50,50);
  
  fill(0,0,0);
  ellipse(575,25,50,50);
  fill(255,255,255);
  ellipse(575,75,50,50);
  
  strokeWeight(w);
}

基本上也就是把老師DEMO的功能跑一遍,
做一些(我自以為)優化,
if判定列我不喜歡每一格都寫開,
用大方向去分成幾個小分支,程式的脈絡比較清楚,
(應該也會稍微加快程式的速度?)

存檔和讀檔的功能很有用

2012年9月25日 星期二

Week03,HW03

第一個作業 有東西隨著滑鼠出現
 
void setup()
{
  size(600,600);
}
void draw()
{
  fill(random(255),random(255),random(255));
  ellipse(mouseX,mouseY,50,50);
}
 
  
第二個作業 有東西追著滑鼠跑 

void setup()
{
  size(600,600);
  //fill(255,255,255);
  //rect(100,100,100,100);
  //frameRate(1);
}
float x=100,y=100;
void draw()
{
  background(0,0,0);
  fill(255,255,0);
  ellipse(mouseX,mouseY,50,50);
  fill(random(255),random(255),random(255));
  ellipse(x,y,30,30);
  x=x*0.9 + mouseX*0.1;
  y=y*0.9 + mouseY*0.1;
//x=(x+mouseX)/2;
//y=(y+mouseY)/2;
}

很基本的上課練習QQ 想不要有什麼花樣可以玩

2012年9月18日 星期二

Week02,HW02


size(800,600);
for(int i=0;i<40;i++)
{
   for(int  j=0;j<30;j++)
  {
    fill(random(255),random(255),random(255));
    rect(i*10,j*10,(i+1)*10,(j+1)*10);
  }
}
for(int i=0;i<40;i++)
{
  for(int j=30;j<60;j++)
  {
    fill(0,j*255/30,i*255/40);
    rect(i*10,j*10,(i+1)*10,(j+1)*10);
  }
}
for(int i=40;i<80;i++)
{
   for(int j =0;j<30;j++)
  {
    fill((i-40)*255/40,j*255/30,0);
    rect(i*10,j*10,(i+1)*10,(j+1)*10);
  }
}
for(int i=40;i<80;i++)
{
   for(int j=30;j<60;j++)
  {
    fill((i-40)*255/40,(j-30)*255/30,(j-30)*255/30);
    rect(i*10,j*10,(i+1)*10,(j+1)*10);
  }
}


把老師教的幾個圖片技巧做在一起


size(800,800);
for(int i=0;i<80;i++)
{
  for(int k=0;k<80;k++)
  {
    fill(0,0,i*255/40);
    ellipse(i*20,k*20,20,20);
    fill(i*255/40,k*255/40,0);
    rect(i*10,k*10,5,5);
  }
}
for(int n=0;n<2000;n++)
{
  fill(random(255),random(255),random(255));
  ellipse(random(800),random(800),random(10),random(10));
}


多方的嘗試了一下 不過不知道怎麼弄才會好看

2012年9月11日 星期二

week01,HW01

1. 分享一個YouTube有關Processing的影片

 
2. Hello Kitty 程式碼
 
size(1080,800);
PImage cat;
cat=loadImage("http://www.kawaiikakkoiisugoi.com/wp-content/uploads/2012/03/hello-kitty-color.gif");
image(cat,20,20);
 
3. 藉由小畫家的幫助畫一張圖

我畫了國旗

以下為程式碼
void setup()
{
size(640,480);
background(255,0,0);
fill(0,0,255);
rect(0,0,320,240);
fill(255,255,255);
ellipse(160,120,140,140);

pushMatrix();
paint(240,110);
rotate(radians(30));
paint(285,15);
rotate(radians(30));
paint(270,-90);
rotate(radians(-60));
popMatrix();
translate(280, -40);

rotate(radians(90));
pushMatrix();
paint(240,110);
rotate(radians(30));
paint(285,15);
rotate(radians(30));
paint(270,-90);
rotate(radians(-60));
popMatrix();
translate(280, -40);

rotate(radians(90));
pushMatrix();
paint(240,110);
rotate(radians(30));
paint(285,15);
rotate(radians(30));
paint(270,-90);
rotate(radians(-60));
popMatrix();
translate(280, -40);

rotate(radians(90));
pushMatrix();
paint(240,110);
rotate(radians(30));
paint(285,15);
rotate(radians(30));
paint(270,-90);
rotate(radians(-60));
popMatrix();
}
void paint(int x,int y)
{
translate(x, y);
triangle(0,0,0,20,30,10);
translate(-x, -y);
} 
 
4. 請寫下你的心得

接觸到全新的一套軟體,似乎和openGL很像,語法結構也幾乎就像是簡單版的C
希望這堂課不會就是個openGL plus之類的東西,有一些openGL沒有的特色可以玩。

不知道是不是S513沒有切螢幕的功能,
老師只用投影片,就算關燈還是看不太清楚。
可以的話還是切螢幕上課比較容易吸收。

blog不太習慣使用,如果可以還是希望用moodle就好。

另外,我沒修過HTML有關的課程,希望老師可以在講授之餘大概的提點一下
(尤其是又要貼到blog上的話...)
如果沒時間的話,也可以比照電腦圖學的做法貼範例在moodle或blog上