2018-10-30 19:55:14 [显示全部楼层]
3624浏览
查看: 3624|回复: 0

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

[复制链接]
本帖最后由 rzyzzxw 于 2018-10-30 20:22 编辑

小斑马 上学校
黑白铅笔买两套
老师叫他画图画
他在身上画道道
【掌控】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()只绘制矩形外框。

画方方,你不来试试。

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

走起。


您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

为本项目制作心愿单
购买心愿单
心愿单 编辑
[[wsData.name]]

硬件清单

  • [[d.name]]
btnicon
我也要做!
点击进入购买页面
上海智位机器人股份有限公司 沪ICP备09038501号-4

© 2013-2024 Comsenz Inc. Powered by Discuz! X3.4 Licensed

mail