You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
** and <a href="https://p5js.org/reference/#/p5/createRadio" target="_blank">createRadio()</a>, you can build different ways to take information submitted through
8
-
** a <a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/select" target="_blank">select</a>,
** or <a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/radio" target="_blank">radio button</a>, and update the DOM based on the information.
11
-
**/
1
+
/**
2
+
* @name DOM Form Elements
3
+
* @description The <a href="https://developer.mozilla.org/en-US/docs/Web/API/Document_Object_Model" target="_blank">Document Object Model</a>,
4
+
* or DOM, represents the resulting structure of the web page. Using p5.js' form elements,
5
+
* such as <a href="https://p5js.org/reference/#/p5/createInput" target="_blank">createInput()</a>,
* and <a href="https://p5js.org/reference/#/p5/createRadio" target="_blank">createRadio()</a>, you can build different ways to take information submitted through
8
+
* a <a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/select" target="_blank">select</a>,
* or <a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/radio" target="_blank">radio button</a>, and update the DOM based on the information.
11
+
**/
12
12
// Define the inputs for this form as global variables.
13
13
letnameInput;
14
14
letfontSelect;
15
15
letfoodRadio;
16
16
17
17
functionsetup(){
18
18
createCanvas(720,400);
19
-
19
+
20
20
// Assign an input box to nameInput.
21
21
nameInput=createInput();
22
22
nameInput.position(25,115);
23
-
23
+
24
24
// Assign radio buttons to foodRadio.
25
25
foodRadio=createRadio();
26
26
foodRadio.position(25,215);
27
-
27
+
28
28
// List the radio options for foodRadio, along
29
29
// with the background color associated with each selection.
30
30
foodRadio.option('#F7F5BC','Cranberries');
31
31
foodRadio.option('#B8E3FF','Almonds');
32
32
foodRadio.option('#C79A9A','Gouda');
33
-
33
+
34
34
// Assign a select dropdown to fontSelect.
35
35
fontSelect=createSelect();
36
36
fontSelect.position(25,300);
37
-
37
+
38
38
// List out the dropdown options for fontSelect.
39
39
fontSelect.option('Sans-serif');
40
40
fontSelect.option('Serif');
41
41
fontSelect.option('Cursive');
42
-
43
-
// If the fontSelect selection is changed, call the
42
+
43
+
// If the fontSelect selection is changed, call the
44
44
// fontChanged function.
45
45
fontSelect.changed(fontChanged);
46
46
}
47
47
48
48
functiondraw(){
49
49
describe(
50
50
'A form with "Welcome to p5.js!" for a header, a text input with the label "What is your name?", and a set of radio buttons with the label "What is your favorite food?", with the options of "Cranberries," "Almonds," or "Gouda." The text submitted through the input appears next to its label. The radio button selection changes the canvas background color. The select element changes the form font.'
51
-
);
51
+
);
52
52
53
53
// Set the background color to the current foodRadio value.
54
54
letbackgroundColor=foodRadio.value();
55
55
background(backgroundColor);
56
-
56
+
57
57
// Create the header for the form.
58
58
textSize(25);
59
59
text('Welcome to p5.js!',25,50);
60
-
61
-
// Create the text inputs that will update with the
60
+
61
+
// Create the text inputs that will update with the
62
62
// new user inputs.
63
63
textSize(20);
64
64
text(`What is your name? ${nameInput.value()}`,25,100);
0 commit comments