Showing posts with label Angles. Show all posts
Showing posts with label Angles. Show all posts

Monday, October 19, 2015

A Pong Game - programmed with Scratch

Different versions of the ever popular Pong game are available on Scratch. Here’s the link from ScratchEd: http://scratched.gse.harvard.edu/sites/default/files/scratch-lesson-7-the-pong-game.pdf. The following lesson plan using Scratch is one that I created for our Grade 5 students, taking inspiration from this sample code for Pong.
Given the code for an interactive Pong video game, the students edit the program to create multiple versions of the game with varying difficulty levels. The aim is to gain familiarity with the Scratch software platform and learn how to create games/ programs that involve user interaction. The students learn to modify the various facets of the code, and in the process learn about reactive programming, conditionals, loops, sprites, backgrounds and variables. They discuss how the variables in the given program can be used to model the different factors (forces, energy, orientation, type of materials, etc.) involved in the movements of a bouncing ball.

Platform

We use the S4A (Scratch for Arduino) platform for the Grade 5 students in our school. This project is intended to provide an introduction to this software platform before the kids start using it as the IDE for Arduino. S4A is based on Scratch from MIT and is quite similar to it. Note that in this particular assignment, we do not use the Arduino.
The sample code for Pong can be found in the Examples/Games folder in S4A.

Computer Science Concepts

Reactive programing
Forever loops
Conditionals

Common Core Standards

  • Variables
  • Angular measurements
  • Coordinate geometry for a 2D plane
  • Forces & interactions involved in a bouncing ball

The Lesson Plan

The aim is to learn about the basics of the Scratch/S4A platform in this assignment:

  • open, edit, save & close a project
  • sprites & backgrounds
  • the Scratch instruction set

The students read the given code and understand the various programming components that are involved in the design of the game. The factors that affect the movement of the pong ball are included as variables in the code. Students learn how modifying them can change the way the game is designed. The difficulty level of the game can be altered by modifying the variables. A discussion on how the variables in the program represent the different factors (forces, energy, orientation, type of materials, etc.) that govern the movement of the pong ball can round up the class.

This assignment also provides a first hand look at the use of conditionals and forever loops. Reactive programming, where the sprites react to various key presses or mouse movement is also learned.

Slides

I put together a set of slides for this lesson as I felt that it might be easier for the kids to tag along with the lecture, by programming on their computers. They can store the different versions of their program under different file names. 

The Pong Game PPT



Programming Assignment

Modify the code for the sprites to create different versions of the game, as suggested below.

Paddle Sprite:

The code for the Paddle Sprite in the sample code is designed to follow the mouse/cursor horizontally.

  1. Can you modify the code for the Paddle Sprite so that it follows the mouse pointer vertically on the screen?
  2. Modify the code for the Paddle Sprite so that it follows the mouse pointer everywhere on the screen.

Ball Sprite:

Try experimenting with different values for the variables. Note the changes you see each time.

  1. Use the “pen down” instruction to track the path of the ball.
  2. Would the game ever take off if the starting position has the ball touching the red zone on the background?
  3. Guess why the “forever loop” is used in the game.
  4. Guess why the “180 - direction” is used to set the direction of the ball when it hits the paddle.
  5. Guess what the “turn random angle” does. Experiment with it to increase the difficulty level of the game.
  6. Can you make the ball move faster at the start of the game by changing one of the variables?
  7. Can you make the ball move faster when it hits the paddle by changing one of the variables?
  8. Increase the difficulty level of the game by increasing the speed & randomness of the ball.

Challenge

  1. Introduce a variable to keep track of scores - you start with zero points & every time the paddle hits the ball, you get a point.
  2. Can you program the paddle to be moved on the screen using the arrow keys on the keyboard, instead of the cursor?

Summary

Summarize the lesson by going over what some of the variables in the game represent. Here are a few examples:

  1. When you change the speed of the ball, what does it imply about the loss/transfer of energy?
  2. If the ball moves faster after hitting the paddle, what kind of material could the paddle be made of? Is it one that absorbs much of the ball’s energy?
  3. The red background in the sample code makes the ball come to rest completely. Discuss the energy transfer of the ball in this case. What materials could possibly have made the pong ball come to rest on coming into contact with it?

Here’s a link with more info about the science of a pong ball, if you would like to go further with the discussions.

Tuesday, April 21, 2015

A Drive through the Zoo: Learning about Angles using Pro-Bot

My child's class started learning about angles about a week ago. And the teacher requested me to design an exercise for Pro-Bot that will introduce the idea of angles. As the kids are very new to the concept, I wanted to keep this one fairly simple, while still using a mix of acute, obtuse and right angles.

A trip to the zoo is almost always part of our field trips every school year. The zoo in our city happens to have buses that drive along the various points of interest/ themed animal enclosures. I felt that the turns made by the bus in this familiar setting of the zoo, might be a good way to introduce angles.

In this exercise, a scaled down version of the bus route, provides the path for Pro-Bot to drive on. As the Bot drives along the path, it is required to make angular turns at each point. I have provided the angular measurements required in degrees and distances in centimeters. The bus travels in a loop, the directions are shown using arrows. Note that the map below is not drawn to scale.





Based on the above map, write a program for Pro-Bot to drive along the following paths, assuming that the Pro-Bot is facing in the forward direction:
  1. The path from the Entrance of the zoo to the African Savanah. How many turns did the Pro-Bot make? Were the angles acute, obtuse or right angles?
  2. To continue from the African Savanah (where you stopped before), to the Elephants enclosure, how many degrees did the Pro-Bot turn? 
  3. Program the path from the African Savanah to the Raptors. How many turns did the Pro-Bot make? Were the angles acute, obtuse or right angles?
  4. Continue the path from the Raptors to the Kids' Play Area. Did you use acute, obtuse or right angles for the turns?
Alternatively, the kids can be asked to program the entire bus route as a single program, marking the types of angles used along the way.


Friday, August 1, 2014

Drawing Polygons using Pro-Bot given Area or Perimeter

In this programming assignment, we shall draw polygons using Pro-Bot, given the area or perimeter of the polygons. Your first task is to figure out the dimensions of the polygons from the given data and your second task is to write programs to draw the polygons using Pro-Bot. You can use either sequential programming or Repeat loops to draw the polygons, depending on whether they are irregular or regular.

Computer Science concepts involved:  Sequential programming, Repeat loops

Math concepts involved:  Polygons (regular and irregular), Area, Perimeter, Measurement, Angles

Grade levels:  4, 5

Hours required: 3 - 4


Draw Polygons using Pro-Bot given the perimeter:

  1. The perimeter of a regular, 4 sided polygon is 32 cm. The interior angles are all 90 degrees each. Can you write a program for Pro-Bot to draw this polygon? What kind of a polygon is it?
  2. The perimeter of a regular, 4 sided polygon is 32 cm. A pair of opposite interior angles are 60 degrees each. Can you write a program for Pro-Bot to draw this polygon? What kind of a polygon is it?
  3. The perimeter of a regular 3 sided polygon is 18 cm. The interior angles are all 60 degrees each. Can you write a program for Pro-Bot to draw this polygon? What kind of a polygon is it?
  4. The perimeter of a 3 sided polygon is 24 cm. The interior angle between the shortest sides is 90 degrees. The interior angle between the shortest and longest sides is 54 degrees. The sum of the lengths of the shortest sides is 14 cm. The difference between the lengths of the shortest sides is 2 cm. What kind of a polygon is it? Can you write a program for Pro-Bot to draw this polygon? 
  5. The perimeter of a 4 sided polygon is 24 cm. Two of its sides are parallel to each other and the other two are not. The sides that are not parallel are equal in length. Both the angles coming from a parallel side are equal: the pair of angles coming from the longer parallel side is 54 degrees each and the pair of angles coming from the shorter parallel side is 126 degrees each. The sum of the lengths of the parallel sides is 14 cm. The shorter of the parallel sides is 4 cm. Can you identify the polygon? Can you write a program for Pro-Bot to draw this polygon?
  6. The perimeter of a 4 sided polygon is 24 cm. Both sets of opposite sides are parallel. What kind of a polygon do you think it is? The ratio of the shorter side to the longer side of this polygon is 1/2; i.e.; each shorter side is half the length of the longer side. One pair of interior opposite angles is 60 degrees and the other pair of interior opposite angles is 120 degrees. Can you write a program for Pro-Bot to draw this polygon?
  7. The perimeter of a 5 sided regular polygon is 25 cm. Can you write a program for Pro-Bot to draw this polygon? What kind of a polygon is it? What is the value of each interior angle?

Drawing Polygons using Pro-Bot given the area:


  1. The area of a regular, 4 sided polygon is 24 square cm. The interior angles are all 90 degrees each. Can you write a program for Pro-Bot to draw this polygon? What kind of a polygon is it?
  2. The area of a 4 sided polygon is 24 square cm. The opposite sides are equal in length and the interior angles are all 90 degrees each. The longer side measures 2 cm more than the shorter side. The sum of the lengths of the long side and the short side is 10 cm. Can you write a program for ProBot to draw this polygon? What kind of a polygon is it?
  3. The area of a 3 sided polygon is 24 square cm. The interior angle between the shortest sides is 90 degrees. The interior angle between the shortest and longest sides is 54 degrees. The sum of the lengths of the shortest sides is 14 cm. The difference between the lengths of the shortest sides is 2 cm. What kind of a polygon is it? Can you write a program for ProBot to draw this polygon? 
  4. The area of a 4 sided polygon is 24 square cm. Both sets of opposite sides are parallel to each other. What kind of a polygon is it? The distance between the longer parallel sides is 4 cm. The perimeter of this polygon is 20 cm. One pair of interior opposite angles is 60 degrees and the other pair of interior opposite angles is 120 degrees. Can you write a program for ProBot to draw this polygon?

Thursday, July 31, 2014

Solutions: Drawing Polygons using Pro-Bot

Here is a subset of the possible solutions for drawing the polygons in this assignment. Please keep in mind that there are multiple correct ways of programming each of these figures.


The following programs draw the polygons without using Repeat Loops.

1. Square of sides 8 cm:
Fd 8
Rt
Fd 8
Rt
Fd 8
Rt
Fd 8
2. Rectangle 4 cm x 6 cm: 
Fd 4
Rt
Fd 6
Rt
Fd 4
Rt
Fd 6
3. Parallelogram 4 cm x 6 cm:
Fd 4
Rt 45
Fd 6
Rt 135
Fd 4
Rt 65
Fd 6
4. Rhombus 6 cm:
Fd 6
Rt 60
Fd 6
Rt 120
Fd 6
Rt 60
Fd 6
5. Equilateral Triangle of sides 6 cm:
Fd 6
Rt 120
Fd 6
Rt 120
Fd 6 
6. Right Triangle of sides 3 cm, 4 cm, 5 cm:
Fd 3
Rt 126
Fd 5
Rt 144
Fd 4 


Drawing Regular Polygons using Repeat Loops in Pro-Bot


All of the regular polygons below have sides of 6 cm.

1. Equilateral Triangle
Rpt 3 [
Fd 6
Rt 120
]
2.  Square
Rpt 4 [
Fd 6
Rt 90
// You can also use the instruction "Rt", instead of "Rt 90" in the code above,                                           // as the default turn is 90 degrees for Pro-Bot.
3. Pentagon
Rpt 5 [
Fd 6
Rt 72
]
4. Hexagon
Rpt 6 [
Fd 6
Rt 60
]
5. Octagon
Rpt 8 [
Fd 6
Rt 45
]
6. Nonagon
Rpt 9 [
Fd 6
Rt 40
7. Decagon
Rpt 10 [
Fd 6
Rt 36
]



A Circle using a Repeat Loop

Rpt 360 [
Fd 1                 // Move 1 cm
Rt 1                 // Turn 1 degree
]

An Algorithm for Drawing Regular Polygons using Repeat Loops 


From the pieces of code above for various regular polygons, the relation between the number of sides of a regular polygon and the angle of turn can be deduced to 360/N where N is the number of sides of the polygon.

The generalized algorithm for drawing regular polygons is:
Rpt N [
Fd X
Rt 360/N
]
where N is the number of sides of the regular polygon, X is the length of each side of the polygon.  



Programming Tangrams using Pro-Bot

This is a comprehensive programming project spanning over 4 hours, that aims to teach the key concepts that can be introduced via Pro-Bot (namely sequential programming, Repeat Loops and Procedures) while applying them to geometrical concepts that are covered in the classrooms. 
We shall make use of the famous tangram puzzles for this assignment. Let us take a quick look at what tangrams are and then talk about how to write programs for Pro-Bot to create them.   


Tangrams:


The tangram is a dissection puzzle consisting of seven flat shapes, called tans, which are put together to form shapes. The objective of the puzzle is to form a specific shape (given only an outline or silhouette) using all seven pieces, which may not overlap. It is reputed to have been invented in China and is one of the most popular dissection puzzles in the world.(Wikipedia)

Research shows that tangrams are helpful for developing an intuitive sense of geometry and developing visual-spatial skills. Tangrams have both geometric and artistic features. They help with classifying shapes, understanding the spatial rotation of shapes, understanding fractions, understanding the properties of various shapes including angles, area, perimeter, etc.


















To create a tangram, a square is divided up into 16 equal squares. Diagonal lines are drawn to produce 7 shapes. The seven pieces (numbered in the above picture) are:
2 large right triangles  (A, D)
1 medium right triangle (E)
2 small right triangles (C, G)
1 square (F)
1 parallelogram (B)

Some of the properties of the tans (puzzle pieces) are: 
  1. The large triangle is twice the area of the medium triangle. 
  2. The medium triangle, the square, and the parallelogram are each twice the area of a small triangle. 
  3. Each angle of the square measures 90 degrees. 
  4. Each triangle contains a 90 degree and two 45 degree angles (isosceles right triangles). 
  5. The parallelogram contains two 45 degree and two 135 degree angles. 
The relationships among the pieces enable them to fit together to form many figures and arrangements.



Now that we have taken a look at tangrams, let us write programs for Pro-Bot to draw the tangram puzzles.

We shall start by writing simple sequential programs to generate the seven individual puzzle pieces of the tangram. Then, we shall modify some of those programs to use Repeat Loops. We may also take a look at developing a generalized algorithm for drawing regular polygons (polygons with all sides equal and all angles equal) using Pro-Bot. Next, we shall learn to store programs for the individual puzzle pieces as Procedures in Pro-Bot’s memory, and then “call” them within programs that draw more complex tangram puzzles. 

Note that the programming questions are given in the order of increasing complexity, starting with simple polygons, then combining two or three of those to create compound figures and finally, creating complex tangram puzzles that use all seven pieces. 



Programming Assignment: 


Given a large square of sides 14 cm each, divide it into sections as shown in the figure below and create the 7 pieces of a tangram. Find the dimensions for each of the seven pieces. Make suitable modifications to the dimensions so that they can be used by Pro-Bot. Write programs to draw each piece separately using Pro-Bot. Finally, draw simple/complex tangram puzzles using Pro-Bot, making use of the programs that you wrote for the 7 tans/puzzle pieces.

Computer Science concepts involved:  Sequential programming, Repeat loops, Procedures/Sub-routines

Math concepts involved:  Polygons (Quadrilaterals, Triangles), Measurement, Fractions, Decimals, Rounding of decimal numbers, Angles, Trigonometry, Area, Perimeter, Congruence, Symmetry

Grade levels:  4, 5, 6

Hours required:  4 or more



Lesson Plan:

Hour 1:   Introduce Pro-Bot and tangrams. 

Allow the students to get familiarized with the Pro-Bot and its control panel. Introduce tangrams. Find out the dimensions of the 7 pieces in the tangram puzzle. Use sequential programming to create each of the 7 pieces in the tangram.

14 cm side square divided into 16 equal parts, 
with the diagonals drawn to create the seven puzzle pieces
























  • On a piece of paper, draw a square of sides 14 cm each.
  • Divide this 14 cm side square into 16 equal squares and trace all 7 shapes, using the above diagram as your guide.     
  • For the right triangles, either calculate the hypotenuse using the mathematical formula or measure it using a ruler.
  • Find the dimensions of the square and the parallelogram.
  • Can you figure out what fraction of the large square is taken up by each of the seven puzzle pieces?
  • Check to see if the dimensions obtained for the sides of the seven puzzle pieces are whole numbers or decimals. If they are decimal numbers, think about whether decimals can be used with Pro-Bot. If not, how can you adjust these numbers to work with Pro-Bot?
  • Once you have adjusted the dimensions so that they work on Pro-Bot, write programs to draw the puzzle pieces using Pro-Bot.
  • You can see that some of the puzzle pieces are congruent. Hence, you need to write the program only once for each set of congruent shapes.
  • Test your programs on Pro-Bot, one at a time to see if you get the desired results for each shape.



Hour 2:    Introduce Repeat Loops on Pro-Bot.
  • Now that all the puzzle pieces have been drawn using sequential programming, show how the programs for the square and the parallelogram can be rewritten using Repeat Loops in Pro-Bot. 
  • Write programs for drawing a few regular polygons using Pro-Bot (polygons with all sides equal and all angles equal) such as pentagon, hexagon, etc. Show how Repeat Loops can be used to write programs for these figures. Develop a generalized algorithm (a set of steps for solving a problem) for drawing regular polygons using Pro-Bot. 


Hour 3:    Introduce Procedures on Pro-Bot. Draw compound figures that use a subset of the seven puzzle pieces.
  • Store the program for each puzzle piece as a Procedure on Pro-Bot. Since the puzzle pieces would be used multiple times in the project, it makes it easier for you as the programmer, to write the program for each puzzle piece just once, store it as a Procedure and re-use it multiple times.
  • Work on a few compound figures that use a combination of just two or three of the puzzle pieces. Call the procedures for the individual puzzle pieces while writing programs for the compound figures.

A.   Write programs for Pro-Bot to draw the following compound figures that use the square and a small triangle from the tangram. 



























B.   Write programs for Pro-Bot to draw the following compound figures that use the parallelogram and two small triangles from the tangram. 





















C.   Your class is planning to do a gardening project. You have decided to grow spinach in an area measuring 12.5 square feet and carrots in 25 square feet. The two designs that you are considering for the garden are the ones in Question A above. Would you choose the square or the triangle part of the garden for the carrots? If the cost of fencing the garden is $5 per foot, which design would you choose so that the cost of fencing can be minimized.

D.   Your school has decided to pursue more vegetable gardening projects. This time, the plan is to grow tomatoes and peppers in spaces of equal area and carrots in a space that is double the area of tomatoes. The garden designs being considered are the ones in Question B above. Determine which vegetable would go in the parallelogram part of the garden and which ones would go in the triangles. How many square feet each of tomatoes, peppers and carrots can be grown? If the cost of fencing the garden is $5 per foot, which design would you choose so that the cost of fencing can be minimized.

E.   Can you make a trapezoid using just two pieces from the tangram? Write a program to draw your trapezoid using Pro-Bot.

F.   Can you make a parallelogram using just two pieces from the tangram? Write a program to draw your parallelogram using Pro-Bot.

G.   In each of the compound figures that you worked with, can you see the relationship between the angles of the puzzle pieces that allows them to fit together seamlessly?




Hour 4:    Write programs to draw complex tangram figures using Pro-Bot, using all seven puzzle pieces. You can choose either option A or option B.


Option A:
Create geometric shapes using all seven puzzle pieces of the tangram. Write programs for Pro-Bot that uses some of the Procedures for the puzzle pieces to draw the following figures. Compare the areas and perimeters among the complex figures that you create.

A.   Can you make a square that uses all 7 of the tangram pieces? Write a program to draw your square using Pro-Bot.

B.   Can you make a triangle that uses all 7 of the tangram pieces? Write a program to draw your triangle using Pro-Bot.

C.   Can you make a trapezoid that uses all 7 of the tangram pieces? Write a program to draw your trapezoid using Pro-Bot.

D.   Can you make a parallelogram that uses all 7 of the tangram pieces? Write a program to draw your parallelogram using Pro-Bot.

E.   How many squares can you make using some or all of the tangram puzzle pieces?


Option B:

You can find hundreds of artistic tangram puzzles on Google. Choose the designs that are the most interesting to you and work with them. Write programs for Pro-Bot that uses some of the procedures for the puzzle pieces to draw the figures that you choose.

Here is an example. Can you write a program for Pro-Bot to draw this figure, using some of the procedures that you previously created for the tangram pieces?