大家好,本文将围绕scratch学到什么程度可以学pathon展开说明,scratch学多久后,可以学python是一个很多人都想弄明白的事情,想搞清楚从scratch到python轻松学需要先了解以下几个事情。
Source code download: 本文相关源码
最新文章请关注「与非学堂」
Arcade,Scratch升Python的选择
Scratch是少儿编程入门的标配了,Python也是乘着AI造势的东风,不少孩子在学。
但是学了Scratch之后的孩子再学Python,究竟怎么起步?
在这里曹老师想拿Scratch与Python的Arcade游戏库作一下对比,以便找到一条教孩子们入门Python的最佳路线用python画简单笑脸代码。
为什么是Arcade游戏库呢?之前有一篇发布的文章,说了说自己对教学、对游戏的思考:编程学习:用游戏的方式在游戏中学做游戏 Learn Programming through, with and for Games
Arcade游戏库的接口与Scratch的实现方式相似度还是极高的。好好利用这一游戏库,可以帮助学生顺利从Scratch过渡至Python。详细情况请见下方大表。
左 Scratch 右 Python Arcade
(?表示无对应实现)
移动……步 移到(随机/鼠标/角色)位置 移到x……y…… 将x/y坐标增加…… 将x/y坐标设为…… | sprite.position/center_x/center_y |
左转/右转……度 面向……方向 面向(鼠标/角色) | sprite.angle/radians |
在……秒内滑行到x……y…… 在……秒内滑行到(随机位置/鼠标指针/角色) | sprite.position/center_x/center_y window.on_update() (间接实现) |
碰到边缘就反弹 | sprite.collides_with_point()/collides_with_sprite()/collides_with_list() (间接实现) |
将旋转方式设为左右翻转 | arcade.load_texture(flipped_horizontally: bool = False) |
说……2秒/说…… 思考……2秒/思考…… | arcade.draw_text() |
换成……造型 下一个造型 | arcade.load_texture() arcade.load_texture_pair() arcade.load_textures() sprite.cur_texture_index/texture/textures sprite.set_texture() |
换成……背景 下一个背景 | window.background_color/current_view window.show_view() |
将大小增加…… 将大小设为…… | sprite.scale |
将颜色/鱼眼/漩涡/像素化/马赛克/亮度特效增加/设定为…… | ? |
将虚像特效增加/设定为…… 显示/隐藏 | sprite.alpha |
移到最前面/后面 前/后移……层 | (用window.on_draw中代码调用的先后顺序实现) |
播放声音…… | sound.play() |
播放声音……等待播完 | sound.play()/get_length/is_complete()/get_stream_position()/get_length() (间接实现) |
停止所有声音 | sound.stop() |
将音量增加/设为…… | sound.get_volume()/set_volume() |
将音调/左右平衡音效增加/设为…… | ? |
当小绿旗被点击 | window.__init__()/setup() |
当按下……键 | window.on_key_press()/on_key_release() |
当角色被点击 | window.on_mouse_press()/on_mouse_release() |
当背景换成…… | (间接实现) |
当响度大于…… | ? |
广播……/广播……并等待/当接收到…… | (间接实现) |
(使用重复执行+移到鼠标指针间接实现) | window.on_mouse_motion()/on_mouse_drag() |
等待……秒 | window.on_update(delta_time) (间接实现) |
重复执行……次/重复执行 | for i in range for item in items while |
如果……那么…… 如果……那么……否则…… | if if else if elif else |
等待…… | while if (间接实现) |
重复执行直到…… | for i in range for item in items while if if else if elif else (间接实现) |
停止这个脚本/当前角色的其他脚本/全部脚本 | break window.close() |
克隆自己/角色 当作为克隆体启动时 删除此克隆体 | (使用Sprite类+SpriteList实现) |
碰到鼠标指针/舞台边缘/角色 | sprite.collides_with_point()/collides_with_sprite()/collides_with_list() (间接实现) |
碰到颜色…… 颜色……碰到颜色…… | ? |
到……的距离 | arcade.get_distance() arcade.get_distance_between_sprites() |
询问……并等待/回答 | ? |
计时器 | window.on_update() (间接实现) |
当前时间的年/月/日/星期/时/分/秒 2000年至今的天数 | (使用datetime库实现) |
用户名 | ? |
+-*/><= | +-*/><= |
在a和b之间取随机数 | random.randint(a,b) |
a与b | a and b |
a或b | a or b |
a不成立 | not a |
连接a和b | 'a'+'b' |
abc的第1个字符 | 'abc'[0] |
abc的字符数 | len(abc) |
abc包含a | a in abc |
a除以b的余数 | a%b |
四舍五入a | round(a) |
绝对值a | abs(a) |
向上取整a | math.ceil(a) |
向下取整a | math.floor(a) |
平方根等其他运算符 | (略) |
将a设为0 | a = 0 |
将a增加1 | a += 1 |
显示变量 | print(a) |
隐藏变量 | #print(a) |
适用于所有角色的变量 | self.a |
仅适用于当前角色的变量 | self._a self.__a |
? | 函数局部变量 |
将e加入list | list.append(e) |
删除list的第i项 | list.pop(i) |
删除list的全部项 | list.clear() |
在list的第i项前插入x | list.insert(i,x) |
将list的第i项替换为x | list[i]=x |
list的第i项 | list[i] |
list中第一个x的编号 | list.index(x) str_list.find(x) |
list的项目数 | len(list) |
list包含x | x in list |
显示列表list | print(list) |
— OVER —
与非学堂
专注青少年信息技术教育,探讨少儿编程的教与学,交流技巧、分享资源
与非学堂小程序
蓝桥杯STEMA科技素养测试、Bebras测试、文化测试
公众号回复「HELP」获取更多精彩
喜欢就请「分享」「点赞」「在看」吧!