【问题标题】:Multiple sketch windows in processing处理中的多个草图窗口
【发布时间】:2017-01-11 09:13:11
【问题描述】:

我目前正在研究一种数据可视化,它从电影中获取信息,实时播放并同时创建。 为此,我想要两个单独的草图窗口。一个窗口应显示实时播放的电影,另一个窗口显示正在进行的可视化。

我似乎无法弄清楚如何轻松添加另一个草图窗口并尝试了一些不再在处理 3 中工作的示例。 (以sojamos库Control p5为例)

然后我偶然发现了这个例子: https://gist.github.com/atduskgreg/666e46c8408e2a33b09a

虽然我可以让它一次显示两个草图窗口,但我显然不能在另一个窗口上使用来自一个窗口的数据。

还有其他方法吗?

谢谢!

【问题讨论】:

  • 我可以确认 ControlP5frame 示例适用于最新版本的 controlP5 和 Processing 3.2.3。

标签: java processing


【解决方案1】:

没有什么可以阻止您在 PWindow 类(创建第二个窗口)中声明一个函数,该函数接受您可以在内部使用并从另一个草图调用它的参数。

因此您可以将表单中的数据作为函数参数传递给第二个窗口。

这个小例子通过一个函数(这里称为evokedFromPrimary)将mousePressed 的相对位置从第一个窗口传递到第二个窗口,并将其存储在ArrayList 中,该ArrayList 在第二个窗口中绘制它们:

PWindow win;

public void settings() {
  size(320, 240);
}

void setup() { 
  win = new PWindow();
}

void draw() {
  background(255, 0, 0);
  text("Click in this window to draw at a relative position in the other window", 10, 10, this.width - 20, 100);
}

void mousePressed() {
  println("mousePressed in primary window");
  float relPosX = map(mouseX, 0, this.width, 0, 100);
  float relPosY = map(mouseY, 0, this.height, 0, 100);
  win.evokedFromPrimary(relPosX, relPosY);
}  

class PWindow extends PApplet {
  ArrayList<PVector> vectors = new ArrayList<PVector>();
  PWindow() {
    super();
    PApplet.runSketch(new String[] {this.getClass().getSimpleName()}, this);
  }

  void evokedFromPrimary(float relPosX, float relPosY) {
    println("evoked from primary");

    float xPos = map(relPosX, 0, 100, 0, this.width);
    float yPos = map(relPosY, 0, 100, 0, this.height);

    vectors.add(new PVector(xPos, yPos));
  }
  void settings() {
    size(500, 200);
  }

  void setup() {
    background(150);
  }

  void draw() {
    background(150);
    //store the vector size before using to avoid ConcurrentModificationException
    int listLength = vectors.size();
    for(int i = 0; i < listLength; i++) {
      PVector v = vectors.get(i);
      ellipse(v.x, v.y, random(50), random(50));
    }

  }

  void mousePressed() {
    println("mousePressed in secondary window");
  }
}

这里的 Pwindow 代码在同一个 .pda 文件中。

【讨论】:

    猜你喜欢
    • 2015-12-24
    • 2014-01-10
    • 2017-12-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多