473,507 Members | 2,776 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to attach a line to a moving object?

16 New Member
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
Expand|Select|Wrap|Line Numbers
  1. from graphics import*
  2. from maze import*
my circle which is my cell

Expand|Select|Wrap|Line Numbers
  1. center = Point(15, 15)
  2. c = Circle(center, 12)
  3. c.setFill('blue')
  4. c.setOutline('yellow')
  5. c.draw(win)
  6.  
  7. p1 = Point(c.getCenter().getX(), c.getCenter().getY())
  8. this is my loop
  9.  
  10.  if mazez.blockedCount(cloc)> 2: 
  11.             mazez.addDecoration(cloc, "grey")
  12.             mazez[cloc].deadend = True
  13.         c.move(-25, 0)
  14.         p2 = Point(p1.getX(), p1.getY())
  15.         line = graphics.Line(p1, p2)
  16.         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

Expand|Select|Wrap|Line Numbers
  1. class Point(GraphicsObject)
  2. Method resolution order:
  3.     Point
  4.     GraphicsObject
  5.     builtins.object
  6.  
  7. Methods defined here:
  8.  
  9. __init__(self, x, y)
  10.  
  11. clone(self)
  12.  
  13. getX(self)
  14.  
  15. getY(self)
Jun 12 '10 #1
9 1705
bvdet
2,851 Recognized Expert Moderator Specialist
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()".
Jun 12 '10 #2
lightning18
16 New Member
@bvdet
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
Jun 12 '10 #3
bvdet
2,851 Recognized Expert Moderator Specialist
You are calling getX() as though it is a stand-alone function when it is actually a Point object method. Try this:
Expand|Select|Wrap|Line Numbers
  1. p2 = Point(c.getCenter().getX(), c.getCenter().getY())
Jun 12 '10 #4
lightning18
16 New Member
@bvdet
thanx bvdet i did what u said but now i get another error which is
Expand|Select|Wrap|Line Numbers
  1. Exception in Tkinter callback
  2. Traceback (most recent call last):
  3.   File "C:\Python31\lib\tkinter\__init__.py", line 1399, in __call__
  4.     return self.func(*args)
  5.   File "C:\Python31\mazefiddle.py", line 38, in handleKeys
  6.     p2 = Point(c.getCenter.getX(), c.getCenter().getY())
  7. AttributeError: 'function' object has no attribute 'getX'
Any ideas why still a getX error whys dat?
Jun 12 '10 #5
bvdet
2,851 Recognized Expert Moderator Specialist
Look carefully:
Expand|Select|Wrap|Line Numbers
  1. p2 = Point(c.getCenter().getX(), c.getCenter().getY())
You are not calling getCenter().
Jun 12 '10 #6
lightning18
16 New Member
@bvdet
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
Jun 13 '10 #7
bvdet
2,851 Recognized Expert Moderator Specialist
@lightning18
Take a look at this code, and tell me if you see any difference between "p.uv" and "p.uv()".
Expand|Select|Wrap|Line Numbers
  1. >>> p = Pt3D(1,2,3)
  2. >>> p.uv
  3. <bound method Pt3D.uv of Pt3D(1.000000, 2.000000, 3.000000)>
  4. >>> p.uv()
  5. Pt3D(0.267261, 0.534522, 0.801784)
  6. >>> 
"p.uv" returns the method bound to instance "p" and "p.uv()" calls method "uv()". The difference is the parentheses.
Jun 13 '10 #8
lightning18
16 New Member
@bvdet
so is this what you are saying ?
if i have
(
Expand|Select|Wrap|Line Numbers
  1. p1 = Point(c.getcenter().getX(), c.getcenter.getY())
  2. p2 = Point(p1.getcenter().getX(), p1.getcenter().getY()
or you saying
Expand|Select|Wrap|Line Numbers
  1. 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
Jun 14 '10 #9
bvdet
2,851 Recognized Expert Moderator Specialist
p2 = Point(c.getCenter.getX(), c.getCenter().getY())
The line of code above should be
Expand|Select|Wrap|Line Numbers
  1. p2 = Point(c.getCenter().getX(), c.getCenter().getY())
You left out the parentheses after "c.getCenter".
Jun 14 '10 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

2
1278
by: cain | last post by:
Hi, I'm new to ASP so bare with me here. I just coded a page and I'm getting an error on line 3, which is the attach line. According to the references I have, this is the correct way to do...
0
2629
by: ding feng | last post by:
I have got formatted files. All of these file takes this form: obj1 method1 obj2 string1 obj3 string2 argument. Of course, each file can have maximum fields as shown above, or minimun fields...
5
1689
by: nukiboy | last post by:
========= test.js =================== function Test() { this.temp = "hehehehe" ; this.method1 = method1 ;
0
1353
by: t2581 | last post by:
I want to run single script that will attach to instance and restore db example file restore_on_dev1.txt -- file restore_on_dev1.txt attach to DEV1 user bamboo using 123456; restote database...
1
15603
by: andrewcw | last post by:
( excuse earlier bad post, I was attemptingt to use tab key which sent message ). I am using a class genereated by XSD. From data I will collect I plan to build the object & serialize as XMl...
2
1094
by: Steve Amey | last post by:
Hi all At the moment I am using the following code to check to see if the oTempDataSet is not nothing and that it has tables in it: If Not oTempDataSet Is Nothing Then If...
2
1047
by: Steve Long | last post by:
Hello, I'm trying to create an object at runtime. The way I used to do this in the COM (vb6) world was to use the ProgID such as: PublicWorksPlugin.PWPlug I kind of know how to do this in .NET...
2
2142
by: kujtim | last post by:
i have problem using ajaxlib.js i have includet as it should in the same directoryy the ajaxlib.js with my codee but i am reciving error "line 15 object required " . here is my...
0
885
by: zjs | last post by:
class CChatSocket : public CSocket { .... } void CChatSocket::OnReceive(int nErrorCode) { CSocket::OnReceive(nErrorCode);//Here I insert a breakpoint, m_pDoc->ProcessPendingRead(); }
10
18878
EJaques
by: EJaques | last post by:
(Using Access 2003) I have a an Object OLE field in a table where users can insert Excel sheets, Word Docs, Pdfs etc. I need to create a button on a formulaire that allows the user to browse...
0
7221
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7109
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7313
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7372
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7029
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5619
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
3190
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3179
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1537
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.