scratch programming for elementary schools’ teachers 賴阿福 台北市立教育大學...

53
Scratch programming for elementary schools’ teachers 賴賴賴 賴賴賴賴賴賴賴賴 賴賴賴賴賴 2011/7/18~7/20 [email protected]

Upload: austen-white

Post on 11-Jan-2016

289 views

Category:

Documents


8 download

TRANSCRIPT

Page 1: Scratch programming for elementary schools’ teachers 賴阿福 台北市立教育大學 資訊科學系 2011/7/18~7/20 lai@go.tmue.edu.tw

Scratch programming for elementary schools’ teachers

賴阿福台北市立教育大學 資訊科學系

2011/7/18~7/[email protected]

Page 2: Scratch programming for elementary schools’ teachers 賴阿福 台北市立教育大學 資訊科學系 2011/7/18~7/20 lai@go.tmue.edu.tw

Scratch • 演變來源:

– Logo : Turtle graphics (MIT Papert)– programmable bricks : LEGO MindStorms (MIT)– The building-block approach draws on previous research on LogoBlocks

(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

Page 3: Scratch programming for elementary schools’ teachers 賴阿福 台北市立教育大學 資訊科學系 2011/7/18~7/20 lai@go.tmue.edu.tw

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

Page 4: Scratch programming for elementary schools’ teachers 賴阿福 台北市立教育大學 資訊科學系 2011/7/18~7/20 lai@go.tmue.edu.tw

Download Scratch 1.4• V

1.4 : http://info.scratch.mit.edu/Scratch_1.4_Download• V 2.0 beta

Page 5: Scratch programming for elementary schools’ teachers 賴阿福 台北市立教育大學 資訊科學系 2011/7/18~7/20 lai@go.tmue.edu.tw

Educational application

• Why learn programming?• Computer curriculum• Integration into teaching

– Math– Art– Music– literature

• Work creation tool in PBL– Game design– Story-telling

Page 6: Scratch programming for elementary schools’ teachers 賴阿福 台北市立教育大學 資訊科學系 2011/7/18~7/20 lai@go.tmue.edu.tw

操作介面 • 標題列:顯示軟體與檔案名

稱。 3• 功能表列:常用的存檔、開

新檔案、開啟舊檔與復原等功能。 4

• 指令分類區: Scratch 指令共分八類均在此區中。 5

• 程式積木區:依指令分類區點選的類別而出現對應的程式積木。 6

• 角色與舞台控制區:點選快速瀏覽區可顯示欲控制角色 ( 舞台 ) 之程式、造型( 背景 ) 與聲音的控制。 77

• 舞台區:動畫編輯的區域。• 舞台背景與角色快速瀏覽區:

舞台背景與角色切換的控制。

1

3

2

45

6

7

Page 7: Scratch programming for elementary schools’ teachers 賴阿福 台北市立教育大學 資訊科學系 2011/7/18~7/20 lai@go.tmue.edu.tw

第一次接觸 : 會塗鴉 (scratch) 的貓

• Two events:– main(),

onload– Click, onlcick

• Can we change drawing color?

Infinite loop

Page 8: Scratch programming for elementary schools’ teachers 賴阿福 台北市立教育大學 資訊科學系 2011/7/18~7/20 lai@go.tmue.edu.tw

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

Page 9: Scratch programming for elementary schools’ teachers 賴阿福 台北市立教育大學 資訊科學系 2011/7/18~7/20 lai@go.tmue.edu.tw

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++) ;–

Page 10: Scratch programming for elementary schools’ teachers 賴阿福 台北市立教育大學 資訊科學系 2011/7/18~7/20 lai@go.tmue.edu.tw

Loop control-2

• Repeat { } until ();

•what’s wrong?

Page 11: Scratch programming for elementary schools’ teachers 賴阿福 台北市立教育大學 資訊科學系 2011/7/18~7/20 lai@go.tmue.edu.tw

Loop control-3

• Similar to While () { }

•what’s wrong?

Page 12: Scratch programming for elementary schools’ teachers 賴阿福 台北市立教育大學 資訊科學系 2011/7/18~7/20 lai@go.tmue.edu.tw

Loop control-4

• Question: 1+3+…+n=?

what’s wrong?

Handle error of input

Page 13: Scratch programming for elementary schools’ teachers 賴阿福 台北市立教育大學 資訊科學系 2011/7/18~7/20 lai@go.tmue.edu.tw

Loop control-5

• Question: n!=1*2*…*n=?

•what’s wrong?

Page 14: Scratch programming for elementary schools’ teachers 賴阿福 台北市立教育大學 資訊科學系 2011/7/18~7/20 lai@go.tmue.edu.tw

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

• If, if..else• Not provide switch case

• Turtle geometry– LOGO

• System Function– Random, math

• User-defined function: Only for event driven function– Onload– Click event (belong to a object)– Multimedia rich environment

• Function communication: shared memory, message passing• Memory management is limit: Variable

– Not offered array, but provide list– String processing is limit– Array of object: not support

• File I/o is limit– The functions of Input, printf are limit

• Game element– Conflict detection

Page 15: Scratch programming for elementary schools’ teachers 賴阿福 台北市立教育大學 資訊科學系 2011/7/18~7/20 lai@go.tmue.edu.tw

Function communication

• shared memory, message passing

Object 1

messagebroadcast

Object 2

Object 3

Object n

accept

Globalvariable

Shared memory

Page 16: Scratch programming for elementary schools’ teachers 賴阿福 台北市立教育大學 資訊科學系 2011/7/18~7/20 lai@go.tmue.edu.tw

Scratch2Exe

• 將 Scratch 的 .sb 檔轉為 .exe(scratch2exe)

• 方法: http://cc1.shsps.kh.edu.tw/xoops/modules/tadnews/index.php?nsn=27

Scratch.sb .exe

scratch2exe

Web browserJava applet

Page 17: Scratch programming for elementary schools’ teachers 賴阿福 台北市立教育大學 資訊科學系 2011/7/18~7/20 lai@go.tmue.edu.tw

Turtle graphics

pendown

logo-1.sb

Main program Run this program

Page 18: Scratch programming for elementary schools’ teachers 賴阿福 台北市立教育大學 資訊科學系 2011/7/18~7/20 lai@go.tmue.edu.tw

variable

Size=input(“ 輸入移動步數” );

• Variable?– Where?– What purpose?

• Make a variable

FD size

logo-2.sb

Page 19: Scratch programming for elementary schools’ teachers 賴阿福 台北市立教育大學 資訊科學系 2011/7/18~7/20 lai@go.tmue.edu.tw

運算式

logo-3.sb

Page 20: Scratch programming for elementary schools’ teachers 賴阿福 台北市立教育大學 資訊科學系 2011/7/18~7/20 lai@go.tmue.edu.tw

猜數值• Random

• 提示輸入數值 ? 大或小• loop 停止條件• 猜的次數

guess-number-1.sb

Page 21: Scratch programming for elementary schools’ teachers 賴阿福 台北市立教育大學 資訊科學系 2011/7/18~7/20 lai@go.tmue.edu.tw

改變背景

1

4

Page 22: Scratch programming for elementary schools’ teachers 賴阿福 台北市立教育大學 資訊科學系 2011/7/18~7/20 lai@go.tmue.edu.tw

加法練習

ADD-drill1.sb

Page 23: Scratch programming for elementary schools’ teachers 賴阿福 台北市立教育大學 資訊科學系 2011/7/18~7/20 lai@go.tmue.edu.tw

減法練習

• 答案不可以為負數

sub-DR~1.sb

Page 24: Scratch programming for elementary schools’ teachers 賴阿福 台北市立教育大學 資訊科學系 2011/7/18~7/20 lai@go.tmue.edu.tw

減法練習 2

• 答錯須重新回答– 運用一變數 correct

• 中文變數

sub-DR~2.sb

Page 25: Scratch programming for elementary schools’ teachers 賴阿福 台北市立教育大學 資訊科學系 2011/7/18~7/20 lai@go.tmue.edu.tw

打擊魔鬼• 打擊者

– 按鍵控制– 廣播”發射子彈”

打擊魔鬼 1/fight-monster-1.sb

Page 26: Scratch programming for elementary schools’ teachers 賴阿福 台北市立教育大學 資訊科學系 2011/7/18~7/20 lai@go.tmue.edu.tw

bullet

• 接到” fire” 之廣播,發射子彈

• 判斷遇到邊緣或魔鬼

• 子彈之初始設定

Page 27: Scratch programming for elementary schools’ teachers 賴阿福 台北市立教育大學 資訊科學系 2011/7/18~7/20 lai@go.tmue.edu.tw

• 魔鬼須不斷上下移動

• 被打到時 : 消失、回到原點

Page 28: Scratch programming for elementary schools’ teachers 賴阿福 台北市立教育大學 資訊科學系 2011/7/18~7/20 lai@go.tmue.edu.tw

Retrieve element from list

• Why not work?

• List: 列表、串列– 替代 array

• 循序讀取

Page 29: Scratch programming for elementary schools’ teachers 賴阿福 台北市立教育大學 資訊科學系 2011/7/18~7/20 lai@go.tmue.edu.tw

List 當題庫

• 結構:題目 + 選項 + 答案• Other method: 運用 6 個 list ,分別存放題目、 4

個選項、答案 (parallel lists) list-process-1-2.sb

Page 30: Scratch programming for elementary schools’ teachers 賴阿福 台北市立教育大學 資訊科學系 2011/7/18~7/20 lai@go.tmue.edu.tw

亂數出題: list 放亂數不重複之題號

3 2 1 4 5

list-process-1-3.sb

1 2 3 4 5

3i 1 pick

Swap /exchange

rseq

rseq

不重複! (1..n)

2i 5pick

Page 31: Scratch programming for elementary schools’ teachers 賴阿福 台北市立教育大學 資訊科學系 2011/7/18~7/20 lai@go.tmue.edu.tw

亂數由題庫抽題

Page 32: Scratch programming for elementary schools’ teachers 賴阿福 台北市立教育大學 資訊科學系 2011/7/18~7/20 lai@go.tmue.edu.tw

Insertion sort

insertion-sort-1.sb

Page 33: Scratch programming for elementary schools’ teachers 賴阿福 台北市立教育大學 資訊科學系 2011/7/18~7/20 lai@go.tmue.edu.tw

Rolling ball

Direct=0 Direct=1

Direct=2Direct=3

第一象限第二象限

第三象限 第四象限

x

y

BALL-B~correct-1.sb

角色: ball

Page 34: Scratch programming for elementary schools’ teachers 賴阿福 台北市立教育大學 資訊科學系 2011/7/18~7/20 lai@go.tmue.edu.tw

Change ball’s direction

Direct=01

3Y>168

X>228

Direct=1 02

Y<-168X>228

Direct=2 31

Y<-168 X<-228

Direct=32

Y>168 0

X<-228

Page 35: Scratch programming for elementary schools’ teachers 賴阿福 台北市立教育大學 資訊科學系 2011/7/18~7/20 lai@go.tmue.edu.tw

Game of 桌球

• 角色: panel

由 ball detect collision

Score varaible

BALL-game-1.sb

角色 :panel

Page 36: Scratch programming for elementary schools’ teachers 賴阿福 台北市立教育大學 資訊科學系 2011/7/18~7/20 lai@go.tmue.edu.tw

Maze game-1

destination

Initial position

Page 37: Scratch programming for elementary schools’ teachers 賴阿福 台北市立教育大學 資訊科學系 2011/7/18~7/20 lai@go.tmue.edu.tw

Maze game-1( 續 )

• Game is over if time out

What’s wrong?

Page 38: Scratch programming for elementary schools’ teachers 賴阿福 台北市立教育大學 資訊科學系 2011/7/18~7/20 lai@go.tmue.edu.tw

Maze game-2 :第二關

換第二關背景Maze←2

maze-2.sb

Page 39: Scratch programming for elementary schools’ teachers 賴阿福 台北市立教育大學 資訊科學系 2011/7/18~7/20 lai@go.tmue.edu.tw

Maze game-2( 續 )

先上後下移動

先右後左移動舞台換背景

Direct :•sprite’s data member•Not global variable

Page 40: Scratch programming for elementary schools’ teachers 賴阿福 台北市立教育大學 資訊科學系 2011/7/18~7/20 lai@go.tmue.edu.tw

Maze game-2( 續 )

• Maze=1– 第一關

• Else (maze=2)– 第二關

Page 41: Scratch programming for elementary schools’ teachers 賴阿福 台北市立教育大學 資訊科學系 2011/7/18~7/20 lai@go.tmue.edu.tw

Maze game-2( 續 )

遇到 crab or ant, then die

二關之起始位置一樣

Page 42: Scratch programming for elementary schools’ teachers 賴阿福 台北市立教育大學 資訊科學系 2011/7/18~7/20 lai@go.tmue.edu.tw

打地鼠

• 地鼠被打到: record[i]=1

• End==1 : 6 隻地鼠全被打到

kill-mice/kill-mice-1.sb

Page 43: Scratch programming for elementary schools’ teachers 賴阿福 台北市立教育大學 資訊科學系 2011/7/18~7/20 lai@go.tmue.edu.tw

打地鼠 (ccont.)

hole1monster1

Die: object 之 data member, not a global variable

將 monster 放在 hole 上

Page 44: Scratch programming for elementary schools’ teachers 賴阿福 台北市立教育大學 資訊科學系 2011/7/18~7/20 lai@go.tmue.edu.tw

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*)

Page 45: Scratch programming for elementary schools’ teachers 賴阿福 台北市立教育大學 資訊科學系 2011/7/18~7/20 lai@go.tmue.edu.tw

Sing a song

• 每個音節有 2 拍,第一個音節就是Do Do 各半拍 (0.5 beats) ,然後 Do Mi 又各半拍 (0.5 beats) 。

Page 46: Scratch programming for elementary schools’ teachers 賴阿福 台北市立教育大學 資訊科學系 2011/7/18~7/20 lai@go.tmue.edu.tw

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

Page 47: Scratch programming for elementary schools’ teachers 賴阿福 台北市立教育大學 資訊科學系 2011/7/18~7/20 lai@go.tmue.edu.tw
Page 48: Scratch programming for elementary schools’ teachers 賴阿福 台北市立教育大學 資訊科學系 2011/7/18~7/20 lai@go.tmue.edu.tw

• Compute who is the winner?– Winner=0 (initial)

– Winner=1 (user)

– Winner=2 (CAT)

1 2 3

4 5 6

7 8 9

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; }

Page 49: Scratch programming for elementary schools’ teachers 賴阿福 台北市立教育大學 資訊科學系 2011/7/18~7/20 lai@go.tmue.edu.tw

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

Page 50: Scratch programming for elementary schools’ teachers 賴阿福 台北市立教育大學 資訊科學系 2011/7/18~7/20 lai@go.tmue.edu.tw

Method of dice

• Accept message to flip its style for CAT

• Click event: user clicks the dice to flip its style

1st dice

Page 51: Scratch programming for elementary schools’ teachers 賴阿福 台北市立教育大學 資訊科學系 2011/7/18~7/20 lai@go.tmue.edu.tw

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•

Page 52: Scratch programming for elementary schools’ teachers 賴阿福 台北市立教育大學 資訊科學系 2011/7/18~7/20 lai@go.tmue.edu.tw

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

Page 53: Scratch programming for elementary schools’ teachers 賴阿福 台北市立教育大學 資訊科學系 2011/7/18~7/20 lai@go.tmue.edu.tw

Resnick’s approach

• Mitchel Resnick