Page 212 - Programming With Python 3
P. 212

An Introduction to STEM Programming with Python — 2019-09-03a                              Page 199
            Chapter 19 — Better Graphics




            Sample Program — Animate a Stick Human

            \ Free
            This program creates a couple of classes to draw multiple shape objects and then animates them. The
            first is called "list_of_shapes" that allows us to make a list of shapes, draw them all at once, and move
            them all with a single method call. The second method inherits list_of_shapes and then creates several
             eBook
            shapes to draw a stick figure.








             Edition








            Please support this work at




                                  http://syw2l.org



                                                                               Free




               1|  import graphics
               2|  import time
               3|
               4|  class list_of_shapes:
               5|      def __init__(self):
               6|          self.shapes = []                        eBook
               7|      def move(self, dx, dy):
               8|          for shape in self.shapes:
               9|              shape.move(dx, dy)
             10|      def draw(self, window):
             11|          for shape in self.shapes:
             12|              shape.draw(window)                Edition
             13|
             14|  class stickman(list_of_shapes):


            Copyright 2019 — James M. Reneau Ph.D. — http://www.syw2l.org — This work is licensed
            under a Creative Commons Attribution-ShareAlike 4.0 International License.
   207   208   209   210   211   212   213   214   215   216   217