var visited = []; // coordinates of the boxes the mouse has visited while pressed once var boxes = []; // all boxes that should be displayed and colored, item is an array [x, y, R, G, B] let boxSize = 40; let color1; let color2; let valid_start = false; let valid_end = false; function setup() { createCanvas(800, 680); background(80); colorMode(RGB); rectMode(CENTER); boxes.push([ 60, 60,[ 13, 27, 68]]); // phthalo blue boxes.push([580, 180,[255, 236, 4]]); // bis yellow boxes.push([420, 60,[255, 236, 4]]); // bis yellow boxes.push([220, 300,[255, 208, 0]]); // hansa yellow boxes.push([420, 380,[ 25, 0, 89]]); // ultramarine blue boxes.push([500, 260,[ 25, 0, 89]]); // ultramarine blue boxes.push([700, 380,[225, 35, 1]]); // cadmium red boxes.push([580, 580,[128, 2, 46]]); // magenta boxes.push([100, 580,[249, 250, 249]]); // white boxes.push([260, 580,[249, 250, 249]]); // white drawBoxes(); } function draw() { // record visited boxes if(mouseIsPressed === true) { let x = snapToGrid(mouseX); let y = snapToGrid(mouseY); let alreadyIn = false; for(let v=0; v 0) { stroke(230); noFill(); setLineDash([5, 5]); for(let v=0; v1 ? v * 1.0/(numVisited-1) : 1; let mixedColor = mixbox.lerp(color1, color2, t); boxes.push([visited[v][0], visited[v][1], mixedColor]); } } else{alert("You must start and end inside colored squares.");} } // clear visited array visited = []; // redraw screen to erase the overlay, clear background, draw boxes background(80); drawBoxes(); } function drawBoxes() { noStroke(); for(let b=0; b 0 && mouseX < width && mouseY > 0 && mouseY < height) {return true;} else {return false}; }