Last active
May 30, 2017 18:47
-
-
Save GoSubRoutine/861b48f0b0118219c6a7cdd28309ee62 to your computer and use it in GitHub Desktop.
DatGuiTest
This file contains 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
height: 600 |
This file contains 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
<script async src=http://CDN.JSDelivr.net/npm/p5></script> | |
<script defer src=http://CDN.JSDelivr.net/gh/dataarts/dat.gui/build/dat.gui.min.js></script> | |
<script defer src=sketch.js></script> |
This file contains 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
/** | |
* DatGuiTest (v2.1.1) | |
* Kuprin5 (2017-Feb-23) | |
* mod GoToLoop | |
* | |
* forum.Processing.org/two/discussion/21777/ | |
* dat-gui-don-t-update-variables-value#Item_1 | |
* | |
* Bl.ocks.org/GoSubRoutine/861b48f0b0118219c6a7cdd28309ee62 | |
*/ | |
"use strict"; | |
const props = { | |
bgColor: [102, 0, 204], | |
fgColor: 204, | |
useStroke: true | |
}; | |
function setup() { | |
createCanvas(600, 600); | |
strokeWeight(2.5).ellipseMode(CENTER); | |
colorMode(RGB).noLoop(); | |
createGUI(); | |
} | |
function draw() { | |
background(props.bgColor).fill(props.fgColor); | |
props.useStroke && stroke(0) || noStroke(); | |
ellipse(width>>1, height>>1, height>>1); | |
} | |
function mousePressed() { // Conflicting listener fix hack! | |
return false; | |
} | |
function createGUI() { | |
const gui = new dat.GUI; | |
gui.addColor(props, 'bgColor').onFinishChange(redraw); | |
gui.add(props, 'fgColor', 0, 0xff, 1).onChange(redraw); | |
gui.add(props, 'useStroke').onChange(redraw); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment