I'm very new to Processing (still) but wrote a program were you can type a sentence and every word of that sentence will appear at a random spot. It works fine, but now I want to add one more thing: random text color.
I want every word to be red, yellow or blue on a random basis.
I know how to make the words really random colors by putting "random(255), random(255), random(255)" as the fill or something like that, but I want the color of the words to be randomly selected from an array.
I already created some sort of array and it picks a random color every time I click play, but then all the words appear in the same color. I want every word to be another color, so every time I hit spacebar there should be selected one, but I don't know how to fix that.
I hope I explained it clear enough. Any help is appreciated.
Here's the code I have so far:
import processing.pdf.*;
boolean saveOneFrame = false;
String tekst = "";
PGraphics textImage;
float x, y;
PImage b;
color cr=color(255,0,0); //defines RED
color cg=color(0,255,0); //defines GREEN
color cb=color(0,0,255); //defines BLUE
color cy=color(255,255,0); //defines YELLOW
color[] colors = { //random selects one of above colors
cr,cg,cb,cy
};
color c1=(colors[int(random(0,4))]); //assigns a random color from above to c1-4
I'm very new to processing, but I want t make a type input where you can type words and every time you hit the spacebar the next word should appear somewhere else (random) in the input field.
This is the code I have so far, but I still didn't find out how to make the cursor move to a random position when I hit the spacebar. Any help is appreciated, thanks in advance.
Roos
String str2 = new String("");
String tekst = "";
PFont font;
void setup() {
size(400, 400);
font = createFont("Helvetica", 18);
}
void draw() {
background(255);
fill(255, 0, 0);
textFont(font, 18);
text(tekst+("_"), 35, 95);
}
void keyReleased() {
if (key != CODED) {
switch(key) {
case BACKSPACE:
tekst = tekst.substring(0, max(0, tekst.length()-1));