Calculating the scale value is also demonstrated within this demo. This project is essentially a combination of PLAYING WITH PATTERNS and TRIGONOMETRY to create an interesting interactive pattern.

Link to Full Codes

                        for (let j = 0; j < numOfSquares; j++) {
                            for (let i = 0; i < numOfSquares; i++) {
                                let transX = i * squareSize + squareSize / 2;
                                let transY = j * squareSize + squareSize / 2;
                    
                                let distance = dist(transX, transY, mouseX, mouseY);
                                // let scaleVal = map(distance, 0, cWidth, 15, squareSize * 2);
                                let scaleVal = map(distance, 0, cWidth, squareSize, 15);
                    
                                push();
                                    translate(transX, transY);
                                    
                                    let rotateVal = atan2(mouseY - transY, mouseX - transX);
                                    rotate(rotateVal);
                    
                                    // noStroke();
                                    fill(i, 0, numOfSquares - j);
                                    ellipse(0, 0, scaleVal, scaleVal);
                                    // noStroke();
                                    stroke(180);
                                    ellipse(10, 0, squareSize / 4, squareSize / 4);
                                pop();
                            }
                        }