you have several ways to achieve it. The best way would be to use radio inputs instead of checkbox ones. By grouping them, you will be able to select only one of them by default.
Then you’ll need only to hide your input.
If we stay on what you already have here, you’ll need first to uncheck the input, accessible by the elt property of your checkbox_b :
checkbox_a.elt.children[0].checked = false; // elt is actually a div containing both the input and its label. We use the children property to access to your input
console.log('hide a', checkbox_a.elt.children)
And then, hide the element by using the built-in fonction of p5.element : hide().
So, in total, you’ll have :
function bbb(){
if (checkbox_a_go){ // if a already checked
checkbox_a.elt.children[0].checked = false;
console.log('hide a', checkbox_a.elt)
// checkbox_b_go = false; // depends on what you want
checkbox_a.hide();
}
}
Thank you for your recommendation but my level is not good enough to associate checkbox and switch-case. Unless you know tutorial that fit my goal.
If I stick with radio.
I understood that the radio.value() works when its parameters correspond to the pre-existing functions like “rect”, “circle”.
But is it possible to switch between different functions created by me?
sorry but I’m not kidding - switch-case is a basic structure, and even though you don’t know it, you can achieve basically the same thing with if-else in this case.
Hello thanks for your help,
Yes, I red your code exemple
I was not clear enough
I would like to use my own function (not the pre-existing function like circle, rect)
Like this: function candy(), function car(), etc.
I’d like to associate them to createRadio.
Is it possible ?
let radio;
function setup() {
createCanvas(400, 400);
radio = createRadio();
radio.option('rect');
radio.option('circle');
radio.selected('rect');
}
function draw() {
background(220);
this[radio.value()](200,200,100)
}
function candy(){
triangle(50,50,100,75,50,100);
circle(150,75,100);
triangle(200,75,250,50,250,100);
}