From d34d6d1ba1f5ed3d1c3112c4f9110d43614cf6a5 Mon Sep 17 00:00:00 2001 From: "A.M. Rowsell" Date: Sun, 27 Jun 2021 16:44:11 -0400 Subject: [PATCH] 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. --- spirographs.glade | 1 + spirographs.py | 30 ++++++++++++++++++++++-------- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/spirographs.glade b/spirographs.glade index d155178..9ad6e2a 100644 --- a/spirographs.glade +++ b/spirographs.glade @@ -136,6 +136,7 @@ True + True False diff --git a/spirographs.py b/spirographs.py index e5796d2..2923717 100644 --- a/spirographs.py +++ b/spirographs.py @@ -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")