直接使用 Processing 和浏览器中的 Processing.js 运行此示例时,我得到了不同的结果。为什么?
我对我的结果很满意,想在开放式处理中分享它,但渲染完全不同,我不明白为什么。下面是一个最小的工作示例。
/* Program that rotates a triange and draws an ellipse when the third vertex is on top of the screen*/
float y = 3*height/2;
float x = 3*width/2;
float previous_1 = 0.0;
float previous_2 = 0.0;
float current;
float angle = 0.0;
void setup() {
size(1100, 500);
}
void draw() {
fill(0, 30);
// rotate triangle
angle = angle - 0.02;
translate(x, y);
rotate(angle);
// display triangle
triangle(-50, -50, -30, 30, -90, -60);
// detect whether third vertex is on top by comparing its 3 successive positions
current = screenY(-90, -60); // current position of the third vertex
if (previous_1 < previous_2 && previous_1 < current) {
// draw ellipse at the extrema position
fill(128, 9, 9);
ellipse(-90, -60, 7, 10);
}
// update the 2 previous positions of the third vertex
previous_2 = previous_1;
previous_1 = current;
}
- 在处理过程中,三角形顶点在上时绘制椭圆,这是我的目标。
- 在在线素描中,椭圆一直在画:/
最佳答案
为了在线获得与本地运行处理相同的结果,您需要在调用 size 时将渲染模式指定为 3d。
例如:
void setup() {
size(1100, 500, P3D);
}
您还需要在调用 screenY()
current = screenY(-90, -60, 0);
通过这两项更改,您应该可以在线获得与在本地运行相同的结果。
在线:
本地:
关于processing - native 和在线草图之间的不同处理渲染,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55429762/