Moxon program in python
following this discussion in the GQRP Club group
https://groups.io/g/gqrp/topic/118936746
translation by ChatGPT of a BASIC program by L. B. Cebik, found on this website
https://antenna2.github.io/cebik/content/moxon/moxgen.html
Screenshot
Code
I pasted it in the Thonny IDE and it ran first time. It needed some adaptation for mm output, and positioning of the texts, nothing really difficult:
---
import tkinter as tk
from tkinter import ttk
import math
def bereken():
try:
F = float(freq_entry.get())
U = unit_var.get()
WD = float(diam_entry.get())
# --- Omrekening draad ---
if U == 1: # inches
WL_unit = 11802.71 / F # golflengte in inches
unit_txt = "in"
DW = WD / WL_unit
elif U == 2: # mm
WL_unit = 299792.5 / F # golflengte in mm
unit_txt = "mm"
DW = WD / WL_unit
else: # wavelengths
WL_unit = 1
unit_txt = "λ"
DW = WD
D1 = 0.4342945 * math.log(DW)
# --- Berekeningen ---
A = (-0.0008571428571 * (D1**2)) + (-0.009571428571 * D1) + 0.3398571429
B = (-0.002142857143 * (D1**2)) + (-0.02035714286 * D1) + 0.008285714286
C = (0.001809523381 * (D1**2)) + (0.01780952381 * D1) + 0.05164285714
D = (0.001 * D1) + 0.07178571429
E = (B + C) + D
# --- Omzetten naar gekozen eenheid ---
A_u = A * WL_unit
B_u = B * WL_unit
C_u = C * WL_unit
D_u = D * WL_unit
E_u = E * WL_unit
result = f"""
A = {A_u:.2f} {unit_txt}
B = {B_u:.2f} {unit_txt}
C = {C_u:.2f} {unit_txt}
D = {D_u:.2f} {unit_txt}
E = {E_u:.2f} {unit_txt}
"""
output_var.set(result)
teken(A_u, B_u, C_u, D_u, E_u, unit_txt)
except Exception as e:
output_var.set(f"Fout: {e}")
def teken(A, B, C, D, E, unit):
canvas.delete("all")
# Vaste afmetingen (pixels)
x0 = 150
y0 = 100
A_px = 300
B_px = 100
C_px = 80
D_px = 80
# Driven element (boven)
canvas.create_line(x0, y0, x0 + A_px, y0, width=3)
canvas.create_line(x0, y0, x0, y0 + B_px, width=3)
canvas.create_line(x0 + A_px, y0, x0 + A_px, y0 + B_px, width=3)
# Reflector (onder)
y1 = y0 + B_px + C_px + D_px
canvas.create_line(x0, y1, x0 + A_px, y1, width=3)
canvas.create_line(x0, y1, x0, y1 - D_px, width=3)
canvas.create_line(x0 + A_px, y1, x0 + A_px, y1 - D_px, width=3)
# Feedpoint
canvas.create_oval(x0 + A_px/2 - 5, y0 - 5, x0 + A_px/2 + 5, y0 + 5, fill="black")
# Labels (positie vast, waarden variabel)
canvas.create_text(x0 + A_px/2, y0 - 20, text=f"A = {A:.2f} {unit}")
canvas.create_text(x0 + A_px + 75, y0 + B_px/2, text=f"B = {B:.2f} {unit}")
canvas.create_text(x0 + A_px + 75, y0 + B_px + C_px/2, text=f"C = {C:.2f} {unit}")
canvas.create_text(x0 + A_px + 75, y1 - D_px/2, text=f"D = {D:.2f} {unit}")
canvas.create_text(x0 + A_px + 170, (y0 + y1)/2, text=f"E = {E:.2f} {unit}")
# GUI
root = tk.Tk()
root.title("Moxon Calculator + Visualisation")
frame = ttk.Frame(root, padding=10)
frame.grid()
ttk.Label(frame, text="Frequency (MHz)").grid(row=0, column=0)
freq_entry = ttk.Entry(frame)
freq_entry.grid(row=0, column=1)
ttk.Label(frame, text="Wire Diameter").grid(row=1, column=0)
diam_entry = ttk.Entry(frame)
diam_entry.grid(row=1, column=1)
unit_var = tk.IntVar(value=1)
ttk.Radiobutton(frame, text="Inches", variable=unit_var, value=1).grid(row=2, column=0)
ttk.Radiobutton(frame, text="mm", variable=unit_var, value=2).grid(row=2, column=1)
ttk.Radiobutton(frame, text="Wavelength", variable=unit_var, value=3).grid(row=2, column=2)
ttk.Button(frame, text="Calculate + Draw", command=bereken).grid(row=3, column=0, columnspan=3)
output_var = tk.StringVar()
ttk.Label(frame, textvariable=output_var).grid(row=4, column=0, columnspan=3)
canvas = tk.Canvas(root, width=700, height=500, bg="white")
canvas.grid()
root.mainloop()
---