我是一个处理初学者。理想情况下,我想在显示时随机更改每个单词的字体。但是,由于我对 JAVA 缺乏了解,我现在只是尝试根据数组“nums”将每种字体更改为特定数字。你能建议我改变每个单词的字体的好主意吗?
PFont f1, f2, f3;
String message = "transText 2013";
int[] nums = {1, 3, 5, 7, 9, 11, 13};
float r,g,b = 0;
float rr = 0.5;
float gg = 0.1;
float bb = 0.3;
float n;
void setup(){
size(800,400);
frameRate(20);
nums = new int[6];
f1 = createFont("Arial-Black", 16, true);
f2 = createFont("Courier", 16, true);
}
void draw(){
rr = rr + 0.02;
gg = gg + 0.02;
bb = bb + 0.02;
background(35);
r = map(random(rr),0,1,100,255);
g = map(random(gg),0,1,100,255);
b = map(random(bb),0,1,100,255);
color n = color(r,g,b);
fill(n);
// The first character is at pixel 10.
int x = 50;
for(int i = 0; i < message.length(); i++) {
if(i == nums){
textFont(f1);
}else{
textFont(f2);
};
textSize(random(12,120));
// Each character is displayed one at a time with the charAt() function.
text(message.charAt(i),x,height/2);
// All characters are spaced 50 pixels apart.
x += textWidth(message.charAt(i));
}
}