}
float x = 200, y=300;
void draw(){
background(255);
stroke(0);
line(200, 100, x, y);
ellipse(x, y, 30, 30);
stroke(255, 0, 0);
line(x, y, x, y+100);
PVector d = new PVector(x-200, y-100).normalize();
PVector d2 = new PVector(0,1);
float g = PVector.dot(d,d2);
d.mult(100*g);
stroke(0, 255, 0);
line(x, y, x+d.x, y+d.y);
}
void mouseDragged(){
x = mouseX;
y = mouseY;
}void setup(){
size(400, 600);
c = new PVector(200, 100);// new出新的物件
p = new PVector(200, 130);// new出新的物件
}
PVector c, p;
void draw(){
background(255);
ellipse(c.x, c.y, 10, 10);//使用物件的c.x
ellipse(p.x, p.y, 10, 10);
}
void setup(){
size(400, 600);
}
float x = 200, y=300;
void draw(){
background(255);
stroke(0);
line(200, 100, x, y);
ellipse(x, y, 30, 30);
stroke(255, 0, 0);
line(x, y, x, y+100);
PVector d = new PVector(x-200, y-100).normalize();
PVector d2 = new PVector(0,1);
float g = PVector.dot(d,d2);
d.mult(100*g);
stroke(0, 255, 0);
line(x, y, x+d.x, y+d.y);
PVector N = new PVector(d.y, -d.x).normalize();
N.mult(100*sin(acos(g)));//g是cos(a),acos(g)就是角度a
stroke(0,0,255);
line(x, y, x+N.x, y+N.y);
}
void mouseDragged(){
x = mouseX;
y = mouseY;
}
會左右擺動但會無限拉長
void setup(){
size(400, 600);
}
float x = 200, y=300;
void draw(){
background(255);
stroke(0);
line(200, 100, x, y);
ellipse(x, y, 30, 30);
stroke(255, 0, 0);
line(x, y, x, y+100);
PVector d = new PVector(x-200, y-100).normalize();
PVector d2 = new PVector(0,1);
float g = PVector.dot(d,d2);
d.mult(100*g);
stroke(0, 255, 0);
line(x, y, x+d.x, y+d.y);
PVector N = PVector.sub(d2.mult(100), d);//PVector N = new PVector(d.y, -d.x).normalize();
//N.mult(100*sin(acos(g)));//g是cos(a),acos(g)就是角度a
stroke(0,0,255);
line(x, y, x+N.x, y+N.y);
v.x += N.x / 1000;
v.y += N.y / 1000;
x += v.x;
y += v.y;
}
PVector v = new PVector();//球的速度,一開始是0
void mouseDragged(){
x = mouseX;
y = mouseY;
}
沒有留言:
張貼留言