复习:画板 III 5 分钟
change pen (color v) by (2)画出一条彩虹线。- 橡皮擦就是一支白色的笔。图章把造型印下来。
tool变量装着一个词,循环在画之前先问它。
快问快答
一支铅笔在 x: 80,y: 20。在舞台另一边,离中间一样远、和它对应的那个点在哪里?
看答案
x: −80,y: 20。一样高,离中间一样远,只是在另一边。今天的全部窍门,就是这一个负号。
今天的主题 3 分钟
- 镜像算式:
((0) - (mouse x)) - 第二支铅笔,画出镜像
- 两个角色收到同一条消息
- 把应用准备好,让别人也会用
学习目标
学完这一课,你会:
- 用一个减法算出镜像的位置。
- 用一个鼠标让两个角色同时画画。
- 把应用做完整,让新用户知道该怎么做。
学一学:两支铅笔,一只手 28 分钟
1 · 镜像算式
舞台的正中间是 x: 0。x: −100 的点在左边 100 的地方。它的镜像在右边 100 的地方,也就是 x: 100。y 不变。
所以任何 x 的镜像都是 ((0) - (x position))。试一试:0 − (−100) 是 100。0 − 60 是 −60。
怎么用: 点绿旗开始。不用再按别的——看那支淡淡的铅笔照着画出心形的左半边。
2 · 一支 Mirror 铅笔
- 右键点 Pencil,选 duplicate(复制)。把复制出来的角色改名叫 Mirror。
- 删掉 Mirror 的按键脚本。保留它的绿旗脚本。
- 把它的
go to [mouse-pointer v]换成go to x: ((0) - (mouse x)) y: (mouse y)。 - 给它加上
set [ghost v] effect to (50),这样你就能分清这两支铅笔。
when flag clicked
go to [back v] layer
set pen color to [#4C4CFF]
set pen size to (4)
set [ghost v] effect to (50)
forever
go to x: ((0) - (mouse x)) y: (mouse y)
if <<mouse down?> and <(mouse y) < (130)>> then
pen down
else
pen up
end
end
when I receive [new colour v]
set pen color to (colour)
怎么用: 点绿旗。点一个球来选颜色,然后在舞台上按住鼠标键拖动来画画。
3 · 准备好分享
你自己做的应用,你当然看得懂。可是新用户从来没见过它。有三样东西能帮他们:
- 开始时的一句提示。把它放在单独的绿旗脚本里运行,这样它就不会拖住铅笔。
- 一个清除键,这样谁都不用按绿旗来重新开始。
- Instructions(操作说明)和 Notes and Credits(备注与致谢),写在作品页面上。说清楚哪个键做什么,再写出你借用了哪些东西。
基础任务:完成的画板 25 分钟
打开你上一课做的画板。
第 1 步:Mirror
- 照着学一学,做出 Mirror。
- 用铅笔工具试一试:两半应该一模一样。
第 2 步:Mirror 也换工具
- 给 Mirror 加上 1、2、3 键的脚本,像 Pencil 的一样,设置它自己的画笔粗细和颜色。
- 在 Mirror 的循环里,pen down 前面也加上一样的
if <(tool) = [rainbow]> then。 - 在两边都试一试橡皮擦。
第 3 步:准备好分享
- 给 Pencil 加第二个绿旗脚本:
say [Drag to draw. Keys 1, 2, 3 change the tool. C clears.] for (3) seconds。 - 加上
when [c v] key pressed,下面放erase all。 - 点 See Project Page(查看作品页面)。写好 Instructions 和 Notes and Credits。
when flag clicked
say [Drag to draw. Keys 1, 2, 3 change the tool. C clears.] for (3) seconds
when [c v] key pressed
erase all
怎么用: 点绿旗,然后点一下舞台。按 1、2 或 3 选工具,点一个球选颜色,按住鼠标键拖动来画画,按 C 清除。
提示出来了,可是三秒钟里什么都画不了。
say [Drag to draw] for (3) seconds 在画画的脚本里。把它移到一个单独的绿旗脚本里。
我用彩虹画笔时,镜像那边一直是蓝色。
Mirror 的循环里少了第 2 步的彩虹判断。
镜像开关
- 一个叫
mirror的变量,显示在舞台上。它从 1 开始。 - 按 M,它变成 0:Mirror 隐藏起来,不再画画。
- 再按 M,它又回来了。
怎么用: 点绿旗,然后点一下舞台。按住鼠标键拖动来画画,然后按 M,再画。
Teacher reveal
when [m v] key pressed
set [mirror v] to ((1) - (mirror))
1 − 1 is 0 and 1 − 0 is 1, so one block flips it both ways. The Mirror’s loop wraps its drawing in if <(mirror) = [1]> then, with hide and pen up in the else.
四个方向
再加两支铅笔,让拖一次就画出四条线。
- 像现在一样,左右镜像。
- 纸的上下也镜像。
- 纸从 y: −180 到 y: 130,所以它的中间是 y: −25。
- 没有一支铅笔会画进工具栏里。
怎么用: 点绿旗,然后在舞台上按住鼠标键拖动来画画。
Teacher reveal
Mirroring about y: −25 is ((-50) - (mouse y)): −25 take away the distance, and the distance is the mouse y + 25. A pencil at the bottom edge, y: −180, mirrors to y: 130 — the toolbar’s edge exactly, so nothing leaks in.
go to x: (mouse x) y: ((-50) - (mouse y))
开始卡片
三秒钟的提示很容易错过。让用户先把它读完。
- 点绿旗时,铅笔显示应用的用法,而且一动不动。
- 这时候还什么都画不了。
- 在任何地方点一下,应用就开始,提示也消失了。
怎么用: 点绿旗,读提示。然后点一下舞台开始,再按住鼠标键拖动来画画。
Teacher reveal
say [Sketch Pad! Drag to draw. Click a ball for a colour. Click to start.]
wait until <mouse down?>
wait until <not <mouse down?>>
say []
The two waits are one click: down, then up. With only the first, the click that starts the app also draws a dot.
万花筒
一只手画出八支铅笔的线。不是八个角色——是一个隐藏的角色和七个克隆体。
- 图案绕着纸的中间 (0, −25) 转。
- 你的 Pencil 是八支中的一支。另外七支是克隆体。
- 每个克隆体都知道自己是七个中的哪一个,并算出自己的位置。
怎么用: 点绿旗,然后在舞台上按住鼠标键拖动来画画。点一个球来换颜色。
Teacher reveal
when flag clicked
hide
set [slot v] to (0)
repeat (7)
change [slot v] by (1)
create clone of [myself v]
end
when I start as a clone
forever
set [dx v] to (mouse x)
set [dy v] to ((mouse y) - (-25))
if <(slot) = [1]> then
go to x: ((0) - (dx)) y: ((-25) + (dy))
end
if <(slot) = [4]> then
go to x: (dy) y: ((-25) + (dx))
end
if <<mouse down?> and <(y position) < (130)>> then
pen down
else
pen up
end
end
Slots 2, 3, 5, 6 and 7 follow the same pattern with the other signs. A hidden clone still draws — the pen does not care whether the sprite is shown.
总结 5 分钟
- x 的镜像是
((0) - (mouse x))。y 不变。 - 第二支铅笔可以跟着同一个鼠标,在算出来的位置上画画。
- 一次广播会传到每个角色,所以每支铅笔都能改自己的笔。
- 新用户只看屏幕就会用了,应用才算准备好分享。
- 镜像
- 同一个形状翻转过来,就像在镜子里看到的一样。
- 对称
- 一幅图的一半和另一半正好对上。
- 操作说明(Instructions)
- 作品页面上告诉用户该怎么做的那个框。
- 致谢(Credits)
- 写出你的作品借用了哪些人和哪些东西。
交作业
保存你的画板——这个单元完成了。下一课,画笔不再跟着你的手走,而是跟着规则走:由代码自己画出图形。