猫史档案馆


【Python作品分享】颜色工具

用户:meowmeow查看:0 回复:0 评论:0 创建时间:2023-05-08T19:16:55


【作品展示】

center_image

 

【作品介绍】

滑动三只海龟调整背景颜色

 

【作品源代码】

import turtle

# 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()

 

【提示】

部分含有Python第三方库相关内容的作品,在海龟编辑器网页端无法运行哦!如遇到这种情况,可以打开下面的链接,下载海龟编辑器客户端:

https://python.codemao.cn


回复

上一页1 页 / 共 0下一页