commit 657e93b6b4b9d0440966bbeea7a39c999af9d84f Author: A.M. Rowsell Date: Sun Jun 27 13:48:32 2021 -0400 Initial commit -- non-working Still need to get the GTK framework in place. But it's always a good idea to start the git repo before getting too far into a project! diff --git a/spirographs.py b/spirographs.py new file mode 100644 index 0000000..18d6c75 --- /dev/null +++ b/spirographs.py @@ -0,0 +1,60 @@ +# gtk imports +import gi +gi.require_version('Gtk', '3.0') +from gi.repository import Gtk, Gdk, GObject, GLib + +# math/plot imports +import numpy as np +import matplotlib.pyplot as plt +import math +import sys + +class spirographs: + + + def calcEpiX(theta, bigRadius, smallRadius, distance): + return ((bigRadius + smallRadius) * math.cos(theta)) - (distance * math.cos(((bigRadius + smallRadius)/(smallRadius))*theta)) + + def calcEpiY(theta, bigRadius, smallRadius, distance): + return ((bigRadius + smallRadius) * math.sin(theta)) - (distance * math.sin(((bigRadius + smallRadius)/(smallRadius))*theta)) + + def calcHypoX(theta, bigRadius, smallRadius, distance): + return ((bigRadius - smallRadius) * math.cos(theta)) + (distance * math.cos(((bigRadius - smallRadius)/(smallRadius))*theta)) + + def calcHypoY(theta, bigRadius, smallRadius, distance): + return ((bigRadius - smallRadius) * math.sin(theta)) - (distance * math.sin(((bigRadius - smallRadius)/(smallRadius))*theta)) + + def __init__(self): + self.bigRadius = 12 + self.smallRadius = 5 + self.distance = 4 + self.highestTheta = (np.lcm(smallRadius, bigRadius)/bigRadius) * 2 * math.pi + self.stepSize = highestTheta / 4096 + self.recalcPoints() + self.showPlot() + + def recalcPoints(self): + self.epiX = np.array([calcEpiX(i, bigRadius, smallRadius, distance) for i in np.arange(0, highestTheta, stepSize)]) + self.epiY = np.array([calcEpiY(i, bigRadius, smallRadius, distance) for i in np.arange(0, highestTheta, stepSize)]) + self.hypoX = np.array([calcHypoX(i, bigRadius, smallRadius, distance) for i in np.arange(0, highestTheta, stepSize)]) + self.hypoY = np.array([calcHypoY(i, bigRadius, smallRadius, distance) for i in np.arange(0, highestTheta, stepSize)]) + + def showPlot(self): + plt.subplot(1, 2, 1) + plt.title(f"Epichondroid of {bigRadius}, {smallRadius}, {distance}") + plt.plot(epiX, epiY) + plt.subplot(1, 2, 2) + plt.title(f"Hypochondroid of {bigRadius}, {smallRadius}, {distance}") + plt.plot(hypoX, hypoY) + plt.show() + + +builder = Gtk.Builder() +builder.add_from_file("spirographs.glade") +sp = spirographs() +builder.connect_signals(sp) +window = builder.get_object("spWindow") +window.show_all() + +Gtk.main() +