Presentation is loading. Please wait.

Presentation is loading. Please wait.

Ms. Deveny Second Semester 2014 - 2015.  Introductions  Interview your table partner  Name  Why taking CPD  Computer experience  Favorite game?

Similar presentations


Presentation on theme: "Ms. Deveny Second Semester 2014 - 2015.  Introductions  Interview your table partner  Name  Why taking CPD  Computer experience  Favorite game?"— Presentation transcript:

1 Ms. Deveny Second Semester 2014 - 2015

2  Introductions  Interview your table partner  Name  Why taking CPD  Computer experience  Favorite game?  Programming skills?  Computers and/or gadgets?  Syllabus  Integrity Policy

3  Computer science is the science of how to treat information. There are many different areas in computer science. Some of the areas consider problems in a more abstract way.  A person who works with computers will often need mathematics, science, and logic in order to make and use computers.  Creating and solving puzzles – ‘two steps forward, one step back’!

4  Problem Solving  Consistency  Asking the right question  Providing enough data  Integrity and Professionalism

5

6

7

8  A set of programs that work together to produce a result.  An operating system and its applications

9

10

11

12

13 http://scratch.mit.edu

14  Simplified, graphical programming language created at MIT  Check out the projects and galleries on http://scratch.mit.edu http://scratch.mit.edu

15 Block Categories Available Blocks Script Area Sprite Stage All sprites in this project

16

17  All the action happens  Add sprites  Act based on their scripts

18 MMain elements of your Scratch programs EEach sprite ◦H◦Has one or more script DDetermines how the sprite acts under different circumstances ◦H◦Has costumes which will change their appearance ◦S◦Scratch has many or you may design your own

19 SScripts control sprites AAll scripts M UST HAVE  a a trigger ssome operations TThe trigger starts the sprite tthe sprite will perform the operations in order WWhat does this script do? trigger operations

20 A group of applications which work in sequence toward a common result.

21 LListed in the upper left of the Scratch window ““Motion” blocks cause sprites to move ““Looks” blocks change a sprite’s appearance EEach block corresponds to one “action” NNotice the shapes!  Actions occur in the order in which the blocks appear in the script.

22  Exercise: Write a script to do the following:  Move the sprite 25 steps,  Have the sprite say your name for 3 seconds  Turn the sprite around and move it back where it came from  Have the sprite say “I love Scratch!” for 5 seconds

23  Blocks in the Pen category allow your sprites to draw things on the stage  The block puts a sprite’s pen down on the stage. The block picks the pen up.  When a sprite’s pen is down, moving will cause it to draw.  You can also change the pen’s color, size, or shade.

24  Exercise 1: Write a script to make your sprite draw a square with 50 step sides.  Exercise 2: Once you’ve done that, write a script to draw two squares next to each other  The squares should not be connected by a line

25  Thought exercise: How can we make sprites move at different “speeds”?  Variables allow us to store data and modify or retrieve it later  Check out the Variables category  Look around for built-in variables  What shape are variable blocks?

26  When we click “Make a variable” we get a dialog box  The name can be anything you want  “For all sprites” means all sprites will be able to see and edit the variable ◦ Why might this be useful? Why might it be dangerous?  “For thissprite only” means only the current sprite can see and edit it

27  The order in which blocks are executed is called the “control flow” of the script  So far all our scripts have just executed blocks in the order given  Consider our script to draw a square  Notice all the repeated code  Wouldn’t it be nice if there were a way to simplify this?

28  Loops cause the sprite to repeat a certain set of blocks multiple times without having to repeat the blocks  Loop blocks in Scratch have the symbol at their bottom right  This indicates that when the end of the loop is hit, the next block executed is back at the beginning  There are several types of loops in Scratch:

29  Exercise 1: Rewrite the script to draw a square using loops. Try not to repeat any code.  Exercise 2: Now rewrite the script to draw two squares next to each other using loops. Again, try not to repeat code.  This is tricky!

30  See the hexagon-shaped hole in ? What goes there?  Look around for blocks with that shape. What does it look like they do?  Hexagon-shaped blocks represent Boolean expressions ◦ Named after 19 th century English mathematician George Boole  Boolean expressions evaluate to either true or false

31  Boolean expressions are used in conditions  Conditions control whether or not certain blocks are executed  The blocks inside of an “if” are executed if and only if the condition is true  The blocks inside of an “else” are executed if and only if the condition is false  Look at the “Sensing” category for lots of interesting things you can test

32  You can also use conditions in loops  is like forever, but only when the condition is true  loops until the condition is true, then moves on  Play with these, as they can be quite useful

33  Boolean expressions can be combined in certain ways  An and expression is true when both parts are true  An or expression is true is when either part is true  A not expression is true when the component expression is false

34  Truth Tables: ANDTF T TF F FF ORTF T TT F TF NOT T F F T

35  Exercise 1: Write a script to do the following:  Generate a random number between 1 and 10  Draw a red square if the number is less than 6  Draw a blue square if the number is 6 or greater  Exercise 2: Write a script to do the following:  Generate two random numbers between 1 and 10  If both are less than 6, draw a red square  If both are 6 or greater, draw a blue square  Otherwise, draw a purple square

36  You can build multiple scripts in the script area for any sprite (or the stage)  All these scripts run at the same time (assuming their triggers occur)  Each script is called a “thread”

37  Exercise: Write multiple scripts to do the following  Very slowly draw squares  Every 2 seconds, change the pen color

38  You can ask the user for input using  The response is stored in  Note that is just a built-in variable  Often, you’ll be storing the input in a variable for later use

39  Exercise 1: Write a script to do the following:  Ask the user for a number between 1 and 10  Draw that many squares  Exercise 2: Write a script to do the following:  Ask the user for a number between 1 and 10  Ask the user for a number between 1 and 255  Draw the first number of squares with the pen color set to the second number

40  So far, we’ve only used simple numbers  It would probably be nice if we could do some math  Check out the Operators category  The first four blocks are your basic arithmetic operators  At the bottom are some more useful operations  As always, notice the shapes– where can we use these blocks?

41  Exercise: Write a script to do the following:  Ask the user for a number between 1 and 5  Draw twice that many squares

42  Sprites can cause each other to act in certain ways by using and  This sends out a message which can be picked up by other sprites  These messages are called events  Events have unique names, and any sprite can broadcast or listen for any event

43  Exercise: Implement “Marco Polo”  Create one sprite at the center of the stage  Create another sprite at a random location and hide it  The arrow keys control the motion of the first sprite  When space is pressed, the first sprite should say “Marco” after which the second sprite should briefly show itself and say “Polo”  If the first sprite says “Marco” when it is touching the second, the second sprite should appear and say “Found me!”

44  If you right-click on the script area, you get an option to “add comment”  Comments are used to describe what’s going on or otherwise annotate code  In Scratch, they look like this:  Scratch comments can be attached to blocks:

45  You should use comments to:  Describe the basic, high-level behavior of any script  Explain anything potentially unclear or tricky  Explain why you chose to do something a certain way if there were multiple options  Etc.  Get in the habit of using comments now. You’ll be graded on them when we get to Java

46  Strings are made of letters, words, or other characters (e.g., apple ; October 2009 ; You win! ).  Strings can be stored in variables or lists (such as or ).  You can join together strings using.

47  You can compare strings using the following blocks:, or  Strings are evaluated as 0 in mathematical operation blocks (such as: ) and in blocks that expect a number (such as and ).

48  You can now create and manipulate lists in Scratch. Lists can store numbers as well as strings of letters and other characters  To create a list, go to the Variables blocks category and click  Lists in scratch are referred to ‘arrays’ in Java

49  When you create a list, a list monitor will appear on the stage. A list monitor shows all the items in a given list. You can type items directly into a list monitor.  At first, the list is empty.  You can add to a list:  The length will increase by 1.

50  You can delete from the list by the delete  But you must know the item number to delete.  You can also replace and insert items from a list.

51  Exercise 1: Write a script to do the following:  Create a ‘to do’ list with user input  If the user item does not exist in the list, add the item to the list.  If the user item does exist, delete it from the list.  The program ends when the user inputs ‘end’.


Download ppt "Ms. Deveny Second Semester 2014 - 2015.  Introductions  Interview your table partner  Name  Why taking CPD  Computer experience  Favorite game?"

Similar presentations


Ads by Google