老師今天幫我們複習一開教的Image 和vector等等的程式。
然後做了一個 像彈弓的準備做憤怒鳥的遊戲。
然後加入了減法/除法/加法 讓彈弓的東西可以飛
接下來安裝搖桿及maker uno
開始使用Arduino來做搖桿的收集參數
加入函式
讓搖桿可以寫字
程式備份:void setup() { pinMode(2,INPUT_PULLUP); Serial.begin(9600);}
void loop() { int x=analogRead(A0); int y=analogRead(A1); int sw=digitalRead(2);
Serial.write(x/4); Serial.write(y/4); Serial.write(sw); delay(20);}程式備份:PVector user;PVector Y,v=null;void setup(){ size(600,400); user = new PVector(100,300); Y=new PVector(100,300);}void draw(){ background(255); line(user.x,user.y,Y.x,Y.y); textSize(40); fill(255,0,0);text("Y",Y.x,Y.y); fill(255);ellipse(user.x,user.y,20,20); if(v!=null)user.add(v);}void mouseDragged(){ user.x=mouseX; user.y=mouseY;}void mouseReleased(){ PVector diff=PVector.sub(Y,user); v=diff.div(10);}程式備份:import processing.serial.*;Serial myPort;void setup(){ size(256,256); myPort= new Serial(this,"COM6",9600);}int ballX=0,ballY=0;void draw(){ if(myPort.available()>=3){ int x = myPort.read(); int y = myPort.read(); int sw = myPort.read(); ballX=x; ballY=y; } ellipse(ballX,ballY,10,10);}
加入函式
讓搖桿可以寫字
程式備份:
void setup() {
pinMode(2,INPUT_PULLUP);
Serial.begin(9600);
}
void loop() {
int x=analogRead(A0);
int y=analogRead(A1);
int sw=digitalRead(2);
Serial.write(x/4);
Serial.write(y/4);
Serial.write(sw);
delay(20);
}
程式備份:
PVector user;
PVector Y,v=null;
void setup(){
size(600,400);
user = new PVector(100,300);
Y=new PVector(100,300);
}
void draw(){
background(255);
line(user.x,user.y,Y.x,Y.y);
textSize(40);
fill(255,0,0);text("Y",Y.x,Y.y);
fill(255);ellipse(user.x,user.y,20,20);
if(v!=null)user.add(v);
}
void mouseDragged(){
user.x=mouseX;
user.y=mouseY;
}
void mouseReleased(){
PVector diff=PVector.sub(Y,user);
v=diff.div(10);
}
程式備份:
import processing.serial.*;
Serial myPort;
void setup(){
size(256,256);
myPort= new Serial(this,"COM6",9600);
}
int ballX=0,ballY=0;
void draw(){
if(myPort.available()>=3){
int x = myPort.read();
int y = myPort.read();
int sw = myPort.read();
ballX=x;
ballY=y;
}
ellipse(ballX,ballY,10,10);
}






沒有留言:
張貼留言