共計 472 個字符,預計需要花費 2 分鐘才能閱讀完成。
你可以使用 Python 中的色彩模塊來生成顏色表。以下是一個使用 Python 中的 colorsys 模塊生成顏色表的示例代碼:
import colorsys
def generate_color_table(num_colors):
color_table = []
for i in range(num_colors):
hue = i / num_colors
rgb = colorsys.hsv_to_rgb(hue, 1, 1)
rgb_int = tuple(int(c * 255) for c in rgb)
color_table.append(rgb_int)
return color_table
# 生成 10 種顏色的顏色表
num_colors = 10
color_table = generate_color_table(num_colors)
# 打印顏色表
for color in color_table:
print(color)
運行上述代碼,將生成一個包含 10 種顏色的顏色表,并將顏色值以 RGB 形式打印出來。
你可以根據需要調整 num_colors 的值來生成不同數量的顏色。
丸趣 TV 網 – 提供最優質的資源集合!
正文完