鼠标移动彩色光谱_鼠标指针跟随效果一例

0 Comments

Python鼠标移动彩色光谱

Python鼠标移动彩色光谱

"""
    鼠标移动彩色光谱.py
"""
from random import randint
from coloradd import colorset
from turtle import Screen,Turtle,TurtleScreenBase

def _onmousemove(self, fun, add=None):
    """绑定鼠标移动事件"""    
    if fun is None:
        self.cv.unbind("" )
    else:
        def eventfun(event):
            x, y = (self.cv.canvasx(event.x)/self.xscale,
                    -self.cv.canvasy(event.y)/self.yscale)
            fun(x, y)
        self.cv.bind("", eventfun, add)

TurtleScreenBase.onmousemove = _onmousemove

screen = Screen()                               # 新建窗口
screen.tracer(0,0)                              # 关闭自动显示
screen.colormode(255)                           # 设定颜色模式为255 
screen.setup(480,360)                           # 设定窗口大小
screen.bgcolor("black")                         # 设定背景颜色

t = Turtle(visible=False,shape='circle')        # 新建圆形海龟
t.penup()
[t.stamp() for _ in range(100)]                  # 盖10个章  
ft = ('',32,'normal')                           # 设定字体风格 
def follow(x,y):
    screen.onmousemove(None)
    t.clearstamps(1)
    t.goto(x,y)
    cc = colorset(abs(x)+abs(y))
    t.color(cc)
    t.stamp()    
    screen.title(str(x) + "," + str(y))
    screen.update()
    screen.onmousemove(follow)

screen.onmousemove(follow)
screen.mainloop()

标签:

发表评论