# colorw.py3 color wheel based on phase angle # copied from 1/1/97 JSS initial version # may be run using python colorw.py3 import tkinter import math top = tkinter.Tk() C = tkinter.Canvas(top, bg="white", width=400, height=400) top.title('colorw.py3') Pi = 3.14159265358979323846 radius_1 = 160.0 radius_2 = 60.0 cnt = 0 xc = 200.0 yc = 210.0 A = -1.0 while(A < 1.0): # walk the angle in bams around the circle # A = arctan(Y, X)/PI for normalized angle from X-Y plot # get double R,G,B R==1 at A==0, G==1 at A==2/3, B==1 at A==-2/3 R = 1.0 - abs(A) AA = A - 2.0/3.0 if(AA < -1.0): AA = 2.0+AA G = 1.0 - abs(AA) AA = A + 2.0/3.0 if(AA > 1.0): AA = 2.0-AA B = 1.0 - abs(AA) # boost low end and normalize (this brightens colors) R = R+0.2 G = G+0.2 B = B+0.2 AAA = max(R, G) AAA = max(AAA, B) R = R/AAA G = G/AAA B = B/AAA # compute line ends x1 = radius_1 * math.cos(A * Pi) y1 = radius_1 * math.sin(A * Pi) x2 = radius_2 * math.cos(A * Pi) y2 = radius_2 * math.sin(A * Pi) A = A + 0.01 # 240 lines, 0.01 200 lines -1.0 to 1.0 rh = hex(int(255*R)) gh = hex(int(255*G)) bh = hex(int(255*B)) color = "#" + rh[2:] + gh[2:] + bh[2:] line = C.create_line(xc+x1, yc+y1, xc+x2, yc+y2, width=5, fill=color) # end while C.pack() top.mainloop()