Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #90423

Re: How to properly apply OOP in the bouncing ball code

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!1.eu.feeder.erje.net!bcyclone04.am1.xlned.com!bcyclone04.am1.xlned.com!newsfeed.xs4all.nl!newsfeed1a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.001
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'position,': 0.05; 'subject:code': 0.07; 'attributes': 0.09; 'friday,': 0.09; 'oop': 0.09; 'prefix': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'screen.': 0.09; 'terms,': 0.09; "they've": 0.09; 'worse': 0.09; 'subject:How': 0.10; 'python': 0.11; '(which,': 0.16; '>on': 0.16; 'ball.': 0.16; 'balls': 0.16; 'bouncing': 0.16; 'compute': 0.16; 'denotes': 0.16; 'display)': 0.16; 'fit,': 0.16; 'message-id:@4ax.com': 0.16; 'nodes': 0.16; 'objects.': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'settings,': 0.16; 'side.': 0.16; 'steps,': 0.16; 'subject:OOP': 0.16; 'tommy': 0.16; 'language': 0.16; 'wrote:': 0.18; 'trying': 0.19; 'advance.': 0.19; 'fit': 0.20; 'settings': 0.22; 'programming': 0.22; 'error': 0.23; 'url:home': 0.24; 'mon,': 0.24; 'query': 0.26; 'pass': 0.26; '(for': 0.26; 'world,': 0.26; 'asking': 0.27; 'gets': 0.27; 'header:X-Complaints-To:1': 0.27; 'appear': 0.29; 'appreciated.': 0.29; 'related': 0.29; 'direction': 0.30; 'errors': 0.30; 'mode': 0.30; "i'm": 0.30; 'code': 0.31; 'getting': 0.31; 'easier': 0.31; 'another.': 0.31; 'ball': 0.31; 'commonly': 0.31; 'dimensions': 0.31; 'implied': 0.31; 'name;': 0.31; 'allows': 0.31; 'class': 0.32; 'probably': 0.32; 'text': 0.33; 'open': 0.33; 'community': 0.33; 'position.': 0.33; 'screen': 0.34; 'updated': 0.34; 'subject:the': 0.34; "i'd": 0.34; 'problem': 0.35; 'knows': 0.35; 'objects': 0.35; 'but': 0.35; 'there': 0.35; '(e.g.,': 0.36; 'controls': 0.36; 'edge': 0.36; 'scheme': 0.36; 'next': 0.36; 'method': 0.36; 'charset:us-ascii': 0.36; 'thanks': 0.36; 'should': 0.36; 'virtual': 0.37; 'list': 0.37; 'conditions.': 0.38; 'handle': 0.38; 'to:addr:python-list': 0.38; 'track': 0.38; 'does': 0.39; 'aspects': 0.39; 'moving': 0.39; 'to:addr:python.org': 0.39; 'either': 0.39; 'received:org': 0.40; 'called': 0.40; 'even': 0.60; 'color': 0.61; 'new': 0.61; 'numbers': 0.61; 'matter': 0.61; 'skip:* 10': 0.61; 'simple': 0.61; 'making': 0.63; 'different': 0.65; 'temporary': 0.65; 'life': 0.66; 'world': 0.66; 'note:': 0.66; 'physical': 0.72; '*data': 0.84; '2015': 0.84; 'bounded': 0.84; 'disappear': 0.84; 'simulation.': 0.84; 'viable': 0.84; 'bounce': 0.91; 'graphical': 0.91; 'simulation': 0.91
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Dennis Lee Bieber <wlfraed@ix.netcom.com>
Subject Re: How to properly apply OOP in the bouncing ball code
Date Mon, 11 May 2015 20:24:32 -0400
Organization IISS Elusive Unicorn
References <009ceef8-066d-4d92-a6c9-761e86584e75@googlegroups.com> <45313faa-d256-4fa4-9e37-4b8dd85e1681@googlegroups.com>
Mime-Version 1.0
Content-Type text/plain; charset=us-ascii
Content-Transfer-Encoding 7bit
X-Gmane-NNTP-Posting-Host adsl-108-79-222-12.dsl.klmzmi.sbcglobal.net
X-Newsreader Forte Agent 6.00/32.1186
X-No-Archive YES
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.20+
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.383.1431390292.12865.python-list@python.org> (permalink)
Lines 63
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1431390292 news.xs4all.nl 2851 [2001:888:2000:d::a6]:58243
X-Complaints-To abuse@xs4all.nl
X-Received-Bytes 8081
X-Received-Body-CRC 3213961658
Xref csiph.com comp.lang.python:90423

Show key headers only | View raw


On Mon, 11 May 2015 08:33:56 -0700 (PDT), zipher
<dreamingforward@gmail.com> declaimed the following:

>On Friday, May 8, 2015 at 10:40:46 AM UTC-5, Tommy C wrote:
>> I'm trying to apply OOP in this bouncing ball code in order to have multiple balls bouncing around the screen. The objective of this code is to create a method called settings, which controls all the settings for the screen and the bouncing behaviour of multiple balls, under the class Ball. However, I keep on getting errors related to attributes (e.g., speed). I'm new to OOP in Python so your help will be much appreciated. Thanks in advance.
>
>You are making a error that few in the programming community have caught up to.  OOP design for *data abstraction* is a completely different beast that OOP for *simulation*.  The confusion is around the use of the word "object" which both denotes a physical world item and a virtual one detached from reality.
>
>I would say that Python might not be the right fit, but instead a language dedicated to simulation.

	The danger there is that a "language dedicated to simulation" might
mean "discrete event" simulation -- which would be an even worse fit to a
problem of particle motion simulation.

For the OP:

	In simple terms, attributes will appear in the methods of the object
class as "self.attribute" (presuming you use the normal practice of using
"self" in the method signature). Names that don't have the "self." prefix
appearing in a method are just temporary local storage (they disappear when
the method exits).

	Ball objects would have a velocity (which, properly, is a speed AND a
direction -- presuming a 2-D world, dX/time-unit and dY/time-unit is
probably easier to track than dDistance/time-unit and Azimuth; that is
10pixelX/sec, 5pixelY/sec is easier than [not the same velocity, just
numbers for an example] 12pixels @ 30degrees)... Other potential attributes
are (for graphical display) color and/or (for text output) name; radius...

	The "world" would contain the dimensions of the, uhm, world (and if it
is bounded [walls, balls bounce off] or open [no walls, balls that go off
the edge are lost] or closed [no walls, balls that go off one edge reappear
on the other... Ever play Asteroids?].

	The world would contain a list of Ball objects.

	Now -- who manages the position of the balls? Should a ball know where
it is, or is that only a matter for the world to know? This gets into
design aspects that may have viable answers on either side. If the ball
knows its position, the world has to ask each ball for the position (and
radius) and then ask each other ball is ballX (pos/radius) has bumped into
it. If the world keeps the positions, it has to pass them in to the balls
to update based on velocity, but it can (after asking for radius) compute
if any ball has hit another.

	I suspect I'd write this with the balls knowing their position --
making a simple ball.update(time_delta) [time_delta allows the world to
control the granularity of time steps, as long as it uses the same
time_delta for all balls per cycle]. Update would have the ball compute its
new position. The world would then query the ball for new location to
update the display... The world would also ask other balls if they've been
impacted.

	NOTE: this scheme does have an implied priority -- no mutual impactors.
Conway's Game of Life commonly uses a double buffered mode -- all nodes are
updated [into "next generation"] based on the "current" generation
conditions. To do that with the balls means .update has to generate a
"next" position -- THEN you handle all collisions based on "next", before
moving all "next" into "current" to start the next cycle.
-- 
	Wulfraed                 Dennis Lee Bieber         AF6VN
    wlfraed@ix.netcom.com    HTTP://wlfraed.home.netcom.com/

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

How to properly apply OOP in the bouncing ball code Tommy C <tommyc168168@gmail.com> - 2015-05-08 08:40 -0700
  Re: How to properly apply OOP in the bouncing ball code Mel Wilson <mwilson@the-wire.com> - 2015-05-08 18:44 +0000
  Re: How to properly apply OOP in the bouncing ball code Ian Kelly <ian.g.kelly@gmail.com> - 2015-05-08 10:22 -0600
  Re: How to properly apply OOP in the bouncing ball code Tommy C <tommyc168168@gmail.com> - 2015-05-11 08:22 -0700
    Re: How to properly apply OOP in the bouncing ball code Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2015-05-12 17:53 +0100
  Re: How to properly apply OOP in the bouncing ball code zipher <dreamingforward@gmail.com> - 2015-05-11 08:33 -0700
    Re: How to properly apply OOP in the bouncing ball code Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2015-05-11 20:24 -0400
      Re: How to properly apply OOP in the bouncing ball code zipher <dreamingforward@gmail.com> - 2015-05-11 17:42 -0700
        Re: How to properly apply OOP in the bouncing ball code Terry Reedy <tjreedy@udel.edu> - 2015-05-12 11:45 -0400
          Re: How to properly apply OOP in the bouncing ball code Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2015-05-13 20:20 +1200

csiph-web