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>
|
<child>
|
||||||
<object class="GtkViewport" id="plotViewport">
|
<object class="GtkViewport" id="plotViewport">
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
|
<property name="app-paintable">True</property>
|
||||||
<property name="can-focus">False</property>
|
<property name="can-focus">False</property>
|
||||||
<child>
|
<child>
|
||||||
<placeholder/>
|
<placeholder/>
|
||||||
|
|
|
@ -24,9 +24,19 @@ class spirographs:
|
||||||
self.distance = 4
|
self.distance = 4
|
||||||
self.highestTheta = (np.lcm(self.smallRadius, self.bigRadius)/self.bigRadius) * 2 * math.pi
|
self.highestTheta = (np.lcm(self.smallRadius, self.bigRadius)/self.bigRadius) * 2 * math.pi
|
||||||
self.stepSize = self.highestTheta / 4096
|
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.recalcPoints()
|
||||||
self.showPlot()
|
self.showPlot()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def calcEpiX(self, theta):
|
def calcEpiX(self, theta):
|
||||||
return ((self.bigRadius + self.smallRadius) * math.cos(theta)) - (self.distance * math.cos(((self.bigRadius + self.smallRadius)/(self.smallRadius))*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):
|
def showPlot(self):
|
||||||
viewport = builder.get_object('plotViewport')
|
viewport = builder.get_object('plotViewport')
|
||||||
self.plotFigure = Figure(figsize=(5, 4), dpi=100)
|
self.plotFigure = Figure(figsize=(5, 4), dpi=100)
|
||||||
self.subPlot1 = self.plotFigure.add_subplot()
|
self.epiPlot, self.hypoPlot = self.plotFigure.subplots(1, 2)
|
||||||
#self.subPlot1.title = f"Epichondroid of {self.bigRadius}, {self.smallRadius}, {self.distance}"
|
self.epiPlot.set_title(f"Epichondroid of {self.bigRadius}, {self.smallRadius}, {self.distance}")
|
||||||
self.subPlot1.plot(self.epiX, self.epiY)
|
self.epiPlot.plot(self.epiX, self.epiY)
|
||||||
self.subPlot2 = self.plotFigure.add_subplot()
|
self.hypoPlot.set_title(f"Hypochondroid of {self.bigRadius}, {self.smallRadius}, {self.distance}")
|
||||||
#self.subPlot2.title = f"Hypochondroid of {self.bigRadius}, {self.smallRadius}, {self.distance}"
|
self.hypoPlot.plot(self.hypoX, self.hypoY)
|
||||||
self.subPlot2.plot(self.hypoX, self.hypoY)
|
|
||||||
|
|
||||||
self.canvas = FigureCanvas(self.plotFigure)
|
self.canvas = FigureCanvas(self.plotFigure)
|
||||||
self.canvas.set_size_request(800, 600)
|
self.canvas.set_size_request(800, 600)
|
||||||
viewport.add(self.canvas)
|
viewport.add(self.canvas)
|
||||||
|
|
||||||
def updatePlot(self):
|
def updatePlot(self):
|
||||||
self.subPlot1.plot(self.epiX, self.epiY)
|
self.epiPlot.clear()
|
||||||
self.subPlot2.plot(self.hypoX, self.hypoY)
|
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 = Gtk.Builder()
|
||||||
builder.add_from_file("spirographs.glade")
|
builder.add_from_file("spirographs.glade")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue