0

所以我需要重复文本 40 次,我想出了如何做一行一定次数,但是对文本使用相同的过程是行不通的,我尝试过使用不同的代码,但我被卡住了。

任何帮助都会很棒。

我只需要在程序中重复“文本”这个词 40 次。

这是我当前的代码:

void setup() {
    size(640, 360);
    textFont(createFont("Georgia", 24));
}

void draw() {
    background(102);
    textAlign(RIGHT);
    drawType(width * 0.10);
}

void drawType(float x) {

    fill(0);

    float y = 35;
    int spacing = 50;
    int endLine = 640;

    while (x <= endLine){
        text("text", x, y, 50, 50);
        x = x + y + spacing;
    }
}

我正在使用语言处理 (processing.org),它是一种 JAVA。

4

1 回答 1

0

只是想我会清楚我的评论:

尝试

String var="";
 for(int i=0;i<40;i++)
    {
       var=var+"text";
     }

//Then use the variable got 

 text(var, x, y, 50, 50);

可能有内置函数可以更好地执行此操作,但这将是解决您的问题的简单方法。

这种方法虽然效率低下,因为 String 操作在 Java 中成本很高,因为它们是不可变的。

上面的示例将在一行中打印相同的字符串 40 次(取决于行的长度)。

If the horizontal length of the line is not sufficient, either increase the line size or decrease the spacing or decrease the number of times you are repeating the string.

于 2012-11-13T17:17:31.100 回答