Skip to main content

Timeline for How clean is my snow?

Current License: CC BY-SA 3.0

18 events
when toggle format what by license comment
Jan 29, 2019 at 19:27 comment added Sjoerd Job Postmus @Schmuddi: As far as I know it has always been the same. [value] * 5 creates a list of 5 entries each referring to the same object, not 5 copies of the object.
Jan 28, 2019 at 16:58 comment added Schmuddi Wow... yes, you're right – I stand corrected. Now, I remember using this type of code for a simple tile-based game years ago in Python 2.1. Has this behavior changed over time?
Jan 28, 2019 at 15:26 comment added Sjoerd Job Postmus @Schmuddi: Please consider out = [[' '] * 7] * 5 followed by out[3][4] = 'X'. Then, out[2][4] will also be set to X, as out[0]..out[4] all reference the same list. A valid alternative might be out = [[' '] * screen[x'] for _ in range(screen['y'])].
Jan 27, 2019 at 7:26 comment added Schmuddi Your version of drawDrops() uses two list generator expressions with underscore dummy variables to initialize out. This is not very expressive – I'd suggest to use the much faster and more explicit alternative out = [[' '] * screen['x']] * screen['y']instead.
Feb 2, 2016 at 14:47 comment added njzk2 @JAtkin (0.5, 1)[i%2] is a little more compact for the speed selection.
Feb 2, 2016 at 13:29 comment added J Atkin @njzk2 Yes, out[drop.y][drop.x] = '#' require a test does, when I rewrote my code I noticed this exact problem. The intent of the speed was to get 0.5 and 1 speed flakes. The flakes that are halfway between pixels are rounded down with int(), and only move every other frame. min((i % 2) + 0.5, 1) is rather clumsy, but I couldn't think of anything better at the moment.
Feb 2, 2016 at 10:06 history edited Sjoerd Job Postmus CC BY-SA 3.0
Removed remark about non-integral `y` (it was speed), and fixed the writing out-of-bounds.
Feb 1, 2016 at 23:43 comment added Sjoerd Job Postmus @njzk2: you're totally right about the out-of-bounds check regarding drop.y during drawing. I was pondering suggesting automated drop removal, but that clashes with the counting to 100.
Feb 1, 2016 at 23:41 comment added Sjoerd Job Postmus @njzk2: after re-reading, the statement is min((i % 2) + 0.5, 1). This takes values (1.0, 1.5)[i % 2]. It might not be what is intended, but it is the current value.
Feb 1, 2016 at 23:31 comment added njzk2 @SjoerdJobPostmus I'm not sure what the intent of the OP is regarding the speed. It looks like it should be 0.5 or 1, so maybe (1.0, 0.5)[i%2]
Feb 1, 2016 at 23:28 comment added njzk2 out[drop.y][drop.x] = '#' requires a prior test, because the drops are exiting the screen at some point
Feb 1, 2016 at 23:28 comment added Sjoerd Job Postmus @njzk2: thanks. I'll take time to fix it tomorrow. Or maybe you can propose an edit?
Feb 1, 2016 at 23:26 comment added njzk2 @SjoerdJobPostmus your remark on y, it is not y, it is speed.
Feb 1, 2016 at 20:00 comment added Sjoerd Job Postmus @JAtkin: snake-case, except for classes which should be PascalCase.
Feb 1, 2016 at 18:07 comment added J Atkin A rather off topic question, is it more common in python to see snake_cased_names or camelCaseNames? (I think the python style guide uses snake_case, though personally I like camelCase much better)
Feb 1, 2016 at 16:31 vote accept J Atkin
Feb 1, 2016 at 16:30 comment added J Atkin Thanks for the answer! This does look much better than my original code. A minor point: in createRandomDrops you point out the min((i % 2) + 0.5, 1) and change it to min(int(i % 2 + 0.5), 1), the original was actually intended to use floats, it changes a number to 1 or 0.5 so I could get a half step snow flake, though it is a bit hard to tell...
Feb 1, 2016 at 15:59 history answered Sjoerd Job Postmus CC BY-SA 3.0