Scratch Logo Turtle graphics MIT Papert programmable bricksLEGO

Scratch • 演變來源: – Logo :Turtle graphics (MIT Papert) – programmable bricks:LEGO Mind. Storms (MIT) – The building-block approach draws on previous research on Logo. Blocks (Begel, 1996) and Etoys (Steinmetz, 2001), • 特色: – Building-block programming. Scratch programming will be based on a building-block Metaphor. Learners will drag-and-drop blocks from the library to create “stacks” (procedures) that govern behaviors of the object. – Multiprocessing will be smoothly integrated into Scratch: different stacks of blocks will automatically execute in parallel. – Programmable image processing – rich media • Principal Investigators: – Mitchel Resnick, MIT Media Laboratory – Yasmin Kafai, UCLA – John Maeda, MIT Media Laboratory

Examples of Scratch script • • • • Turtle graphics Loop control 猜數值 加法練習: 亂數出題 減法練習 打擊魔鬼 Retrieve element from list List當題庫 Rolling ball Ball game Maze game music OX棋

Download Scratch 2. 0 • 離線V 2. 0: https: //scratch. mit. edu/scratchr 2/static/sa/Scratch 461. exe • V 3. 0 beta:The Scratch 3. 0 Beta is here! • Go to: https: //beta. scratch. mit. edu

Educational application • Why learn programming? • Computer curriculum • Integration into teaching – Math – Art – Music – literature • Work creation tool in PBL – Game design – Story-telling


第一次接觸: 會塗鴉(scratch)的貓 • Two events: – main(), onload – Click, onlcick • Can we change drawing color? Infinite loop

Basic elements of programming • Structure programming – Sequence – Iteration, repetition • For, while, repeat until – Selection • • • If else if … , switch case Memory control – Variable, – Array, list • Input /output – Console I/O – File I/O – Database • Event – Keyboard – Mouse – Startup • Function, method, subroutine, procedure – Caller – Callee • Object (sprite, stage) – Method – Data (property) In Scratch: no offered

Loop control-1 • • • Question: 1+2+…+n=? what’s wrong? Similar to c – For(i=0; i<n; i++, sum=sum+i) ; – For(i=0; i<n+1; sum=sum+I, i++) ; –

Loop control-2 • what’s wrong? • Repeat { } until ();

Loop control-3 • what’s wrong? • Similar to While () { }

Loop control-4 Handle error of input what’s wrong? • Question: 1+3+…+n=?

Loop control-5 • what’s wrong? • Question: n!=1*2*…*n=?

Features • Visualized programming environment – – – • • Brick building and assembling Syntax-error free multithread Object-like : method for each object, we can clone them Structured programming is convenient – – – Iteration ( Loop): for, while, repeat…. utile Sequence Selection • • • Turtle geometry – • Not offered array, but provide list String processing is limit Array of object: not support File I/o is limit – • Onload Click event (belong to a object) Multimedia rich environment Function communication: shared memory, message passing Memory management is limit: Variable – – – • Random, math User-defined function: Only for event driven function – – – • • LOGO System Function – • If, if. . else Not provide switch case The functions of Input, printf are limit Game element – Conflict detection

Function communication • shared memory, message passing accept broadcast message Object 1 Global variable Shared memory Object 2 Object 3 Object n

Scratch 2 Exe • 將Scratch的. sb檔轉為. exe(scratch 2 exe) • 方法: http: //cc 1. shsps. kh. edu. tw/xoops/modules/ tadnews/index. php? nsn=27 Scratch . sb scratch 2 exe Java applet . exe Web browser

Turtle graphics Main program pendown logo-1. sb Run this program

variable • Variable? – Where? – What purpose? • Make a variable Size=input(“輸入移動步數”); FD size logo-2. sb

運算式 logo-3. sb



加法練習 ADD-drill 1. sb






Retrieve element from list • List: 列表、串列 – 替代array • Why not work? • 循序讀取


亂數出題:list放亂數不重複之題號 不重複!(1. . n) Swap /exchange rseq list-process-1 -3. sb 1 2 i 1 pick 3 3 2 i 2 3 4 5 1 4 5 pick 5


Insertion sort insertion-sort-1. sb

Rolling ball 角色:ball Direct=1 Direct=0 Direct=2 Direct=3 第二象限 y 第一象限 x 第三象限 BALL-B~correct-1. sb 第四象限

Change ball’s direction Y>168 Direct=0 3 1 X>228 0 Direct=1 Y<-168 Direct=2 X>228 3 1 Y<-168 Y>168 Direct=3 2 X<-228 0 2 X<-228

Game of 桌球 角色: panel • 角色:panel Score varaible 由ball detect collision BALL-game-1. sb

Maze game-1 Initial position destination

Maze game-1(續) What’s wrong? • Game is over if time out

Maze game-2:第二關 換第二關背景 Maze← 2 maze-2. sb

Maze game-2(續) Direct : • sprite’s data member • Not global variable 先上後下移動 舞台換背景 先右後左移動


Maze game-2(續) 遇到crab or ant, then die 二關之起始位置一樣


打地鼠(ccont. ) Die: object之data member, not a global variable hole 1 monster 1 將monster放在hole上

music • note(音符) 60代表Do(1)、62 Re(2)、64 Mi(3)、65 Fa(4)、67 Sol(5)、69 La(6)、71 Si(7)、72 高音Do(1*)


OX棋 • Use list “record” to record player’ dice – 0: null – 1: user – 2: CAT • Each dice: has 3 styles • Cat broadcast message “flip i”, dice i will flip its style for CAT. • User can click the dice to flip it. • There are some drawbacks in it. – Please revise them. ox-game-1. sb


• Compute who is the winner? – Winner=0 (initial) – Winner=1 (user) – Winner=2 (CAT) If (Record[1]=record[2] and record[2]=record[3]) { If record[1]=1 then winner=1; Else if record[1]=2 then winner=2; } 1 2 3 4 5 6 7 8 9

• If winner is known, then this game is over!

Method of dice • Accept message to flip its style for CAT • Click event: user clicks the dice to flip its style 1 st dice

BYOB • Build Your Own Blocks (BYOB) 3. 1 – a modification of Scratch, made by the Scratch Team member Jens and user bharvey. – It includes many new features - from building your own blocks to Mesh. The primary focus for this Scratch modification is first-class data. • Make a block •

Programming pedagogy for elementary students • Conventional method – Based on command – flowchart • Project-based method – According to the need of project, then impart command – Focus on analysis, design, coding, debug, revise, elaborate • 眼高手低 • Time is inefficient

Resnick’s approach • Mitchel Resnick
- Slides: 52