Generate a single file p5.js sketch on a 400x400 canvas that simulates an LED electrical circuit.
The circuit has had the following elements connected in series.
// Function for drawing an animated wire function drawAnimatedWire(x1, y1, x2, y2, speed1, state) { if (state) { let distance = dist(x1, y1, x2, y2); let circlePos = map((millis() * speed1) % distance, 0, distance, 0, 1); // lerp generates the percent between two values let x = lerp(x1, x2, circlePos); let y = lerp(y1, y2, circlePos); stroke(0); strokeWeight(lineWidth) line(x1, y1, x2, y2); // Draw the wire fill(255, 0, 0); noStroke(); circle(x, y, 10); // Draw the moving circle (electron) } else { stroke(0); strokeWeight(lineWidth) line(x1, y1, x2, y2); // Draw the wire } }