473,770 Members | 4,522 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to bounce a ball within a square?

1 New Member
I am doing a project of creating a playing pool and 2 balls bouncing within the pool. I have tried to use "while loop" and "if statement" to set restriction limiting the ball not to bounce out of the pool. However, the ball doesn't move or bounce.

It moves but stops after it hits one of the walls when I write this function below:
Expand|Select|Wrap|Line Numbers
  1. def move_ball(heading):
  2.     t1=turtle.Pen()
  3.     t1.color("yellow")
  4.     t1.shape("circle")
  5.     x,y=turtle.position()
  6.     while 200 > (t1.xcor()) >-200 and -90< (t1.ycor())<90:
  7.         t1.forward(1)
  8.         t1.setheading(heading)  
But, it doesn't move at all when I write this function below:
Expand|Select|Wrap|Line Numbers
  1. # here I try to do all restrictions of 4 walls  
  2.  
  3. # just 2 walls here
  4.  
  5. def wall_bottom(heading):
  6.     t1=turtle.Pen()
  7.     t1.color("yellow")
  8.     t1.shape("circle")
  9.     current=0
  10.     if 100<t1.ycor()<-100:
  11.         if 270 < t1.setheading() < 360:
  12.             t1.forward(1)
  13.             t1.setheading(0+(360-(t1.heading())))
  14.         else:
  15.             t1.forward(1)
  16.             t1.setheading(180-(t1.heading()-180))
  17.  
  18. def wall_top(heading):
  19.     t1=turtle.Pen()
  20.     t1.color("yellow")
  21.     t1.shape("circle")
  22.     if 200> t1.xcor() >-200:
  23.         if 90> t1.setheading()<0:
  24.             t1.forward(1)
  25.             t1.setheading(0-(180-(t1.heading())))
  26.         else:
  27.             t1.forward(1)
  28.             t1.setheading(180-(t1.heading()-180))
I don't know if I am doing the right things. This is so confusing. Please Help me for this. I want the ball bounce. Thanks!
Feb 16 '09 #1
0 1979

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

Similar topics

4
2641
by: Bloon | last post by:
I have a question that how to debug a program only having .exe file. Is there any techniques or tools that can do that? Thanks a lot.
12
2911
by: Gerard Flanagan | last post by:
Hello I'm pretty new to Python and was wondering why the 'Square' method in the following code doesn't work. It doesn't fail, just doesn't do anything ( at least, not what I'd like! ). Why doesn't 'A.a' equal 2 after squaring? TIA. class FibonacciMatrix:
2
2290
by: Arjen | last post by:
Hello, When I send an e-mail to this sample e-mail address sample@mail.com then there are three options. 1. The e-mail comes over; 2. The e-mail bounce, because the e-mail address doesn't excist; 3. The e-mail bounce, because the e-mail box is full. Is it posible to check these options?
3
2217
by: Darren Clark | last post by:
HI, I am after some assistance in finding what is the best way to parse through bounce back text...... because each server is different i cant really depend on Line x being the line where the error message is... the only reliable way i can think of it so search for the error message by name,
2
2006
by: Phlip | last post by:
Newsgroupies: One myth about USENET is that each group has a charter; some "official" list of on-topic concepts. When a post arrives "violating" this myth, the replies that support the myth can in fact damage a newsgroup's health. This post is a seasonal feature on behalf of the bouncier regulars here. news:comp.lang.c++ discusses an advanced language often thrust upon neophytes. They frequently misunderstand the relationships...
8
1558
by: bevanward | last post by:
Hi all I have a large data set of points situated in 3d space. I have a simple primary key and an x, y and z value. What I would like is an efficient method for finding the group of points within a threshold. So far I have tested the following however it is very slow.
7
3999
by: Bigs | last post by:
Source: http://fileho.com/download/120846695042/bounce2.zip.html How would I go about making a wall for my bouncing ball? For example if the ball hit the center box it would bounce.
2
1773
by: SilentCodingOne | last post by:
I have a application where each time you click the add ball button a new randomly colored ball is added to the jpanel. It works fine except that the balls suddenly stop at the same spot. I want them to continue to bounce for a longer period of time instead of like 8 bounces. It was going around withoutstopping prior to my getting the add new ball part working. I cannot seem to figure out what I did wrong. Also curious if anyone new of a tip as...
18
2388
by: Grant Edwards | last post by:
Could whoever is responsible for the gateway that is grabbing my postings off of Usenet and e-mailing them out please fix the headers in the mail messages so that I don't get the bounce messages? While you're at it, might as well fix it for everybody else too. ;) Its a bit rude to send out mass e-mail messages with headers faked up so that the bounce messages go to somebody else.
0
9602
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9439
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10237
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10071
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10017
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9882
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6690
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
2
3589
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2832
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.