{ name: "Red", color: [255, 0, 0] },
{ name: "Yellow", color: [255, 255, 0] },
{ name: "Blue", color: [0, 0, 255] }
"Red+Yellow": { color: [255, 165, 0], name: "Orange" },
"Yellow+Blue": { color: [0, 255, 0], name: "Green" },
"Red+Blue": { color: [128, 0, 128], name: "Purple" }
bgImage = loadImage('background.jpg');
brushImage = loadImage('brush.png');
paletteImage = loadImage('palette.png');
textAlign(CENTER, CENTER);
image(paletteImage, paletteX, paletteY, paletteWidth, paletteHeight);
{ x: paletteX + 140, y: paletteY + 150 },
{ x: paletteX + 140, y: paletteY + 60 },
{ x: paletteX + 210, y: paletteY + 80 }
for (let i = 0; i < primaryColors.length; i++) {
fill(primaryColors[i].color);
ellipse(colorPositions[i].x, colorPositions[i].y, 60, 60);
text("Click two colors to mix!", 400, 80);
if (selectedColors.length > 0) {
for (let i = 0; i < selectedColors.length; i++) {
fill(selectedColors[i].color);
ellipse(300 + i * 100, 250, 50, 50);
rect(450, 150, 100, 100);
text("Mixed Color", 500, 220);
text(mixedColorName, 500, 240);
image(brushImage, mouseX - brushSize / 2, mouseY - brushSize / 2, brushSize, brushSize);
function mousePressed() {
{ x: 240, y: 250, radius: 30 },
{ x: 240, y: 160, radius: 30 },
{ x: 310, y: 180, radius: 30 }
for (let i = 0; i < primaryColors.length; i++) {
let dx = mouseX - colorPositions[i].x;
let dy = mouseY - colorPositions[i].y;
let distance = sqrt(dx * dx + dy * dy);
if (distance <= colorPositions[i].radius) {
if (!selectedColors.some(color => color.name === primaryColors[i].name)) {
selectedColors.push(primaryColors[i]);
if (selectedColors.length === 2) {
let colorKey = `${selectedColors[0].name}+${selectedColors[1].name}`;
let reverseKey = `${selectedColors[1].name}+${selectedColors[0].name}`;
if (colorMixMap[colorKey]) {
mixedColor = colorMixMap[colorKey].color;
mixedColorName = colorMixMap[colorKey].name;
} else if (colorMixMap[reverseKey]) {
mixedColor = colorMixMap[reverseKey].color;
mixedColorName = colorMixMap[reverseKey].name;
mixedColor = [128, 128, 128];
mixedColorName = "Unknown Mix";