xxxxxxxxxx
42
let input, button, greeting, reset;
function setup() {
// create canvas
createCanvas(710, 400);
input = createInput();
input.position(20, 65);
button = createButton('submit');
button.position(input.x + input.width, 65);
button.mousePressed(greet);
button = createButton('reset');
button.position(input.x, 85);
button.mousePressed(reset);
greeting = createElement('h2', 'what is your name?');
greeting.position(20, 5);
textAlign(CENTER);
textSize(50);
}
function greet() {
const name = input.value();
greeting.html('hello ' + name + '!');
input.value('');
for (let i = 0; i < 50; i++) {
push();
fill(random(255), random(255), random(255));
translate(random(width), random(height));
rotate(random(2 * PI));
text(name, 0, 0);
pop();
}
function reset() {
const restart = input.value();
reset = restart;
input.value('');
}
}