Saturday, December 21, 2013

A Simple Animation Exercise


   In his book, The Armchair Universe, computer scientist A.K. Dewdney reprints 5 Easy Pieces, one of his Computer Recreations columns published in Scientific American. The first easy piece was to program a moving, segmented caterpillar.
   I first programmed this easy piece in the BASIC programming language. In BASIC, the coordinates of each segment were stored in a 1-dimensional array. To compute the next cycle, the new position for the head was computed and then every segment was moved up one element of the array. Only one new movement computation had to be made per cycle of animation!
   In Scratch, I used the point towards block to simplify the animation.
   The script uses 11 sprites to create a head, a tail, and nine intervening segments. The ‘head’ selects a turn angle between 30º to the left and 30º to the right and then moves 3 steps. Every other sprite ‘points towards’ the sprite in front of it and then moves 3 steps. For example, sprite 4 points towards sprite 3 and moves 3 steps. This simple technique creates the illusion of a crawling caterpillar!       
    Here’s a screenshot of showing how the caterpillar starts in 11 segments.
    The segments soon fit loosely together since they are all travelling at the same speed but after a few reflections off the sides, the segments fit together as is shown in this screenshot.
    The project can be viewed and downloaded by clicking on this link.



Tuesday, December 10, 2013

Jackson Pollack Creates Chaos


Scratch Simulates a Jackson Pollack Painting

The following is taken from:
Order in Pollock's Chaos
Richard P. Taylor
Scientific American
December 2002


   "In a drunken, suicidal state on a stormy March night, Jackson Pollock (1912–1956) laid down the foundation of his masterpiece Blue Poles: Number 11, 1952. He unrolled a large canvas across his windswept barn and, using a wooden stick, dripped the canvas with house-hold paint from an old can."
   Physicist Taylor goes on to explain in his article how his analysis of Pollack's painting revealed that the structure underlying Pollack's random dribbling of paint onto canvas is fractal.
   To view the Scratch construction of a simulated Pollack, click on the following link. To study the scripts, download the Scratch project.

    A free two-page pdf file with a bit more information can be had by sending an email to grandadscience@gmail.com

Friday, November 1, 2013

Chaos Lurks in the Equation y = Rx(1 – x)

   The image shown above is often used to illustrate what deterministic chaos  looks like. The image is the iterated map of the equation y = Rx(1­ – x) with x =0.1 as the seed and R-settings from R = 2.95 to R = 3.95.
   I have uploaded a Scratch project, Chaos Lurks in y=Rx(1–x), to the Scratch website.
The image above has the value of R decreasing from the top down. This is the popular orientation of the image. In my Scratch project, I used the normal convention of R increasing up the y-axis.

   You can view and interact with this project by clicking on this link.
   The Notes and Credits section of the project gives you R settings for computing an approximation of Feigenbaum’s constant.
   A discussion of Feigenbaim’s constant can be viewed at the Sixty Symbols web site.
   If you would like a three-part tutorial in PDF format on the origin of Feigenbaum’s constant just send an email request to http://www.grandadscience.com.


Monday, October 14, 2013

The Pledge Maze-solving Algorithm


   John Pledge was a 12 year-old Exeter, England school student when he invented the maze-solving algorithm that bears his name.
   His algorithm collects local information by adding turns to the left as positive numbers and turns to the right as negative values to a variable called Total Turning.
   Total Turning is initially set to zero. The robot then moves forward until it strikes a barrier. It turns left, adding the angle measure of the turn to Total Turning and then executes the rest of the algorithm until Total Turning equals zero degrees (not 360º) that indicates the robot has navigated around the barrier. The algorithm resets Total Turning to zero, and the robot again moves forward until it strikes another barrier. And so on.
    A complete discussion of the Pledge algorithm can be found in the book Turtle Geometry, by Harold Abelson and Andrea A. diSessa published by the MIT Press in 1980.
    In the book, I was amazed to learn that if a robot following the Pledge algorithm can escape the interior of a capital letter G, then the robot can escape from any of the mazes commonly seen in books.
    Years ago (1986) I implemented the Pledge algorithm in Terrapin Logo. Searching Scratch for Pledge, I found a project ( http://scratch.mit.edu/projects/763827/) with all of the variable names written in a foreign language. I remixed the project by decoding the variable names into English. I discovered that my Logo algorithm and the remixed algorithm used the same technique of ‘holding the right hand on the wall of the maze’.
   I have shared, on the Scratch website, three Pledge Algorithm projects. The first is the Letter G-Maze Test project that tests the Scratch version of the Pledge algorithm.

   You can view and download this project by clicking on the following link.
   The second Scratch project, Pledge Algorithm Maze, pays homage to John Pledge by creating a maze made of the capital letters of his last name. The algorithm from the Letter G project was simply copied into this project. It was drawing the maze that took time.

   You can view and download this project by clicking on this link.
   The third project, The Pledge Algorithm – Large Maze project, adds a much more complicated maze than the first two projects. But again, exactly the same Pledge algorithm code was copied into this project. The little robot will now navigate through the maze from any point within the maze.

   You can also view and download this project by clicking on this link.
   I have written a written a document that describes, in detail, the Pledge Algorithm. You can obtain a copy of this document, free, by sending an email request to

Saturday, October 12, 2013

Spirolaterals in Scratch


   Way back in the early 1980s, the first Apple II (Integer BASIC) program I ever saw programmed a pencil and graph paper exploration called Spirolaterals. I had a lot of success using Spirolaterals with middle school and secondary students. I used them to introduce the concept of mathematical conjecture.

   The simplest spirolateral is defined as follows:
   Start at some grid point on the Cartesian plane.
      move forward x steps, turn right 90,
      move forward 2x steps, turn right 90,
      move forward 3x steps, turn right 90.
      move forward 4x steps, turn right 90
      
      move forward nx steps, turn right.

   The coefficient of the last x is called the order.
   This graphic shows the path of a 4x  or order 4 spirolateral.
   The order can be repeated and the number of repetitions is called the cycle. In the following graphic the order 3 spirolateral has been repeated 4 times, starting with the red, then the green, the blue, and finishing with the black order 3. 
 As is evident in the graphic, the order 3 cycle 4 spirolateral closes. It’s the relationship between order and cycle that can be explored and, by reviewing order-cycle data, a conjecture can be formed.
   The following graphic is a screen shot of the Scratch program that just computed the path followed by an order 9 cycle 4 spirolateral.
   This project can be viewed and downloaded by clicking on the following link.
    The second Spirolateral Scratch project mixes left and right turns. This greatly increases the number of patterns an order 5 spirolateral can compute. For example, there are 32 ways to order right and left turns for Order 5. In the graphic below, the right-right-left-right-right pattern for order 5 cycle 4 has been computed.

   This project is also a simple exercise for learning about how to store and retrieve data from a list.
   If enough data is collected by experiment, patterns in behavior do emerge. In other words, there is a relationship between order and cycle in this project that also leads to a conjecture.
   This project, Spirolateral Bot 2, can be viewed and downloaded by clicking on this link.
    Patterns really begin to get complicated (and even more interesting) when other turns, like 60 degree turns, and both left
and right turns are allowed.
   The project Spirolateral Bot 3 implements 60º right turns but can easily be modified to allow turns of any degree and both left and right turns. Doing so would make a nice exercise.
   In the graphic, an order 5 cycle 3 spirolateral has been computed.

   The project can also be viewed and downloaded by clicking on the link below.
    I do have pdf files for Spirolateral Bots 1 and 2 that go into more detail about programming spirolaterals in Scratch. To request a free copy, send an email to grandadscience@gmail.com


Tuesday, October 8, 2013

Five More Methods for Computing the Sierpinski Triangle

   In a previous post (see An Iconic Image of Deterministic ChaosFebruary 23, 2013), I shared a Scratch project that used mathematician Michael Barnsley’s Collage theorem to compute the Sierpinski triangle.
   I know five other methods for computing the same image;
(1) by playing the Chaos game, 
(2) by coloring the odd numbers in Pascal’s triangle, 
(3) using recursion and the initiator-generator method, 
(4) using the Lindenmayer L-system method, and 
(5) by using Wolfram’s linear cellular automaton, Rule 90.
   It’s the last method, Wolfram’s Rule 90, that is the subject of this post. Here is Rule 90.

   For any three-cell group, the state of the center cell, in the next generation, is determined by the black and white pattern of the three cells. Examine Rule 90 and you will find that the center cell transforms to a black cell in the next generation if the XOR operator (black = 1 or white = 0) of the left and right cells returns a 1 (black).
   You can view this project in action by clicking on this link. You do not need to have Scratch installed as the program will run in your browser.

   If you would like a detailed walk-through of Wolfram’s Rule 90, in a PDF file, email your request to:

Sunday, August 18, 2013

Help Getting Started with Scratch


   I will be teaching a mathematics class this Fall for middle and high school math teachers. The course requires that students do a bit of programming in the Scratch environment. To smooth their entry into Scratch,  I have written three Getting Started with Scratch  documents.
   The first document guides the reader through the steps of building a script that draws a square with a side length of 100 steps. This introduces the blocks menu and the mechanics of connecting blocks together to build a script.
   The second document describes how to create variables, sliders, and how to set the minimum and maximum values in a slider. The size of the square is now under variable control.
   The third document helps the reader build a script that will draw any regular polygon. In a regular polygon the side lengths are equal. A slider controls the number of sides and again, the side length is controlled by a slider. 
   The relationship between the number of sides and the turn angle for a regular polygon of n sides requires a bit of mathematical analysis.

   You may request any or all of these documents—in PDF format— by sending an email to: grandadscience@gmail.com.           
            Getting Started with Scratch – Part 1
            Getting Started with Scratch – Part 2
            Getting Started with Scratch – Part 3

Thursday, August 8, 2013

A Simple Model of Diffusion

  This Scratch project is an over-simplified look at the physical process that occurs when a drop of ink is placed in a very thin layer of water.        
   The ink molecules perform random walks. Over time, the molecules drift from the center and diffuse throughout the water. 
   In the following short video, I demonstrate how to add a drop of red food coloring to a very thin layer of water and then watch as the coloring diffuses in a near perfect circle. Several billions of red-colored particles are involved in the video and the statistics that govern the random walks of such a large number of particles accounts for the circular diffusion.
   The following Scratch project is my first look at 'cloning', available in the new 2.0 version of Scratch. Years ago I did this same project in Starlogo


   Starlogo has a crt X command (create turtles X) that commands the X number of turtles to execute (in parallel) the same procedure. If you 'See inside' to look at the code, I think you will see that  I used 'clone sprite 1' to the same effect in this project.
   Here's a very short video of the Scratch project in action.
   The maximum number of particles I can clone in Scratch 2.0 is 300 so there aren't the billions of particles in the Scratch simulation that there are in the actual food coloring demonstration.
Still, even with such a low number of particles, one can see the diffusion away from the center and the roughly circular shape emerging from the random walks.
   This is the link to the project.
   The ability to 'clone' a sprite means only one script has to be written and it controls all of the clones!
   Notice that this project is an extension from the one-dimensional random walk on the integer number line (see previous post) to the the two-dimensional plane.

Tuesday, July 9, 2013

Feynman's Linear Random Walk


   The famous physicist Richard Feynman is performing a random walk on the integer number line. Starting at position 0, he flips a coin. If it's heads, he takes one step to the right or, if tails, one step to the left, and flips again and again until a preset number of flips have been completed. He then marks his position.
   

   This type of random walk is called a Symmetric Random Walk on the 1-D Lattice. It's symmetric because the transition probability from left-to-right is 0.5.
   Most people think the most probable position to end a walk is 0, where the walk began. They reason that if the probability is 50-50, the walk should end on or near the origin.
   In The Feynman Lectures on Physics, Volume 1, Chapter 6, Probability, physicist Richard Feynman proves the amazing fact that for the random walk described above, the random walk is 'most likely' to end at the position marked by the 'square root of the number of steps in the walk'! If n is the number of steps in the walk, then the most probable end point of the walk is √(n).
   This Scratch project allows you to explore a simulation that should convince you of the truth of his finding. Click on the following link to view and use the Scratch project.

http://scratch.mit.edu/projects/11282377/ - player

   Set the Number of coin flips slider to a value from 500 to 1000 flips.
   Click on the green flag, run in Turbo if you want to speed up the random walk.
   Compare the position of the walker to the RMS distance prediction.
   A derivation of the Root Mean Square law (PDF format) can be obtained (free) by sending an email to grandadscience@gmail.com.

Sunday, June 23, 2013

Preparing to Teach a Fractals and Chaos Course


   I will soon be teaching (for the fifteenth time) an introductory course called Fractals and Chaos. The students are middle and secondary school math and science teachers. As part of the course, they are required to do a certain amount of programming and I have been converting the program assignments from another language to Scratch. Below are just three of the conversions that have been uploaded to My Stuff on Scratch. 
   The first two projects are examples of what are called strange attractors. The first really famous strange attractor was the Lorenz attractor (already in My Stuff).  Before attempting to understand strange attractors, we study the concept of a mathematical attractor using a simple linear equation and iteration.

The Hénon Attractor

The Rössler Attractor


   One of the curves that forced mathematicians to redefine the definition of 'curve' was the Koch snowflake. The snowflake curve is an example of a similarity fractal. It's mathematical properties are counter-intuitive. For example, it's perimeter is infinite in length but it bounds a finite area. Students are assigned the task of constructing their own similarity fractal.
The Koch Snowflake

   Additional information about each of these projects (in the form of PDF files) can be had by sending an email request to grandadscience@gmail.com.