处理:将一串随机单词变成一个句子
Processing: Turning a string of random words into a single sentence
我正在尝试在 Processing 中生成伪随机格式化句子。
我发现许多示例草图将一个句子分成一个单词列表,但是 none 将分开的单词合并为一个句子。
比如我有没有办法把字符串words[n]转换成一个句子?
String[] Space = {
" " };
String[] Verbs = {
"like", "kill", "taste", "save" };
String[] PossessiveAdjectives = {
"your", "her", "his", "my" };
String[] Nouns = {
"apple", "bank", "cat", "dog" };
void setup(){
size(800,400);
background(0);
textAlign(CENTER);
textSize(100);
new_sentence();
}
void draw(){
}
void write_word(String[] words){
int n = int(random(words.length));
print(words[n]);
text(words[n], 0.5*width ,0.5*height+25);
}
void new_sentence(){
write_word(Verbs);
write_word(Space);
write_word(PossessiveAdjectives);
write_word(Space);
write_word(Nouns);
}
void mousePressed(){
setup();
}
已解决:
它现在包含String Sentence中随机选择的单词,并将它们与+" "+
组合
int screenWidth = 800;
int screenHeight = 400;
void setup() {
size(screenWidth, screenHeight);
sentence();
}
void sentence() {
String[] Verbs = {
"like", "kill", "taste", "save"
};
String[] PossessiveAdjectives = {
"your", "her", "his", "my"
};
String[] Nouns = {
"apple", "bank", "cat", "dog"
};
int verb = int(random(Verbs.length));
int possessiveAdjective = int(random(PossessiveAdjectives.length));
int noun = int(random(Nouns.length));
String Sentence = Verbs[verb]+" "+PossessiveAdjectives[possessiveAdjective]+" "+Nouns[noun];
println(Sentence);
background(0);
textAlign(CENTER);
textSize(100);
text(Sentence, 0.5*screenWidth, 0.5*screenHeight+25);
}
void draw() {
}
void mousePressed() {
sentence();
}
我正在尝试在 Processing 中生成伪随机格式化句子。
我发现许多示例草图将一个句子分成一个单词列表,但是 none 将分开的单词合并为一个句子。
比如我有没有办法把字符串words[n]转换成一个句子?
String[] Space = {
" " };
String[] Verbs = {
"like", "kill", "taste", "save" };
String[] PossessiveAdjectives = {
"your", "her", "his", "my" };
String[] Nouns = {
"apple", "bank", "cat", "dog" };
void setup(){
size(800,400);
background(0);
textAlign(CENTER);
textSize(100);
new_sentence();
}
void draw(){
}
void write_word(String[] words){
int n = int(random(words.length));
print(words[n]);
text(words[n], 0.5*width ,0.5*height+25);
}
void new_sentence(){
write_word(Verbs);
write_word(Space);
write_word(PossessiveAdjectives);
write_word(Space);
write_word(Nouns);
}
void mousePressed(){
setup();
}
已解决:
它现在包含String Sentence中随机选择的单词,并将它们与+" "+
组合int screenWidth = 800;
int screenHeight = 400;
void setup() {
size(screenWidth, screenHeight);
sentence();
}
void sentence() {
String[] Verbs = {
"like", "kill", "taste", "save"
};
String[] PossessiveAdjectives = {
"your", "her", "his", "my"
};
String[] Nouns = {
"apple", "bank", "cat", "dog"
};
int verb = int(random(Verbs.length));
int possessiveAdjective = int(random(PossessiveAdjectives.length));
int noun = int(random(Nouns.length));
String Sentence = Verbs[verb]+" "+PossessiveAdjectives[possessiveAdjective]+" "+Nouns[noun];
println(Sentence);
background(0);
textAlign(CENTER);
textSize(100);
text(Sentence, 0.5*screenWidth, 0.5*screenHeight+25);
}
void draw() {
}
void mousePressed() {
sentence();
}