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

Tuesday, October 18, 2016

The Sound of Music - A Scratch Project

Hope the new school year has been going well for everyone. Sharing here a Scratch project that we worked on in the classroom before the summer vacations started. An interdisciplinary project, this one combines music with programming, and was intended to be a Father's Day gift from the kids to their dads. It came as a pleasant surprise that Scratch was having a similar theme that month (June 2016) for their Design Studio. 

Here are the sample Scratch projects that I created: one of my fav songs ever, Do-Re-Mi from The Sound of Music and the Carol of the Bells. Note that the sample projects are intended to be just a starting point to familiarize the students with the programming concepts that would be used in the assignment.


Aim

Create your own Music Project, using the instructions in the Sound section of Scratch.

Objective

Students learn to create their own piece of music using Scratch programming.

Saturday, October 24, 2015

A Formal Lesson Plan for the Scratch Food Chain

Here is a formal lesson plan that I designed for our Grade 5 students, to create an animated representation of a food chain. I have previously published a Scratch project for a food chain: A Food Chain in the Northern Temperate ForestThe lesson plan below is intended to help the instructor introduce the project in the classroom step by step, so that the students can learn the logic involved and gain familiarity with the Scratch instruction set. Food chains are part of the Grade 5 Science Standards, and this project could easily evolve into a presentation by the students at the end of the session.

Friday, July 31, 2015

An Introduction to Arduino & S4A (Scratch for Arduino)

Arduino is a very popular hardware platform with makers & hobbyists. The microcontroller board provides sensors and actuators that allow for interaction with the physical world. The official website for Arduino (arduino.cc) defines it as:
Arduino is an open-source prototyping platform based on easy-to-use hardware and software. It's intended for anyone making interactive projects. Arduino boards are able to read inputs - light on a sensor, a finger on a button, or a Twitter message - and turn it into an output - activating a motor, turning on an LED, publishing something online. All this is defined by a set of instructions programmed through the Arduino Software (IDE)
A more detailed explanation of "What is Arduino?" can be found on the Arduino Intro page.

Personally, I find Arduino to be a very versatile platform, that provides the opportunity for children to unleash their creativity. It would also allow for the development of interdisciplinary projects. While designing projects for children, I am always on the lookout for platforms that allow for the development of problem solving skills, logical analysis and thinking-outside-the-box, without getting trapped in the intricacies of the platform itself. I was thrilled by the opportunities that Arduino could provide, but was really skeptical about using its IDE for younger students.

A program or code written for Arduino is called a "sketch". Arduino programs are usually written in C or C++.  However, these languages are too complex for the younger kids to master and use. Hence, I did my bit of research and came across S4A - Scratch for Arduino. Developed by Citilab, a group in Spain, it is an improvised version of Scratch from MIT, with instructions that can be used to control the Arduino hardware. Here was the perfect solution to my dilemma: My students are already familiar with Scratch and absolutely love working with it; all they need to do is familiarize themseves with the extra set of instructions for the hardware. The instructions, written in plain English, are simple enough for the kids to understand and are very intuitive to use. It would open up the Arduino platform for them, without getting tangled in the intricacies of the syntax and grammar of a formal programming language.

The S4A site provides instructions on the download and installation; and frankly, it's quite a simple process. The main difference from the online Scratch is that you need to download and install S4A on your machine. And you are not allowed to share the S4A projects on the Scratch community website. The Arduino board is represented as a Sprite on this version of Scratch, and you have access to blocks that can perform digital/analog reads and writes, as well as blocks that can control motors. S4A is compatible with a few versions of Arduino, but I'll be primarily working with the Arduino Uno. Unless specifically mentioned, all references to Arduino in this blog will default to the Uno.

In the upcoming weeks, I'll be posting a few projects for Arduino, using S4A as the IDE.

Monday, July 27, 2015

Doodle Pencil - Using the Pen & Mouse Pointer Coordinates in Scratch

Here's a fun little Doodler made with Scratch:  The Doodle Pencil
















This was rather a spur-of-the-moment project... inspired by Etch-a-Sketch...  and kind of a follow-up on the Pac-Man game...

The code is minimal, and I feel not much of an explanation is required. The instructions are mainly from the Pen area of the Scratch Instruction Set, along with the instruction to follow the mouse-pointer. The "green flag click" handler does the initialization - clearing the screen, setting the sprite size and setting up the pen size & color.

The code is interactive, and it's designed to enable the user to lift and lower the pen as required while doodling: Move the mouse pointer to the desired location on screen and then click on the up arrow key; the pen will start drawing now by following the movements of your mouse pointer. Click on the down arrow key to stop drawing at any point.

This could be a fun little exercise for the kids to see how different combinations of the "Pen" and "Motion" instructions interact with each other.

Enjoy doodling!

Saturday, July 25, 2015

A Simple Math Game in Scratch - Introducing Conditionals & Comparators

Video games are ever popular among kids. And there are plenty of Math tutorials out there that use the format of video games to entice kids to practice their arithmetic. My child definitely enjoys working with these, and I am sure yours do as well. So, how about getting the kids to design and program their own little Math video game?

The students shall design the Math questions (and figure out the answers) to use in the game. They shall use comparators to decide if the answers entered by the user are correct or not. Variables shall be used to keep track of the number of right and wrong answers. This could potentially be a project for grade 4 and above, since variables are introduced as part of grade 4 Math.

Aim:  


Design a simple, interactive Math Video Game, with a pre-decided set of questions. The user gets to enter the answers, and the game should tell the user if the answers are right or wrong. The game should also keep track of the number of right and wrong answers, and display the scores at the end of the game.


Programming Concepts Introduced:

  1. Conditionals    (If - Then - Else)
  2. Comparators   (Equality testing)
  3. Variables        (To keep track of the game scores)

Implementation:


Here's the Scratch project that my child and I made:  A Simple Math Game.























The Design Process:


The exercise is intended to introduce the students to Conditionals and Comparators.

To make the game, start off by writing up a few Math questions and their answers. Have this list ready with you. Next, choose a fun sprite and a background, to make the game look interesting. Now, build up the program step-by-step.

Look at the requirements for the assignment. The game asks questions to the user and the user types in answers. The sprite could ask the questions. Since we need to keep track of the user input, the best option is to use the "ask and wait" instruction in the "Sensing" area of the Scratch Instruction Set.

Once the user types in an answer, it gets stored in the "answer" variable, again available in the "Sensing" area of the Scratch Instruction Set. This is the value that we need to compare against the pre-set correct answers from our list.


Introduce Comparators:  Equality operator

Lead the discussion with the question "How can we find out if the user entered the right answer?"

In the "Operators" area of the Scratch Instruction set, you will find 3 different comparators - less than, equal to & greater than. Discuss with the kids as to which one of these would be the best choice for checking if the user entered the right answer (we shall use the "equal to" operator in this case to compare the user input to the right answer).

For example, if the right answer is 10, we shall check the user input using the following comparator:





Introduce Conditionals:  If-Then-Else 

The next step is to decide what to do if the answer is right or wrong. Here's where the If-Then-Else statement comes into play. If-Then-Else can be found in the "Control" section of the Scratch Instruction Set. You could start by giving the students a few simple examples:
1.  If we behave well, then the teacher will give us extra recess time;
     else we shall have a shorter recess.
2.  If it rains, I shall bring my umbrella to school;
     else I shall leave my umbrella at home.

The simplest step could be the sprite announcing that the answer is right or wrong:
  • Every time the user's answer is correct, say "Right Answer" & 
  • Every time the answer is wrong, say "Wrong Answer". 









Use of Variables:

The final requirement for the game is to keep track of the number of right and wrong answers. We need two variables for this purpose. The variables can be created under the "Data" section:  Click on "Make a Variable", and choose a (meaningful) name for the variable. Make two variables, say "Points" & "Wrong Answers", as in the sample project. Make sure to display both variables on screen, using the "Show Variable" instruction.

Initialize both variables to zero at the start of the game. Discuss with the students why we need to do so. Now, add the following steps to the above If-Then-Else statement:

  • Every time the user's answer is correct, increase the variable "Points" & 
  • Every time the answer is wrong, increase the variable "Wrong Answers". 















We are almost done with the design at this point. To start and stop the game, use an event, such as "When green flag clicked" or a key press, etc., found under the "Events" section. You can add in as many questions as you like to make the game interesting. Make sure to test the code every few steps, as you build up the program.

Note: 

If you look at the sample project that my child and I made, you would see that we grouped the questions into different blocks/function. This keeps the code clean and provides for easier maintenance and testing, but it's definitely not a requirement for creating the game.


Have fun creating your own Math Video Game!!

Friday, July 10, 2015

CopyCat - A Simple Intro to User Input and Variables via Scratch

My child and I worked on CopyCat as a simple introduction to variables and user input in Scratch. Algebra is part of the Grade 4 Math curriculum in the USA, and this project could be a fun way to introduce the use of variables.


Aim:  

Design an interactive game in Scratch, where a CopyCat copies/repeats everything that you type in.

The Design Process:


  • Only a single sprite is required: the CopyCat. You can either choose from the list of sprites already available on Scratch, or draw your own. 

  • To provide user interaction in starting and stopping the game, we used the "green flag click" to start and the "space key click" to stop the game (both of which can be found under the section "Events" in the Scripts area in Scratch). You can choose any of the options that are available in "Events" to do the same.


Various sections in the Scripts area of Scratch

And now the fun part: CopyCat needs to copy everything that you type in.
How can we achieve this?

  • Under "Sensing" in the Scripts area in Scratch, you will find a block that asks for user input and waits for it. This is what we shall use, to ask the user to type in anything they like.


  • Once the user input is received, CopyCat needs to repeat it. But, how can CopyCat remember what the user typed in? Here is where the concept of variables comes into play. In the section "Sensing", you will find the variable "answer", which stores whatever the user typed in. 

  • I recommend selecting the box right next to "answer", so that it is visible on the screen and the kids can see how its value varies (hence the name variable), depending on the user input.


  • The CopyCat can now use this variable along with the "say" instruction (found in the "Looks" area of Scripts in Scratch), to repeat/copy whatever the user types in.



Ask the students to try writing the code upto this point:

  1. When "green flag clicked" (or other event), CopyCat asks the user to type in something.
  2. CopyCat repeats the user input, via the variable "answer". 
  3. When "space key clicked" (or other event), stop the program.



Let the students experiment with different values for the user input and observe how the variable changes accordingly. Once comfortable with the use of the variable, they can hide it by deselecting the box next to "answer".  It would be good to remind the students at this point, that this feature is helpful for debugging.

Here are three screen shots to demonstrate how the user input gets stored in the variable "answer".

  Asking for user input; variable is empty

User input entered; variable is empty till Return key is pressed

User input is now stored in the variable

Tuesday, June 16, 2015

Pac-Man is Chasing my Planet!

My child's class was recently introduced to Cartesian coordinates in Math. And in our coding class, we have been practicing interactive programming for the last few weeks. So, I thought of putting together a very simple template that  combines both the concepts, that the kids could then remix...  Pac-Man is Chasing my Planet! was the result... took me less than 10 minutes to put together and the kids loved it.

We went through the Pac-Man template code as a group & discussed the use of the XY coordinates. I showed the kids how the XY coordinates displayed under the Scratch animations area change, as I move the cursor around on the screen. Our discussion then proceeded along the following lines:


  • If I wanted my sprite (the planet, in this case) to move anywhere the cursor moves, what values should I use for the sprite's X and Y coordinates? 
  • The above point was also a good place to talk about variables, and how the change of the cursor position is always reflected in the planet's position. 
  • Should I move the planet around for just a few times or all the time? What kind of a loop should I use here?
  • How can I make Pac-Man always follow the planet? Which loop should I use? 
  • What values should I use for Pac-Man's X and Y coordinates? 
  • Here, the kids quickly saw that without a small degree of separation between the coordinate values of the planet & Pac-Man, the two sprites overlap each other.
  • BTW, the "if-else" clause was purely optional, for those to wanted to add another level to their game. The majority went with just a "go to x() y()"
  • And finally, the interactive part of the game... I put in the requirement that there should "a key press" or "the green flag click" to make the game start, and something similar to end the game. 

In the next one hour, the children came up with multiple variations of the game, making their own sprites and designing various versions of tag... All in all, a very fun class for them and me to wrap up the school year.

Happy Summer!!

Tuesday, May 26, 2015

Goldilocks and the Three Bears: A Scratch Project


Here is a Scratch project that my child and I have been working on recently:  Goldilocks and the Three Bears

Based on the familiar fairy tale, the idea was to use event handlers to create an interactive version of the story. 


Flappy Bird in code.org is a favorite with my child and has been a great intro to event handlers (and it's been the same story with all of my students...). As a follow-up to Flappy, this fun depiction of "Goldilocks and the Three Bears" allows you to interact with the story by clicking on multiple sprites. This was intended to provide more practice with the concept of event handling. In addition, it focuses on timing, and coordinating multiple actions via message passing between the sprites.






To make the story more interesting, we also did transitions among the backgrounds, and worked on showing/hiding sprites as required in various parts of the story. Creating the sprites and the backgrounds was definitely fun; copying a single sprite and tweaking it to produce multiple characters was something new for the kid as well.


Hope you enjoy the story! Let us know your comments!

Saturday, April 11, 2015

A Food Chain: Made from Scratch

Here is a Scratch project that my 9-year-old put together, depicting a Food Chain in the Northern Temperate Forests. An avid lover of animals, this project combining learning in two areas, was a very fun one for him. I loved the fact that he could create a presentation about an ecosystem, while combining his learning with art, storytelling and programming. A good example of an interdisciplinary project...

This project took him a few weeks to create, including the time for the initial research about the ecosystem. We went through the project in small steps, designing the various stages... deciding on the characters in the food chain, the order in which they appear, special effects if any, etc. As you can see from the progression along the length of the project, more special effects started appearing as he learned more about creating animations.

Major learnings for my child were:
  • Using "show" and "hide" instructions to make characters appear and disappear in the story.
  • Timing -- using the wait statement and figuring out how long to wait, before each sprite makes its appearance on screen.
  • Animation: Creating multiple costumes for a sprite and alternating between them to create the effect of movement.
  • Changing the size of a sprite to create the visual effect of distance.
  • Creating and using different backdrops at various points to create the effect of multiple scenes.
  • Using XY coordinates to decide on positions of the sprite at various points of the presentation.







Note:

This project simulating a food chain, could potentially be a Grade 5 class project. Food chains are part of the Grade 5 syllabus; the description can be found here on the NGSS (Next Generation Science Standards) website. The students are expected to  "develop an understanding of the idea that plants get the materials they need for growth chiefly from air and water. Using models, students can describe the movement of matter among plants, animals, decomposers, and the environment and that energy in animals’ food was once energy from the sun".

Saturday, February 28, 2015

A Scratch Project for Drawing Tangrams and Compound Figures


Here is my Scratch project that draws two sample tangrams and the compound figures from this assignment (using Pro-Bots) created for grade 5 students.

I have created 5 different procedures for drawing the 5 components of the tangram. Please note that this is just one way of coding the figures; there are multiple correct ways of writing the programs for the same.


The functions (procedures) that are used for drawing the various polygons in the tangram can be found under the blocks titled:
  • parallelogram
  • square
  • largeTriangle
  • medTriangle
  • smallTriangle

The functions (procedures) for the compound figures that use the square and the triangle can be found under the blocks titled:
  • Square+Triangle
  • Square+Triangle_2

The functions (procedures) for the compound figures using the parallelogram and the small triangles can be found under the blocks titled:
  • TriParall_1
  • TriParall_2

I have given the code for two tangrams here as samples: one is the Monk with No Foot from the famous "Two Monks Paradox" and the other is a tangram for a House. The functions (procedures) for these can be found under the blocks titled:
  • MonkNoFoot
  • HouseTangram



Note:   The various dimensions in the assignment for Pro-Bot have been multiplied by a factor of 10 in my Scratch project, as we are dealing with pixels here and not centimeters, as in the case of Pro-Bot.