【发布时间】:2017-01-09 13:24:27
【问题描述】:
我的处理代码基于 Daniel Shiffman 的 Nature Of Code 的振荡章节,主要是他根据前进方向(鼠标)旋转移动器的示例。 它不起作用,尽管我很确定这是某个地方的一个小错误。矩形只是飞出屏幕。 书中的例子(不完整):
void display() {
float angle = velocity.heading2D;
stroke(0); fill(175); pushMatrix(); rectMode(CENTER);
translate(location.x,location.y);
rotate (angle);
rect(0,0,30,10);
popMatrix();
}
我的代码:
void show() {
angle = velocity.heading2D();
rectMode(CENTER);
pushMatrix();
translate(location.x,location.y);
rotate(angle);
fill(255,20,20,150);
rect(location.x,location.y,carSize,carSize);
popMatrix();
}
设置和绘制:
Car car ;
void setup() {
car = new Car();
}
void draw() {
mouse = new PVector(mouseX,mouseY);
background(255);
car.show();
car.move();
car.update();
}
【问题讨论】:
-
你能发一个minimal reproducible example吗?不要只发布没有任何
setup()或draw()函数的整个课程(这意味着我们无法运行您的代码),而是将您的问题缩小到几行示例代码。 -
对不起,我改一下。
-
另外,我不知道 translate(location.x,location.y) 是做什么的
标签: java animation rotation processing trigonometry