顯示具有 07161036_洪楷勛 標籤的文章。 顯示所有文章
顯示具有 07161036_洪楷勛 標籤的文章。 顯示所有文章

2020年12月28日 星期一

2020/12/28

 

期末



#include <Keypad.h>    // 引用Keypad程式庫

#include <LiquidCrystal_I2C.h>


LiquidCrystal_I2C lcd(0x27,16,2); 

#define KEY_ROWS 4 // 按鍵模組的列數

#define KEY_COLS 4 // 按鍵模組的行數


#define BUZZER 8


#define NOTE_C1 261 //F,C

#define NOTE_C2 293 //E,D

#define NOTE_C3 329 //D,E

#define NOTE_C4 349 //C,F

#define NOTE_C5 391 //B,G

#define NOTE_C6 440 //3,A

#define NOTE_C7 493 //6,B

#define NOTE_C8 532 //9,C



#define NOTE_C9 587 //A,D

#define NOTE_C10 659 //2,E

#define NOTE_C11 698 //5,F

#define NOTE_C12 783 //8,G

#define NOTE_C13 880 //0,A

#define NOTE_C14 987 //1,B

#define NOTE_C15 1046 //4,C

#define NOTE_C16 1174 //7,D



// 依照行、列排列的按鍵字元(二維陣列)

char keymap[KEY_ROWS][KEY_COLS] = {

  {'F', 'B', 'A', '0'},

  {'E', '3', '2', '1'},

  {'D', '6', '5', '4'},

  {'C', '9', '8', '7'}

};

byte colPins[KEY_COLS] = {7, 6, 5, 4};     // 按鍵模組,行1~4接腳。

byte rowPins[KEY_ROWS] = {12, 11, 10, 9}; // 按鍵模組,列1~4接腳。 

// 初始化Keypad物件

// 語法:Keypad(makeKeymap(按鍵字元的二維陣列), 模組列接腳, 模組行接腳, 模組列數, 模組行數)

Keypad myKeypad = Keypad(makeKeymap(keymap), rowPins, colPins, KEY_ROWS, KEY_COLS);

void setup(){

  Serial.begin(9600);

  lcd.init();


lcd.backlight();//是否開啟背光

/*

lcd.setCursor(2,0);//設定游標位置


lcd.print("TAIWAN 2021");//寫入字串


lcd.setCursor(1,1);//設定游標位置


lcd.print("Happy New Year");//寫入字串

*/

} 

void loop(){

  // 透過Keypad物件的getKey()方法讀取按鍵的字元

  char key = myKeypad.getKey();

  

  if (key){  // 若有按鍵被按下…

    Serial.println(key);  // 顯示按鍵的字元

    

     if(key=='F') {tone(BUZZER, NOTE_C1, 200);lcd.setCursor(0,0);lcd.print("0");}

     if(key=='E') {tone(BUZZER, NOTE_C2, 200);lcd.setCursor(1,0);lcd.print("1");}

     if(key=='D') {tone(BUZZER, NOTE_C3, 200);lcd.setCursor(2,0);lcd.print("2");}

     if(key=='C') {tone(BUZZER, NOTE_C4, 200);lcd.setCursor(3,0);lcd.print("3");}

     if(key=='B') {tone(BUZZER, NOTE_C5, 200);lcd.setCursor(4,0);lcd.print("4");}

     if(key=='3') {tone(BUZZER, NOTE_C6, 200);lcd.setCursor(5,0);lcd.print("5");}

     if(key=='6') {tone(BUZZER, NOTE_C7, 200);lcd.setCursor(6,0);lcd.print("6");}

     if(key=='9') {tone(BUZZER, NOTE_C8, 200);lcd.setCursor(7,0);lcd.print("7");}


    if(key=='A') {tone(BUZZER, NOTE_C9, 200);lcd.setCursor(8,0);lcd.print("8");}

    if(key=='2') {tone(BUZZER, NOTE_C10, 200);lcd.setCursor(9,0);lcd.print("9");}

    if(key=='5') {tone(BUZZER, NOTE_C11, 200);lcd.setCursor(10,0);lcd.print("A");}

    if(key=='8') {tone(BUZZER, NOTE_C12, 200);lcd.setCursor(11,0);lcd.print("B");}

    if(key=='0') {tone(BUZZER, NOTE_C13, 200);lcd.setCursor(12,0);lcd.print("C");}

    if(key=='1') {tone(BUZZER, NOTE_C14, 200);lcd.setCursor(13,0);lcd.print("D");}

    if(key=='4') {tone(BUZZER, NOTE_C15, 200);lcd.setCursor(14,0);lcd.print("E");}

    if(key=='7') {tone(BUZZER, NOTE_C16, 200);lcd.setCursor(15,0);lcd.print("F");}

  }

}

2020年12月14日 星期一

2020/12/14

 搖桿控制音調

連接 COM6


void setup() {

  pinMode(13,OUTPUT);

}


void loop() {

  int now = analogRead(A0);

  tone(8,now);

}




搖桿控制音調 + 燈光


void setup() {

  // put your setup code here, to run once:

  for(int i=2;i<=13;i++){

    pinMode(i,OUTPUT);

  }

}


void loop() {

  // put your main code here, to run repeatedly:

  int now = analogRead(A0);

  int level = now/(512/13);

  for(int i=2;i<=13;i++){

    if(i<level) digitalWrite(i,HIGH);

    else digitalWrite(i,LOW);

  }

  tone(8,now);

}




旋鈕控制顏色







2020年12月7日 星期一

2020/12/7

🔘連接麵包版 + 按鈕🔘


🔘按鈕連接🔘

SW - 2
VRY - A1
VRX - A0
+5V - 5V
GND - GND


🔘無聲🔘

void setup() {

  Serial.begin(9600); //usb

  pinMode(2,INPUT_PULLUP);

  pinMode(8,OUTPUT); //buzzer

}


int state=0; //0=not pressed;1=pressed



void loop() {

  if(digitalRead(2)==LOW && state==0){

    state=1; //pressed

    Serial.write("1");

  }

  if(digitalRead(2)==HIGH && state==1){

    state=0; //0=not pressed

    Serial.write("0");

  }

  delay(100); //慢0.1s

}


網路連線程式

//先匯入udp函式庫



import hypermedia.net.*;

UDP udp;

void setup(){

   size(300,200);

   udp = new UDP(this,6000);

   udp.send("bruh","120.125.70.53",6100);

}


void draw(){

  

}


void mousePressed(){

   udp.send("mousePressed","120.125.70.53",6100); 

}

2020年11月30日 星期一

week12 發出音樂

 簡單馬力歐開頭音樂


#define NOTE_C5 523

#define NOTE_E5 659

#define NOTE_G5 784


#define BUTTON 2

#define BUZZER 8


int melody[] = {

  NOTE_E5, NOTE_E5, 0, NOTE_E5, 0, NOTE_C5, NOTE_E5, 0, NOTE_G5

};


int noteDurations[] = {

  10, 10, 10, 10, 10, 10, 10, 10, 10

};


int pin;

int ledArrayHigh;

int ledArrayLow;

boolean mode = false;

boolean buttonPressed = false;


void setup()

{

  delay(1000);

  

  pinMode(BUTTON, INPUT_PULLUP);

  for (pin = 3; pin < 14; pin++) { 

    pinMode(pin, OUTPUT);

  }


  for (int thisNote = 0; thisNote < 9; thisNote++) {

    int noteDuration = 1000 / noteDurations[thisNote];

    tone(BUZZER, melody[thisNote], noteDuration);

    int pauseBetweenNotes = noteDuration * 1.30;

    delay(pauseBetweenNotes);

    noTone(BUZZER);

  }

}


void loop()

{

  for (pin = 0; pin < 5; pin++) {

    if (digitalRead(BUTTON) == LOW &&

        buttonPressed == false) {

      buttonPressed = true;

      mode = !mode;

      pin = 0;

      if (mode == false) {

        tone(BUZZER, NOTE_C5, 100);

        delay(100);

        tone(BUZZER, NOTE_G5, 100);

        delay(100);

        noTone(BUZZER);

      }

      else if (mode == true) {

        tone(BUZZER, NOTE_G5, 100);

        delay(100);

        tone(BUZZER, NOTE_C5, 100);

        delay(100);

        noTone(BUZZER);

      }

    }


    if (mode == false) {

      ledArrayHigh = 13 - pin;

      ledArrayLow = 7 - pin;

    }

    else if (mode == true) {

      ledArrayHigh = 9 + pin;

      ledArrayLow = 3 + pin;

    }

    digitalWrite(ledArrayHigh, HIGH);

    digitalWrite(ledArrayLow, HIGH);

    delay(100);

    digitalWrite(ledArrayHigh, LOW);

    digitalWrite(ledArrayLow, LOW);

    if (pin == 4) delay(100);

  }


  if (buttonPressed == true) {

    buttonPressed = false;

  }

}



2020年11月23日 星期一

week11

 

Maker Uno 開發板

聲音撥放器


#define D 523

#define R 587

#define M 659

#define F 698

#define S 784


int music[]={D,D,S,S};

void setup() {

  // put your setup code here, to run once:

  delay(1000); //開始延遲

  pinMode(8,OUTPUT);

  for(int i=0;i<11;i++){

    tone(8,music[i],100); //8號鍵位,播放,聲音持續時間

    delay(130); //聲音延遲

  }

}


void loop() {

  // put your main code here, to run repeatedly:


}


Undertale - Megalovania


#define N_B0  31

#define N_C1  33

#define N_CS1 35

#define N_D1  37

#define N_DS1 39

#define N_E1  41

#define N_F1  44

#define N_FS1 46

#define N_G1  49

#define N_GS1 52

#define N_A1  55

#define N_AS1 58

#define N_B1  62

#define N_C2  65

#define N_CS2 69

#define N_D2  73

#define N_DS2 78

#define N_E2  82

#define N_F2  87

#define N_FS2 93

#define N_G2  98

#define N_GS2 104

#define N_A2  110

#define N_AS2 117

#define N_B2  123

#define N_C3  131

#define N_CS3 139

#define N_D3  147

#define N_DS3 156

#define N_E3  165

#define N_F3  175

#define N_FS3 185

#define N_G3  196

#define N_GS3 208

#define N_A3  220

#define N_AS3 233

#define N_B3  247

#define N_C4  262

#define N_CS4 277

#define N_D4  294

#define N_DS4 311

#define N_E4  330

#define N_F4  349

#define N_FS4 370

#define N_G4  392

#define N_GS4 415

#define N_A4  440

#define N_AS4 466

#define N_B4  494

#define N_C5  523

#define N_CS5 554

#define N_D5  587

#define N_DS5 622

#define N_E5  659

#define N_F5  698

#define N_FS5 740

#define N_G5  784

#define N_GS5 831

#define N_A5  880

#define N_AS5 932

#define N_B5  988

#define N_C6  1047

#define N_CS6 1109

#define N_D6  1175

#define N_DS6 1245

#define N_E6  1319

#define N_F6  1397

#define N_FS6 1480

#define N_G6  1568

#define N_GS6 1661

#define N_A6  1760

#define N_AS6 1865

#define N_B6  1976

#define N_C7  2093

#define N_CS7 2217

#define N_D7  2349

#define N_DS7 2489

#define N_E7  2637

#define N_F7  2794

#define N_FS7 2960

#define N_G7  3136

#define N_GS7 3322

#define N_A7  3520

#define N_AS7 3729

#define N_B7  3951

#define N_C8  4186

#define N_CS8 4435

#define N_D8  4699

#define N_DS8 4978


int const TEMPO = 1200;


int melody[] = {

  N_D3, N_D3, N_D4, N_A3, 0, N_GS3, N_G3, N_F3, N_D3, N_F3, N_G3, N_C3, N_C3, N_D4, N_A3, 0, N_GS3, N_G3, N_F3, N_D3, N_F3, N_G3, N_B2, N_B2, N_D4, N_A3, 0, N_GS3, N_G3, N_F3, N_D3, N_F3, N_G3, N_AS2, N_AS2, N_D4, N_A3, 0, N_GS3, N_G3, N_F3, N_D3, N_F3, N_G3, N_D3, N_D3, N_D4, N_A3, 0, N_GS3, N_G3, N_F3, N_D3, N_F3, N_G3, N_C3, N_C3, N_D4, N_A3, 0, N_GS3, N_G3, N_F3, N_D3, N_F3, N_G3, N_B2, N_B2, N_D4, N_A3, 0, N_GS3, N_G3, N_F3, N_D3, N_F3, N_G3, N_AS2, N_AS2, N_D4, N_A3, 0, N_GS3, N_G3, N_F3, N_D3, N_F3, N_G3, N_D4, N_D4, N_D5, N_A4, 0, N_GS4, N_G4, N_F4, N_D4, N_F4, N_G4, N_C4, N_C4, N_D5, N_A4, 0, N_GS4, N_G4, N_F4, N_D4, N_F4, N_G4, N_B3, N_B3, N_D5, N_A4, 0, N_GS4, N_G4, N_F4, N_D4, N_F4, N_G4, N_AS3, N_AS3, N_D5, N_A4, 0, N_GS4, N_G4, N_F4, N_D4, N_F4, N_G4, N_D4, N_D4, N_D5, N_A4, 0, N_GS4, N_G4, N_F4, N_D4, N_F4, N_G4, N_C4, N_C4, N_D5, N_A4, 0, N_GS4, N_G4, N_F4, N_D4, N_F4, N_G4, N_B3, N_B3, N_D5, N_A4, 0, N_GS4, N_G4, N_F4, N_D4, N_F4, N_G4, N_AS3, N_AS3, N_D5, N_A4, 0, N_GS4, N_G4, N_F4, N_D4, N_F4, N_G4, N_F4, N_F4, N_F4, N_F4, N_F4, N_D4, N_D4, N_D4, N_F4, N_F4, N_F4, N_G4, N_GS4, N_G4, N_F4, N_D4, N_F4, N_G4, 0, N_F4, N_F4, N_F4, N_G4, N_GS4, N_A4, N_C5, N_A4, N_D5, N_D5, N_D5, N_A4, N_D5, N_C5, N_F4, N_F4, N_F4, N_F4, N_F4, N_D4, N_D4, N_D4, N_F4, N_F4, N_F4, N_F4, N_D4, N_F4, N_E4, N_D4, N_C4, 0, N_G4, N_E4, N_D4, N_D4, N_D4, N_D4, N_F3, N_G3, N_AS3, N_C4, N_D4, N_F4, N_C5, 0, N_F4, N_D4, N_F4, N_G4, N_GS4, N_G4, N_F4, N_D4, N_GS4, N_G4, N_F4, N_D4, N_F4, N_F4, N_F4, N_GS4, N_A4, N_C5, N_A4, N_GS4, N_G4, N_F4, N_D4, N_E4, N_F4, N_G4, N_A4, N_C5, N_CS5, N_GS4, N_GS4, N_G4, N_F4, N_G4, N_F3, N_G3, N_A3, N_F4, N_E4, N_D4, N_E4, N_F4, N_G4, N_E4, N_A4, N_A4, N_G4, N_F4, N_DS4, N_CS4, N_DS4, 0, N_F4, N_D4, N_F4, N_G4, N_GS4, N_G4, N_F4, N_D4, N_GS4, N_G4, N_F4, N_D4, N_F4, N_F4, N_F4, N_GS4, N_A4, N_C5, N_A4, N_GS4, N_G4, N_F4, N_D4, N_E4, N_F4, N_G4, N_A4, N_C5, N_CS5, N_GS4, N_GS4, N_G4, N_F4, N_G4, N_F3, N_G3, N_A3, N_F4, N_E4, N_D4, N_E4, N_F4, N_G4, N_E4, N_A4, N_A4, N_G4, N_F4, N_DS4, N_CS4, N_DS4, 

};

int noteDurations[] = {

  16, 16, 8, 6, 32, 8, 8, 8, 16, 16, 16, 16, 16, 8, 6, 32, 8, 8, 8, 16, 16, 16, 16, 16, 8, 6, 32, 8, 8, 8, 16, 16, 16, 16, 16, 8, 6, 32, 8, 8, 8, 16, 16, 16, 16, 16, 8, 6, 32, 8, 8, 8, 16, 16, 16, 16, 16, 8, 6, 32, 8, 8, 8, 16, 16, 16, 16, 16, 8, 6, 32, 8, 8, 8, 16, 16, 16, 16, 16, 8, 6, 32, 8, 8, 8, 16, 16, 16, 16, 16, 8, 6, 32, 8, 8, 8, 16, 16, 16, 16, 16, 8, 6, 32, 8, 8, 8, 16, 16, 16, 16, 16, 8, 6, 32, 8, 8, 8, 16, 16, 16, 16, 16, 8, 6, 32, 8, 8, 8, 16, 16, 16, 16, 16, 8, 6, 32, 8, 8, 8, 16, 16, 16, 16, 16, 8, 6, 32, 8, 8, 8, 16, 16, 16, 16, 16, 8, 6, 32, 8, 8, 8, 16, 16, 16, 16, 16, 8, 6, 32, 8, 8, 8, 16, 16, 16, 8, 16, 8, 8, 8, 8, 4, 16, 8, 16, 8, 8, 8, 16, 16, 16, 16, 16, 8, 8, 16, 8, 8, 8, 8, 8, 8, 8, 8, 16, 16, 16, 2, 8, 16, 8, 8, 8, 8, 4, 16, 8, 16, 8, 8, 8, 8, 8, 16, 8, 16, 8, 8, 8, 8, 8, 8, 8, 16, 8, 15, 8, 8, 2, 3, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 8, 2, 16, 8, 16, 8, 16, 16, 16, 16, 16, 16, 8, 8, 8, 8,  8, 8, 16, 16, 16, 2, 8, 8, 8, 8, 4, 4, 4, 4, 4, 4, 2, 8, 8, 8, 8, 2, 2, 3, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 8, 2, 16, 8, 16, 8, 16, 16, 16, 16, 16, 16, 8, 8, 8, 8,  8, 8, 16, 16, 16, 2, 8, 8, 8, 8, 4, 4, 4, 4, 4, 4, 2, 8, 8, 8, 8, 2, 1

};


//melody = 266 notes


void setup() {

  int melody_len = sizeof(melody)/sizeof(melody[0]);


  for (int thisNote = 0; thisNote < melody_len; thisNote++) {

    int noteDuration = TEMPO / noteDurations[thisNote];

    tone(8, melody[thisNote], noteDuration);

    int pauseBetweenNotes = noteDuration * 1.45;

    delay(pauseBetweenNotes);

    noTone(8);

  }

}


void loop() {}






2020年11月2日 星期一

week05 水果忍者

 水果忍者

圖片會由上往下掉落



PImage img;
float x=100, y=200, vx=3, vy= -30;//(x,y)
int fruitDie=0;
void setup(){
  size(500,500);
  img = loadImage("fruit.png");
}


void draw(){
  background(0);
  image(img,x,y,100,100);
  x += vx;
  y += vy;
  vy += 0.98;
  if(y>500) fruitDie=1;
  if(x<mouseX&&mouseX<x+100&&y<mouseY&&mouseY<y+100)fruitDie=1;
  stroke(255);line(mouseX,mouseY,pmouseX,pmouseY);
  if(fruitDie==1){
  if(frameCount%2==0){
    x=random(250); y=500; vx=random(2,3);vy=-random(28,32);
  }
  else{
      x=random(250,500);y=500; vx=-random(2,3); vy=-random(28,32);
    }
    fruitDie=0;
  }
}

week08 pixel、期末作品製作


期中作品

遊玩方式:人物會在桌上行走,畫面中有加分及扣分道具,點擊畫面可讓人物跳起並越過障礙。












2020年10月26日 星期一

week07 圖形繪製

 

圓

size(500,500);

for(int angle=0;angle<360;angle+=30){

    float angle2 = radians(angle);

    float x = 100+cos( angle2 )*50;

    float y = 100+sin( angle2 )*50;

    ellipse(x,y,2,2);

}




多邊形


size(500,500);

beginShape();

for(int angle=0;angle<360;angle+=30){ //可調角度

    float angle2 = radians(angle);

    float x = 100+cos( angle2 )*50;

    float y = 100+sin( angle2 )*50;

    vertex(x,y);//ellipse(x,y,2,2);

}


endShape(CLOSE);






圖形旋轉


size(500,500);

}

void draw(){

background(255); //殘影效果

beginShape();

for(int angle=0;angle<360;angle+=30){

    float angle2 = radians(angle+mouseX);

    float x = mouseX+cos( angle2 )*50;

    float y = mouseY+sin( angle2 )*50;

    vertex(x,y);//ellipse(x,y,2,2);

  }

endShape(CLOSE);

}





接水果


color c1=color(0,255,255);

color c2=color(20,30,40);


void draw(){

   background(255);

   fill(c2);

   rect(kidX,kidY,50,80);

   kidX = mouseX;

   ellipse(fruitX,fruitY,60,80);

   fruitY++;

   if(fruitY>kidY){

      if(kidX < fruitX && fruitX < kidX+80){

         score+=10;

         fruitY=0;

         fruitX=random(50,450);

      }

      else{

        fruitY=0;

        fruitX=random(50,450);

      }

   }

}




接水果  隨機變色


float [] fruitX=new float[10];

float [] fruitY=new float[10];

float kidX=150,kidY=450;

int score=0;

void setup(){

   size(500,500); 

   for(int i=0;i<10;i++){

       fruitX[i] = random(50,450);

       fruitY[i] = -i*100;

   }

}


void draw(){


  color c1=color(random(255),random(255),random(255));


   background(255);

   fill(c1);

   rect(kidX,kidY,50,80);

   kidX = mouseX;

   for(int i=0;i<10;i++){

     ellipse(fruitX[i],fruitY[i],60,80);

     fruitY[i]++;

     if(fruitY[i]>kidY){

        if(kidX < fruitX[i] && fruitX[i] < kidX+80){

           score+=10;

           fruitY[i]=0;

           fruitX[i]=random(50,450);

        }

        else{

          fruitY[i]=0;

          fruitX[i]=random(50,450);

        }

     }

  }

}










2020年10月19日 星期一

week06 方格圖形製作

顏色陣列




泡泡紙





int [][]A={{2,2,2,2,},{0,1,1,1},{0,1,1,1},{2,2,2,2}};
 
PImage bird,pig;
void setup(){
   size(400,400);
   bird=loadImage("bird.png");
   pig=loadImage("pig.png");
}

void draw(){
   background(0);
   for(int i=0;i<4;i++){
      for(int j=0;j<4;j++){
         if(A[i][j]==1) image(bird,j*100,i*100,100,100); 
         if(A[i][j]==2) image(pig,j*100,i*100,100,100); 
      }
   }
}


點擊消失


int [][]A={{2,1,2,1},{1,2,1,2},{2,1,2,1},{1,2,1,2}};
 
 
PImage bird,pig;
void mousePressed(){
  int i= int(mouseY/100);
  int j= int(mouseX/100);
  A[i][j]=0;
}

void setup(){
   size(400,400);
   bird=loadImage("bird.png");
   pig=loadImage("pig.png");
}

void draw(){
   background(0);
   for(int i=0;i<4;i++){
      for(int j=0;j<4;j++){
         if(A[i][j]==1) image(bird,j*100,i*100,100,100); 
         if(A[i][j]==2) image(pig,j*100,i*100,100,100); 
      }
   }
   ellipse(mouseX,mouseY,25,25);
  text("mouseX:"+mouseX+" mouseY:"+mouseY,100,100);
  print("mouseX:"+mouseX+" mouseY:"+mouseY+"\n");
}







2020年10月12日 星期一

2020/10/12

 

讀入圖片

PImage img;


float x=100,y=100,vx=3,vy=-30;


void setup(){


    size(500,500);


    img = loadImage("bruh.jpg");


}


void draw(){


    image(img,x,y,100,100);


x += vx;


y += vy;


vy += 0.98;


}








2020年10月5日 星期一

week04 讀入圖片

讀入單一圖片 


PImage img;

size(184,184);

img = loadImage("kekw.jpg");

image( img,0,0);




讀入雙圖

PImage img;
PImage img2;

void setup(){
size(800,498);

img = loadImage("kekw.jpg");
img2 = loadImage("pog.jpg");

}

int x=0;
void draw(){
  
image( img,0,0);
image( img2,mouseX-54/2,mouseY-49/2);

}







符合物理運動的球

float x=250,y=200;
float vx=10.0,vy=10.0; //speed
void setup(){
   size(500,400); 
}
void draw(){
   ellipse(x,y,10,10);
   x+=vx;
   y+=vy;
  if(x>500||x<0) vx=-vx;
  if(y>400||y<0) vy=-vy;
}





符合牛頓第二物理運動的球

float x=250,y=200;
float vx=20.0,vy=20.0;
void setup(){
   size(1600,1200); 
}
void draw(){
  background(255);
  if(mousePressed) line(mouseX,mouseY,x,y);
  
   ellipse(x,y,10,10);
   ellipse(mouseX,mouseY,10,10);
   x+=vx;
   y+=vy;
  if(x>1600||x<0) vx=-vx;
  if(y>1200||y<0) vy=-vy;
}

void mouseReleased(){
    vx=x-mouseX;vy=y-mouseY;
}
















2020年9月21日 星期一

week02 視窗、圖形、小畫家

 

2020/9/21

打開 processing.exe



輸入size,line等指令

可繪製圖形






自動閃爍 LED 燈

void setup(){
   size(500,500); 
}
int a=0;

void draw(){
   a++;
   if(a%2==0/*mousePressed*//*手動變色*/) background(255,0,255);  //自動變色
   else background(255,255,255);
}





小畫家

void setup(){
   size(1000,800); 
}

int a=0;

void draw(){
   a++;
   if(mousePressed){
     stroke(255,0,0);  //變色
     line(mouseX,mouseY,pmouseX,pmouseY); 
   }
}