嗯哼嗯哼,稍微複習一下之前ㄉ東C
———————————————————————————————————————
size(1138,640);
PImage img = loadImage("helios.png");
PVector pt = new PVector(10,20,0);
image(img,0,0);
println(pt.x);
//以前要用ㄉ時候
float userX=10,userY=20,userZ=0;
float user2X=30,user2Y=40,user2Z=0;
//現在可以用物件讓它有條理
PVector user = new PVector(10,20,0);
PVector user2 = new PVector(30,40,0);
———————————————————————————————————————
做憤怒鳥辣!
先弄球球出來
點擊球球會跟著動
放開會彈飛出去
———————————————————————————————————————
PVector user;//在外面宣告,setup()、draw()都看ㄉ到
PVector Y,v=null;
void setup(){
size(500,500);
user = new PVector(10,20);//只在setup()new一次
Y = new PVector(100,300);
}
//以前音樂 Minim minim = new Minim(this);
//UDP udp = new UDP(this,6000);
void draw(){
background(250);
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);
v.y += 0.98;
}//加法
}
void mouseDragged(){
user.x = mouseX;
user.y = mouseY;
}
void mouseReleased(){
PVector diff = PVector.sub(Y, user);//減法
v = diff.div(10);//除法
}
———————————————————————————————————————
———————————————————————————————————————
Ardino
void setup() {
// put your setup code here, to run once:
pinMode(2,INPUT_PULLUP);
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
int x = analogRead(A0);
int y = analogRead(A1);
int sw = analogRead(2);
Serial.write(x/4);
Serial.write(y/4);
Serial.write(sw);
delay(20);
}
———————————————————————————————————————
Processing
Processing
import processing.serial.*;
Serial myPort;
void setup(){
size(256,256);
myPort = new Serial(this, "COM6",9600);
}
int ballX=0,ballY=0;
void draw(){
background(200);
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);
}
———————————————————————————————————————





沒有留言:
張貼留言