Processing: Array in If statement
I'm a processing beginner. Ideally, I'd like to randomly change font by
each word when it's showed. However, because of my lack of appreciation
for JAVA, I'm just trying to change each font by specific numbers
according to array "nums" for now. Could you advice me excellent idea to
change font by each word?
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));
}
}
No comments:
Post a Comment