【掌控】mpython-18…小斑马画道道

2018-10-307989
AI 快速预览详细 收起
mPython 18是一个基于MicroPython的创意编程平台,适合少儿编程入门。通过本项目,孩子们可以学习for语句和使用display.line()函数绘制各种线条图案,从简单的对角线到复杂的扇面图案。项目难度适中,适合6-12岁的儿童进行编程启蒙。


小斑马 上学校
黑白铅笔买两套
老师叫他画图画
他在身上画道道
【掌控】mpython-18…小斑马画道道图1

一首儿歌,送给大家。
今天的帖(lian)子(xi),我们就是画道道了。
这道道要画好,也是要好好练习的呢。
【小目标】
1、for  语句练习
2、设想一些线条画面,并实现它
3、用实时运行,方便的查看代码效果

【课前预习】
display.line(x1, y1, x2, y2, c) 可以绘制任意方向的线,起始坐标(x1, y1),终点坐标(x2, y2), c 为颜色值。

【画一条对角线】
从 0,0 画到 128,64
[mw_shl_code=python,true]from mpython import *

display.fill(0)
display.line(0, 0, 128, 64, 1)
display.show()[/mw_shl_code]
【掌控】mpython-18…小斑马画道道图2

【线条填充】以0,0为定点

[mw_shl_code=python,true]from mpython import *

display.fill(0)
for i in range(64):   
    display.line(0, 0, 128, i, 1) # 让终点的y值由0变化到64
    display.show()
for i in range(128):
    display.line(0, 0, 127 - i, 64, 1) # 让终点的x值由127变化到0
    display.show()
[/mw_shl_code]

【线条填充】以0,0为定点,间隔填充
开门
[mw_shl_code=python,true]from mpython import *

display.fill(0)
for i in range(32):   
    display.line(0, 0, 128, i * 2, 1)
    display.show()
for i in range(64):
    display.line(0, 0, i * 2, 64, 1)
    display.show()[/mw_shl_code]

【扇面1】
[mw_shl_code=python,true]from mpython import *

display.fill(0)
for i in range(32):   
    display.line(0, 0, 128, i * 2, 1)
    display.show()
for i in range(64):
    display.line(0, 0, 127 - i * 2, 64, 1)
    display.show()[/mw_shl_code]

【扇面2】
[mw_shl_code=python,true]from mpython import *

display.fill(0)
for i in range(32):   
    display.line(64, 0, 128, i * 2, 1) # 让终点的y值由0变化到64
    display.show()
for i in range(64):
    display.line(64, 0, 127 - i * 2, 64, 1) # 让终点的x值由127变化到0
    display.show()
for i in range(32):   
    display.line(64, 0, 0, 64 - i * 2, 1) # 让终点的y值由0变化到64
    display.show()
[/mw_shl_code]

【芝麻开门】

[mw_shl_code=python,true]from mpython import *

display.fill(1)
for i in range(64):   
    display.line(64 - i, 0, 64 - i, 64 , 0)
    display.line(64 + i, 0, 64 + i, 64 , 0)
    display.show()
display.fill(0)   
for i in range(65):   
    display.line(128 - i, 0, 128 - i, 64 , 1)
    display.line(0 + i, 0, 0 + i, 64 , 1)
    display.show()
[/mw_shl_code]

下面代码什么效果呢?

[mw_shl_code=python,true]from mpython import *

display.fill(1)
for i in range(32):   
    display.line(64 - 2 * i, 0, 64 - 2 * i, 64 , 0)
    display.line(64 + 2 * i, 0, 64 + 2 * i, 64 , 0)
    display.show()
display.fill(0)   
for i in range(32):   
    display.line(128 - 2 * i, 0, 128 - 2 * i, 64 , 1)
    display.line(2 + 2 * i, 0, 2 + 2 * i, 64 , 1)
    display.show()
[/mw_shl_code]
【拓展练习】
更多效果自己来造。
加上按钮玩如何。
再加上灯光,音效呢。

【新任务】
display.rect(x, y, w, h, c)用于绘制矩形外框。起始坐标为(x, y),宽度 w , 高度 h 的矩形外框。c 为颜色值。
display.fill_rect(x, y, w, h, c)用于绘制填充颜色的矩形,方法与rect()相同。不同于rect()只绘制矩形外框。

画方方,你不来试试。

大圣老师的砖就抛到这里,更多好玩的,自己来玩吧。

走起。


创作许可协议

本项目采用 None(不开放任何权利,保留所有权利) 进行许可。

评论(0)
- 没有更多了 -