本文介绍了在Processing中创建单个草图的多个窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在Processing中创建单个草图的多个窗口?
How to create more than one window of a single sketch in Processing?
实际上我想在一个窗口中检测并跟踪特定颜色(通过网络摄像头)将检测到的坐标显示为另一个窗口中的一个点。现在我可以在检测它的同一窗口中显示这些点。但是我想把它分成两个不同的窗口。
Actually I want to detect and track a particular color (through webcam) in one window and display the detected co-ordinates as a point in another window.Till now I'm able to display the points in the same window where detecting it.But I want to split it into two different windows.
推荐答案
您需要创建一个新框架和一个新的PApplet ......这是一个示例草图:
You need to create a new frame and a new PApplet... here's a sample sketch:
import javax.swing.*;
SecondApplet s;
void setup() {
size(640, 480);
PFrame f = new PFrame(width, height);
frame.setTitle("first window");
f.setTitle("second window");
fill(0);
}
void draw() {
background(255);
ellipse(mouseX, mouseY, 10, 10);
s.setGhostCursor(mouseX, mouseY);
}
public class PFrame extends JFrame {
public PFrame(int width, int height) {
setBounds(100, 100, width, height);
s = new SecondApplet();
add(s);
s.init();
show();
}
}
public class SecondApplet extends PApplet {
int ghostX, ghostY;
public void setup() {
background(0);
noStroke();
}
public void draw() {
background(50);
fill(255);
ellipse(mouseX, mouseY, 10, 10);
fill(0);
ellipse(ghostX, ghostY, 10, 10);
}
public void setGhostCursor(int ghostX, int ghostY) {
this.ghostX = ghostX;
this.ghostY = ghostY;
}
}
这篇关于在Processing中创建单个草图的多个窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!