Last active
August 29, 2015 14:24
-
-
Save shiffman/7549e5225c042ee25a80 to your computer and use it in GitHub Desktop.
Ideas for checkbox and select elements in p5.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var checkbox; | |
| function setup() { | |
| checkbox = createCheckbox('the label'); | |
| checkbox.checked(true); // passing in an arg sets its state? | |
| // What should this be called?? | |
| // it's wrapping 'onchange' | |
| checkbox.changed(myCheckedEvent); // even for when the user does something | |
| } | |
| function draw() { | |
| // No argument return its state | |
| if (checkbox.checked()) { | |
| } | |
| } | |
| function myCheckedEvent() { | |
| if (this.checked) { | |
| console.log("It's checked!"); | |
| } else { | |
| console.log("It's not checked!"); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var dropdown; | |
| function setup() { | |
| dropdown = createSelect(); // or create dropdown? | |
| dropdown.option('name 1','value1'); | |
| dropdown.option('name 2','value2'); | |
| dropdown.option('name 3','value3'); | |
| dropdown.option('pear','pear'); | |
| dropdown.select('value3'); | |
| dropdown.changed(mySelectEvent); | |
| } | |
| function draw() { | |
| if (dropdown.selected === 'pear') { | |
| ellipse(0, 0, 100, 100); | |
| } | |
| } | |
| function mySelectEvent() { | |
| var selected = this.selected(); | |
| if (selected === 'pear') { | |
| console.log("it's a pear!"); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment