what does bad color sequence mean in python turtle?

what does bad color sequence mean in python turtle?

 

评论

Run screen.colormode(255) and it should work.
– Blender
May 27, 2013 at 18:00
 
 
回答1

From the docs:

Each of r, g, and b must be in the range 0..colormode, where colormode is either 1.0 or 255 (see colormode()).

Your colormode is probably set to 1.0, so either the individual color coordinates need to be floats in the range 0 to 1, or you need to set the colormode to 255.

 

 回答2

you will get this error in case you are generating a random color using a function and you are using the random module and then returning a tuple of 3 random integers, and pass this tuple color function you can fix this issue by writing this turtle.colormode(255)

use this code

import random
import turtle

from turtle import Turtle
turtle.colormode(255)
tim = Turtle()
tim.speed("fastest")
direction = [90,  270]
#colours = ["CornflowerBlue", "DarkOrchid", "IndianRed", "DeepSkyBlue", "LightSeaGreen", "wheat", "SlateGray", "SeaGreen"]
tim.pensize(5)

def random_color():
    r = random.randint(0, 255)
    g = random.randint(0, 255)
    b = random.randint(0, 255)
    random_color = (r, g, b)
    return random_color


while True:
    move = random.choice(direction)
    tim.forward(40)
    tim.color(random_color())
    tim.left(move)

 

作者:Chuck Lu    GitHub    
posted @   ChuckLu  阅读(63)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
历史上的今天:
2021-09-17 向量内积(点乘)和外积(叉乘)概念及几何意义
2021-09-17 jQuery Migrate
2021-09-17 Best way to expose resource strings to JavaScript files in ASP.NET MVC?
2021-09-17 What's the difference between sweetalert and sweetalert2?
2021-09-17 Does javascript have an Equivalent to C#s HttpUtility.HtmlEncode? [duplicate]
2021-09-17 sweetalert2 and xss
2021-09-17 上海居住证办理条件以及流程?
点击右上角即可分享
微信分享提示