Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.mixmin.net!eweka.nl!hq-usenetpeers.eweka.nl!xlned.com!feeder5.xlned.com!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.011 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; '16,': 0.03; 'skip:\xa0 30': 0.05; 'column': 0.07; 'list?': 0.07; 'subject:Question': 0.07; 'classes.': 0.09; 'function,': 0.09; 'grid': 0.09; 'try:': 0.09; 'width': 0.09; 'runs': 0.10; 'cc:addr:python-list': 0.11; 'python': 0.11; 'def': 0.12; 'assume': 0.14; 'itself.': 0.14; 'language.': 0.14; '(0,': 0.16; '20)': 0.16; 'arg2,': 0.16; 'be:': 0.16; 'call?': 0.16; 'excellent,': 0.16; 'formula': 0.16; 'function?': 0.16; 'likewise': 0.16; 'non-trivial': 0.16; 'pygame': 0.16; 'thoroughly.': 0.16; '(you': 0.16; 'wrote:': 0.18; 'do.': 0.18; 'wed,': 0.18; 'bit': 0.19; 'seems': 0.21; '8bit%:5': 0.22; 'appears': 0.22; 'programming': 0.22; 'cc:addr:python.org': 0.22; 'replace': 0.24; 'skip:\xa0 20': 0.24; '\xa0if': 0.24; "haven't": 0.24; 'cc:2**0': 0.24; 'cc:no real name:2**0': 0.24; '>': 0.26; '15,': 0.26; 'define': 0.26; 'nearly': 0.26; 'header :In-Reply-To:1': 0.27; "doesn't": 0.30; '8bit%:3': 0.30; 'andrew': 0.30; 'message-id:@mail.gmail.com': 0.30; "i'm": 0.30; 'url:mailman': 0.30; 'code': 0.31; 'lines': 0.31; 'too.': 0.31; '13,': 0.31; 'alan': 0.31; 'assumes': 0.31; 'cells': 0.31; 'initialized': 0.31; 'parameters.': 0.31; 'class': 0.32; 'lists': 0.32; 'probably': 0.32; 'another': 0.32; 'quite': 0.32; 'worked': 0.33; 'url:python': 0.33; "i'd": 0.34; 'could': 0.34; 'classes': 0.35; 'something': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'really': 0.36; '14,': 0.36; 'explains': 0.36; "he's": 0.36; 'height': 0.36; 'url:listinfo': 0.36; 'url:org': 0.36; 'should': 0.36; 'example,': 0.37; 'list': 0.37; 'list.': 0.37; 'being': 0.38; 'represent': 0.38; 'thank': 0.38; 'list,': 0.38; 'pm,': 0.38; 'previous': 0.38; 'skip:& 20': 0.39; '12,': 0.39; '\xa0\xa0\xa0': 0.39; 'delete': 0.39; 'url:mail': 0.40; 'how': 0.40; 'skip:u 10': 0.60; 'around.': 0.60; 'dave': 0.60; 'utilize': 0.61; 'new': 0.61; 'numbers': 0.61; 'entire': 0.61; 'simply': 0.61; 'simple': 0.61; "you're": 0.61; 'here:': 0.62; "you've": 0.63; 'show': 0.63; 'kind': 0.63; 'such': 0.63; 'decided': 0.64; 'week,': 0.64; 'more': 0.64; 'taking': 0.65; '(that': 0.65; 'afraid': 0.65; 'size.': 0.65; 'reply': 0.66; 'experience.': 0.67; 'between': 0.67; 'details,': 0.68; 'skip:r 30': 0.69; 'url:me': 0.69; 'demonstrates': 0.84; 'gap': 0.84; 'ian,': 0.84; 'started,': 0.84; 'typically,': 0.84; 'well..': 0.84; '\xa0but': 0.84; 'angel': 0.91; 'good,': 0.91; '2013': 0.98 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:in-reply-to:references:date:message-id :subject:from:to:cc:content-type; bh=5zxNxXtxYfnVBtaBPnId5AR48AdDeCqQtYMBiwYLJnM=; b=UtAlC3aC83UavHu+tLiP2eCnGBTbp5WOVZA8boBriBBfYvMJnuQd7XWMk3poDpC98P ibVfrPFA7Q3+DNZ5565UHPfOEXY3ukqcdPxrylDhK2xuRe5otc5TjT0HngKB0q6GfBSP bAVE6aFm7lMPMkGzFtfK1sywDtz6umi4A9Zg4crS9+gCZqQZLrcWSdVp39PH70wX+38y TDvP4PlD08ak6xWxfaO3/6L1BJ1uVVNPPhpg+V/H8NEDTofamLdq/XUxzxUU9TAXR0HK 6+zyRAFeeGyax2tFAva8euHUdixADB0r5OVhG7qlPAPDuS0DlRU6O4ELmlrY5t2gos9J 2IhQ== MIME-Version: 1.0 X-Received: by 10.50.114.104 with SMTP id jf8mr6472053igb.77.1368650157559; Wed, 15 May 2013 13:35:57 -0700 (PDT) In-Reply-To: <5193E8C0.1060004@davea.name> References: <5193CC16.80304@davea.name> <5193E8C0.1060004@davea.name> Date: Wed, 15 May 2013 16:35:57 -0400 Subject: Re: Question re: objects and square grids From: Andrew Bradley To: Dave Angel Content-Type: multipart/alternative; boundary=047d7b3a9b267696a104dcc7b242 Cc: python-list@python.org X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 255 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1368650160 news.xs4all.nl 15963 [2001:888:2000:d::a6]:60369 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:45370 --047d7b3a9b267696a104dcc7b242 Content-Type: text/plain; charset=ISO-8859-1 Now I want to show you what I have written: row = (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10) column = (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20) SQUARESIZE = 43 grid = [] for row in range(10): row_squares = [] for column in range(20): rect = Rect(12 + column * SQUARESIZE, 10 + row * SQUARESIZE, SQUARESIZE, SQUARESIZE) row_squares.append(rect) grid.append(row_squares) It appears to be working (that is, the program still runs without crashing). So now, how can I utilize this new grid list? Thank you for the help so far, I feel like the entire grid is now being worked out. -Andrew On Wed, May 15, 2013 at 3:57 PM, Dave Angel wrote: > On 05/15/2013 02:14 PM, Andrew Bradley wrote: > > Please reply on the list, not privately, unless it's something like a > simple thank-you. Typically, you'd do a reply-all, then delete the people > other than the list itself. Or if you're using Thunderbird, you could just > reply-list. > > > Thank you very much for your response: it seems excellent, but I'm > afraid I > > do not understand it fully. Your code here: > > > > > maxrows = 10 > > maxcols = 20 > > grid = [] > > for row in range(maxrows): > > rowdata = [] > > for column in range(maxcols): > > arg1 = ... > > arg2 = ... > > arg3 = ... > > arg4 = ... > > rowdata.append(pygame.Rect(arg > > 1, arg2, arg3, arg4) > > grid.append(rowdata) > > > > Seems very good, but keep in mind I just started programming last week, > and > > this is hard for me to wrap my head around. Do I really just write grid = > > []? or is this like a def grid(): function? > > This code was intended to replace the 200 lines you started, A1= pygame... > A2= A3= etc. I'd have put them inside a function, but this is just one > of the things I'd have initialized in such a function. grid is a list of > lists, not a function. > > > > What do you mean by rowdata = []? > > [] is the way you define an empty list. Another way might be: > rowdata = list() > > > > And how exactly would I make the formula for a rect call? > > Well, for row==0 and col==0, you say you wanted 10, 12, 43, and 43 for the > four parameters. But you never said how you were going to (manually) > calculate those numbers for other cells. Only once you've decided that can > you fill in "formulas" for arg1 and arg2. I suspect that arg3 and arg4 are > simply 43 and 43 respectively, since you want all the cells to be the same > size. > > taking my clue from Ian, I might try: > > x_offset = 10 > y_offset = 12 > width = height = 43 > arg1 = column * width + x_offset > arg2 = row * height + y_offset > arg3 = width > arg4 = height > > That assumes that there is no gap between cells in this grid. If you want > a gap, then the width value used in the arg1 formula would be more than 43 > (width). Likewise the height value used in the arg2 formula would be more > than 43 (height). > > > If there's a good website for these kind of details, I would appreciate > that too. > > You cannot begin to write a non-trivial program in Python without > understanding lists pretty thoroughly. Perhaps you should start with Alan > Gauld's tutorial, which doesn't assume previous programming experience. > http://www.alan-g.me.uk/ > > I haven't studied it, as Python was about my 35th programming language. > But he's very active on Python-tutor, and explains things very well. So > his website is probably very good as well. > > Now, as you can see from Ian's message, writing a game using pygame will > require quite a bit of other understanding. He demonstrates with classes > to represent cells, which is indeed what I'd do. But I suspect you're not > nearly ready to consider writing classes. (You use classes all the time. > For example, 5 is an instance of class int.) > > > -- > DaveA > > > > -- > DaveA > -- > http://mail.python.org/**mailman/listinfo/python-list > --047d7b3a9b267696a104dcc7b242 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
Now I want to show you what I have written:

row =3D (0, 1, 2= , 3, 4, 5, 6, 7, 8, 9, 10)
column =3D (0, 1, 2, 3, 4, 5, 6, 7, 8, = 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20)
SQUARESIZE =3D 43

grid =3D []
for row in range(= 10):
=A0=A0=A0 row_squares =3D []
=A0=A0=A0 for column in= range(20):
=A0=A0=A0=A0=A0=A0=A0 rect =3D Rect(12 + column * SQUA= RESIZE, 10 + row * SQUARESIZE, SQUARESIZE, SQUARESIZE)
=A0=A0=A0=A0=A0=A0=A0 row_squares.append(rect)
=A0=A0=A0 gri= d.append(row_squares)

It appears to be working (that is, the p= rogram still runs without crashing). So now, how can I utilize this new gri= d list? Thank you for the help so far, I feel like the entire grid is now b= eing worked out.
-Andrew



On Wed, May 15, 2013 at 3:= 57 PM, Dave Angel <davea@davea.name> wrote:
On 05/15/2013 02:14 PM, Andrew Bradley wrote= :

Please reply on the list, not privately, unless it's something like a s= imple thank-you. =A0Typically, you'd do a reply-all, then delete the pe= ople other than the list itself. =A0Or if you're using Thunderbird, you= could just reply-list.

> Thank you very much for your response: it seems excellent, but I'm= afraid I
> do not understand it fully. Your code here:

>
> maxrows =3D 10
> maxcols =3D 20
> grid =3D []
> for row in range(maxrows):
> =A0 =A0 =A0rowdata =3D []
> =A0 =A0 =A0for column in range(maxcols):
> =A0 =A0 =A0 =A0 =A0arg1 =3D ...
> =A0 =A0 =A0 =A0 =A0arg2 =3D ...
> =A0 =A0 =A0 =A0 =A0arg3 =3D ...
> =A0 =A0 =A0 =A0 =A0arg4 =3D ...
> =A0 =A0 =A0 =A0 =A0rowdata.append(pygame.Rect(arg
> 1, arg2, arg3, arg4)
> =A0 =A0 =A0grid.append(rowdata)
>
> Seems very good, but keep in mind I just started programming last week= , and
> this is hard for me to wrap my head around. Do I really just write gri= d =3D
> []? or is this like a def grid(): function?

This code was intended to replace the 200 lines you started, A1=3D pygame..= . A2=3D =A0A3=3D =A0 etc. =A0I'd have put them inside a function, but t= his is just one of the things I'd have initialized in such a function. = =A0grid is a list of lists, not a function.


> What do you mean by rowdata =3D []?

[] is the way you define an empty list. =A0Another way might be:
=A0 =A0 rowdata =3D list()


> And how exactly would I make the formula for a rect call?

Well, for row=3D=3D0 and col=3D=3D0, you say you wanted 10, 12, 43, and 43 = for the four parameters. =A0 But you never said how you were going to (manu= ally) calculate those numbers for other cells. =A0Only once you've deci= ded that can you fill in "formulas" for arg1 and arg2. =A0I suspe= ct that arg3 and arg4 are simply 43 and 43 respectively, since you want all= the cells to be the same size.

taking my clue from Ian, I might try:

=A0 =A0 x_offset =3D 10
=A0 =A0 y_offset =3D 12
=A0 =A0 width =3D height =3D 43
=A0 =A0 arg1 =3D column * width + x_offset
=A0 =A0 arg2 =3D row * height + y_offset
=A0 =A0 arg3 =3D width
=A0 =A0 arg4 =3D height

That assumes that there is no gap between cells in this grid. =A0If you wan= t a gap, then the width value used in the arg1 formula would be more than 4= 3 (width). =A0Likewise the height value used in the arg2 formula would be m= ore than 43 (height).

> If there's a good website for these kind of details, I would appre= ciate that too.

You cannot begin to write a non-trivial program in Python without understan= ding lists pretty thoroughly. =A0Perhaps you should start with Alan Gauld&#= 39;s tutorial, which doesn't assume previous programming experience. =A0 =A0http://www.al= an-g.me.uk/

I haven't studied it, as Python was about my 35th programming language.= =A0But he's very active on Python-tutor, and explains things very well= . So his website is probably very good as well.

Now, as you can see from Ian's message, writing a game using pygame wil= l require quite a bit of other understanding. =A0He demonstrates with class= es to represent cells, which is indeed what I'd do. =A0But I suspect yo= u're not nearly ready to consider writing classes. =A0(You use classes = all the time. =A0For example, 5 is an instance of class int.)


--
DaveA

--047d7b3a9b267696a104dcc7b242--