turtle - turtledemo - colormixer [调色板]

【 调 色 板 】

# colormixer

from turtle import Screen, Turtle, mainloop

class ColorTurtle(Turtle):

    def __init__(self, x, y):

        Turtle.__init__(self)

        self.shape("turtle")

        self.resizemode("user")

        self.shapesize(3,3,5)

        self.pensize(10)

        self._color = [0,0,0]

        self.x = x

        self._color[x] = y

        self.color(self._color)

        self.speed(0)

        self.left(90)

        self.pu()

        self.goto(x,0)

        self.pd()

        self.sety(1)

        self.pu()

        self.sety(y)

        self.pencolor("gray25")

        self.ondrag(self.shift)

    def shift(self, x, y):

        self.sety(max(0,min(y,1)))

        self._color[self.x] = self.ycor()

        self.fillcolor(self._color)

        setbgcolor()

def setbgcolor():

    screen.bgcolor(red.ycor(), green.ycor(), blue.ycor())

def main():

    global screen, red, green, blue

    screen = Screen()

    screen.delay(0)

    screen.setworldcoordinates(-1, -0.3, 3, 1.3)

    red = ColorTurtle(0, .5)

    green = ColorTurtle(1, .5)

    blue = ColorTurtle(2, .5)

    setbgcolor()

    writer = Turtle()

    writer.ht()

    writer.pu()

    writer.goto(1,1.15)

    writer.write("DRAG!",align="center",font=("Arial",30,("bold","italic")))

    return "EVENTLOOP"

if __name__ == "__main__":

    msg = main()

    print(msg)

    mainloop()

===
内容来源:官方文库
牛猫名言:最好的资料就是官方文档
===
本文链接:https://www.jianshu.com/p/2c5dea78dbe6
转载请注明,谢谢!
编辑:牛猫大侠

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

友情链接更多精彩内容