Concept:
I had a project in mind: making sentences pop up on the canvas. So I tried making that But I got stuck in the part where I should formulate the sentence. Hence, I got peer help. Ayazhan Gabitkyzy’s code helped me a lot in figuring out what could be done and how to debug my code. There were even useless blocks of code that I realized after I have gotten Aya’s code help. I changed the word combination to predict more logical sentences. And I was pretty satisfied with the result.
Code:
let VERB1 = 0;
let WORD1 = 1;
let VERB2 = 2;
let WORD2 = 3;
let words = [];
let wordctr = 0;
let strings = [];
function setup() {
createCanvas(600,600);
background(153,0,0);
strings = loadStrings("words.csv");
}
let csvRowNumber = 0;
function generatemessages(){
let rand = int(random(0, 100));
let rand2 = int(random(0, 100));
if(rand % 7 == 0){
if(rand2 % 3 == 0){
if(rand2 % 2 == 0 && rand % 2 == 0){
words[wordctr] = new sentences();
words[wordctr].display();
wordctr++;
}
}
}
}
function displaymessages(){
for(let i = 0; i < words.length; i++){
words[i].display();
if(words[i].y > height){
words.splice(i,1);
wordctr--;
}
}
}
function draw() {
// generatemessages();
// displaymessages();
frameRate(3);
if(wordctr > 30){
clear();
background(153,0,0);
wordctr = 0;
}
generate_text();
}
function generate_text(){
let singleRow = [];
message = "I want to " ;
singleRow = split(strings[int (random(strings.length))], ',');
message += singleRow[VERB1];
message+=" ";
singleRow = split(strings[int (random(strings.length))], ',');
message += singleRow[WORD1];
message2 = "I don't want to " ;
singleRow = split(strings[int (random(strings.length))], ',');
message2 += singleRow[VERB2];
message2+=" ";
singleRow = split(strings[int (random(strings.length))], ',');
message2 += singleRow[WORD2];
fill(245,213,10);
textSize(20);
textFont('Georgia');
let randnumber=int(random(1,3));
if (randnumber==1){
text(message,random(0,width-60),random(0,height-2));
// return message;
// text(this.message,this.x,this.y);
wordctr++;
}
else if(randnumber==2){
text(message2,random(0,width-60),random(0,height-2));
wordctr++;
// return message2;
// text(this.message,this.x,this.y);
}
}
class sentences{
constructor(){
this.x = 20;
this.y = -20;
this.message = generate_text();
}
display(){
// this.tempo.remove();
this.tempo = text(this.message,this.x,this.y);
this.y+=20;
}
}
Project:
Reflection:
I would love to make add effects to the text in the future like a shadow or make them move on their own.. or add an illustration by which instead of disappearing, the sentences by animation make another sentence.
I was wondering as well if the sentences can be more coherent and more logical. However, I feel like for that to take place there should be a use of AI or machine learning so that the sentences can make sense and will sound like it was written by a human not a machine.