def test_geometry(self): self.ip = ImagePoint("bunny.png", (0, 0)) self.ip.movable = True self.p1 = Point((0, 0), color=Color(0x008000, 1)) self.p1.movable = True self.p2 = Point((0, -1)) self.p3 = Point((1.2, 0)) self.l1 = LineSegment(self.p2, self.p3, style=LineStyle(3, Color(0, 1))) self.l2 = LineSegment(self.p2, self.p1, style=LineStyle(3, Color(0, 1))) self.c2 = Circle((-1, -1), self.p1) ma = MathApp() ma.run() self.ip.destroy() self.p1.destroy() self.p2.destroy() self.p3.destroy() self.c2.destroy() self.l1.destroy() self.l2.destroy()
def run(self, rocket=None): """ Execute the Planet (and Rocket) simulation. Optional parameters: * **rocket** Reference to a Rocket object - sets the initial view """ if rocket: viewalt = rocket.altitude viewanom = rocket.tanomaly else: viewalt = 0 viewanom = pi / 2 self.viewaltitude = self.kwargs.get('viewalt', viewalt) # how high to look self.viewanomaly = self.kwargs.get('viewanom', viewanom) # where to look self.viewanomalyd = self.kwargs.get('viewanomd', degrees(self.viewanomaly)) self._planetcircle = Circle((0, 0), self.radius, style=LineStyle(1, Color(self.color, 1)), color=Color(self.color, 0.5)) r = self.radius + self.viewaltitude self.viewPosition = (r * cos(self.viewanomaly), r * sin(self.viewanomaly)) super().run()
def __init__(self, **kwargs): scale = kwargs.get("viewscale", 10) # 10 pixels per meter default self.radius = kwargs.get("radius", 6.371e6) # Earth - meters self.mass = kwargs.get("planetmass", 5.9722e24) # Earth - kg self.color = kwargs.get("color", 0x008040) # greenish self.viewaltitude = kwargs.get("viewalt", 0) # how high to look self.viewanomaly = kwargs.get("viewanom", pi / 2) # where to look self.viewanomalyd = kwargs.get("viewanomd", degrees(self.viewanomaly)) self._planetcircle = Circle( (0, 0), self.radius, style=LineStyle(1, Color(self.color, 1)), color=Color(self.color, 0.5), ) super().__init__(scale)
class TestMathMethods(unittest.TestCase): def buttonstatus(self): return "True" if self.imgbutton() else "False" def labelcoords(self): return (100 + self.vslider1(), 175) def buttoncoords(self): return (300 + self.vslider1(), 175) def labelcolor(self): colorval = self.vslider1() return Color(colorval * 256, 1) def pressbutton(self, caller): print("button pressed: ", caller) def __init__(self, arg): super().__init__(arg) def test_controls(self): self.imgbutton = InputImageButton( "ggame/images/button-round.png", self.pressbutton, (0, 0), frame=Frame(0, 0, 100, 100), qty=2, ) self.imgbutton.scale = 0.5 self.vslider1 = Slider( (100, 150), 0, 250, 125, positioning="physical", steps=10 ) self.label = Label( self.labelcoords, self.buttonstatus, size=15, positioning="physical", color=self.labelcolor, ) self.button = InputButton( self.pressbutton, self.buttoncoords, "Press Me", size=15, positioning="physical", ) self.numinput = InputNumeric((300, 275), 3.14, positioning="physical") ma = MathApp() ma.run() self.vslider1.destroy() self.label.destroy() self.button.destroy() self.numinput.destroy() self.imgbutton.destroy() def test_geometry(self): self.ip = ImagePoint("bunny.png", (0, 0)) self.ip.movable = True self.p1 = Point((0, 0), color=Color(0x008000, 1)) self.p1.movable = True self.p2 = Point((0, -1)) self.p3 = Point((1.2, 0)) self.l1 = LineSegment(self.p2, self.p3, style=LineStyle(3, Color(0, 1))) self.l2 = LineSegment(self.p2, self.p1, style=LineStyle(3, Color(0, 1))) self.c2 = Circle((-1, -1), self.p1) ma = MathApp() ma.run() self.ip.destroy() self.p1.destroy() self.p2.destroy() self.p3.destroy() self.c2.destroy() self.l1.destroy() self.l2.destroy() def test_fancycontrols(self): self.imgbutton = InputImageButton( "ggame/images/button-round.png", self.pressbutton, (0, 0), frame=Frame(0, 0, 100, 100), qty=2, ) self.imgbutton.scale = 0.5 self.ii = ImageIndicator( "ggame/images/red-led-off-on.png", (300, 500), self.imgbutton, positioning="physical", frame=Frame(0, 0, 600, 600), qty=2, ) self.ii.scale = 0.1 self.glassbutton = GlassButton(None, (0, -0.5)) self.toggle = MetalToggle(0, (0, -1)) self.Li = LEDIndicator((300, 450), self.glassbutton, positioning="physical") self.Lit = LEDIndicator((300, 480), self.toggle, positioning="physical") ma = MathApp() ma.run() self.imgbutton.destroy() self.ii.destroy() self.glassbutton.destroy() self.toggle.destroy() self.Li.destroy() self.Lit.destroy() def timercallback(self, timer): self.assertEqual(timer, self.timer) self.callbackcomplete = True def test_timer(self): self.callbackcomplete = False self.timer = Timer() self.timer.callAfter(0.1, self.timercallback) ma = MathApp() ma.run() for i in range(10): time.sleep(1 / 60) ma._animate(1) self.assertEquals(self.callbackcomplete, True) self.timer.destroy()
class TestMathMethods(unittest.TestCase): def buttonstatus(self): return "True" if self.imgbutton() else "False" def labelcoords(self): return (100 + self.vslider1(), 175) def buttoncoords(self): return (300 + self.vslider1(), 175) def labelcolor(self): colorval = self.vslider1() return Color(colorval * 256, 1) def pressbutton(self, caller): print("button pressed: ", caller) def __init__(self, arg): super().__init__(arg) def test_controls(self): self.imgbutton = InputImageButton( "images/button-round.png", self.pressbutton, (0, 0), frame=Frame(0, 0, 100, 100), qty=2, ) self.imgbutton.scale = 0.5 self.vslider1 = Slider((100, 150), 0, 250, 125, positioning="physical", steps=10) self.label = Label( self.labelcoords, self.buttonstatus, size=15, positioning="physical", color=self.labelcolor, ) self.button = InputButton( self.pressbutton, self.buttoncoords, "Press Me", size=15, positioning="physical", ) self.numinput = InputNumeric((300, 275), 3.14, positioning="physical") ma = MathApp() ma.run() self.vslider1.destroy() self.label.destroy() self.button.destroy() self.numinput.destroy() self.imgbutton.destroy() def test_geometry(self): self.ip = ImagePoint("bunny.png", (0, 0)) self.ip.movable = True self.p1 = Point((0, 0), color=Color(0x008000, 1)) self.p1.movable = True self.p2 = Point((0, -1)) self.p3 = Point((1.2, 0)) self.l1 = LineSegment(self.p2, self.p3, style=LineStyle(3, Color(0, 1))) self.l2 = LineSegment(self.p2, self.p1, style=LineStyle(3, Color(0, 1))) self.c2 = Circle((-1, -1), self.p1) ma = MathApp() ma.run() self.ip.destroy() self.p1.destroy() self.p2.destroy() self.p3.destroy() self.c2.destroy() self.l1.destroy() self.l2.destroy() def test_fancycontrols(self): self.imgbutton = InputImageButton( "images/button-round.png", self.pressbutton, (0, 0), frame=Frame(0, 0, 100, 100), qty=2, ) self.imgbutton.scale = 0.5 self.ii = ImageIndicator( "images/red-led-off-on.png", (300, 500), self.imgbutton, positioning="physical", frame=Frame(0, 0, 600, 600), qty=2, ) self.ii.scale = 0.1 self.glassbutton = GlassButton(None, (0, -0.5)) self.toggle = MetalToggle(0, (0, -1)) self.Li = LEDIndicator((300, 450), self.glassbutton, positioning="physical") self.Lit = LEDIndicator((300, 480), self.toggle, positioning="physical") ma = MathApp() ma.run() self.imgbutton.destroy() self.ii.destroy() self.glassbutton.destroy() self.toggle.destroy() self.Li.destroy() self.Lit.destroy() def timercallback(self, timer): self.assertEqual(timer, self.timer) self.callbackcomplete = True def test_timer(self): self.callbackcomplete = False self.timer = Timer() self.timer.callAfter(0.1, self.timercallback) ma = MathApp() ma.run() for i in range(10): time.sleep(1 / 60) ma._animate(1) self.assertEquals(self.callbackcomplete, True) self.timer.destroy()
""" Example of using MathApp Circle class. """ from ggame.point import Point from ggame.circle import Circle from ggame.mathapp import MathApp # P1 is the center of the circle P1 = Point((0.5, 1)) # P2 is on the perimeter P2 = Point((1.3, 1)) # define a circle from center and perimeter points C = Circle(P1, P2) # allow the user to drag the perimeter point to resize the circle P2.movable = True MathApp().run()