from sprites import Sprite ,mouse_pos
bug = Sprite()
bug.goto(100,100)
w = bug.write('中华人民共和国') # w记录了字在画布上的编号
bug.goto(-100,0)
d1 = bug.dot(30,'blue') # 打圆点
bug.goto(-100,30)
bug.randomcolor()
d2 = bug.dot(20,'magenta')
bug.goto(100,-100)
bug.down()
bug.pensize(5)
bug.fd(50) # 前进,留下线条
shortline = bug.currentLineItem
bug.penup()
bug.randomcolor()
bug.goto(100,200)
bug.down()
bug.pensize(15)
for _ in range(4):
bug.fd(100) # 前进,留下线条
bug.left(90)
# 由于抬笔会重新确立一个看不见的线条对象
# 所以下面要记录下刚才的线条对象
lastline = bug.currentLineItem
print('lastline = ',lastline)
bug.penup()
print(bug.currentLineItem) # 抬笔后生成了初始的当前线条对象
while True:
mx,my = mouse_pos()
bug.goto(mx,my)
if bug.overlap_with(lastline): # 和当前线条碰到
print('碰到最后画的正方形框框')
if bug.overlap_with(w): # 刚才写的字
print('碰到"中华人民共和国"')
if bug.overlap_with(d1): # 刚才蓝色的圆点
print('碰到"蓝点"')
if bug.overlap_with(d2): # 刚才magenta的圆点
print('碰到"品红色的点"')
if bug.overlap_with(shortline):
print('碰到"短线"')
|