Larson Scanner
Run the Larson Scanner MicroSim
About this MicroSim
This MicroSim teaches us how the Larson Scanner animation works.
Sample Prompt
Create a p5.js sketch for a simulation of a Larson Scanner.
The project has a row of 12 red evenly spaced horizontal
circles at the top of the 600x300 canvas that fade in
and out like a Cylon robot eyes. A slider below the
drawing area allows a user to control the speed of
the animation.
ChatGPT o1-mini Sample Response
Sure! Below is a complete p5.js sketch that simulates a Larson Scanner with the specifications you provided. This sketch features 12 red circles that fade in and out sequentially, mimicking the iconic Cylon robot eyes. A slider is included below the canvas to allow users to control the speed of the animation.
How It Works:
-
Setup:
- A canvas of size 600x300 is created.
- 12 circles are positioned evenly across the top of the canvas.
- A slider is added below the canvas to control the animation speed.
-
Animation Logic:
- The animation moves a "scanner" across the circles from left to right and then back from right to left.
- The current active circle's brightness is controlled using alpha transparency to create a fading effect.
- The speed of the scanner is adjustable via the slider, affecting how quickly the scanner moves from one circle to the next.
-
Interactivity:
- Users can adjust the slider to make the scanner move faster or slower.
Complete p5.js Sketch:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
|
How to Run the Sketch:
-
Using the p5.js Web Editor:
-
Go to the p5.js Web Editor.
- Create a new sketch.
- Replace the existing code with the code provided above.
- Click the "Play" button to run the sketch.
-
Locally on Your Computer:
-
Ensure you have the p5.js library included in your project.
- Save the above code in a file named
sketch.js
. - Create an
index.html
file and include the p5.js library and yoursketch.js
. - Open
index.html
in your web browser to see the simulation.
Customization:
- Number of Circles: You can change the
numCircles
variable to increase or decrease the number of circles in the scanner. - Circle Size: Adjust the diameter values in the
ellipse
function calls to make the circles larger or smaller. - Colors: Modify the
fill
colors to change the appearance of the scanner. - Initial Speed: Change the default value in the
createSlider
function to set a different initial speed.
Feel free to experiment with the parameters to create a Larson Scanner that fits your preferences!