问题描述
我正在做一个项目,我想运行一个 Python 脚本来生成一个带有许多抽象彩色线条的图像,然后将该图像输入到朋友的程序中。也就是说,我用我朋友的程序可以识别和操作的某些十六进制代码对这些行进行了着色,但是即使我指定了这些值,生成的图像也没有我需要的特定颜色。对此,我意识到我使用的 graphics engine 是建立在一个叫做 tkinter 的小东西之上的,不知何故,它正在增加颜色。以下是一些预期和记录的颜色示例:
- 预期>>记录
- 255 128 0 >> 255 126 44
- 0 128 255 >> 0 130 247
- 128 255 0 >> 111 254 80
...等等。另外,如果有帮助,这是我的代码:
from graphics import *
from random import randint
def main():
# First I'll initialize a black window:
win = GraphWin("Click on the screen while the small window is green",1000,700)
win.setBackground("black")
# Indicator window initialization
indicator = GraphWin("green = ready,red = drawing",50,50)
indicator.setBackground("green")
# Setup initial ghost lines
left = Line(Point(10,10),Point(10,690))
right = Line(Point(990,Point(990,690))
lines =[left,right] # this array is really important
arr = []
for x in range(50):
p = win.getMouse() # click
indicator.setBackground("red") # drawing time!
# Gets the midpoint of each line drawn before the click,and
# draws a line from each midpoint to the click.
num = len(lines)
for i in range(num):
q = lines[i].getCenter()
newline = Line(p,q)
doodle(newline,randcolor(),win)
lines.append(newline)
indicator.setBackground("green") # click time!
def randcolor():
r = randint(0,5)
bright_orange = color_rgb(255,128,0) # 255 128-6 0-44
bright_sapphire = color_rgb(0,255) # 0 128-30 255-47
bright_lime = color_rgb(128,255,0) # 128-11 255-4 0-80
dark_orange = color_rgb(128,64,0) # 128-30 64-3 0-16
dark_sapphire = color_rgb(0,128) # 0 64-5 128-4
dark_lime = color_rgb(64,0) # 64-55 128 0-35
# reso_wires = ["#ff8000","#0080ff","#80ff00","#804000","#004080","#408000"]
reso_wires = [bright_orange,bright_sapphire,bright_lime,dark_orange,dark_sapphire,dark_lime]
color = reso_wires[r]
return color
def doodle(x,color,win):
'''
This is your one-stop drawing function. It colors the line,sends it to the
window,and it even supports line declaration as the first parameter.
'''
x.setoutline(color)
x.setWidth(5)
x.draw(win)
nodepoints = [x.getP1(),x.getP2()]
rc = Image(nodepoints[0],"xor_node.png")
rc.draw(win)
rd = Image(nodepoints[1],"xor_node.png")
rd.draw(win)
main()
有人可以帮我调试这个十六进制颜色不一致的问题吗?我完全理解解决这个问题的唯一方法是深入研究 tkinter 的 Canvas 本身的代码并处理 x11 原语。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)