let newFont;
let currentLightColor = "yellow";
let hasRed = false;
let hasGreen = false;
let hasBlue = false;
function preload() {
newFont = loadFont('fonts/Montserrat.otf');
}
function setup() {
createCanvas(600, 300, WEBGL);
textFont(newFont, 16);
// Create 3 checkboxes for mixing 3 colors
redCheckbox = createCheckbox('Red', false);
redCheckbox.position(30, 70);
redCheckbox.changed(() => hasRed = !hasRed);
greenCheckbox = createCheckbox('Green', false);
greenCheckbox.position(90, 70);
greenCheckbox.changed(() => hasGreen = !hasGreen);
blueCheckbox = createCheckbox('Blue', false);
blueCheckbox.position(170, 70);
blueCheckbox.changed(() => hasBlue = !hasBlue);
// Create a selector for selecting
// the directional light color
lightColorSel = createSelect();
lightColorSel.position(30, 120);
lightColorSel.option('yellow');
lightColorSel.option('magenta');
lightColorSel.option('cyan');
lightColorSel.changed(() => {
currentLightColor = lightColorSel.value();
});
}
function draw() {
background('white');
fill('black');
text("Select an option below to set the light "
+ "and ambient material color", -285, -125);
text("Select directional light color", -285, -100);
text("Select ambient material color", -285, -50);
shininess(10);
noStroke();
// Define the color based on the checkboxes
let currentAmbientColor = color(hasRed ? 255 : 0,
hasGreen ? 255 : 0, hasBlue ? 255 : 0);
// Set the ambient material to the defined color
ambientMaterial(currentAmbientColor);
// Set the directional to the selected color
directionalLight(color(currentLightColor),
height / 2, width / 2, -250);
// Draw the sphere
translate(100, 0, 0);
sphere(100);
translate(-100, 0, 0);
}