From 9d98349805dc26eca2aac5c698987cbe5dd0d10f Mon Sep 17 00:00:00 2001 From: "A.M. Rowsell" Date: Mon, 28 Jun 2021 00:48:02 -0400 Subject: [PATCH] Added text entry beside sliders These automatically are updated when the slider moves, and vice versa. Still cannot seem to fix the adjustment increment. It makes no sense. --- spirographs.glade | 344 +++++++++++++++++++++++++++++----------------- spirographs.py | 49 +++++-- 2 files changed, 254 insertions(+), 139 deletions(-) diff --git a/spirographs.glade b/spirographs.glade index 1b75573..08c4e53 100644 --- a/spirographs.glade +++ b/spirographs.glade @@ -10,6 +10,225 @@ 5 + + False + Spirographs + center + 800 + 800 + + + + + True + False + 5 + 5 + 5 + 5 + 10 + + + True + False + img/small_epitrochoid.png + + + 0 + 2 + + + + + True + False + img/small_hypotrochoid.png + + + 1 + 2 + + + + + True + True + False + natural + natural + + + + + + 0 + 0 + 2 + + + + + + True + False + 5 + 5 + 5 + 5 + + + True + True + True + bigRadiusAdjustment + True + 100 + 1 + + + 2 + 0 + + + + + True + True + True + distanceAdjustment + True + 100 + 1 + + + 2 + 2 + + + + + True + True + True + smallRadiusAdjustment + True + 100 + 1 + + + 2 + 1 + + + + + True + True + center + 10 + 10 + 10 + 32 + 0.5 + False + False + number + + + + 1 + 0 + + + + + 100 + True + False + start + Big Radius (R): + + + 0 + 0 + + + + + 100 + True + False + start + Small Radius (r): + + + 0 + 1 + + + + + 100 + True + False + start + Distance (d): + + + 0 + 2 + + + + + 100 + True + True + center + 10 + 10 + 10 + 5 + 7 + 0.5 + number + + + + 1 + 1 + + + + + 100 + True + True + center + 10 + 10 + 10 + 5 + 5 + 0.5 + number + + + + 1 + 2 + + + + + 0 + 1 + 2 + + + + + 0.5 100 @@ -26,129 +245,4 @@ 5 - - False - - - - - True - False - 10 - True - - - True - True - bigRadiusAdjustment - True - 100 - 1 - - - 1 - 1 - - - - - True - True - smallRadiusAdjustment - True - 100 - 1 - - - 1 - 2 - - - - - True - True - distanceAdjustment - True - 100 - 1 - - - 1 - 3 - - - - - True - False - Big Radius (R): - - - 0 - 1 - - - - - True - False - Small Radius (r): - - - 0 - 2 - - - - - True - False - Distance (d): - - - 0 - 3 - - - - - True - False - img/small_epitrochoid.png - - - 0 - 4 - - - - - True - False - img/small_hypotrochoid.png - - - 1 - 4 - - - - - True - True - False - - - - - - 0 - 0 - 2 - - - - - diff --git a/spirographs.py b/spirographs.py index 38d43ad..f503fa0 100644 --- a/spirographs.py +++ b/spirographs.py @@ -25,17 +25,23 @@ class spirographs: 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') + self.bigRadiusAdjustment = builder.get_object('bigRadiusAdjustment') + self.smallRadiusAdjustment = builder.get_object('smallRadiusAdjustment') + self.distanceAdjustment = builder.get_object('distanceAdjustment') + self.bigRadiusEntry = builder.get_object('bigRadiusEntry') + self.smallRadiusEntry = builder.get_object('smallRadiusEntry') + self.distanceEntry = builder.get_object('distanceEntry') # set the initial values to a neat shape - bigRadiusAdjustment.set_value(self.bigRadius) - smallRadiusAdjustment.set_value(self.smallRadius) - distanceAdjustment.set_value(self.distance) + self.bigRadiusAdjustment.set_value(self.bigRadius) + self.smallRadiusAdjustment.set_value(self.smallRadius) + self.distanceAdjustment.set_value(self.distance) + self.bigRadiusEntry.set_text(str(self.bigRadius)) + self.smallRadiusEntry.set_text(str(self.smallRadius)) + self.distanceEntry.set_text(str(self.distance)) # try and set the step size?! - bigRadiusAdjustment.set_step_increment(0.5) - smallRadiusAdjustment.set_step_increment(0.5) - distanceAdjustment.set_step_increment(0.5) + self.bigRadiusAdjustment.set_step_increment(0.5) + self.smallRadiusAdjustment.set_step_increment(0.5) + self.distanceAdjustment.set_step_increment(0.5) # create initial plot self.recalcPoints() self.showPlot() @@ -58,19 +64,34 @@ class spirographs: def bigRadiusAdjustment_value_changed_cb(self, widget): self.bigRadius = widget.get_value() + self.bigRadiusEntry.set_text(str(self.bigRadius)) self.recalcPoints() self.updatePlot() + def bigRadiusEntry_changed_cb(self, widget): + self.bigRadius = float(widget.get_text()) + self.bigRadiusAdjustment.set_value(self.bigRadius) + def smallRadiusAdjustment_value_changed_cb(self, widget): self.smallRadius = widget.get_value() + self.smallRadiusEntry.set_text(str(self.smallRadius)) self.recalcPoints() self.updatePlot() + def smallRadiusEntry_changed_cb(self, widget): + self.smallRadius = float(widget.get_text()) + self.smallRadiusAdjustment.set_value(self.smallRadius) + def distanceAdjustment_value_changed_cb(self, widget): self.distance = widget.get_value() + self.distanceEntry.set_text(str(self.distance)) self.recalcPoints() self.updatePlot() + def distanceEntry_changed_cb(self, widget): + self.distance = float(widget.get_text()) + self.distanceAdjustment.set_value(self.distance) + def recalcPoints(self): self.epiX = np.array([self.calcEpiX(i) for i in np.arange(0, self.highestTheta, self.stepSize)]) self.epiY = np.array([self.calcEpiY(i) for i in np.arange(0, self.highestTheta, self.stepSize)]) @@ -79,11 +100,11 @@ class spirographs: def showPlot(self): viewport = builder.get_object('plotViewport') - self.plotFigure = Figure(figsize=(5, 5), dpi=100) + self.plotFigure = Figure(figsize=(5, 8), dpi=100) self.epiPlot, self.hypoPlot = self.plotFigure.subplots(1, 2) - self.epiPlot.set_title(f"Epichondroid of {self.bigRadius}, {self.smallRadius}, {self.distance}") + self.epiPlot.set_title(f"Epitrochoid 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.set_title(f"Hypotrochoid of {self.bigRadius}, {self.smallRadius}, {self.distance}") self.hypoPlot.plot(self.hypoX, self.hypoY) self.canvas = FigureCanvas(self.plotFigure) @@ -93,8 +114,8 @@ class spirographs: def updatePlot(self): 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.set_title(f"Epitrochoid of {self.bigRadius}, {self.smallRadius}, {self.distance}") + self.hypoPlot.set_title(f"Hypotrochoid 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()