We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi,
I try to add dat.GUI to my sketch. GUI load variables correct, but not change they values.
var bgColor = [102, 0, 204];
var eStroke = true;
function setup() {
createCanvas(600, 600);
createGUI();
}
function draw() {
background(bgColor);
fill(204);
if (eStroke) {
strokeWeight(2);
} else {
noStroke();
}
ellipse(width/2, height/2, 300);
}
function createGUI() {
gui = new dat.GUI();
var keys = {
"bgColor" : bgColor,
"eStroke" : eStroke,
}
gui.addColor(keys, 'bgColor');
gui.add(keys, 'eStroke');
}
How I can fix it?
Answers
The bgColor[] array property from your keys{} object declared locally inside createGUI() function isn't the same as the global array variable bgColor[] declared at the top of your sketch! [-X
In other words, your dat.GUI instance is changing the keys{}'s properties, not your global variables! =;
How about declaring your keys{} object globally, so both p5.js & dat.GUI libs can have access to it? *-:)
Go to the link below and watch the tweaks I've made to your sketch: B-)
http://Bl.ocks.org/GoSubRoutine/861b48f0b0118219c6a7cdd28309ee62
GoToLoop, thanks! It's really work!
One more question. When I press mouse and move it across the canvas appears a text cursor, although the mouse is in the p5 canvas. How can this be corrected?
That's the same regular select text cursor I get when I press mouse's left button at any non-clickable place. I doubt we can change that, unless we turn the canvas to be clickable. :-??
Hi, GoToLoop! I make clickable sketch. But the problem remained. However, if I press H to hide GUI, text cursor no longer appears. I think that here the problem is the interaction of DOM elements. Are there any ideas on this?
Sorry but I've never used dat.GUI before. I didn't even know about that hide H key. =P~
But if it's detecting key presses outside its GUI, it means it's listening globally.
And guess what, p5.js also attach listeners globally! 3:-O
Maybe they're conflicting w/ each other? Dunno. :-/
I think I found a solution to a similar error with another library. How would this be applied to p5js?
I'm very noob w/ DOM. So I can only blind-guess. X_X
If onmousedown() is related to that glitch, just maybe add this to the p5.js sketch. No guarantees at all:
GoToLoop, it's really work! Big thanks!
Worked?! O_o
Wow! That was just a shot in the dark! :))
NEWS! Updated to version 2.1!
return false;
hack for mousePressed() to fix conflict w/ dat.GUI.blendMode(REPLACE);
b/c it's buggy under Firefox-based browsers! :-&http://Bl.ocks.org/GoSubRoutine/861b48f0b0118219c6a7cdd28309ee62