processing - native 和在线草图之间的不同处理渲染

标签 processing open-source p5.js processing.js

直接使用 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()

时指定 z 坐标
current = screenY(-90, -60, 0);

通过这两项更改,您应该可以在线获得与在本地运行相同的结果。

在线:

Triangle Ellipse Example

本地:

Triangle Ellipse Exampl

关于processing - native 和在线草图之间的不同处理渲染,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55429762/

相关文章:

java - 如何增加堆栈大小以允许更多递归?

java - 需要 TRIPLE_DOT,发现为 ';'

java - Daisy CMS 构建时遇到问题

javascript - 在同一个 Sublime Text 窗口中使用 paper.js 和 p5.js

javascript - 使用 canvas 和 p5.js 移动正方形

javascript - 动态 "unload"从 Canvas 处理 JS 草图

javascript - 不能将 'PImage' 作为 Processing.js 中的类属性

初学者程序员的 C++ 开源项目?

open-source - StreamBase是否有开源替代方案?

javascript - React 渲染两个 p5.js Canvas