【问题标题】:How do I check when when a diagonal line is off the window? Processing如何检查对角线何时离开窗口?加工
【发布时间】:2015-02-27 05:43:11
【问题描述】:

我无法弄清楚如何让线路在离开屏幕后重复。我尝试了许多 if 语句,但没有运气。截至目前,我只有这条线,但没有我提到的其他部分。谁能帮帮我。

抱歉,这里有一个更简单的版本。

float[] speeds = new float[1];
float[] diaxPos = new float[1];
float[] diayPos = new float[1];
float[] dia2xPos = new float[1];
float[] dia2yPos = new float[1];


void setup() {
  size(300, 300);
  diaxPos[0] = 0;
  diayPos[0] = 0;
  dia2xPos[0] = 0;
  dia2yPos[0] = 0;
  speeds[0] = 2;
 }

void draw() {
  background(0);
  stroke(255);


diayPos[0] += speeds[0];
  dia2xPos[0] += speeds[0];



 (diaxPos[0], diayPos[0], dia2xPos[0], dia2yPos[0]);
      }

【问题讨论】:

  • 那是很多额外的代码,你能发一个MCVE 代替吗?我们不需要所有非对角线的代码。
  • 在那里,我发布了我需要帮助的唯一代码部分。

标签: if-statement processing lines diagonal


【解决方案1】:

只需检查线路是否已离开屏幕。在您的情况下,当 X 或 Y 值大于 600 时会发生这种情况。获取一些网格纸并绘制一些示例以找出模式。

float[] speeds = new float[1];
float[] diaxPos = new float[1];
float[] diayPos = new float[1];
float[] dia2xPos = new float[1];
float[] dia2yPos = new float[1];

void setup() {
  size(300, 300);
  diaxPos[0] = 0;
  diayPos[0] = 0;
  dia2xPos[0] = 0;
  dia2yPos[0] = 0;
  speeds[0] = 2;
}

void draw() {
  background(0);
  stroke(255);

  diayPos[0] += speeds[0];
  dia2xPos[0] += speeds[0];

  if (diayPos[0] > 600) {
    diayPos[0] = 0;
    dia2xPos[0] = 0;
  }

  line(diaxPos[0], diayPos[0], dia2xPos[0], dia2yPos[0]);
}

【讨论】:

    猜你喜欢
    • 2015-09-03
    • 1970-01-01
    • 2021-06-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-30
    相关资源
    最近更新 更多