Wednesday, September 30, 2015

Sprite Position and Direction

  1. "U1L2-Interface"Start a New Project called U1L2-Interface
    Creating a New Project   Starting a New Project
    1. If there is a Snap! file open, save it.
    2. Go to the Snap! File menu, File button, and choose "New".
    3. Click "Yes" to replace the current project.
    4. In the Snap! File menu, File button, choose either "Save" or "Save as..."
    5. Name the file "U1L2-Interface"
  2. There are also other backgrounds built into Snap! that you can use for other projects.
  3. Change the background on your stage so that you see the coordinate plane grid and axes.
    Changing the Background 
    1. In the Sprite Corral, select the Stage thumbnail.
    2. Then, choose "Backgrounds" from the Snap! File menu, File button .
    3. Choose "xy-grid.gif" to show the grid.
  4. Turn on watchers to show the direction of the sprite and its x and y coordinates.
    Adding Sprite Watchers 
    1. In the blue Motion palette, click on the gray checkbox next to the x position block. Drag the sprite around and to see the watcher display the changing x-position of the sprite.
      X Position block's checkbox X Position stage watcher
    2. Create watchers for y position and direction by checking their boxes in the same palette. Move the sprite around using commands or by just dragging it with your mouse. Notice which actions change which values.
Your stage should look like this with axes, a grid, the origin, and 3 watchers: x-position, y-position, and direction.
The coordinates in Snap! are only integers.
In many programing languages, the origin is at the upper left corner of the screen and the numbers go up to the right and up as you go down the screen.
Coordinate Grid
Take turns speaking Coordinate systems for computer screens may be set up differently than in mathematics.
  • In Snap!, the origin, (0, 0), is in the middle of the stage and the signs of the coordinates in the quadrants are the same as in algebra.
  • Unlike mathematical convention, the numbers naming sprite direction in Snap! start with 0 at the top and count up in degrees going clockwise.
    grid and axes on Snap stage with sprite watchers
  1. What are the position coordinates of the sprite in the image above?
  2. In what direction is the sprite pointing?
  3. The tip of the sprite arrow is the point in question.
  4. Experiment by dragging around a sprite image (sprite) to make sure you see which part of the sprite graphic the coordinates are describing.
  5. Once the pen is down, it stays down even in a different script. If you want your script to move the sprite without leaving a trace, use the pen up block to "lift the pen."
  6. Assemble a collection of blocks from the "Motion" and "Pen" tabs into a script that, with one click, draws a square or triangle or some other a simple picture. You will almost certainly want at least these blocks:
    Move 10 Steps Block  Turn Right 15 Degrees Block  Clear Block  and Pen Up Block.
  1. This script was intended to create a pentagon, but it has bugs. Without building it, try to figure out what it does instead. Then build it and try it out. What change(s) would fix this script?
    penDown, forever (turn CW 10 deg, change x by 10)
  2. Create a program with the x-y-grid in the background that labels each of the quadrants with the signs of their coordinates.

No comments:

Post a Comment