Showing posts with label Scratch. Show all posts
Showing posts with label Scratch. Show all posts

Monday, July 6, 2015

How to Program a Circle in Scratch - Part 2

I’ve taken a cue from Dr. Papert (the inventor of Logo, the grandfather of Scratch) and decided that geometry provides the best context, at least in the beginning, for learning the rudiments of Scratch. Everyone is friendly with triangles and squares.
   You have most likely created a Scratch algorithm (see A) that drew a square with a side length of 100 steps. Scratch could draw the square anywhere on the screen but only that particular square.
   In a later script (see B), you created a variable named length of side and took a step towards generalizing your square script so that it would draw a square of any size as set by the minimum and maximum values in a slider. But still, it could only draw a square.  
   A square is a quadrilateral but it’s also a polygon. But so is a triangle a polygon. Let’s extend what you’ve learned and create a Scratch script that draws any regular polygon. This script will require that both the number of sides in the polygon and the length of each side be controlled by variables. We will call this script G-poly.
The Generalized Polygon Algorithm (G-poly)
   When you first drew a square in Scratch you didn’t have to think about interior and exterior angles (see A) because in a square, they are both equal to 90º. 
   Perhaps your first attempt to draw an equilateral triangle produced the path seen in graphic B.  Your experience with polygons had always focused on the interior angles of the polygon. Therefore, it was natural to think that your program to draw an equilateral triangle would require a turn angle of 60º when in fact it requires a turn angle of 120º, the measure of the exterior angle.  
   Knowing the relationship between the interior and exterior angle when drawing a square and a triangle is the first step towards building G-poly, the code that will generate a closed polygon with any number of sides and side length. For example, our generalized polygon (G-poly) program will draw a closed polygon with 17 sides, each side with a length of 30 units. Or a polygon with 41 sides and a side length of 10 units.
   But first, let's step away from the computer and use paper and pencil and our knowledge of mathematics to collect data that will help identify the needed relationships. Knowing that the sprite turns through the exterior angle to draw a regular polygon, take time to complete the following table.
   In the Scratch code to draw a square of a variable size, (length of side) is the variable that controls the size of the square. You could make the (length of side) variable into a slider and set the slider to the value you wanted or you could ask for input directly from the keyboard. Either way, the Scratch script works fine.
   The (length of side) variable was easy to identify but what about the (turn right) variable? This is where the data from the above table becomes helpful. For a square, the turn angle is 90º. Note that column A x B is always 360º. This is because the product of the Number of Sides column and the Measure of One Exterior Angle column is always 360º. This guarantees that the regular polygon will close, that is, the ant will end at the point it started.
   The [turn right___degrees] block needs to know the external angle to turn through. From the data in the table, the relationship between column A x B and the Number of Sides column is
   Once you have defined the length of side variable (click on the data tab) you can drop it into the [move _____] block. Get a green divide operator and type 360 in the top white space, drop a (number of sides) variable in the bottom white space, and set the operator in the [turn _______] block as shown below.
   Drop a (number of sides)variable in the [repeat _______] block.
   Since the move and turn blocks work together. set them inside the repeat block.

   This repeat[(number of sides)] block is the working part of the code, the code that draws the generalized regular polygon.
   Now that the heavy thinking has been done its time to go to the computer and put the pieces together. It’s a good idea to clear the screen every time the script is run to keep the screen from filling up with distractions. It’s also a good idea to start the sprite (ant) at the same location every time the script is run. I call this step housecleaning because its purpose is to keep the screen tidy.
   Here’s where you can pick the pen color and the pen size to suit your artistic tastes. The pen up and pen down blocks are in the correct logical places although it doesn’t make any practical difference the order in which you place the [pen down] block, the [set pen color to ____] block, or the [set pen size to ____] block.
   The algorithm is complete once the above set of blocks is attached to the bottom of the code that takes care of clearing the screen, setting the sprite’s position, and setting the pen’s color and size.
   Go to your Scratch offline editor or login to the browser and build the code as shown above. You may think it’s correct but until you actually test it, you won't know for sure so click on the green flag and test it by drawing several different polygons. 
   If you would like to use the top view of an ant sprite moving on a bed of sand then request the Scratch file G-poly (start).sb2 at grandadscience@gmail.con. Note that the file already has the variables (length of side) and (number of sides) defined. The min and max for each of the variables has been set so that the ant cannot hit any one of the four sides. A sprite is well behaved as long as it's moving within the boundaries of the screen. If it hits an edge of the screen, it can move in ways not predicted or controlled by your algorithm.
   A pdf version of this post can also be had by emailing a request to
  In the next post we will modify G-poly so that it can find the center of any regular polygon. This is the next step in developing the code that will draw a circle or arc of a circle from a given point with a given radius.

Saturday, November 22, 2014

Scratch as a Social Community

   The Swiss psychologist Jean Piaget theorized that the cognitive development of children goes through four stages: the sensorimotor, the preoperational, the concrete operational, and the formal operational stage. Piaget’s work led to the theory of knowledge called constructivism. The essence of constructivism is that although information, facts, etc. can be transferred from teacher to student, knowledge has to be constructed by the student.

   Seymour Papert, the creator of Logo, the first programming language for kids, took the construction idea, tied it to making things, and called it constructionism.
   As Edith Ackermann says, “Piaget’s constructivism offers a window into what children are interested in, and able to achieve, at different stages of their development.” She goes on to say, “Papert’s constructionism, in contrast, focuses more on the art of learning, or ‘learning to learn’, and on the significance of making things in learning.”

    Logo, through the work of Mitchel Resnick and his group at MIT, has evolved to Scratch.

    Dr. Resnick explains the three design criteria used to build Scratch, “Learning lessons from Papert’s experiences of Logo, we’ve designed Scratch to move beyond Logo along three dimensions, making programming more tinkerable, more meaningful, and more social.”

    He goes on to describe the social side of Scratch, “Our development of the Scratch programming language has been tightly coupled with development of the Scratch Website and online community. For Scratch to succeed, we feel the language needs to be linked to a community where people can support, collaborate, and critique one another and build on one another’s work.”

    That Scratch is a success as a social constructionism community is reflected in its numbers.

    As of November 21, 2014, these are the Scratch statistics.

   Educators and parents interested in students building their knowledge should take a serious look at Scratch at 

and join the community.

 Ackermann, Edith K. (2001)
Piaget’s Constructivism, Papert’s Constructionism: What’s the difference?
Future of Learning Group
MIT Media Laboratory

Resnick, Mitchel. (2012)
Educational Technology, vol. 52, no. 4, pp. 42-46.

Sunday, November 2, 2014

A List of Great Resources that Support Scratch

   I recently met with a group of K-12 educators interested in banding together to support the current usage of Scratch in classrooms and to develop strategies as to how to expand the number of teachers that will introduce Scratch to their students. An agenda item asked that everyone report on the Scratch resources they knew were available on the web so that a list could be compiled, distributed, and kept current.
   What follows is the list generated from our first meeting. As new resources are discovered, I will update the list.

Scratch Resources You May or May Not Know About

(1) Scratch MIT -

(2) Scratchjr MIT -
     Available as a free iPad APP at the App Store
     Scratchjr available as Web Browser in 2015

(3)  Android - (read the About Us)

(4) Scratch Education - Now at Harvard - Web Site Called Creative Computing
   Free Downloads: (1) Scratch Educators Guide (2) Scratch Student Workbook
   (3) Both the Guide and Workbook in editable PowerPoint format.

(5) Computational Thinking with Scratch Site
   What is computational thinking?
   How do I assess the development of CT?
   How do I support the development of CT?

(6) One Hour of Coding with Scratch - December 8-14, 2014

(7) Raspberry Pi ­- a $35 computer (cannibalize old keyboards, monitors, etc.)
     Scratch 1.4 is already loaded into the module but so are web browsers for
     accessing Scratch 2.0.

(8)  Google’s Scratch-based site.

(9) Report of a Workshop on The Scope and Nature of Computational Thinking
         Committee for the Workshops on Computational Thinking
            Computer Science and Telecommunications Board
Division on Engineering and Physical Sciences

(10) This is a Scratch-based curriculum designed for grades eight and up.
Exploring Computer Science

(11)  Exploring Computer Science curriculum and Principled Assessment of Computational Thinking

(12) Computer Science Unplugged
Designed for classrooms that do have computers or access to computers. There are a lot of great ideas that would make great Scratch programming projects.

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:           
            Getting Started with Scratch - Part 1
            Getting Started with Scratch - Part 2
            Getting Started with Scratch - Part 3

Thursday, November 29, 2012


   The purpose of this blog is to provide detailed information about the mathematics, science, and programming techniques embedded in the Scratch programming projects I so love doing.
   I was motivated to start this blog by a comment one viewer made in regard to a project I posted on my Scratch page at
   Here is a screen shot of the project. The squareflake has the unusual property of always maintaining the same area as its originating square (in yellow) even if the perimeter is increased indefinitely by repeatedly applying the Lindenmayer rule!

   The aforementioned Scratch user had viewed my Lindenmayer System Squareflake project at 
and posted this comment,

AWESOME! How does it work?

   How code works is always a good question. I did include numerous comments in the Scratch scripts included in the project but they would most likely be helpful only to those that already knew something about Lindenmayer systems.
   Lindenmayer systems are not difficult to understand.  In fact, I did the project because I did not understand a Lindenmayer system!
   For those with an interest in learning the mathematics behind the code, I’ve written a detailed description of what Lindenmayer systems are, how they work, the applied mathematics, and how to program such systems in Scratch.

   To obtain a free pdf file for the Lindenmayer project simply email a request to and ask for Lindenmayer Systems in Scratch.

   Registered Scratch users can download the project by clicking on the above link. To download Scratch for the PC and Mac and become a registered user go to