最新消息:

【micro:bit Micropython】The LED Display(5)Image图片的移动

Micro Bit 少儿编程 1831浏览 0评论

Shift(移位)函数:

# returns a new image created by shifting the picture left ‘n’ times. image.shift_left(n) # returns a new image created by shifting the picture right ‘n’ times. image.shift_right(n) # returns a new image created by shifting the picture up ‘n’ times. image.shift_up(n) # returns a new image created by shifting the picture down ‘n’ times. image.shift_down(n)

移位运动,也就是我们俗称的“走字”。


项目活动1:Image图片向左移位运动(走字)至消失

【micro:bit Micropython】The LED Display(5)Image图片的移动

方法1:

from microbit import * a="00900:09000:99999:09000:00900" while True:   for i in range(0,6):     display.show(Image(a).shift_left(i))     sleep(200);   sleep(1000) 

方法2:

from microbit import * pic=Image("00900:09000:99999:09000:00900") while True:   for i in range(0,6):     display.show(pic.shift_left(i))     sleep(200);   sleep(1000) 

方法3:

from microbit import * while True:   for i in range(0,6):     display.show(Image.ARROW_W.shift_left(i))     sleep(200);   sleep(1000) 

同理,向右、向上、向下方法一致。


如果不使用Shift(移位)函数,如何实现相同效果?

以“向上”和“向下”为例:

项目活动2:Image图片向上移位运动(走字)至消失

【micro:bit Micropython】The LED Display(5)Image图片的移动
from microbit import * a="00900:09990:90909:00900:00900" b="" while True:   display.show(Image(a))   sleep(200)   for i in range(1,5):       b=a[6*i:29]       #print(b)       for j in range(0,i):           b=b+":00000"       display.show(Image(b))       sleep(200)       b=""   b="00000:00000:00000:00000:00000"   display.show(Image(b))   sleep(1000) 

项目活动3:Image图片向下移位运动(走字)至消失

【micro:bit Micropython】The LED Display(5)Image图片的移动
from microbit import * a="00900:00900:90909:09990:00900" while True:   b=a   c=""   display.show(Image(b))   sleep(200)   for i in range(1,5):       c=""       for j in range(0,i):           c=c+"00000:"                  c=c+b[6*(i-1):29-6]       #print(b)           display.show(Image(c))       sleep(200)       b=c   b="00000:00000:00000:00000:00000"   display.show(Image(b))   sleep(1000) 

如果不只是Image图片消失,而是希望隔开一行(一列)后,再次出现原Image图片,怎么做到?

项目活动4:Image图片向上移位运动(走字),隔开一行,再次出现

【micro:bit Micropython】The LED Display(5)Image图片的移动
from microbit import * a="00900:09990:90909:00900:00900:00000" b=a while True:   for i in range(0,5):     b=b[6:29+6]+":"+b[0:5]     #print(b)     display.show(Image(b[0:29]))     sleep(200) 

项目活动5:Image图片向下移位运动(走字),隔开一行,再次出现

【micro:bit Micropython】The LED Display(5)Image图片的移动
from microbit import * a="00000:00900:00900:90909:09990:00900" b=a while True:   for i in range(0,5):     b=b[24+6:29+6]+":"+b[0:23+6]     #print(b)     display.show(Image(b))     sleep(200) 

作业:

第一张Image图片向左移位运动,图片右侧隔开一列,紧接着出现第二张Image图片跟着向左移位运动,图片右侧隔开一列,紧接着出现第三张Image图片跟着向左移位运动,图片右侧隔开一列,紧接着又出现第一张Image图片跟着向左移位运动。

即总共有三张不同的Image图片依次隔开一列出现,首、尾两张图片隔开一列相接、循环,怎么做到?

您必须 登录 才能发表评论!