Skip to content

Language Settings

Input and Button

Input text and click the button to see it affect the the canvas.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
let input, button, greeting;
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);
  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 < 200; i++) {
    push();
    fill(random(255), 255, 255);
    translate(random(width), random(height));
    rotate(random(2 * PI));
    text(name, 0, 0);
    pop();
  }
}
X

creative commons license