Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save bevchou/7447f5a98f41fe821aa8253bf5238527 to your computer and use it in GitHub Desktop.
Save bevchou/7447f5a98f41fe821aa8253bf5238527 to your computer and use it in GitHub Desktop.
//input fields
let inpH = 550;
//name
let nameInput;
let newName = "Who is this?";
//nouns
let nounInput;
let nounArray = [];
let nounPara = [];
//adjectives
let adjInput;
function setup() {
createCanvas(500, 500);
//name
nameInput = createInput('Who is this?');
nameInput.position(100, inpH);
nameInput.changed(updateName);
//what do you like
nounInput = createInput('in one word');
nounInput.position(250, inpH);
//describe yourself
adjInput = createInput('in one word');
adjInput.position(400, inpH);
}
function draw() {
background(255);
textSize(40);
//name
text(newName, 100, 100);
//what do you like
nounInput.changed(updateNoun);
console.log(nounArray);
}
function updateName() {
console.log(nameInput.value());
newName = nameInput.value();
}
function updateNoun() {
//do not allow user to input white space or empty string into the word array
if (trim(nounInput.value()) != "") {
//push input to word array
nounArray.push(nounInput.value());
//display submitted words below input field
nounPara.push(createP(nounInput.value()));
for (let i = 0; i < nounPara.length; i++) {
nounPara[i].position(250, inpH + 20 * (i - 1));
}
//clear input field
nounInput.remove();
nounInput = createInput('');
nounInput.position(250, inpH + nounArray.length * 20);
}
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment