简体   繁体   English

使列表中的每个单词出现然后在处理中消失

[英]Make each word within a list appear and then disappear in Processing

I'm completely new to Processing, very enthusiastic, but really stumped at the first hurdle. 我对Processing完全陌生,非常热情,但真正遇到了第一步。 I really appreciate the fact that this is surely very basic stuff, but would be so happy if anyone could give me a hand to move on a bit. 我真的很欣赏这个事实,它肯定是非常基础的东西,但是如果有人可以帮我继续前进,那将是非常高兴的。

I'm looking for a way to input a long-ish list of words which will then display one by one, with each appearing for 1 second and then disappearing. 我正在寻找一种输入长长的单词列表的方法,然后将它们依次显示,每个单词出现1秒钟,然后消失。

I've found a way to print a whole sentence and have words disappear individually, and tried the below which seems to work a little better. 我找到了一种打印整个句子并使单词单独消失的方法,并尝试了以下似乎更有效的方法。 The problem with this is I can't work out how to add more words to the loop, it seems to only consider one against the other. 这样做的问题是我无法弄清楚如何在循环中添加更多单词,似乎只考虑了一个。 Is there an entirely different approach I can take? 我可以采取一种完全不同的方法吗?

Many thanks, this is where I'm up to 非常感谢,这是我的职责

String Carol = "Carol";
String Charlotte = "Charlotte";
String Ellen = "Ellen";
String displayed ="";

int interval = 1000; // s
int time;

PFont font;

void setup() {
size(500, 500);
font = createFont("arial", 44);
background(0);
displayed = Carol;
time = millis();
textFont(font);
fill(255);
}

void draw() {
background(0);
text(displayed, width/2 - textWidth(displayed)/2, height/2);

if (millis() - interval > time) {
displayed = displayed.equals(Carol)? Charlotte:Carol;
time  = millis();

Stack Overflow isn't really designed for general "how do I do this" type questions. 堆栈溢出并不是真正针对一般的“我该怎么做”类型的问题而设计的。 It's for specific "I tried X, expected Y, but got Z instead" type questions. 它是针对特定的“我尝试过X,期望是Y,但改为Z”这样的问题。 But I'll try to help in a general sense. 但我会尽力提供一般帮助。

You need to break your problem down into smaller steps and then take those steps on one at a time. 您需要将问题分解为更小的步骤 ,然后一次执行一次。 For example, can you write a simple example program that just shows a single hard-coded string? 例如,您可以编写一个仅显示单个硬编码字符串的简单示例程序吗? Now can you make it so the string disappears after 1 second? 现在您可以使它在1秒后消失吗? Then try to add a second hard-coded string that appears after the first one. 然后尝试添加第二个硬编码字符串,该字符串出现在第一个之后。

Then if you get stuck, you can post a MCVE along with a specific technical question. 然后,如果遇到问题,可以发布MCVE以及特定的技术问题。 Good luck. 祝好运。

Hint: You can probably use the millis() function or the frameCount variable. 提示:您可能可以使用millis()函数或frameCount变量。 The Processing reference is your friend. 处理参考是您的朋友。 But again, start simple and work your way forward in small incremental steps! 但同样,请从简单开始,并以较小的增量步骤逐步前进!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM