900 likes | 1.21k Views
An intro to Scratch. Notes and Tasks for ITEC-I5 Camp Leaving lots of exploration for the future. What are our goals?. Learn some computing concepts. Use Octave as computing tool. Use Scratch as computing and multimedia tool. Have fun with Scratch creating stories, games, art.
E N D
An intro to Scratch Notes and Tasks for ITEC-I5 Camp Leaving lots of exploration for the future. ITEC-I5 Scratch Aug 2009
What are our goals? • Learn some computing concepts. • Use Octave as computing tool. • Use Scratch as computing and multimedia tool. • Have fun with Scratch creating stories, games, art. • Learn some computing concepts. ITEC-I5 Scratch Aug 2009
Who computes? • Scientists • Engineers • Businessmen • Social scientists • Artists • FBI agents • Brain surgeons • Grandkids ITEC-I5 Scratch Aug 2009
Monday concepts (20 min) What is an algorithm? An algorithm for an average and min An algorithm for sorting ITEC-I5 Scratch Aug 2009
Algorithm for computing the average of two numbers • Let the first number be A; say A=12 • And the second number be B; say B=15 • To compute the average _____________ • So the average of 12 and 15 = ________ ITEC-I5 Scratch Aug 2009
What algorithm for the average age of two people? • Input this • Do precisely this • Do precisely that • Output what 12 15 ITEC-I5 Scratch Aug 2009
problem: finding min • Person B is the “ref” watching A. • Person A has list of numbered cards, but cannot look at all the numbers. • A can look at 2 numbers at a time only -- one card in each hand. • A must find the min of all cards. • Exchange roles, with A the “ref” and B “the player”. • HOW TO ALWAYS FIND THE MIN? ITEC-I5 Scratch Aug 2009
Problem: team finding the min • Person A can look at no numbers! • No numbers can be seen by A, ever! • Person B can look at only two numbers on cards given by person A. • Person B gives back to A first the card with the smaller number (if numbers are = then it doesn’t matter which is given first) • Person A must find the min and show it to the instructor WITHOUT EVER SEEING IT • A and B should switch roles and repeat. ITEC-I5 Scratch Aug 2009
Problem: how to sort? Use set of cards for each team. How can A sort using B as comparer? ITEC-I5 Scratch Aug 2009
Sorting two-person game • This is a 2-person exercise. • To solve the sorting puzzle, person A must form an ordered list of cards, which the instructor will check for order (this is the OUTPUT). • Person B can only compare two numbers by seeing the numbers. Person B gives A the smaller number card first (precise operations). • Person A can only ask Person B which of two cards has the smaller number. Person A never ever looks at any numbers. • To solve the sorting puzzle, person A must start from an unordered list of cards (this is the INPUT). ITEC-I5 Scratch Aug 2009
Sorting by selecting minimum • Spread out list of number cards 31, 22, 13, 32, 11, 21, 23, 33, 12 • Select the minimum and begin a new list 11 • Select the min of what’s left and add it to the end of the new list. 11, 12, • Repeat this process until the original list is empty and the new list has all the cards. 11, 12, 13, 21, 22, 23, 31, 32, 33 ITEC-I5 Scratch Aug 2009
Problem: what is the average age of our class? • How do we define this? ..compute this? • An algorithm computes some output from the given input using precise steps that a machine can follow ITEC-I5 Scratch Aug 2009
Students use Octave (10 min) Verify the work and problem solutions as below [while the instructor leads]. ITEC-I5 Scratch Aug 2009
sum = 12 + 15 sum = 27 average = sum/2 average = 13.500 sum is a variable; set its value to 12+15 average is another variable; set its value to the value of sum divided by 2 Compute the average of two numbers using Octave ITEC-I5 Scratch Aug 2009
Octave has many useful ops • It can operate on numbers -- +, /, sqrt • It can operate on lists of numbers – min, max, length, mean • Use Octave as needed in camp and after! ITEC-I5 Scratch Aug 2009
gKids = 10 13 11 12 13 • >> length(gKids) • ans = 5 • >> sum(gKids) • ans = 59 • >> avgAge = sum(gKids)/length(gKids) • avgAge = 11.8000 Precise steps to compute the output from the input. The input is the list of ages; the output is the average of all the ages in the list. You can use the ages of the actual group present. ITEC-I5 Scratch Aug 2009
sort a list into order • >> gKids • gKids = 10 13 11 12 13 • >> sort(gKids) • ans = 10 11 12 13 13 • >> min(gKids) • ans = 10 • >> max(gKids) • ans = 13 • >> What algorithm does MATLAB use to sort the list? What algorithm finds the min? What algorithm finds the max? ITEC-I5 Scratch Aug 2009
There are MANY sorting algorithms. Recursively selecting the min is a BAD algorithm when the list is big. Computer scientists know many different algorithms, some good for small and some good for big lists. ITEC-I5 Scratch Aug 2009
Start scratch and let’s go! (90 min) • Click on the cat icon • If not on desktop, download from www.scratch.mit.edu • Scratch programming environment comes up quickly • We will first do simple ops ITEC-I5 Scratch Aug 2009
Goals for Scratch • Learn about objects and behavior • Programming motion and sound • Programming user interaction • Creating your own story, game, entertainment piece, or simulation (starting Wednesday) ITEC-I5 Scratch Aug 2009
PREFACE • These slides are intended to be used in an active lab demo and discussion and are therefore not complete by themselves. • Scratch has a nice facility for working with sounds; however, during the intro only the instructor’s computer should have speakers. When students get to individual work later, they can use headsets and microphones. ITEC-I5 Scratch Aug 2009
Simple ops first • Sprites are objects • We operate on their color, size, position • We move them • We have them say things ITEC-I5 Scratch Aug 2009
Click on the “Looks” button at the top left. ITEC-I5 Scratch Aug 2009
Major components • At right: the stage with sprite[s] or objects or actors • At left: operations and attributes for the sprites • Center: scripts or program[s] for the behavior[s] of the sprites • Your sprites are actors that you direct with your scripts ITEC-I5 Scratch Aug 2009
The “hello” script • Can do it in 57 languages – java, C++, … Scratch • Easy in Scratch: select “Looks” operations and drag the “hello operation” onto your center panel. • Then double click on this “lego block”: check your sprite behavior at the right Your very first Scratch program! ITEC-I5 Scratch Aug 2009
Make the cat 50% larger • Select “Looks” operations • Drag the “change size” operator into your script • Click and edit for a 50% change (increase) • Double click your one operation script • Did your cat sprite get 50% bigger? ITEC-I5 Scratch Aug 2009
Putting a sprite in a location • Motion ops • Go to x , y • Set x to • Set y to • Glide to X is + Y is + X is – Y is + Origin is (0, 0) X is – Y is - X is + Y is - ITEC-I5 Scratch Aug 2009
Your sprite’s “attitude” Try a “move op” to see changes. Try “rotation ops” as well. Choose “Motion” ops Click on “attitude variables” ITEC-I5 Scratch Aug 2009
Locating your sprite Interesting task: make your own “glide to” operation and have your sprite glide to (200, -100) ITEC-I5 Scratch Aug 2009
Scripting a sequence of ops • Do ops in the following order by dragging operation blocks into a single connected block • Say hello • Move 200 steps forward • Grow 50% bigger • Make the “meow sound” ITEC-I5 Scratch Aug 2009
Result of 4 operation script ITEC-I5 Scratch Aug 2009
Some new operations • color change (Looks) • wait (Control) • move (Motion) ITEC-I5 Scratch Aug 2009
Exercise: write a script to • Make the cat move along a square path • Say “hi” at all four corners • Wait 3 seconds at each corner • Change color at all four corners • Double size when back to the original starting location. • Say “That’s all folks” when done. Show an instructor that you have achieved this. ITEC-I5 Scratch Aug 2009
Using variables • Script might have to remember information • How far is the cat from the dog? • How fast is the rocket moving? • Where did the user click on the stage? ITEC-I5 Scratch Aug 2009
Let’s implement an algorithm to average two numbers • Make a variable “number1” (click and drag and set) • Make another one “number2” ITEC-I5 Scratch Aug 2009
Compute average first as sum • Make variable average • Drag a “set operation” to script area • Drag a + operation • Drag variables number1 and number2 to parameters • Click to execute ITEC-I5 Scratch Aug 2009
Average script as 4 operation sequence. Change the two numbers and click the sequence to execute the block again. ITEC-I5 Scratch Aug 2009
Elements of Scratch: objects • Colors • Sounds • Locations in 2D space • Sprites • Costumes • Variables (to remember the state of things) • Events: that are broadcast for communication We want to use Scratch to program with multimedia. ITEC-I5 Scratch Aug 2009
Elements of Scratch: control • Sequence of operations • Loops or repetition • Detecting events (key or mouse pressed, sprites overlapping each other, sprites hitting edge of stage, sensor giving value) ITEC-I5 Scratch Aug 2009
Loops are for repeating sequences • Bethoven’s 5th: bump-bump-bam; bump-bump-bam; … • Running the bases in baseball or driving around the block. • Milling around waiting for some event to occur (in the aquarium example, the fish sprites mill around forever) ITEC-I5 Scratch Aug 2009
Loop constructs in Scratch Try these! • Repeat N times • Repeat forever • Repeat forever if some condition exists (suppose I’m a sprite wandering about this lab until someone asks a question) ITEC-I5 Scratch Aug 2009
Exercise: use a loop to • Move sprite around the 4 corners of the square • Wait 2 seconds at each corner • Say something at each corner • Double size when done • Change color when done Show an instructor that you have achieved this. ITEC-I5 Scratch Aug 2009
Play and examine MadLib • Choose the “file” option at the top of the window • Choose “open”, then “examples” • Choose “stories” • Choose “MadLib” and then read the authors instructions • Click OK, wait for load, click green flag ITEC-I5 Scratch Aug 2009
About the MadLib story • How many actors (sprites)? • What is the role of the girl? • How are the answers you give 'remembered' and then used in later actions? • What is the role of the little whale? • What makes the little whale flip around? • What makes the big whale spout? ITEC-I5 Scratch Aug 2009
Tuesday: computing distances and directions (30 min) • How to go from here (A) to there (B)? • Computing distance • Computing direction or heading • How useful in Scratch or navigation, etc.? ITEC-I5 Scratch Aug 2009
Angles are important 180 degrees (straight angle) About 30 degrees 215 deg About 45 degrees 90 degrees (right angle) 360 deg complete circle http://www.mathsisfun.com/geometry/degrees.html To see animation of angle measure. ITEC-I5 Scratch Aug 2009
Using a protractor to measure angles ITEC-I5 Scratch Aug 2009
Measure some angles with a protractor C Q P B A ITEC-I5 Scratch Aug 2009
The treasure is buried under an oak tree 42 degrees to the right of the line between the statue and post post 42 deg statue ITEC-I5 Scratch Aug 2009
Right triangles are special What is the distance from point A to point B? Do this on graph paper. Draw the triangle ABC with side CB = 3 and side CA = 4. Cut a “ruler” out of graph paper to measure the side AB. B 3 C A 4 ITEC-I5 Scratch Aug 2009