Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个问题,我必须画海龟,但是我需要每一个都是独特的颜色。海龟的数量没有限制,但我会欣赏至少 50 种独特的颜色。此外,颜色应该在视觉上不同,否则我每次都会为每个 (r,g,b) 添加 1。(我根本不允许导入任何其他模块)
如果您不能随机导入,那么使用时间将是获取颜色的一个很好的选择。下面的 python 代码获取当前时间,然后提取 24(0xffffff) 位,然后将其转换为十六进制格式以进行颜色表示。
import time epoch_time = int(time.time()) print(epoch_time) mask = 0xffffff color = hex(epoch_time & mask) print(color)