The demos on these pages are from experiments in realizing this goal with students in two contexts: a high-school physics class programming with the Vpython language, and a summer-science enrichment program where students used the language Actionscript. Without delving into Language War issues, let it be known that both languages have significantly valuable properties for introducing students to programming and visualization. We want to engage students in programming, with language-specific details taking a back seat.
The graphical, dynamic simulations students develop are small-scale versions of the grand challenges of computing today such as climate modeling. Through developing simulations on their own, students come to appreciate the role of simulations in understanding and visualizing science and mathematics today, understanding that simulations are now key tools of science that bridge physical experimentation and symbolic equations, providing key visualizations of the dynamic unfoldings of systems.
Now draw more "objects" and animate them with the same lines of code, the only difference being the initializations for 'n':
We've introduced the basics of objects, and by creating them graphically with Flash's drawing tools, we've avoided the messy conceptual overhead associated with the syntax and semantics of object creation through many lines of code - code distinctly NOT friendly to someone with only one hour of programming background.
NOW... simply do for 'y' coordinates what was done for 'x' - nothing new conceptually, just replicate code and change x's to y's. No new concepts.
But... WHAT HAVE WE HERE ???
Several deep concepts have emerged out of this new animation; it's up to the teacher as to where the fit in the students discovery of knowledge, but let us note:
VECTOR MOTION has emerged. Diagonal motion is a composite of independent dimensions!
ANGLE OF INCIDENCE = ANGLE OF REFLECTION. Note that the balls bouncing off the walls bounce realistically (well, realistically in the ideal sense), with the incoming angle equal to the outgoing angle. You could potentially prove this law of physics, at least intuitively, by observations of what is happenning independently in x and y. And if the cushion absorbs some energy - what would that look like? Think about it, then simulate it!
What to do with this? Well, now, that depends on the teacher and the lesson...
HOMEWORK: So far, the circles were simply sliding (translating) across the screen. Realistically, a wheel would roll, that implies a rotation.
_rotation = _rotation + ??? ;
But how much? Make it happen realistically...
Planetary Motion: a Dynamic Simulation
In Lesson One, velocity was fixed. Let's add acceleration. In lesson one, constant velocity changes position at each time step. With acceleration in the picture, first use acceleration to change velocity, then use this new velocity to change position. I won't lead you through all the steps this time, but first make a planet orbit the sun, then make a moon orbit the planet (already orbiting the sun). Add a few new programming constructs now to make buttons:
[[ Click the start button to kick things off. Planet and moon can be dragged to different places while animation is stopped.]]
Here's a parameterized model we can explore. After watching it a bit, 'RESET' the animation, highlight the '30' , change it to 25, restart the model, and watch the new system through time.
If you've watched this for more than 10 seconds, consider yourself hooked. You are not being wow-ed by state-of-the-art animations and cool graphics. It's a bit cheesy by current visual appeal standards. So why are you watching? And if you'd created it, you'd be watching even longer!!! We've implemented some physics, developed parameterized models we can play with, and driven the solar system from it's basic laws. Impressed? Students have been. It has engaged them further in both programming and in the sciences.
Buffon's Needle: A Stochastic Simulation
Buffon's Needle is an old problem in the field of geometrical probability. First stated in 1777, it involves dropping a needle on a lined sheet of paper and determining the probability of the needle crossing one of the lines on the page - that probability is directly related to the value of π. [[For an analysis, see: George Reese's web page on Buffon's Needle, where he references Schroeder, L. (1974), “Buffon's needle problem: An exciting application of many mathematical concepts”, Mathematics Teacher, 67 (2), 183-186.]] For a large number of repeated tosses, where the distance between lines is equal to the length of the needle, twice the total number of tosses divided by the number of tosses where the needle crosses a line provides a stochastic approximation of π.
Only three lines of code are needed to repetitively and randomly "toss" the needle onto the parallel-ruled "paper":
_rotation = 360*Math.random();
_x = 50+Math.random()*300;
_y = 50+Math.random()*200;
This coding provides an introduction to the concept of a random variate, and uses that concept to simulate a random toss, by “randomly” rotating the needle and then “randomly” placing the needle's center on the 400x300 field. To figure out if the needle has crossed a line, the hitTest method is then introduced, a method that determines whether two objects intersect (in this case, the needle and any of the parallel rules). With another few statements, statistics can be accumulated over a long number of iterations. Nine programming statements essentially does it all.
SO... Here's an application with both concept and historical interest. The implementation reinforces both, and provides a short but sweet entree to stochastic simulations. And watching the estimate over time develops intuition into the nature of statistical convergence with increasing n.
This demo version is yet further embellished, speeding up the tosses after the first few to speed up convergence, and allowing the user to restart the counters for another run. If it runs for a some time, it converges not quite to 3.14159 ... What's up? The needle and line do have an actual physical width, as opposed to the idealized lines of the analysis - a key point in contrasting abstractions vs. implementations.