【发布时间】:2017-02-07 15:45:31
【问题描述】:
这是我的图像生成器,可用于切换。我想在新窗口中有切换按钮。我尝试使用 PApplet,但它似乎没有显示任何内容。如何为切换添加额外的窗口?
import controlP5.*;
PFont myFont;
boolean showBackground = false;
boolean showObjects = false;
boolean showGrids = false;
boolean showType = false;
ControlP5 cp5;
PImage[] objects = new PImage[30];
PImage[] grids = new PImage[29];
PImage[] backgrounds = new PImage[30];
PImage[] type = new PImage[30];
int currentBackgrounds;
int currentGrids;
int currentObjects;
int currentType;
void setup() {
size(1436, 847);
//load objects
for (int i=0; i<objects.length; i++) {
objects[i] = loadImage ( "o" + i + ".png");
}
//load grids
for (int i = 0; i < grids.length; i++) {
grids[i] = loadImage ( "g" + i + ".png");
}
//load backgrounds
for (int i = 0; i < backgrounds.length; i++) {
backgrounds[i] = loadImage( "b" + i + ".jpg");
}
//load type
for (int i = 0; i < type.length; i++) {
type[i] = loadImage ("t" + i + ".png");
}
//setup UI
String[] args = {"TwoFrameTest"};
SecondApplet sa = new SecondApplet();
PApplet.runSketch(args, sa);
}
public class SecondApplet extends PApplet {
public void settings() {
size(200, 100);
}
// create a toggle and change the default look to a switch look
public void draw() {
cp5 = new ControlP5(this);
PFont font = createFont("EurostileLTStd-BoldEx2.otf", 10);
cp5.addToggle("showBackground")
.setColorForeground(color(255, 255, 255))
.setColorBackground(color(255, 255, 255))
.setColorActive(color(255, 0, 0))
.setPosition(40, 250)
.setFont(font)
.setSize(20, 20)
.setValue(false)
.setMode(ControlP5.SWITCH);
cp5.addToggle("showObjects")
.setPosition(40, 400)
.setFont(font)
.setSize(50, 20)
.setValue(false)
.setMode(ControlP5.SWITCH);
cp5.addToggle("showGrids")
.setPosition(40, 600)
.setFont(font)
.setSize(50, 20)
.setValue(false)
.setMode(ControlP5.SWITCH);
cp5.addToggle("showType")
.setPosition(40, 800)
.setFont(font)
.setSize(50, 20)
.setValue(false)
.setMode(ControlP5.SWITCH);
}
}
void mousePressed() {
//next img
currentObjects = currentObjects + int(random(10));
currentGrids = currentGrids + int(random(10));
currentType = currentType + int(random(10));
currentBackgrounds = currentBackgrounds + int(random(10));
if (currentObjects >= objects.length) {
currentObjects = 0;
}
if (currentGrids >= grids.length) {
currentGrids = 0;
}
if (currentType >= type.length) {
currentType = 0;
}
if (currentBackgrounds >= backgrounds.length) {
currentBackgrounds = 0;
}
}
void draw() {
//clear frame
background(211);//
if (showBackground==true) {
image(backgrounds[currentBackgrounds], 0, 0, 1436, 847); // b
}
if (showGrids==true) {
image(grids[currentGrids], 0, 0, 1436, 847); // g
}
if (showObjects==true) {
image(objects[currentObjects], 0, 0, 1436, 847); // o
}
if (showType==true) {
image(type[currentType], 0, 0, 1436, 847); // o
}
}
【问题讨论】:
-
In Processing check out File > Examples > Contributed Libraries > ControlP5 > extra > ControlP5frame。在该示例中,您可以看到提到的
runSketchKevin,以及如何使用plugTo()将来自ControlFrame小程序的控件插入到第一个小程序的属性中。 -
你有想过这个问题吗?
-
不,从来没有弄清楚..
标签: image window toggle processing generator