憤怒鳥
PVector user;
PVector Y, v=null;
void setup(){
size(600, 400);
user = new PVector(100, 300);//(2)只在setu
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);
}
傳輸速率
void setup(){
pinMode (2, INPUT_PULLUP) ; //拉高的Input
Serial.begin (9600);//開始設定USB的傳輸速度
}
void loop() {//1000Hz (1000 fps)
int x = analogRead (A0);//0...1023
int y = analogRead(A1);//0...1023
int sw= digitalRead(2);//HIGH(放開)or LOW(按下去)
Serial.write (x);
Serial.write ('+') ;
Serial.write(y) ;
Serial.write ('+') ;
Serial.write (sw) ;
Serial.write(' ');
delay (20) ;//1000ms/20ms => 50fps,變慢了
}
import processing.serial.*;
Serial myPort;
void setup(){
size(256,256);
myPort = new Serial(this, "COM6",9600);
}
int bal1X=0,bal1Y=0;
void draw()
{
if(myPort.available()>=3)
{
int x = myPort.read();
int y = myPort.read();
int sw = myPort.read();
bal1X=x;
bal1Y=y;
}
ellipse(bal1X,bal1Y,10,10);
}
沒有留言:
張貼留言