Random Text Generator (using stored text/data)

Hi there,
I would like to use a ‘random text generator’ in a project I’m doing using Processing.
The idea is that a participant would do a ‘quiz’ on processing in which the answers would be stored as data and would then be used as ‘answers’ - which would be generated by the random text generator.

This feels like quite a big project and I’m new to coding…so, any ideas on how to do this?
Many Thanks and Best Wishes,
M

1 Like

can you elaborate on that?
you want make a kind of text window where the player can type / edit
text/answers ( on your predefined quiz questions / list )
( again stored to a answers list )

just that text window would be nothing easy,
what have you tested insofar? from a library?

Hi @kll, yes what you’ve described is right.
I may simplify my project first however and create a random text generator which generates text when mousepressed.

I am using this example code so far but I don’t know where to add in mousepressed as I keep getting an error that I am mixing active and static modes:

background(50,100,150);
fill(255);

PFont letterGothic;
letterGothic = loadFont("NotoNastaliqUrdu-48.vlw");
textFont(letterGothic,32);

// Array 

String[] nouns = {"monkey","space","cowboy","King","nut"};
String[]adjectives = {"crazy","spinning","bubbly","stinky","smelly","unreal","slow","purple"}; 

int n = int(random(6));
int m = int(random(8));

textAlign(CENTER);
text(nouns[n],45,60);
text(adjectives[m],45,40);

When I get this right I will look into getting the ‘text data’ entered by a player/participant.

But for the meantime trying to work out where to put mousePressed and why!
M

1 Like

when you learn to format your code? please repair above post!

PFont letterGothic;
//letterGothic = loadFont("NotoNastaliqUrdu-48.vlw");
//textFont(letterGothic,32);
String[] nouns = {"monkey", "space", "cowboy", "King", "nut"};
String[]adjectives = {"crazy", "spinning", "bubbly", "stinky", "smelly", "unreal", "slow", "purple"};
int n, m;

void shuffle() {
  n = int(random(5));
  m = int(random(8));
}

void setup() {
  size(500, 500, P2D);
  background(50, 100, 150);
  fill(0, 0, 200);
  textSize(32);
  //textAlign(CENTER);
}

void draw() {
  background(200, 200, 0);
  text(nouns[n], 45, 60);
  text(adjectives[m], 245, 60);
}

void mousePressed() {
 shuffle(); 
}


now that part with random text / words from a list is easy,

still, if you want the user to type ( edit ) some text
i recommend you start with that little part first
( no array, no show… )

Hi @kll
Thanks! I’ve repaired the code - just learned to code recently and realised where I went wrong!

Yes, I would like the user to type (edit) some text and for this text to be the text generated in the Random Text Generator.

Could you elaborate on what you mean when you say start with the little part first (no array, no show?)
Thanks,
M

please format your code posting by pasting it into the

</> code button

of the editor header menu ( context name: Preformatted text )
it looks like
```
type or paste code here
```

also can use the ``` manually above and below your code.

thank you.


now we need you to REPAIR your above CODE POSTING,
not make a new / better post.
( just think about the hundred people opening your topic in the future )


a new project just to test some keyboard input
aggregated to ONE string
and show that string

  • on console
  • on canvas

in minimal form


but if you not want try / learn that you still can use a good library

G4P created by Peter Lager

import g4p_controls.*;
GTextField txa;

String userinput="";

public void setup_textarea() {
  G4P.setInputFont("Times New Roman", G4P.PLAIN, 14); // New for G4P V4.3
  G4P.setGlobalColorScheme(GCScheme.PURPLE_SCHEME);
  txa = new GTextField(this, 10, 10, 200, 20);
  txa.tag = "txa";
  txa.setPromptText("Text area ");
  //txa.setText("test", 300);
}

public void show_userinput() {
  fill(0); //________________________ for result text userinput
  text(userinput, 20, height-20); //_ show ( default empty )
}

public void setup() {
  size(300, 300);
  setup_textarea();
}

public void draw() {
  background(200, 200, 0);
  show_userinput();
}

public void handleTextEvents(GEditableTextControl name, GEvent event) { 
    if ( name == txa  && event == GEvent.ENTERED ) {
      userinput = trim( txa.getText() );
      txa.setFocus(false);
      //txa.setText("over write new?");
      txa.setText("");
      txa.setPromptText("next value");
    }
}

// with current G4P V4.3.1
// there is a WARNING
// ####  Unable to create data logger  ####
// please ignore that

1 Like