【发布时间】:2023-04-03 05:37:01
【问题描述】:
在直接使用 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;
}
- 在处理中,当三角形顶点位于顶部时绘制椭圆,这是我的目标。
- 在在线素描中,椭圆是在整个过程中绘制的:/
【问题讨论】:
-
请注意 processing.js 已于 2018 年 12 月停用。请勿使用它编写代码。另请注意,它与 p5js 不是同一个项目,仍然维护着很多 。
标签: processing open-source p5.js processing.js