This interactive circuit simulator helps students understand Ohm's Law (V = IR) through hands-on experimentation. By adjusting voltage and resistance values, students can observe how current changes in real-time, discovering the direct relationship between voltage and current and the inverse relationship between resistance and current.
Key Features
Animated Current Flow: Yellow particles flow through the circuit at speeds proportional to the current
Dynamic Resistor Color: The resistor changes from blue (cold) to red (hot) based on current level
Overload Warning: When current exceeds 20A, the ammeter flashes red with "OVERLOAD!" warning
Real-time Equation Display: Shows the V = IR calculation updating as you adjust parameters
Circuit Components
Battery (left): Provides voltage from 1V to 24V
Resistor (top): Provides resistance from 1 ohm to 20 ohms, color indicates heat level
Ammeter (right): Displays the calculated current in Amperes
// Ohm's Law Circuit Simulator// Demonstrates V = IR relationshipletcanvasWidth=800;letdrawHeight=400;letcontrolHeight=50;letcanvasHeight=drawHeight+controlHeight;letvoltage=12;letresistance=4;letcurrent=3;letvoltageSlider,resistanceSlider;functionsetup(){updateCanvasSize();createCanvas(canvasWidth,canvasHeight);voltageSlider=createSlider(1,24,12,0.5);resistanceSlider=createSlider(1,20,4,0.5);textFont('Arial');}functiondraw(){background(255);voltage=voltageSlider.value();resistance=resistanceSlider.value();current=voltage/resistance;// Draw circuit and display valuesfill(0);textSize(20);textAlign(CENTER);text("V = "+voltage.toFixed(1)+"V",width/2,100);text("R = "+resistance.toFixed(1)+" ohms",width/2,150);text("I = "+current.toFixed(2)+"A",width/2,200);text("V = I x R",width/2,280);}functionupdateCanvasSize(){constcontainer=document.querySelector('main');if(container){canvasWidth=container.offsetWidth;}}