Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/362.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python (Tkinter)如何使用此图案为对象着色?_Python_Animation_Tkinter_Rgb_Physics - Fatal编程技术网

Python (Tkinter)如何使用此图案为对象着色?

Python (Tkinter)如何使用此图案为对象着色?,python,animation,tkinter,rgb,physics,Python,Animation,Tkinter,Rgb,Physics,我试着按照与电场相同的模式给物体着色(对一种叫做“电荷”的特定类型物体的放置作出反应)。颜色是表示电场强度的一种方式:每当电场为正时,就会出现红色阴影,如果为负,则为蓝色,如果电场为0,则为黑色(对象是空间中点的表示,它们是“离散”空间的一种方式,我将它们放在矩阵中) 这样做的目的是使电场的表示与电场电势的表示相似 基于超位置原理,我试图定义一个函数,首先计算电荷到每个物体的距离,然后通过添加值给每个物体上色​​在红色通道中(我假设放置的电荷为正),根据其位置,只要其值​​在该通道中,在某个限制

我试着按照与电场相同的模式给物体着色(对一种叫做“电荷”的特定类型物体的放置作出反应)。颜色是表示电场强度的一种方式:每当电场为正时,就会出现红色阴影,如果为负,则为蓝色,如果电场为0,则为黑色(对象是空间中点的表示,它们是“离散”空间的一种方式,我将它们放在矩阵中)

这样做的目的是使电场的表示与电场电势的表示相似

基于超位置原理,我试图定义一个函数,首先计算电荷到每个物体的距离,然后通过添加值给每个物体上色​​在红色通道中(我假设放置的电荷为正),根据其位置,只要其值​​在该通道中,在某个限制范围内或对象是完全黑色的;以防它有值​​在蓝色通道中,它将减去它们。蓝色也一样

def ncolor(r,g,b):
    nr = int(r)
    ng = int(g)
    nb = int(b)
    color = "#%4.4x%4.4x%4.4x" % (nr,ng,nb)
    return color

def interaction(charge, pol): 
    for o in range(columobjects):
        for p in range(rowobjects):
            (r, g, b) = window.winfo_rgb(canvas.itemcget(objectop, "fill"))
            dis = math.sqrt((charge.x - objectoj.x)**2 + (charge.y - objectoj.y)**2)
            if pol == 0: 
                if dis <= 100: 
                    if float(r)==0 and float(b)==0 or 0 < float(r) < 10536: 
                        (r,g,b) = np.array((r,g,b))+np.array((5268*2, 0, 0))
                        color = ncolor(r,g,b)
                        canvas.itemconfig(objectop, fill=color)
                    elif float(r)==0 and float(b)!=0:
                        (r,g,b) = np.array((r,g,b))-np.array((0, 0, 5268*2))
                        color = ncolor(r,g,b)
                        canvas.itemconfig(objectop, fill=color)
                elif 100 < dis <= 200: 
                    if float(r)==0 and float(b)==0 or 0 < float(r) < 52680: 
                        (r,g,b) = np.array((r,g,b))+np.array((5268, 0, 0))
                        color = ncolor(r,g,b)
                        canvas.itemconfig(objectop, fill=color)
                    elif float(r)==0 and float(b)!=0:
                        (r,g,b) = np.array((r,g,b))-np.array((0, 0, 5268))
                        color = ncolor(r,g,b)
                        canvas.itemconfig(objectop, fill=color) 
            else: pass    
            if pol == 1: 
                if dis <= 100: 
                    if float(r)==0 and float(b)==0 or 0 < float(r) < 10536: 
                        (r,g,b) = np.array((r,g,b))+np.array((0, 0, 5268*2))
                        color = ncolor(r,g,b)
                        canvas.itemconfig(objectop, fill=color)
                    elif float(r)==0 and float(b)!=0:
                        (r,g,b) = np.array((r,g,b))-np.array((5268*2, 0, 0))
                        color = ncolor(r,g,b)
                        canvas.itemconfig(objectop, fill=color)
                elif 100 < dis <= 200: 
                    if float(r)==0 and float(b)==0 or 0 < float(r) < 52680: 
                        (r,g,b) = np.array((r,g,b))+np.array((0, 0, 5268))
                        color = ncolor(r,g,b)
                        canvas.itemconfig(objectop, fill=color)
                    elif float(r)==0 and float(b)!=0:
                        (r,g,b) = np.array((r,g,b))-np.array((5268, 0, 0))
                        color = ncolor(r,g,b)
                        canvas.itemconfig(objectop, fill=color) 
            else: pass                                                  
def n颜色(r、g、b):
nr=int(r)
ng=int(g)
nb=int(b)
color=“#%4.4x%4.4x%4.4x”%(nr、ng、nb)
返回颜色
def相互作用(电荷、pol):
对于范围内的o(对象):
对于范围内的p(行对象):
(r,g,b)=window.winfo_rgb(canvas.itemcget(objectop,“fill”))
dis=math.sqrt((charge.x-objectoj.x)**2+(charge.y-objectoj.y)**2)
如果pol==0:
如果dis