Computer Simulation

We can use computer simulations to help us learn and understand how things work.

We will use 2Code in Purple Mash to make a computer simulation of our light box.

Log in to Purple Mash and find your 2Do called “Light Box Simulation”. Start the 2Do!

2Code Recap

Let’s take a careful look back at 2Code. Watch this screen recording to recap the different parts of the app.

Our Simulation

We need to make the objects in our design work to simulate the electric circuit in our light box. None of the 2Code objects “know” anything about electricity or light. We must apply our own science knowledge to make them do the right things.

Getting the design right

Use Design to look at how the electrical parts have been simulated. What is wrong with the wires?


Using code to simulate a working circuit

When we run the program and press the “On” button, the code makes the angle of the line object change and it appears to “complete” the circuit.

What should we do, to simulate what happens when the switch closes? In other words, what would we expect the bulb to do if this was a real circuit with a good battery?


How can we do that in 2Code?


Evaluation

With these steps we have created a computer program that quite closely simulates the electric circuit in our light box.

We can go further with 2Code and simulate the light shining out of the front panel of your box. Press next, below, so see how.