We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Please check
https://forum.processing.org/two/discussion/comment/120544/#Comment_120544
Also
https://forum.processing.org/two/search?Search=adjectives
https://forum.processing.org/two/search?Search=adverbs
Kf
String[] adjective1 = loadStrings("adjectives.txt");
String[] noun1 = loadStrings("nouns.txt");
String[] adverb1 = loadStrings("adverbs.txt");
String[] verb1 = loadStrings("verbs.txt");
String[] adjective = loadStrings("adjectives.txt");
String[] noun = loadStrings("nouns.txt");
void setup ( )
adjective1 = loadStrings("adjectives.txt");
noun1 = loadStrings("nouns.txt");
adverb1 = loadStrings("adverbs.txt");
verb1 = loadStrings("verbs.txt");
adjective = loadStrings("adjectives.txt");
noun = loadStrings("nouns.txt");
{
size(500,500);
background(0);
}
Would it be along the lines of that then? I am still working on correctly structuring my code. I am looking at split[] now
I can see the 3d shapes being drawn to my Processing window, but the saveFrame() I have at the very end of draw isn't picking up my 3d shapes, nor is Syphon. What the heck?
class Trackbox {
// testing...
// Am I available to be matched?
boolean available;
// Should I be deleted?
boolean delete;
// How long should I live if I have disappeared?
int timer = 8; // in frames
// Assign a number to each face
int id;
//float newX, newY, newW, newH; // tweened values
PVector coords, dims;
static final float LERP_SPD = .5; // how quick the box is. lower number is smoother but slower
static final float ROT_SPD = .1;
float rot = 0; // rotation for other shapes
int adverbID, emotionID; // which adverb and emo gets printed below face
Trackbox(Rectangle r) {
coords = new PVector(r.x * SCALER, r.y * SCALER);
dims = new PVector(r.width * SCALER, r.height * SCALER);
// pick an adverb and emotion out
adverbID = floor(random(adverbs.length));
emotionID = floor(random(emotions.length));
// the face lock stuff...
available = true;
delete = false;
id = faceCount;
faceCount++;
}
void update(Rectangle r) {
coords.lerp(r.x * SCALER, r.y * SCALER, 0, LERP_SPD);
dims.lerp(r.width * SCALER, r.height * SCALER, 0, LERP_SPD);
}
void display() {
// set up color and such
noFill();
stroke(255, 255, 0);
strokeWeight(lineThickness);
// rect around face
if (drawRect) {
rect(coords.x, coords.y, dims.x, dims.y);
}
// lines from corners
if (cornerLines) {
line(0, 0, coords.x, coords.y);
line(0, height, coords.x, coords.y + dims.y);
line(width, height, coords.x + dims.x, coords.y + dims.y);
line(width, 0, coords.x + dims.x, coords.y);
}
// drawing cube
if (drawBox) {
pushMatrix();
translate(coords.x + dims.x / 2, coords.y + dims.y / 2, 0);
rotateY(rot += ROT_SPD);
rotateX(rot);
box((dims.x + dims.y) / 2);
popMatrix();
}
// copy face
if (copyFace) {
PImage face = get(int(coords.x), int(coords.y), int(dims.x), int(dims.y));
image(face, 0, 0);
}
// filter face
if (blurFace || threshFace) {
PImage face = get(int(coords.x), int(coords.y), int(dims.x), int(dims.y));
if (blurFace)
face.filter(BLUR, 10);
if (threshFace)
face.filter(THRESHOLD, .5);
image(face, coords.x, coords.y);
}
// meta cube
if (meta) {
PImage face = get(int(coords.x), int(coords.y), int(dims.x), int(dims.y + 20));
TexturedCube(face);
}
// text
if (drawText) {
textAlign(CENTER);
textSize(TEXT_SIZE);
String a = adverbs[adverbID];
String e = emotions[emotionID];
String s = "YOU ARE " + a + " " + e;
text(s, coords.x + dims.x / 2, coords.y + dims.y + TEXT_SIZE);
}
}
// beta... create a textured cube of face
void TexturedCube(PImage tex) {
pushMatrix();
//tint(255,200);
translate(coords.x + dims.x / 2, coords.y + dims.y / 2, 0);
rotateY(rot += ROT_SPD);
rotateX(rot);
scale((dims.x + dims.y) / 4);
beginShape(QUADS);
noStroke();
textureMode(NORMAL);
texture(tex);
// +Z "front" face
vertex(-1, -1, 1, 0, 0);
vertex( 1, -1, 1, 1, 0);
vertex( 1, 1, 1, 1, 1);
vertex(-1, 1, 1, 0, 1);
// -Z "back" face
vertex( 1, -1, -1, 0, 0);
vertex(-1, -1, -1, 1, 0);
vertex(-1, 1, -1, 1, 1);
vertex( 1, 1, -1, 0, 1);
// +Y "bottom" face
vertex(-1, 1, 1, 0, 0);
vertex( 1, 1, 1, 1, 0);
vertex( 1, 1, -1, 1, 1);
vertex(-1, 1, -1, 0, 1);
// -Y "top" face
vertex(-1, -1, -1, 0, 0);
vertex( 1, -1, -1, 1, 0);
vertex( 1, -1, 1, 1, 1);
vertex(-1, -1, 1, 0, 1);
// +X "right" face
vertex( 1, -1, 1, 0, 0);
vertex( 1, -1, -1, 1, 0);
vertex( 1, 1, -1, 1, 1);
vertex( 1, 1, 1, 0, 1);
// -X "left" face
vertex(-1, -1, -1, 0, 0);
vertex(-1, -1, 1, 1, 0);
vertex(-1, 1, 1, 1, 1);
vertex(-1, 1, -1, 0, 1);
endShape();
noTint();
popMatrix();
}
// testing...
// Count me down, I am gone
void countDown() {
timer--;
}
// I am deed, delete me
boolean dead() {
if (timer < 0) return true;
return false;
}
}
I'll just assume it's the latter. A simple loadStrings() will do the whole work then:
https://processing.org/reference/loadStrings_.html
In order to store the output from loadStrings(), we're gonna need Map<String, String[]>.
// forum.processing.org/two/discussion/10726/
// php-to-processing-variable-variables
// 2015-May-11
final String[] LIST = {
"interjections",
"determiners",
"adjectives",
"nouns",
"adverbs",
"verbs",
"prepositions",
"conjunctions",
"comparatives"
};
import java.util.Map;
import java.util.Map.Entry;
final int CAPACITY = ceil(LIST.length/.75);
final Map<String, String[]> grammar = new HashMap<String, String[]>(CAPACITY);
for (String entry : LIST) grammar.put(entry, loadStrings(entry + ".txt"));
for (Entry<String, String[]> pair : grammar.entrySet()) {
println(pair.getKey(), ':');
printArray(pair.getValue());
println();
}
print("Random word value from \"verbs\" key: ");
String[] words = grammar.get("verbs");
println("\"" + words[(int) random(words.length)] + "\"");
exit();
Before anything, an alternative to previous example: :D
// forum.processing.org/two/discussion/10726/
// php-to-processing-variable-variables
final String[] lists = {
"interjections",
"determiners",
"adjectives",
"nouns",
"adverbs",
"verbs",
"prepositions",
"conjunctions",
"comparatives"
};
import java.util.Map;
import java.util.Map.Entry;
final int capacity = ceil(lists.length/.75), len = 2;
final Map<String, char[]> chars = new HashMap<String, char[]>(capacity);
for (String part : lists) {
char[] ch = new char[len];
for ( int i = 0; i != len; ch[i++] = part.charAt((int) random(part.length())) );
chars.put(part, ch);
}
for (Entry<String, char[]> pair : chars.entrySet()) {
print(pair.getKey(), ": ");
for (char ch : pair.getValue()) print(ch, ' ');
println();
}
println("\nverbs:", chars.get("verbs")[0], chars.get("verbs")[1]);
exit();
In Java, the []
array access operator always means the index of some array:
https://processing.org/reference/arrayaccess.html
Seems like in PHP, []
has multiple meanings.
While in ${$part}[$i] =
the []
over there means array access,
in ${$part}[rand( ... )]
apparently it means a char
position within the String now.
And translating the latter to Java's String, it corresponds to its method charAt():
https://processing.org/reference/String_charAt_.html
Plus the count() function would correspond to String's length() method:
https://processing.org/reference/String_length_.html
And obviously, rand() is Processing's random(): 3:-O
https://processing.org/reference/random_.html
In short, it's randomly picking up 1 char
outta the String as value and associating it w/ the same String as the key.
So the {key : value} pair relationship is <String, Character>
in Java.
For that, this time we're gonna use a HashMap<String, Character> in place of previous StringDict.
More specifically, an array of Map<String, Character>[]: :D
https://processing.org/reference/HashMap.html
You see, If I got that right, the ${$part}[$i]
is actually creating an array of Map[] in order to store 1 random() char
.
Well, here it goes the probable solution for your mysterious PHP sample: #:-S
// forum.processing.org/two/discussion/10726/
// php-to-processing-variable-variables
final String[] lists = {
"interjections",
"determiners",
"adjectives",
"nouns",
"adverbs",
"verbs",
"prepositions",
"conjunctions",
"comparatives"
};
import java.util.Map;
final int capacity = ceil(lists.length/.75);
final Map<String, Character>[] chars = new Map[] {
new HashMap<String, Character>(capacity), new HashMap<String, Character>(capacity)
};
for (String part : lists) for (int i = 0; i != chars.length; ++i)
chars[i].put( part, part.charAt((int) random(part.length())) );
printArray(chars);
println();
println("verbs:", chars[0].get("verbs"), chars[1].get("verbs"));
exit();
Dunno PHP, sorry. And Java, just like C/C++, is very strongly typed.
That is, in Java we gotta declare the type of each variable and each container.
Your $lists seems like an array of String[] type.
So it's something like: String[] lists = {}
Unfortunately, we can't dynamically create variables in Java.
That is, all variables gotta be explicitly written in the source.
We can't just pick or concatenate a String and state that is a new variable now.
However, we can use a Map type container w/ {key : value} pairs.
I've chosen StringDict for this attempt: https://processing.org/reference/StringDict.html
But some HashMap<String, String> would be even faster...
// forum.processing.org/two/discussion/10726/
// php-to-processing-variable-variables
final String[] lists = {
"interjections",
"determiners",
"adjectives",
"nouns",
"adverbs",
"verbs",
"prepositions",
"conjunctions",
"comparatives"
};
final StringDict paths = new StringDict(lists.length);
for (String part : lists) paths.set(part, dataPath(part + ".txt"));
println(paths);
println();
println("verbs:", paths.get("verbs"));
exit();
I am still having issues with the spacing and I think it is because my code elsewhere.
// Template sketch for Random sentences d
// **** Declare four arrays of String, one for each of adjectives, adverbs, nouns and verbs
String [] adjective;
String [] adverb;
String [] noun;
String [] verb;
int oddEven = 0 ;
// **** Declare seperate String variables to hold each part of speech randomly
// **** selected -- two nouns, two adjectives, one adverb and one verb.
void setup ( ) {
noun = loadStrings("noun.txt");
adjective = loadStrings("adj.txt");
verb = loadStrings("verb.txt");
adverb = loadStrings("adv.txt");
// Ths code just flashes a rectangle so you see that the
// sketch is running while waiting for a mouse click
size ( 200, 200 ) ;
background ( 0 ) ;
frameRate ( 10 ) ; // This slows the program down a bit to make the output easier to read
}
void draw ( )
{
int index1 = int(random(adjective.length));
String adj1 = adjective[index1];
int index2 = int(random(adjective.length));
String adj2 = adjective[index2];
int index3 = int(random(noun.length));
String noun1 = noun[index3];
int index4 = int(random(noun.length));
String noun2 = noun[index4];
int index5 = int(random(verb.length));
String verb1 = verb[index5];
int index6 = int(random(adverb.length));
String adverb1 = adverb[index6];
if ( oddEven %2 == 0 )
{
fill ( 255, 0, 0 ) ;
}
else
{
fill ( 0, 0, 255 ) ;
}
oddEven ++ ;
rect ( 100, 100, 50, 50 ) ;
// end of rectangle blinking code
if ( mousePressed )
{
// **** select a random adjective from the adjectives array, store it in String
// **** Repeat this logic for one more adjective, two nouns, one adverb and one adjective
// **** Modify this to print out your random parts of speech to make a "sentence", well sort of
println ( "The "+ adj1 +""+ adj2 +""+ noun1 +""+ noun2 +""+ verb1 +""+ adverb1 + "!");
} // end mousepressed
}
// end setup
// Template sketch for Random sentences d
// **** Declare four arrays of String, one for each of adjectives, adverbs, nouns and verbs
String [] adjective;
String [] adverb;
String [] noun;
String [] verb;
int oddEven = 0 ;
// **** Declare seperate String variables to hold each part of speech randomly
// **** selected -- two nouns, two adjectives, one adverb and one verb.
void setup ( ) {
noun = loadStrings("noun.txt");
noun = loadStrings("noun.txt");
adjective = loadStrings("adj.txt");
adjective = loadStrings("adj.txt");
verb = loadStrings("verb.txt");
adverb = loadStrings("adv.txt");
// Ths code just flashes a rectangle so you see that the
// sketch is running while waiting for a mouse click
size ( 200, 200 ) ;
background ( 0 ) ;
frameRate ( 10 ) ; // This slows the program down a bit to make the output easier to read
}
void draw ( )
{
int index1 = int(random(adjective.length));
String adj1 = adjective[index1];
int index2 = int(random(adjective.length));
String adj2 = adjective[index2];
int index3 = int(random(noun.length));
String noun1 = noun[index3];
int index4 = int(random(noun.length));
String noun2 = noun[index4];
int index5 = int(random(verb.length));
String verb1 = verb[index5];
int index6 = int(random(adverb.length));
String adverb1 = adverb[index6];
if ( oddEven %2 == 0 )
{
fill ( 255, 0, 0 ) ;
}
else
{
fill ( 0, 0, 255 ) ;
}
oddEven ++ ;
rect ( 100, 100, 50, 50 ) ;
// end of rectangle blinking code
if ( mousePressed )
{
// **** select a random adjective from the adjectives array, store it in String
// **** Repeat this logic for one more adjective, two nouns, one adverb and one adjective
// **** Modify this to print out your random parts of speech to make a "sentence", well sort of
println ( "The "+ (adj1) + (adj2) +(noun1) + (noun2) + (verb1) + (adverb1));
} // end mousepressed
}
// end setup
// Template sketch for Random sentences d
// **** Declare four arrays of String, one for each of adjectives, adverbs, nouns and verbs String [] adjective; String [] adverb; String [] noun; String [] verb;
int oddEven = 0 ;
// **** Declare seperate String variables to hold each part of speech randomly
// **** selected -- two nouns, two adjectives, one adverb and one verb.
void setup ( ) {
noun = loadStrings("noun.txt"); noun = loadStrings("noun.txt"); adjective = loadStrings("adj.txt"); adjective = loadStrings("adj.txt"); verb = loadStrings("verb.txt"); adverb = loadStrings("adv.txt"); // Ths code just flashes a rectangle so you see that the // sketch is running while waiting for a mouse click size ( 200, 200 ) ;
background ( 0 ) ;
frameRate ( 10 ) ; // This slows the program down a bit to make the output easier to read
}
void draw ( )
{
int index1 = int(random(adjective.length));
String adj1 = adjective[index1];
int index2 = int(random(adjective.length));
String adj2 = adjective[index2];
int index3 = int(random(noun.length));
String noun1 = noun[index3];
int index4 = int(random(noun.length));
String noun2 = noun[index4];
int index5 = int(random(verb.length));
String verb1 = verb[index5];
int index6 = int(random(adverb.length));
String adverb1 = adverb[index6];
if ( oddEven %2 == 0 ) { fill ( 255, 0, 0 ) ; } else { fill ( 0, 0, 255 ) ; }
oddEven ++ ;
rect ( 100, 100, 50, 50 ) ;
// end of rectangle blinking code
if ( mousePressed ) { // **** select a random adjective from the adjectives array, store it in String
// **** Repeat this logic for one more adjective, two nouns, one adverb and one adjective
// **** Modify this to print out your random parts of speech to make a "sentence", well sort of
println ( "The "+ (adj1) + (adj2) +(noun1) + (noun2) + (verb1) + (adverb1));
} // end mousepressed } // end setup
That was a big help! The only issue I have now is the spacing between each.
// Template sketch for Random sentences d
// **** Declare four arrays of String, one for each of adjectives, adverbs, nouns and verbs String [] adjective; String [] adverb; String [] noun; String [] verb;
int oddEven = 0 ;
// **** Declare seperate String variables to hold each part of speech randomly
// **** selected -- two nouns, two adjectives, one adverb and one verb.
void setup ( ) {
noun = loadStrings("noun.txt"); noun = loadStrings("noun.txt"); adjective = loadStrings("adj.txt"); adjective = loadStrings("adj.txt"); verb = loadStrings("verb.txt"); adverb = loadStrings("adv.txt"); // Ths code just flashes a rectangle so you see that the // sketch is running while waiting for a mouse click size ( 200, 200 ) ;
background ( 0 ) ;
frameRate ( 10 ) ; // This slows the program down a bit to make the output easier to read
}
void draw ( )
{
int index1 = int(random(adjective.length));
String adj1 = adjective[index1];
int index2 = int(random(adjective.length));
String adj2 = adjective[index2];
int index3 = int(random(noun.length));
String noun1 = noun[index3];
int index4 = int(random(noun.length));
String noun2 = noun[index4];
int index5 = int(random(verb.length));
String verb1 = verb[index5];
int index6 = int(random(adverb.length));
String adverb1 = adverb[index6];
if ( oddEven %2 == 0 ) { fill ( 255, 0, 0 ) ; } else { fill ( 0, 0, 255 ) ; }
oddEven ++ ;
rect ( 100, 100, 50, 50 ) ;
// end of rectangle blinking code
if ( mousePressed ) { // **** select a random adjective from the adjectives array, store it in String
// **** Repeat this logic for one more adjective, two nouns, one adverb and one adjective
// **** Modify this to print out your random parts of speech to make a "sentence", well sort of
println ( "The "+ (adj1) + (adj2) +(noun1) + (noun2) + (verb1) + (adverb1));
} // end mousepressed } // end setup
Almost there! I really appreciate your help. It runs but the output is garbled.
// Template sketch for Random sentences d
// **** Declare four arrays of String, one for each of adjectives, adverbs, nouns and verbs String [] adjective; String [] adverb; String [] noun; String [] verb;
int oddEven = 0 ;
// **** Declare seperate String variables to hold each part of speech randomly
// **** selected -- two nouns, two adjectives, one adverb and one verb.
void setup ( ) {
noun = loadStrings("noun.txt"); noun = loadStrings("noun.txt"); adjective = loadStrings("adj.txt"); adjective = loadStrings("adj.txt"); verb = loadStrings("verb.txt"); adverb = loadStrings("adv.txt"); // Ths code just flashes a rectangle so you see that the // sketch is running while waiting for a mouse click size ( 200, 200 ) ;
background ( 0 ) ;
frameRate ( 10 ) ; // This slows the program down a bit to make the output easier to read
}
void draw ( )
{
int index1 = int(random(adjective.length));
String adj1 = adjective[index1];
int index2 = int(random(adjective.length));
String adj2 = adjective[index2];
int index3 = int(random(noun.length));
String noun1 = noun[index3];
int index4 = int(random(noun.length));
String noun2 = noun[index4];
int index5 = int(random(verb.length));
String verb1 = verb[index5];
int index6 = int(random(adverb.length));
String adverb1 = adverb[index6];
if ( oddEven %2 == 0 ) { fill ( 255, 0, 0 ) ; } else { fill ( 0, 0, 255 ) ; }
oddEven ++ ;
rect ( 100, 100, 50, 50 ) ;
// end of rectangle blinking code
if ( mousePressed ) { // **** select a random adjective from the adjectives array, store it in String
// **** Repeat this logic for one more adjective, two nouns, one adverb and one adjective
// **** Modify this to print out your random parts of speech to make a "sentence", well sort of
println ( "The" + adjective + adjective + noun + noun + verb + adverb);
} // end mousepressed } // end setup
// Template sketch for Random sentences d
// **** Declare four arrays of String, one for each of adjectives, adverbs, nouns and verbs String [] adjective; String [] adverb; String [] noun; String [] verb;
int oddEven = 0 ;
// **** Declare seperate String variables to hold each part of speech randomly
// **** selected -- two nouns, two adjectives, one adverb and one verb.
void setup ( ){ String [] adjective = loadStrings("adj.txt"); String [] adverb = loadStrings("adv.txt"); String [] noun = loadStrings("noun.txt"); String [] verb = loadStrings("verb.txt"); // Ths code just flashes a rectangle so you see that the // sketch is running while waiting for a mouse click size ( 200, 200 ) ;
background ( 0 ) ;
frameRate ( 10 ) ; // This slows the program down a bit to make the output easier to read } void draw ( ) {
if ( oddEven %2 == 0 ) { fill ( 255, 0, 0 ) ; } else { fill ( 0, 0, 255 ) ; }
oddEven ++ ;
rect ( 100, 100, 50, 50 ) ;
// end of rectangle blinking code
if ( mousePressed ) { // **** select a random adjective from the adjectives array, store it in String
// **** Repeat this logic for one more adjective, two nouns, one adverb and one adjective
// **** Modify this to print out your random parts of speech to make a "sentence", well sort of
int index1 = int(random(adjective.length));
adjective = adjective[index1];
int index2 = int(random(adjective.length));
adjective = adjective[index2];
int index3 = int(random(noun.length));
noun = noun[index3];
int index4 = int(random(noun.length));
noun = noun[index4];
int index5 = int(random(verb.length));
verb = verb[index5];
int index5 = int(random(adverb.length));
adverb = adverb[index6];
println ( "The" + adj + adj + noun + noun + verb + adv) ;
} // end mousepressed } // end setup
// Template sketch for Random sentences d
// **** Declare four arrays of String, one for each of adjectives, adverbs, nouns and verbs String [] adjective; String [] adverb; String [] noun; String [] verb;
int oddEven = 0 ;
// **** Declare seperate String variables to hold each part of speech randomly
// **** selected -- two nouns, two adjectives, one adverb and one verb.
void setup ( ) { String [] adjective = loadStrings("adj.txt"); String [] adverb = loadStrings("adv.txt"); String [] noun = loadStrings("noun.txt"); String [] verb = loadStrings("verb.txt"); // Ths code just flashes a rectangle so you see that the // sketch is running while waiting for a mouse click size ( 200, 200 ) ;
background ( 0 ) ;
frameRate ( 10 ) ; // This slows the program down a bit to make the output easier to read
} void draw ( ) {
if ( oddEven %2 == 0 ) { fill ( 255, 0, 0 ) ; } else { fill ( 0, 0, 255 ) ; }
oddEven ++ ;
rect ( 100, 100, 50, 50 ) ;
// end of rectangle blinking code
if ( mousePressed ) { // **** select a random adjective from the adjectives array, store it in String
// **** Repeat this logic for one more adjective, two nouns, one adverb and one adjective
// **** Modify this to print out your random parts of speech to make a "sentence", well sort of
int index1 = int(random(adjective.length));
adjective = adjective[index1];
int index2 = int(random(adjective.length));
adjective = adjective[index2];
int index3 = int(random(noun.length));
noun = noun[index3];
int index4 = int(random(noun.length));
noun = noun[index4];
int index5 = int(random(verb.length));
verb = verb[index5];
int index5 = int(random(adverb.length));
adverb = adverb[index6];
println ( "The" + adj + adj + noun + noun + verb + adv) ;
} // end mousepressed } // end setup
I am trying to get the code to go in correctly but having issues. I have revised after rereading everything but am having the same issues. The confusion lies in how it opens the file located in it's folder and then thus randomly generates the sentences in the display. Also I am sorry for the improper formation but I cannot it to go all in as code below. Not sure why.
// Template sketch for Random sentences d
// **** Declare four arrays of String, one for each of adjectives, adverbs, nouns and verbs String [] adjective; String [] adverb; String [] noun; String [] verb;
int oddEven = 0 ;
// **** Declare seperate String variables to hold each part of speech randomly
// **** selected -- two nouns, two adjectives, one adverb and one verb.
void setup ( ) { size ( 200, 200 ) ;
background ( 0 ) ;
frameRate ( 10 ) ; // This slows the program down a bit to make the output easier to read
adjective = loadStrings("adj.txt"); adverb = loadStrings("adv.txt"); noun = loadStrings("noun.txt"); verb = loadStrings("verb.txt"); } void draw ( ) {
// Ths code just flashes a rectangle so you see that the // sketch is running while waiting for a mouse click if ( oddEven %2 == 0 ) { fill ( 255, 0, 0 ) ; } else { fill ( 0, 0, 255 ) ; }
oddEven ++ ;
rect ( 100, 100, 50, 50 ) ;
// end of rectangle blinking code
if ( mousePressed ) { // **** select a random adjective from the adjectives array, store it in String
// **** Repeat this logic for one more adjective, two nouns, one adverb and one adjective
// **** Modify this to print out your random parts of speech to make a "sentence", well sort of
String adjective = int(random(adjective.length));
String noun = int(random(noun.length));
String verb = int(random(verb.length));
String adverb = int(random(adverb.length));
//int index1 = int(random(adjectives));
//adj1 = adjectives[index1];
//int index2 = int(random(adjectives));
//adj2 = adjectives[index2];
//int index3 = int(random(noun.length));
//noun1 = noun[index3];
//int index4 = int(random(noun.length));
//noun2 = noun[index4];
//int index5 = int(random(verbs.length));
//verb = verbs[index5];
println ( "The" + "adj" + "adj" + "noun" + "noun" + "verb" + "adv!" ) ;
} // end mousepressed } // end setup )
this works
also: println : text in "" is constant, text without means he uses the variables and places their value / content
// Template sketch for Random sentences d
// **** Declare four arrays of String, one for each of adjectives, adverbs, nouns and verbs
String [] adj= {
"green", "hollow", "great"
};
String [] adv = {
"fast", "competently", "nicely"
};
String [] noun = {
"tree", "harbour", "neighbour"
};
String [] verb = {
"runs", "moves", "walks"
};
int oddEven = 0 ;
// **** Declare seperate String variables to hold each part of speech randomly
// **** selected -- two nouns, two adjectives, one adverb and one verb.
void setup ( ) {
size ( 700, 700 ) ;
background ( 0 ) ;
frameRate ( 10 ) ; // This slows the program down a bit to make the output easier to read
}
//String lines [] = loadStrings("adj.txt"); // ??????????????????
//String lines [] = loadStrings("adj.txt");
//String lines [] = loadStrings("noun.txt");
//String lines [] = loadStrings("noun.txt");
//String lines [] = loadStrings("verb.txt");
//String lines [] = loadStrings("adv.txt");
void draw ( ) {
// Ths code just flashes a rectangle so you see that the
// sketch is running while waiting for a mouse click
if ( oddEven %2 == 0 ) {
fill ( 255, 0, 0 ) ;
}
else {
fill ( 0, 0, 255 ) ;
}
oddEven ++ ;
rect ( 100, 100, 50, 50 ) ;
// end of rectangle blinking code
if ( mousePressed ) {
// **** select a random adjective from the adjectives array, store it in String
// **** Repeat this logic for one more adjective, two nouns, one adverb and one adjective
// **** Modify this to print out your random parts of speech to make a "sentence", well sort of
int index1 = int(random(adj.length));
String adj1 = adj[index1];
int index2 = int(random(adj.length));
String adj2 = adj[index2];
int index3 = int(random(noun.length));
String noun1 = noun[index3];
int index4 = int(random(noun.length));
String noun2 = noun[index4];
int index5 = int(random(verb.length));
String verb1 = verb[index5];
int index6 = int(random(adv.length));
String adv1 = adv[index5];
println ( "The" + "adj" + "adj" + "noun" + "noun" + "verb" + "adv!" ) ;
println ( "The " + adj1 +" "+ adj2 +" "+ noun1 + " " + verb1 + " " + adv1 + "!" ) ;
} // end mousepressed
}
// end setup
hello
I post the same code better formatted
you need to post the code better
also when you have a problem you have to describe better what's the problem
also in line 23 following, you can't use always he same name lines - why not take adj, adv etc. instead?
loadString better place in setup after size
// Template sketch for Random sentences d
// **** Declare four arrays of String, one for each of adjectives, adverbs, nouns and verbs
String [] adj;
String [] adv;
String [] noun;
String [] verb;
int oddEven = 0 ;
// **** Declare seperate String variables to hold each part of speech randomly
// **** selected -- two nouns, two adjectives, one adverb and one verb.
void setup ( ) {
size ( 200, 200 ) ;
background ( 0 ) ;
frameRate ( 10 ) ; // This slows the program down a bit to make the output easier to read
}
String lines [] = loadStrings("adj.txt"); // ??????????????????
String lines [] = loadStrings("adj.txt");
String lines [] = loadStrings("noun.txt");
String lines [] = loadStrings("noun.txt");
String lines [] = loadStrings("verb.txt");
String lines [] = loadStrings("adv.txt");
void draw ( ) {
// Ths code just flashes a rectangle so you see that the
// sketch is running while waiting for a mouse click
if ( oddEven %2 == 0 ) {
fill ( 255, 0, 0 ) ;
}
else {
fill ( 0, 0, 255 ) ;
}
oddEven ++ ;
rect ( 100, 100, 50, 50 ) ;
// end of rectangle blinking code
if ( mousePressed ) {
// **** select a random adjective from the adjectives array, store it in String
// **** Repeat this logic for one more adjective, two nouns, one adverb and one adjective
// **** Modify this to print out your random parts of speech to make a "sentence", well sort of
int index1 = int(random(adjectives));
adj1 = adjectives[index1];
int index2 = int(random(adjectives));
adj2 = adjectives[index2];
int index3 = int(random(noun.length));
noun1 = noun[index3];
int index4 = int(random(noun.length));
noun2 = noun[index4];
int index5 = int(random(verbs.length));
verb = verbs[index5];
println ( "The" + "adj" + "adj" + "noun" + "noun" + "verb" + "adv!" ) ;
println ( "The " + adj +" "+ adj2 +" "+ noun1 + " "+noun2 + " " + verb + " " + adv + "!" ) ;
} // end mousepressed
}
// end setup
I am going through tutorials and trying to figure out how to create a random sentence generator with 2 adjectives, 2 nouns, 1 verb and 1 adverb. Here is my code and I cannot figure out what I am missing
// Template sketch for Random sentences d
// **** Declare four arrays of String, one for each of adjectives, adverbs, nouns and verbs
String [] adj;
String [] adv;
String [] noun;
String [] verb;
int oddEven = 0 ;
// **** Declare seperate String variables to hold each part of speech randomly
// **** selected -- two nouns, two adjectives, one adverb and one verb.
void setup ( )
{
size ( 200, 200 ) ;
background ( 0 ) ;
frameRate ( 10 ) ; // This slows the program down a bit to make the output easier to read
}
String lines [] = loadStrings("adj.txt");
String lines [] = loadStrings("adj.txt");
String lines [] = loadStrings("noun.txt");
String lines [] = loadStrings("noun.txt");
String lines [] = loadStrings("verb.txt");
String lines [] = loadStrings("adv.txt");
void draw ( )
{
// Ths code just flashes a rectangle so you see that the
// sketch is running while waiting for a mouse click
if ( oddEven %2 == 0 )
{
fill ( 255, 0, 0 ) ;
}
else
{
fill ( 0, 0, 255 ) ;
}
oddEven ++ ;
rect ( 100, 100, 50, 50 ) ;
// end of rectangle blinking code
if ( mousePressed )
{
// **** select a random adjective from the adjectives array, store it in String
// **** Repeat this logic for one more adjective, two nouns, one adverb and one adjective
// **** Modify this to print out your random parts of speech to make a "sentence", well sort of
int index1 = int(random(adjectives));
adj1 = adjectives[index1];
int index2 = int(random(adjectives));
adj2 = adjectives[index2];
int index3 = int(random(noun.length));
noun1 = noun[index3];
int index4 = int(random(noun.length));
noun2 = noun[index4];
int index5 = int(random(verbs.length));
verb = verbs[index5];
println ( "The" + "adj" + "adj" + "noun" + "noun" + "verb" + "adv!" ) ;
} // end mousepressed
} // end setup