Working version!
Had to get the canvas object to draw_idle() in order for it to be refreshed. Now it works great! I might tweak the step size for the sliders, as 0.1 can end up with weird, not quite complete plots.
This commit is contained in:
parent
3e96363771
commit
d34d6d1ba1
2 changed files with 23 additions and 8 deletions
|
@ -136,6 +136,7 @@
|
|||
<child>
|
||||
<object class="GtkViewport" id="plotViewport">
|
||||
<property name="visible">True</property>
|
||||
<property name="app-paintable">True</property>
|
||||
<property name="can-focus">False</property>
|
||||
<child>
|
||||
<placeholder/>
|
||||
|
|
|
@ -24,9 +24,19 @@ class spirographs:
|
|||
self.distance = 4
|
||||
self.highestTheta = (np.lcm(self.smallRadius, self.bigRadius)/self.bigRadius) * 2 * math.pi
|
||||
self.stepSize = self.highestTheta / 4096
|
||||
# update initial slider positions
|
||||
bigRadiusAdjustment = builder.get_object('bigRadiusAdjustment')
|
||||
smallRadiusAdjustment = builder.get_object('smallRadiusAdjustment')
|
||||
distanceAdjustment = builder.get_object('distanceAdjustment')
|
||||
bigRadiusAdjustment.set_value(self.bigRadius)
|
||||
smallRadiusAdjustment.set_value(self.smallRadius)
|
||||
distanceAdjustment.set_value(self.distance)
|
||||
# create initial plot
|
||||
self.recalcPoints()
|
||||
self.showPlot()
|
||||
|
||||
|
||||
|
||||
def calcEpiX(self, theta):
|
||||
return ((self.bigRadius + self.smallRadius) * math.cos(theta)) - (self.distance * math.cos(((self.bigRadius + self.smallRadius)/(self.smallRadius))*theta))
|
||||
|
||||
|
@ -67,20 +77,24 @@ class spirographs:
|
|||
def showPlot(self):
|
||||
viewport = builder.get_object('plotViewport')
|
||||
self.plotFigure = Figure(figsize=(5, 4), dpi=100)
|
||||
self.subPlot1 = self.plotFigure.add_subplot()
|
||||
#self.subPlot1.title = f"Epichondroid of {self.bigRadius}, {self.smallRadius}, {self.distance}"
|
||||
self.subPlot1.plot(self.epiX, self.epiY)
|
||||
self.subPlot2 = self.plotFigure.add_subplot()
|
||||
#self.subPlot2.title = f"Hypochondroid of {self.bigRadius}, {self.smallRadius}, {self.distance}"
|
||||
self.subPlot2.plot(self.hypoX, self.hypoY)
|
||||
self.epiPlot, self.hypoPlot = self.plotFigure.subplots(1, 2)
|
||||
self.epiPlot.set_title(f"Epichondroid of {self.bigRadius}, {self.smallRadius}, {self.distance}")
|
||||
self.epiPlot.plot(self.epiX, self.epiY)
|
||||
self.hypoPlot.set_title(f"Hypochondroid of {self.bigRadius}, {self.smallRadius}, {self.distance}")
|
||||
self.hypoPlot.plot(self.hypoX, self.hypoY)
|
||||
|
||||
self.canvas = FigureCanvas(self.plotFigure)
|
||||
self.canvas.set_size_request(800, 600)
|
||||
viewport.add(self.canvas)
|
||||
|
||||
def updatePlot(self):
|
||||
self.subPlot1.plot(self.epiX, self.epiY)
|
||||
self.subPlot2.plot(self.hypoX, self.hypoY)
|
||||
self.epiPlot.clear()
|
||||
self.hypoPlot.clear()
|
||||
self.epiPlot.set_title(f"Epichondroid of {self.bigRadius}, {self.smallRadius}, {self.distance}")
|
||||
self.hypoPlot.set_title(f"Hypochondroid of {self.bigRadius}, {self.smallRadius}, {self.distance}")
|
||||
self.epiPlot.plot(self.epiX, self.epiY)
|
||||
self.hypoPlot.plot(self.hypoX, self.hypoY)
|
||||
self.canvas.draw_idle()
|
||||
|
||||
builder = Gtk.Builder()
|
||||
builder.add_from_file("spirographs.glade")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue