How to attach a line to a moving object?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • lightning18
    New Member
    • May 2010
    • 16

    How to attach a line to a moving object?

    Hello i have designed a maze and i want to draw a path between the cells as the 'person' moves from one cell to the next. So each time i move the cell a line is drawn Also i am using the graphics module

    The graphics module is an object oriented library

    Im importing
    Code:
    from graphics import*
    from maze import*
    my circle which is my cell

    Code:
    center = Point(15, 15)
    c = Circle(center, 12)
    c.setFill('blue')
    c.setOutline('yellow')
    c.draw(win)
    
    p1 = Point(c.getCenter().getX(), c.getCenter().getY())
    this is my loop
    
     if mazez.blockedCount(cloc)> 2: 
                mazez.addDecoration(cloc, "grey")
                mazez[cloc].deadend = True
            c.move(-25, 0)
            p2 = Point(p1.getX(), p1.getY())
            line = graphics.Line(p1, p2)
            cloc.col = cloc.col - 1
    Now it says getX not defined every time i press a key is this because of p2???

    ive found this in the module about Point

    Code:
    class Point(GraphicsObject)
    Method resolution order:
        Point
        GraphicsObject
        builtins.object
    
    Methods defined here:
    
    __init__(self, x, y)
    
    clone(self)
    
    getX(self)
    
    getY(self)
  • bvdet
    Recognized Expert Specialist
    • Oct 2006
    • 2851

    #2
    Without seeing your code for "Circle", I have no way of knowing what your problem is other than you did not define a method "center()".

    Comment

    • lightning18
      New Member
      • May 2010
      • 16

      #3
      Originally posted by bvdet
      Without seeing your code for "Circle", I have no way of knowing what your problem is other than you did not define a method "center()".
      ey ive just shown u the code for circle its right there lol andi have edited my question of my post and my code
      # c is my circle

      Comment

      • bvdet
        Recognized Expert Specialist
        • Oct 2006
        • 2851

        #4
        You are calling getX() as though it is a stand-alone function when it is actually a Point object method. Try this:
        Code:
        p2 = Point(c.getCenter().getX(), c.getCenter().getY())

        Comment

        • lightning18
          New Member
          • May 2010
          • 16

          #5
          Originally posted by bvdet
          You are calling getX() as though it is a stand-alone function when it is actually a Point object method. Try this:
          Code:
          p2 = Point(c.getCenter().getX(), c.getCenter().getY())
          thanx bvdet i did what u said but now i get another error which is
          Code:
          Exception in Tkinter callback
          Traceback (most recent call last):
            File "C:\Python31\lib\tkinter\__init__.py", line 1399, in __call__
              return self.func(*args)
            File "C:\Python31\mazefiddle.py", line 38, in handleKeys
              p2 = Point(c.getCenter.getX(), c.getCenter().getY())
          AttributeError: 'function' object has no attribute 'getX'
          Any ideas why still a getX error whys dat?

          Comment

          • bvdet
            Recognized Expert Specialist
            • Oct 2006
            • 2851

            #6
            Look carefully:
            Code:
            p2 = Point(c.getCenter().getX(), c.getCenter().getY())
            You are not calling getCenter().

            Comment

            • lightning18
              New Member
              • May 2010
              • 16

              #7
              Originally posted by bvdet
              Look carefully:
              Code:
              p2 = Point(c.getCenter().getX(), c.getCenter().getY())
              You are not calling getCenter().
              what you mean iam not calling getCenter? it is in my p1 and p2 shouldnt it be called already?
              how do i call something then?
              I also changed my code for the p2 bit

              Comment

              • bvdet
                Recognized Expert Specialist
                • Oct 2006
                • 2851

                #8
                Originally posted by lightning18
                what you mean iam not calling getCenter? it is in my p1 and p2 shouldnt it be called already?
                how do i call something then?
                I also changed my code for the p2 bit
                Take a look at this code, and tell me if you see any difference between "p.uv" and "p.uv()".
                Code:
                >>> p = Pt3D(1,2,3)
                >>> p.uv
                <bound method Pt3D.uv of Pt3D(1.000000, 2.000000, 3.000000)>
                >>> p.uv()
                Pt3D(0.267261, 0.534522, 0.801784)
                >>>
                "p.uv" returns the method bound to instance "p" and "p.uv()" calls method "uv()". The difference is the parentheses.

                Comment

                • lightning18
                  New Member
                  • May 2010
                  • 16

                  #9
                  Originally posted by bvdet
                  Take a look at this code, and tell me if you see any difference between "p.uv" and "p.uv()".
                  Code:
                  >>> p = Pt3D(1,2,3)
                  >>> p.uv
                  <bound method Pt3D.uv of Pt3D(1.000000, 2.000000, 3.000000)>
                  >>> p.uv()
                  Pt3D(0.267261, 0.534522, 0.801784)
                  >>>
                  "p.uv" returns the method bound to instance "p" and "p.uv()" calls method "uv()". The difference is the parentheses.
                  so is this what you are saying ?
                  if i have
                  (
                  Code:
                  p1 = Point(c.getcenter().getX(), c.getcenter.getY())
                  p2 = Point(p1.getcenter().getX(), p1.getcenter().getY()
                  or you saying
                  Code:
                  p1.p2()
                  something like that
                  i understand it but do not know whot to implement it with my code bit confused how mine needs to be like that
                  thanks

                  Comment

                  • bvdet
                    Recognized Expert Specialist
                    • Oct 2006
                    • 2851

                    #10
                    p2 = Point(c.getCent er.getX(), c.getCenter().g etY())
                    The line of code above should be
                    Code:
                    p2 = Point(c.getCenter().getX(), c.getCenter().getY())
                    You left out the parentheses after "c.getCente r".

                    Comment

                    Working...