xxxxxxxxxx
29
let shouldSend;
let slider, button;
function setup() {
createCanvas(400, 400);
// Create a slider and place it at the top of the canvas.
slider = createSlider(0, 255);
slider.position(10, 10);
slider.size(80);
button = createButton('Toggle Send');
button.position(10, 40);
}
function draw() {
// Use the slider as a grayscale value.
let g = slider.value();
background(g);
button.mousePressed(toggleSend);
if (shouldSend) {
console.log(g);
}
}
function toggleSend() {
shouldSend = !shouldSend;
}