Processing 处理:我需要计数器内的绘图功能
我正在使用Processing 处理:我需要计数器内的绘图功能,processing,Processing,我正在使用controlP5处理GUI,我需要draw()函数中的计数器 我知道draw()函数连续运行,每个for循环都显示在最后一步中 我需要看到每一步。由于draw(),我有两个输入,只能输入一次。我需要draw()函数来等待输入或类似的东西 import controlP5.*; Textarea myTextareaMI; Textarea myTextareaVI; Textarea my; String textValueBODOVI = ""; String textValu
controlP5
处理GUI,我需要draw()函数中的计数器
我知道draw()
函数连续运行,每个for循环都显示在最后一步中
我需要看到每一步。由于draw()
,我有两个输入,只能输入一次。我需要draw()
函数来等待输入或类似的东西
import controlP5.*;
Textarea myTextareaMI;
Textarea myTextareaVI;
Textarea my;
String textValueBODOVI = "";
String textValueZVANJE = "";
boolean mi=false, vi=false;
int i=1;
ControlP5 cp5;
int myColor = color(255);
int c1, c2;
float n, n1;
void setup() {
size(320, 480);
noStroke();
PFont font = createFont("arial", 20);
cp5 = new ControlP5(this);
cp5.addButton("NOVA PARTIJA")
.setValue(0)
.setPosition(0, 0)
.setSize(480, 19)
;
cp5.addButton("PONISTI ZADNJI UNOS")
.setValue(100)
.setPosition(0, 20)
.setSize(480, 19)
;
cp5.addBang("MI")
.setPosition(60, 80)
.setSize(60, 20)
.getCaptionLabel().align(ControlP5.CENTER, ControlP5.CENTER)
;
cp5.addBang("VI")
.setPosition(123, 80)
.setSize(60, 20)
.getCaptionLabel().align(ControlP5.CENTER, ControlP5.CENTER)
;
cp5.addTextfield("BODOVI")
.setPosition(60, 41)
.setSize(60, 20)
.setFont(font)
.setColor(color(255, 0, 0))
;
cp5.addTextfield("ZVANJE")
.setPosition(123, 41)
.setSize(60, 20)
.setFont(font)
.setColor(color(255, 0, 0))
;
;
int l=0;
for (int i=1;i<11;i++,l=l+22) {
my = cp5.addTextarea("MIVI"+i).setPosition(60, 101+l).setSize(123, 20).setFont(createFont("arial", 14))
.setLineHeight(14)
.setColor(color(128))
.setColorBackground(color(255, 100))
.setColorForeground(color(255, 100))
;
}
}
public void bang() {
}
void draw() {
delay(15);
background(myColor);
myColor = lerpColor(c1, c2, n);
n += (1-n)* 0.1;
funkcija();
}
void funkcija(){
int suma= 0;
for( i=1;i<=11;i++){
int brojmi=0;
textValueZVANJE = cp5.get(Textfield.class, "ZVANJE").getText();
textValueBODOVI = cp5.get(Textfield.class, "BODOVI").getText();
int bodovi = int(textValueBODOVI);
int zvanje = int(textValueZVANJE);
int mii, vii;
if(bodovi>0){
if (mi) {
println("mi"+brojmi+i);
int ukupno = 162 + zvanje;
vii = ukupno - bodovi;
cp5.get(Textarea.class, "MIVI"+i).setText(textValueBODOVI+" "+vii);
mi=false;
vi=false;
cp5.get(Textfield.class, "BODOVI").clear();
cp5.get(Textfield.class, "ZVANJE").clear();
loop();
}
if (vi) {
println("vi"+i);
int ukupno = 162 + zvanje;
mii = ukupno - bodovi;
cp5.get(Textarea.class, "MIVI"+i).setText(mii+" "+textValueBODOVI);
mi=false;
vi=false;
cp5.get(Textfield.class, "BODOVI").clear();
cp5.get(Textfield.class, "ZVANJE").clear();
}
}
brojmi++; }
}
public void controlEvent(ControlEvent theEvent) {
mi = theEvent.getController().getName().equals("MI");
vi = theEvent.getController().getName().equals("VI");
}
public void clear() {
cp5.get(Textfield.class, "BODOVI").clear();
cp5.get(Textfield.class, "ZVANJE").clear();
}
导入控制p5.*;
Textarea myTextareaMI;
Textarea myTextareaVI;
文本区域我的;
字符串textValueBODOVI=“”;
字符串textValueZVANJE=“”;
布尔值mi=false,vi=false;
int i=1;
控制p5-cp5;
int myColor=color(255);
int c1,c2;
n,n1;
无效设置(){
尺寸(320480);
仰泳();
PFont font=createFont(“arial”,20);
cp5=新控制P5(本);
cp5.addButton(“NOVA PARTIJA”)
.setValue(0)
.设置位置(0,0)
.设置大小(480,19)
;
cp5.添加按钮(“Poniti ZADNJI UNOS”)
.设定值(100)
.设置位置(0,20)
.设置大小(480,19)
;
cp5.addBang(“MI”)
.设置位置(60,80)
.设置大小(60,20)
.getCaptionLabel().align(ControlP5.CENTER,ControlP5.CENTER)
;
cp5.addBang(“VI”)
.设置位置(123,80)
.设置大小(60,20)
.getCaptionLabel().align(ControlP5.CENTER,ControlP5.CENTER)
;
cp5.addTextfield(“BODOVI”)
.设置位置(60,41)
.设置大小(60,20)
.setFont(字体)
.setColor(颜色(255,0,0))
;
cp5.addTextfield(“ZVANJE”)
.设置位置(123、41)
.设置大小(60,20)
.setFont(字体)
.setColor(颜色(255,0,0))
;
;
int l=0;
对于(inti=1;iMmmmm,我不知道我是否明白你的问题。
如果您的问题是:“我需要draw()函数等待输入或类似的内容”,则使用标志(布尔值)来决定是否绘制。当用户输入某个内容时,将该值指定为true
因此,您的代码应该是:
void draw () {
// put the code you want to run anyways here...
// code
// code
if (hasUserInput) {
// here write the code you should wait to execute
}
}