I'm trying to make a processing.js sketch change color in response to clicks on html divs.
The idea is that the id of the div will determine the color in the sketch, so I've given each div a hex value as an id.
Here's an example div from my html file:
<div class="swatch" id="008A2E"><img src="img/green.png"></div>
I've initialized a global variable 'color' in my javaScript file and added an onclick function 'selectColor(this.id)' to all the color swatch divs.
var color = "FFD119";
function selectColor(id) {
color = id;
}
This is the javascript function that gets called from within my processing.js file:
function getColor() {
var hex = parseInt(color, 16);
return hex;
}
Here's the relevant bit of the Processing.js file:
function setFrameColor() {
var hex = javascript.getColor();
frameColor = hex;
}
This function is called in:
void mouseClicked(){
setFrameColor();
if(!cycling){
loop();
cycling = true;
} else {
noLoop();
cycling = false;
}
}
It's sort of working except that all I get are shades of grey. I'm obviously not converting the string data from the div ids correctly. Processing's hex() function doesn't help because it returns a string. Is what I'm trying to do even possible? I've also tried sending the div ids directly to the processing sketch (without using parseInt()) but that seems to have no effect.
Thanks.