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!
This commit is contained in:
commit
657e93b6b4
1 changed files with 60 additions and 0 deletions
60
spirographs.py
Normal file
60
spirographs.py
Normal file
|
@ -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()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue