Showing posts with label XY coordinates. Show all posts
Showing posts with label XY coordinates. Show all posts

Saturday, May 14, 2016

Catch the Star! - A Scratch Project

Over the past several weeks, I have been working with my child's classroom, focusing exclusively on Scratch! The kids LOVE it! :) We have been focusing mainly on game design, and of course, I try to make connections with the classroom syllabus at the same time. The class has been learning about the coordinate system and algebra over the last 2 months, hence the projects that I developed focus mainly on these two concepts.

I provided this sample program to get things started: Catch the Star! We went over the sample code and then the kids developed their own games using the concepts learned.
















Aim:
Create a game where a sprite constantly glides from one end of the screen to the other (much like the chimneys in the popular Flappy Bird game on code.org). If another sprite hits it, you get/lose a point. 

Friday, February 12, 2016

Valentine's Day Greeting Card - programmed with Scratch

With Valentine's Day coming up, this week I decided to do a fun little Scratch project with my child's class - make animated Valentine's Day greeting cards. The lesson plan is meant to introduce the kids to the following concepts:
  1. create animation effects by changing the size of a sprite
  2. make clones/ copies of a sprite
  3. position a sprite at a random location 
  4. provide background music for the animation
I made this sample skeletal program to use as a starting point.

There are 4 sprites in my sample program - Heart Face, Greeting, Balloon, and Heart.







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!

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".

Tuesday, August 5, 2014

Transmit Electricity with Minimum Loss from the Power Plant to the Cities

In this programming assignment, we shall work on finding the shortest path to reach a point on the XY plane. We shall then write a program for Pro-Bot to travel along the shortest path that we found. This is a peek into the world of optimization, comparing and contrasting various solutions to a problem and choosing the best one that fits our needs and constraints. 

Your task is to find the paths to the various points on the XY plane, given the XY coordinates. Next, compare and contrast the cost options for the different paths and choose the best one that meets the constraints. Once you have found the best option, determine the  distances and angles at which Pro-Bot has to make turns, in order to traverse the path and write your program. 



Computer Science Concepts involved:   Sequential programming, Optimization

Math concepts involved:   Right triangles, Coordinates on XY plane, Measuring distances between points given (x, y) coordinates, Angles,  Finding shortest paths

Grade levels:   4, 5

Hours required:   1



Programming Assignment



Electricity is generated in power stations and then it gets transported to various cities for distribution to the consumers. Not all of the electricity that gets generated will reach the consumer. Several losses occur along the way on the distribution network. The power company would like to keep the distribution losses at a minimum as the consumers do not pay for it. 


Here is a set of coordinates given, representing 3 cities X, Y and Z and the power generation station at point A. 





















Power is generated at location A and then transported to the cities. For each unit of distance between the points, 1 Kilowatt-hour of energy is lost (Kilowatt-hour is a unit  used to measure energy). Your task is to find the best option for drawing electric lines between the power station and the cities, which will have minimum total loss of electric power during transmission.

Your options are: 
(a) to have direct power lines drawn from A to the cities separately or 
(b) draw power lines from A to a city and then draw more power lines from that city to the next and so on. 

Given the coordinates of the cities and the power station, can you find the shortest distances between them? Use the values that you found to calculate the amount of electrical energy that is lost during transmission to the various cities. Which option do you think would work better, option (a) or option (b) as given above? 

Compare all options to see which approach can minimize the total loss of power during transmission from the power station A to all three cities X, Y and Z. 

If Pro-Bot is driving along the path that provides the minimum loss of electricity, starting from point A and visiting all three cities, can you write a program to trace Pro-Bot’s path? Assume that Pro-Bot is at the point (0, 0) and facing the X axis when it starts its journey.

Friday, August 1, 2014

A Treasure Hunt with Pro-Bot

In this assignment, we shall use Pro-Bot to do a treasure hunt. We shall work with a graph and use XY coordinates to specify the points where the treasures are located. We shall also think of ways of optimizing our paths to get to the various locations.

The minimum distance that Pro-Bot can traverse is 1cm. Hence, the graph paper that you use should have grids of a minimum dimension of 1cm x 1cm. If not, you can always draw your own set of XY axes and put in coordinates 1 cm or more apart. You can then set each step of Pro-Bot to be the distance between successive points on your XY axes. 


Computer Science concepts involved:  Sequential programming, Optimization

Math concepts involved:  XY coordinates, Measuring distances on a graph, Finding shortest path between points, Cost comparison, Angles

Grade levels:  3, 4, 5

Hours required:  1 or more

Compare and Contrast Different Paths for Pro-Bot’s Treasure Hunt


Pro-Bot is going on a treasure hunt. It has been told the coordinates at which the treasures are kept. Can you write the programs for Pro-Bot to get to the treasure?

Let us start with Pro-Bot placed at location (0, 0).
  1. The first treasure is located at the coordinates (3, 4). Can you write a program for Pro-Bot to get to this point by traveling only along horizontal and vertical paths (i.e., turns only at 90 degrees)? There are no limits on the number of units of horizontal or vertical distance that Pro-Bot can travel continuously at a time. Remember that Pro-Bot starts its journey from location (0, 0).
  2. What is the total distance traveled by Pro-Bot in your above program? Is there a shorter path for Pro-Bot to reach the point (3, 4) from its starting point of (0, 0), if you did not have the condition that Pro-Bot can only travel along horizontal and vertical paths? 
  3. Can you write a program for Pro-Bot to travel along your new shorter path to get to the point (3, 4)? Assume that Pro-Bot is facing the X-axis at the start point.
  4. If gas costs $3.00 per gallon, and Pro-Bot uses a gallon of gas per step, how much did it cost for gas using your first program? How much did it cost by using your second program with the shorter path? How much money did you save?

     A second treasure for Pro-Bot:
  1. There is a second treasure located at the coordinates (6, 8). If Pro-Bot has to pick up the second treasure soon after the first one, what path would it take under the condition that it can only use horizontal and vertical paths (i.e., turns only at 90 degrees)? Can you modify your first program to allow Pro-Bot to pick up both treasures, with the starting point at (0, 0)? 
  2. What is the total distance traveled by Pro-Bot now in your above program? Is there a shorter path for Pro-Bot to reach both points ((3, 4) and (6, 8)) from its starting point of (0, 0), if you did not have the condition that Pro-Bot can only travel along horizontal and vertical paths?
  3. Can you write a program for Pro-Bot to travel along the shorter path to get to both the points (3, 4) and (6, 8)? Assume that Pro-Bot is facing the X-axis at the start point.
  4. If gas costs $3.00 per gallon, and Pro-Bot uses a gallon of gas per step, how much did it cost for gas in your first program where you traveled only along horizontal and vertical paths? How much money did it cost using your second program with the shorter path? How much money did you save?



A Different Spin on Pro-Bot’s Treasure Hunt


Let’s try a variation on our treasure hunt. This time, we have an extra condition:  
Pro-Bot can take only one step (or 1 unit) at a time in any direction. 

For example, to get to a point with coordinates (2, 1), Pro-Bot cannot travel 2 cm straight along the X axis; it can take 1 step horizontally along the X axis, and then move up 1 step and then turn and move 1 step horizontally to get to (2, 1). 
  1. Can you write a program for Pro-Bot to get to the treasure at location (3, 4) starting from (0, 0) with the condition that you can take only one step at a time in any direction. Do you travel more distance to get to the treasure under this condition?
  2. If gas costs $3 per gallon and Pro-Bot uses a gallon of gas per step, how much does it cost to get to the treasure?
  3. Can you write a program for Pro-Bot to get to the treasure at location (6, 8) starting from (0, 0) with the condition that you can take only one step at a time in any direction. 
  4. If gas costs $3 per gallon and Pro-Bot uses a gallon of gas per step, how much does it cost to get to the treasure?
  5. Can you write a program for Pro-Bot to get to the treasure at location (6, 8) starting from (3, 4) with the condition that you can take only one step at a time in any direction.