【问题标题】:How do I change the color of the turtle, not the pen?我如何改变乌龟的颜色,而不是笔?
【发布时间】:2020-08-11 17:02:10
【问题描述】:

你如何改变乌龟看起来的颜色,而不是笔?我希望乌龟在屏幕上绘制白色,但如果我将颜色更改为“白色”,我就再也看不到乌龟了。有turtle.turtlecolor之类的吗?

【问题讨论】:

  • 记得接受答案。

标签: python python-3.x turtle-graphics python-turtle


【解决方案1】:

我们可以使用用户光标定义函数将光标的颜色(轮廓和填充)与光标绘制的颜色(轮廓和填充)断开:

from turtle import Screen, Shape, Turtle

screen = Screen()
screen.bgcolor('black')

turtle = Turtle()
turtle.shape("turtle")
polygon = turtle.get_shapepoly()

fixed_color_turtle = Shape("compound")
fixed_color_turtle.addcomponent(polygon, "orange", "blue")

screen.register_shape('fixed', fixed_color_turtle)

turtle.shape('fixed')
turtle.color('white')
turtle.circle(150)

screen.exitonclick()

这个海龟光标是橙色的,带有蓝色轮廓,但它画了一条白线:

【讨论】:

    【解决方案2】:

    肯定有!

    turtle.shape("turtle")
    turtle.fillcolor("red")
    

    现在你得到了一只红海龟。

    【讨论】:

    • 该海龟绘制的颜色将与该海龟光标的轮廓颜色相同。 by 这个海龟填充的填充颜色将与 of 这个海龟光标的填充颜色相同。我相信 OP 试图将这些概念分开,让乌龟 看起来 的样子不反映乌龟 所做的
    猜你喜欢
    • 2013-12-17
    • 1970-01-01
    • 2019-09-17
    • 1970-01-01
    • 2018-05-24
    • 1970-01-01
    • 1970-01-01
    • 2015-12-29
    • 2021-11-09
    相关资源
    最近更新 更多