-
Notifications
You must be signed in to change notification settings - Fork 0
/
pc_circles.py
51 lines (50 loc) · 2.2 KB
/
pc_circles.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#
import time
import math
import tkinter as tk
screen_height = 400
screen_width = 400
center_x = screen_width/2
center_y = screen_height/2+100
sin_30 = 100
cos_30 = 173
rad=5
# Define Tk root
root = tk.Tk()
canvas = tk.Canvas(root, width=screen_width, height=screen_height+100, borderwidth=0, highlightthickness=0, bg="#27272d")
canvas.grid()
def _create_circle(self, x, y, r, **kwargs):
return self.create_oval(x-r, y-r, x+r, y+r, **kwargs)
tk.Canvas.create_circle = _create_circle
def drawcircle(canv,x,y,rad):
# changed this to return the ID
return canv.create_oval(x-rad,y-rad,x+rad,y+rad,width=0,fill='yellow')
canvas.create_circle(center_x, center_y, 197, fill="#2f2f34", outline="#7d7d81", width=3)
for r in range(175,0,-25):
canvas.create_circle(center_x, center_y, r, fill="#2f2f34", outline="#7d7d81")
canvas.create_line(0,center_y,screen_width,center_y,fill="#7d7d81")
canvas.create_line(center_x,100,center_x,screen_height+100,fill="#7d7d81")
canvas.create_line(center_x-cos_30,center_y-sin_30,center_x+cos_30,center_y+sin_30,fill="#7d7d81")
canvas.create_line(center_x-sin_30,center_y-cos_30,center_x+sin_30,center_y+cos_30,fill="#7d7d81")
canvas.create_line(center_x-cos_30,center_y+sin_30,center_x+cos_30,center_y-sin_30,fill="#7d7d81")
canvas.create_line(center_x-sin_30,center_y+cos_30,center_x+sin_30,center_y-cos_30,fill="#7d7d81")
root.wm_title("Polar Plot")
circ1=drawcircle(canvas,100,100,rad)
mag_block=canvas.create_text(15,110,fill="white",font="Times 15",text="Mag = 1.2", anchor="w")
ph_block=canvas.create_text(282,110,fill="white",font="Times 15",text="Phase = 180.0", anchor="w")
logo = tk.PhotoImage(file='Keysight_Logo.PNG')
canvas.create_image(30,5,image=logo, anchor="nw")
# Start main loop
for m in range (10,200,10):
for d in range (361):
x = m*math.cos(math.radians(d))
y = m*math.sin(math.radians(d))
mag = math.sqrt(x*x + y*y)
out_str = "Mag = " + str(round(mag,2))
canvas.itemconfigure(mag_block,text=out_str)
out_str = "Phase = " + str(round(math.degrees(math.atan2(-y,x)),1))
canvas.itemconfigure(ph_block,text=out_str)
canvas.coords(circ1,center_x+x+rad,center_y+y+rad,center_x+x-rad,center_y+y-rad)
canvas.update()
time.sleep(0.01)
root.mainloop( )