code logs -> 2010 -> Wed, 21 Jul 2010< code.20100720.log - code.20100722.log >
--- Log opened Wed Jul 21 00:00:15 2010
00:02 You're now known as TheWatcher[T-2]
00:04 You're now known as TheWatcher[zZzZ]
00:09
< Tarinaky>
No-one about?
00:10 * Vornicus gnaws Tarinaky's head.
00:10
< Tarinaky>
I'm having trouble working out how OOP works in Python.
00:11
< Tarinaky>
Plus I can't figure out how I import custom classes.
00:11
< Vornicus>
All right what are you trying to do.
00:11
< Tarinaky>
At the moment? Stub out a class that encapsulates the game.
00:12
< Vornicus>
Okay. So let's see the code you've written.
00:12
< Tarinaky>
Gimmie a second. I forgot to push.
00:12
< Vornicus>
(though, note: It's generally a better idea to use an entire module for global data, but we'll get to that in a moment)
00:15
< Tarinaky>
Can't figure out how to get eclipse to save my git settings so I don't have to keep entering the uri by hand when I want to push.
00:15
< Tarinaky>
But that's a different problem.
00:16
< Tarinaky>
http://github.com/Tarinaky/becquerel/blob/master/engine.py
00:17
< Vornicus>
RunControl = int <--- If this is supposed to be doing what I suspect it is? It's not.
00:17
< Tarinaky>
How do I declare members?
00:18
< Vornicus>
By assigning to them.
00:18
< Tarinaky>
Isn't what that does?
00:18
< Vornicus>
Yes, but that there is saying that "RunControl is the constructor for integers"
00:18
< Tarinaky>
Oh.
00:19
< Tarinaky>
What's the best way of saying int RunControl then?
00:19
< Vornicus>
Lines 24 and 27 do that. Sort of.
00:19
< Vornicus>
This is Python, you don't need to declare types, and reasonably often you don't need to /care/ about types.
00:19
< Tarinaky>
I feel uncomfortable if I don't at least have a -list- of attributes.
00:20
< Tarinaky>
I mean. How else am I going to be able to keep track of my code? :/
00:20
< Vornicus>
Just put them in the docstring.
00:20
< Tarinaky>
What's a docstring?
00:21
< Vornicus>
If the first thing in a class or function is a string, that string is considered to be the "docstring". You can then see that documentation from within the interpreter.
00:22
< Vornicus>
Use """triple quotes""" around it, and you can make the docstring several lines long without escaping anything but /other/ triple quotes.
00:26
< Tarinaky>
Gimmie a second. I need to work out how to change the configured git repos before I go mad.
00:29
< Tarinaky>
GAAAAH. >.>
00:30
< Vornicus>
Too late?
00:30
< Tarinaky>
Yeah.
00:31
< Tarinaky>
I'm tinkering with the git repo itself by hand in the hope's I can fix it that way.
00:31
< Tarinaky>
.git/config looks like what I want.
00:32 shade_of_cpux is now known as cpux
00:33 Attilla [Attilla@Nightstar-0e520fa4.threembb.co.uk] has quit [[NS] Quit: ]
00:33
<@ToxicFrog>
Tarinaky: what, exactly, are you trying to do?
00:33
<@ToxicFrog>
I mean, editing .git/config will work, but there's usually a command for it
00:33
< Tarinaky>
I have the wrong uri saved.
00:34
< Tarinaky>
I have it done now anyway.
00:34
< Tarinaky>
Oh no. Nm.
00:34
< Tarinaky>
Still broken :/
00:34
<@ToxicFrog>
Broken in what way?
00:35
< Tarinaky>
It's not working.
00:35
<@ToxicFrog>
...
00:35
< Tarinaky>
It still only works when I enter the uri in as a 'custom uri'.
00:35
< Tarinaky>
Which doesn't save any settings.
00:36
< Tarinaky>
"Can't connect to any repository: "
00:37
<@ToxicFrog>
What commands, and what output?
00:37
< Tarinaky>
I don't know. I'm doing it through eclipse.
00:37
< Tarinaky>
Because the whole point of having a sodding IDE is so I don't have to keep a dozen bloody terminals open.
00:37
< Tarinaky>
"git push" in bash works fine.
00:38
<@ToxicFrog>
Then your first step is to determine whether it's a git problem or an eclipse problem, by trying it through git directly.
00:38
<@ToxicFrog>
Ok then, it's an eclipse problem. Good luck.
00:38
< Tarinaky>
Can I have a decent IDE please?
00:38
< Tarinaky>
inb4 vim/emacs
00:39
<@ToxicFrog>
Personally, I use JEdit, but it's not an IDE, just a powerful editor.
00:39
<@ToxicFrog>
Also I'm pretty sure it has no git integration, although I must confess I haven't looked very hard because I prefer the command line.
00:40
< Tarinaky>
Okay. Lets try this another way.
00:40
< Tarinaky>
How can I 'delete' any reference to origin?
00:41
<@ToxicFrog>
Command line: git remote rm origin
00:41
<@ToxicFrog>
.git/config: delete everything under [remote "origin"] and every line of the form "remote = origin"
00:42
<@ToxicFrog>
Git gui: Remote->Remove->origin
00:43 * Tarinaky has just deleted the local repo and attempted to import it again from the remote repo.
00:43
< Tarinaky>
Nope. That's still throwing the same error :/
00:43
<@ToxicFrog>
The error being...?
00:44
< Tarinaky>
"Can't connec to any URI:"
00:44
< Tarinaky>
The URI is correct however.
00:44
<@ToxicFrog>
That error is coming from Eclipse, then, not git?
00:44
< Tarinaky>
Yes.
00:45
< Tarinaky>
git itself works fine.
00:45 * ToxicFrog shrugs. I've got nothing.
00:47
< Tarinaky>
I suspect the problem is it's not prompting me for the password.
00:47
< Tarinaky>
Which it does fine when I use the single-shot push wizard.
00:48
<@ToxicFrog>
Aah. What protocol are you using , ssh?
00:49
< Tarinaky>
Yes.
00:49
<@ToxicFrog>
Get your keypair authentication on, then, and do away with passwords entirely?
00:50
< Tarinaky>
I have no idea what that means.
00:50
< Tarinaky>
I just followed a tutorial for getting github working.
00:50
< Tarinaky>
And as a result have a key file.
00:51
<@ToxicFrog>
...so, wait, hang on
00:51
<@ToxicFrog>
Your repo is hosted on github
00:51
<@ToxicFrog>
But when you do a 'git clone' or 'git push' or similar from the command line, it asks for a password?
00:51
< Tarinaky>
The password associated with my ssh key file.
00:51
< Tarinaky>
I think.
00:51
<@ToxicFrog>
Aah.
00:52
<@ToxicFrog>
You might be able to unfuck eclipse by removing the password on your key, then, if that is indeed the problem
00:52
< Tarinaky>
How would I do that?
00:53
<@ToxicFrog>
ssh-keygen -p
00:53
< Tarinaky>
Doesn't that generate a new key?
00:53
<@ToxicFrog>
man ssh-keygen
00:53
<@ToxicFrog>
And look up the '-p' option.
00:53
<@ToxicFrog>
It'll ask for the file to modify, then the old passphrase, then the new. Just press enter when it asks for the new passphrase.
00:54
< Tarinaky>
Isn't not having a passphrase dangerous?
00:54
<@ToxicFrog>
If someone else gets ahold of that keyfile, yes
00:55
< Tarinaky>
Also - same error in eclipse.
00:55
<@ToxicFrog>
I generally operate on the assumption that if someone has access to my home directory on Orias, I'm fucked anyways, and only passphrase keys that I'm putting on USB sticks or the like.
00:59
<@ToxicFrog>
Tarinaky: https://bugs.eclipse.org/bugs/show_bug.cgi?id=317389 -- this look like the same bug you're having?
00:59
< Tarinaky>
I've just found that.
00:59
< Tarinaky>
And the fix works.
01:00
< Tarinaky>
Right. Back to the python >.>
01:00
< Tarinaky>
http://github.com/Tarinaky/becquerel/blob/master/engine.py << Like this?
01:02
<@ToxicFrog>
...looks like Python to me, yep
01:04
< Tarinaky>
Right. How would I import this into another file?
01:04
< Tarinaky>
What's the equiv of #include "foo.h" ?
01:05
<@ToxicFrog>
"import foo", but surely you already know this, since you're using import
01:05
<@ToxicFrog>
Also, I don't really use Python, you're best off asking Vorn or Der python questions
01:06
< Tarinaky>
Oh. So it looks in the cwd automatically?
01:06
<@ToxicFrog>
(also, you'll find that HLLs usually don't have an equivalent to #include; import is more like dynamic linking, there's no texture transformation (and thus no scope hacking))
01:06
<@ToxicFrog>
I think so? Like I said, I don't use python.
01:06
<@ToxicFrog>
s/texture/textual/
01:07
< Tarinaky>
I'm probably best off waiting for Vorn then :/
01:07
<@ToxicFrog>
I'm pretty sure there's tutorials and whatnot on the pygame site and python.org, too
01:11
< Tarinaky>
Oh I see.
01:12
< Tarinaky>
To be honest. I've mostly been cribbing off the pygame site.
01:13
< Vornicus>
"import foo", will import foo.py
01:13
< Vornicus>
(or foo.pyc or foo.pyo)
01:14
< Tarinaky>
Yes. I see now.
01:14
< Vornicus>
(if the latter don't exist or are older than foo.py, then it'll generate foo.pyc; use -o on the command line to get the pyo, which is optimized in certain ways.)
01:16
< Tarinaky>
Only load times, not run times.
01:17
< Tarinaky>
Which isn't really very handy~
01:24
< Tarinaky>
I'm going to go to bed before I melt.
01:24
< Tarinaky>
It's too hot :/
01:26
<@ToxicFrog>
Tarinaky: pyc is optimized load time (no compile step). -O is first optimization (removes asserts). -OO is second optimization (removes asserts and docstrings)
01:26
<@ToxicFrog>
Conceptually, -O is "safe optimizations" and -OO is "unsafe optimizations", but that's all they do at present in the reference interpreter.
01:27
< Tarinaky>
G'night.
01:27
<@ToxicFrog>
'night
01:28 Tarinaky [Tarinaky@Nightstar-f349ca6d.plus.com] has quit [Connection closed]
01:30 AnnoDomini [annodomini@Nightstar-41bcfdf5.adsl.tpnet.pl] has quit [[NS] Quit: Hmmm.]
01:53 cpux [Moo@Nightstar-20a84089.dyn.optonline.net] has quit [Connection reset by peer]
02:10 Zed [Zed@Nightstar-e4835f03.or.comcast.net] has quit [Ping timeout: 121 seconds]
02:11 Zed [Zed@Nightstar-e4835f03.or.comcast.net] has joined #code
02:45 Tarinaky [Tarinaky@Nightstar-f349ca6d.plus.com] has joined #code
02:45
< Tarinaky>
Can't sleep.
02:45
< Tarinaky>
I'm panicking about University again :/
02:58 cpux [Moo@Nightstar-20a84089.dyn.optonline.net] has joined #code
03:00
< simon_>
why?
03:01
< simon_>
did you just apply?
03:09 gnolam [lenin@Nightstar-38637aa0.priv.bahnhof.se] has quit [[NS] Quit: Z?]
03:13
< Tarinaky>
I'm reapplying in September.
03:13
< Tarinaky>
I got kicked out last month.
03:18 Stalker [Z@3A600C.A966FF.5BF32D.8E7ABA] has quit [Ping timeout: 121 seconds]
03:21
< simon_>
oh
03:22
< simon_>
we have some rules here on how long one is allowed to take
03:22
< simon_>
then one can apply to have that period extended, and if one gets kicked out, one can reapply and get complete merits.
03:23
< Tarinaky>
I'm applying elsewhere.
03:23
< simon_>
ah
03:23
< simon_>
computer science? math?
03:24
< Tarinaky>
I was doing Physics.
03:24
< Tarinaky>
I want to change to CompSci.
03:24
< Tarinaky>
also - is it possible to extend a python dictionary by extra key-value pairs?
03:24
< Tarinaky>
The documentation is unclear.
03:25
<@ToxicFrog>
how do you mean? Mutate a dictionary by adding KV pairs to it after creation? Yes.
03:25
< Tarinaky>
How?
03:25
< simon_>
somedict[key] = value?
03:26
<@ToxicFrog>
http://docs.python.org/tutorial/datastructures.html#dictionaries
03:26
< Tarinaky>
I was looking at that.
03:26
< Tarinaky>
It didn't seem to say.
03:27
< simon_>
or, somedict.update(otherdict)
03:30
<@ToxicFrog>
Tarinaky: it doesn't seem to say? Read the "small example using a dictionary".
03:30
< Tarinaky>
Ah. So it does.
03:30
< Tarinaky>
Sorry. It was a bit burried.
03:31
< celticminstrel>
Yay, Python!
03:37
< Tarinaky>
Gah. Why is it giving me Undefined variable when I can -see- the variable being defined in the class initialiser.
03:37
< celticminstrel>
Context?
03:37
< Tarinaky>
pygame.
03:38
< celticminstrel>
...that doesn't help. My initial suggestion is that perhaps you forgot self?
03:38
< Tarinaky>
http://tarinaky.pastebin.com/1bVmSiWa
03:38
< celticminstrel>
Which line generates the error?
03:38
< Tarinaky>
Line 31
03:39
< celticminstrel>
It's complaining about surfaceWindow being undefined?
03:39
< Tarinaky>
But Line 32 is the one that's underlined in red.
03:39
< Tarinaky>
Yes.
03:39
< celticminstrel>
Then yes, you need self.
03:39
< celticminstrel>
You can't just omit that like in C++.
03:39
< Tarinaky>
I don;t understand :/
03:39
< celticminstrel>
self.surfaceWindow = ...
03:40
< celticminstrel>
Everywhere it appears it needs to be qualified like that.
03:40
< Tarinaky>
Oh.
03:40
< Tarinaky>
Annoying!
03:40
< celticminstrel>
A little, yes.
03:48
< Tarinaky>
How do I perform arithmetic on tuples?
03:50
< Tarinaky>
I have a tuple representing the dimensions of my screen buffer and a tuple with the dimensions of an image I'm blitting.
03:51
< Tarinaky>
SDL wants the position of the top-left corner of the image I'm blitting.
03:54
<@ToxicFrog>
I don't know how to do math on the entire tuple at once, but you can always work on the parts individually.
03:54
<@ToxicFrog>
Eg, size = (640,480); size[0] == 640, size[1] == 480
03:55
< Tarinaky>
It strikes me as a bit of a hole given their use as coordinates :/
03:56
< celticminstrel>
I think this is doable with the map function or whatever it's called.
03:56
< celticminstrel>
Give me a moment to verify.
03:58
< celticminstrel>
>>> import operator
03:58
< celticminstrel>
>>> map(operator.add,(1,2),(3,4))
03:58
< celticminstrel>
[4, 6]
03:58
< celticminstrel>
Is that what you want?
03:58
< Vornicus>
wrap that in tuple() and you'll get a tuple back.
03:59
< Tarinaky>
celticminstrel: I don't know. It looks correct.
03:59
< Tarinaky>
What I've got atm is:
03:59
< Tarinaky>
Ax,Ay = self.surfaceWindow.get_size()
03:59
< Tarinaky>
Bx,By = self.tableImages['PlayerShip'].get_size()
03:59
< Tarinaky>
_center = (((Ax-Bx)/2,(Ay-By)/2))
03:59
< celticminstrel>
Unless it's being used as a dictionary key, you don't really need to make it a tuple.
03:59
< celticminstrel>
Okay, and...?
04:00
< Tarinaky>
I thought it was a bit of a hole for it not to be as simple as (A-B)/2 for the whole thing :/
04:00
< celticminstrel>
Ah.
04:03
< celticminstrel>
You'd need a vector class for that, I think.
04:04
< Vornicus>
pygame's "rect" may be of some assistance.
04:05
< Tarinaky>
Well. Anyway. I'm going to try and go back to sleep I think.
04:08 Tarinaky [Tarinaky@Nightstar-f349ca6d.plus.com] has quit [Client closed the connection]
04:14 Thaqui [Thaqui@27B34E.D54D49.F53FA1.6A113C] has joined #code
04:46 Kazriko [kaz@Nightstar-e09690fa.client.bresnan.net] has joined #code
04:46 mode/#code [+o Kazriko] by Reiver
05:59 cpux [Moo@Nightstar-20a84089.dyn.optonline.net] has quit [[NS] Quit: ChatZilla 0.9.86 [Firefox 3.6.6/20100625231939]]
06:02 Orthia [orthianz@Nightstar-32b4252e.xnet.co.nz] has joined #code
06:02
< Orthia>
Hey folks, is this card much good? http://www.firstin.co.nz/products/xfx-ati-radeon-hd-4750-1gb-pci-e-graphics-card -2911/?utm_source=MailingList&utm_medium=email&utm_campaign=July+21st+2010
06:02
< Orthia>
I'm outta touch with where cards fall nowadays.
06:10 celticminstrel [celticminstre@Nightstar-f8b608eb.cable.rogers.com] has quit [[NS] Quit: And lo! The computer falls into a deep sleep, to awake again some other day!]
06:30 Zed [Zed@Nightstar-e4835f03.or.comcast.net] has quit [Connection reset by peer]
06:31 Zed [Zed@Nightstar-e4835f03.or.comcast.net] has joined #code
06:33 Syloqs-AFH [Syloq@NetworkAdministrator.Nightstar.Net] has quit [Ping timeout: 121 seconds]
06:40 Syloqs_AFH [Syloq@NetworkAdministrator.Nightstar.Net] has joined #code
06:41 Syloqs_AFH is now known as Syloqs-AFH
07:14
<@McMartin>
Orthia: tomshardware is a good place for recent reviews.
07:51 Rhamphoryncus [rhamph@Nightstar-bbc709c4.abhsia.telus.net] has joined #code
07:52 You're now known as TheWatcher
07:54
< Orthia>
McM: Cheers
07:57
<@McMartin>
When I specced out Astatine last year they had a reasonably current article that ranked cards in each price range.
08:51 AnnoDomini [annodomini@Nightstar-fb29b369.adsl.tpnet.pl] has joined #code
08:51 mode/#code [+o AnnoDomini] by Reiver
09:18 gnolam [lenin@Nightstar-38637aa0.priv.bahnhof.se] has joined #code
10:02
<@TheWatcher>
... it's kinda sad how hard I laugh at some of the stuff in Wall et al.'s Programming Perl
10:06
< gnolam>
?
10:20
<@TheWatcher>
Just things like (when discussing a regexp that could work indefinitely) "We don't know how long it would take. We didn't care to wait around watching it not fail. In any event, your computer is likely to crash before the heat death of the universe, and this regular expression takes longer than either of those."
10:21
<@TheWatcher>
It's written in a far more conversational tone than any 1k+ page programming book I've seen (that has been worth reading)
10:39 Vornicus is now known as Vornicus-Latens
12:53 Rhamphoryncus [rhamph@Nightstar-bbc709c4.abhsia.telus.net] has quit [Client exited]
13:37 celticminstrel [celticminstre@Nightstar-f8b608eb.cable.rogers.com] has joined #code
13:54 Tarinaky [Tarinaky@Nightstar-f349ca6d.plus.com] has joined #code
14:15 Stalker [Z@3A600C.A966FF.5BF32D.8E7ABA] has joined #code
14:29
< Tarinaky>
Does anyone have suggestions on how to draw a star field?
14:30
<@AnnoDomini>
Bright dots on a dark background.
14:32
< Tarinaky>
Any idea how big the dots should be?
14:33
< Tarinaky>
I'm also not entirely sure how to go about placing the starts in a pseudorandom way.
14:33
<@AnnoDomini>
Pixels.
14:33
<@AnnoDomini>
int x = rand(0,max_x); int y = rand(0,max_y);
14:34
< celticminstrel>
Single pixels, or perhaps five pixels in a cross.
14:34
< Stalker>
Didn't Vorn write that part of his MoO restoration project?
14:34
< Stalker>
There's also that "Explore the night sky" or whatever program similar to google earth, except for the sky/Galaxies.
14:35
< Tarinaky>
The problem is I have a scrolling background buffer filled with stars. It seems to me to be a bad idea to actually store a giant pixel buffer though when only a small viewport is going to be seen in each frame.
14:35
< Stalker>
I know the one with galaxies is moddable.
14:35
< Tarinaky>
So I'm wondering how I can generate portions of it on demand.
14:35
< Stalker>
What do you need a star field for?
14:36
< Tarinaky>
Scrolling background buffer.
14:36
< Tarinaky>
I can live without parallax.
14:40
< Tarinaky>
My best idea atm is to use an arrangement of generated tiles. But I'm not sure what the best way of retrieving what tile corresponds to a particular part of space.
14:41
< Tarinaky>
(Because it'll be lulsy if you fly forwards and see one set of stars then break and fly backwards to be greated by different ones)
15:01 * TheWatcher eyes
15:01 * Tarinaky flees and hides.
15:01
< Tarinaky>
What's up?
15:03
<@TheWatcher>
assuming that the starfield only scrolls horizontally, imagine splitting it up into a series of vertical strips of a given width. Assign each strip a number, say an strip x position. As you scroll right, the x increases, left the x decreases. As you scroll, and need to generate a new strip to either side, use the strip x value as the seed for a random number generator, then use the random number generator to create stars in that strip
15:04
<@TheWatcher>
As number generators are deterministic and will generate the same sequence given the same seed, you'll get the same stars generated in the strip, regardless of which direction you generate it from
15:04
<@TheWatcher>
That's the first method that springs to mind, anyway
15:09
< Tarinaky>
I thought the built in PRNG wasn't that... exposed?
15:09
< celticminstrel>
Python?
15:09
< Tarinaky>
Yes.
15:10
< celticminstrel>
import random; random.seed(12); print random.randint(2,15);
15:10
< celticminstrel>
Something along those lines, anyway.
15:10
< celticminstrel>
The range for randint is inclusive, by the way.
15:11
< celticminstrel>
On both ends.
15:11
< Tarinaky>
Ah-hah.
15:11
< celticminstrel>
Or you can instantiate the Random class if you need more than one generator.
15:11
< Tarinaky>
Just as an unrelated aside. It's not possible to have two sep- That's what I wanted to know.
15:28 * Tarinaky grumbles. I'm having trouble finding clear examples on how function declarations are meant to look.
15:29
< celticminstrel>
def func(var1,var2,var3=default,*extra_args,**extra_kw_args):
15:29
< celticminstrel>
Obviously some of that is optional.
15:29
< celticminstrel>
.
15:29
< celticminstrel>
Those last two are for variable arity functions.
15:29
< Tarinaky>
How do I make one of the arguments a tuple?
15:29
< celticminstrel>
Depends.
15:30
< celticminstrel>
Do you just want to pass in the tuple?
15:30
< Tarinaky>
Yes.
15:30
< celticminstrel>
Or do you want to unpack the tuple into parameters?
15:30
< celticminstrel>
If you just want to pass in a tuple, you can't specify that in the function declaration.
15:30
< celticminstrel>
You can however put a line below to make sure it's a tuple.
15:31
< celticminstrel>
if type(arg) == tuple: raise TypeError
15:31
< celticminstrel>
^ !=
15:31
< Tarinaky>
Ahah.
15:32
< Tarinaky>
Are tuples 'hashable' btw?
15:32
< celticminstrel>
Yes, I believe they are.
15:33
< celticminstrel>
If you do def func(arg1,(arg2,arg3)), and call it as func(a,b) where b is a two-element list or tuple, then arg1 will be a, arg2 will be b[0], and arg3 will be b[1]. I think this is deprecated though and unavailable in Python 3.
15:33
< Tarinaky>
How do you test the size of a tuple?
15:34
< celticminstrel>
The len function.
15:34
< Tarinaky>
Ahah.
15:34
< Tarinaky>
Cheers.
15:34
< celticminstrel>
Which calls the __len__ member function, but that's implementation detail that you only need to know if creating a class that has a size.
15:35
< celticminstrel>
^an imp. detail
15:44
< Tarinaky>
Umm. What'd be the equivalent of... void foo() { static int i = 0; } ?
15:45
< Tarinaky>
That is, shared memory in a function.
15:45
< celticminstrel>
There's no direct equivalent; what precisely do you need it for?
15:46
< Tarinaky>
I've forgotten. I don't think I need it at all.
15:46
< celticminstrel>
Oh. Alright then.
15:46
< Tarinaky>
Oh yes. I remember now.
15:47
< celticminstrel>
Yes?
15:47
< Tarinaky>
In SDL blitting several pixels at once is cheaper than writing pixels one at a time.
15:47
< Tarinaky>
The first time the function's called I want it to store a particular pattern of pixels as a surface and then 'save' it to be used every time that function is called.
15:47
< Tarinaky>
Rather than writting pixel-by-pixel each time it'll only do it the first time.
15:48
< celticminstrel>
I think you'll have to use a class for that.
15:48
< celticminstrel>
Create a class with two functions, __init__ and __call__; the first stores the surface, then calls the second, and they both take the same arguments.
15:49
< celticminstrel>
(The other method of simulating static memory is with the yield keyword, but I don't think that'd work here.)
15:50
< Tarinaky>
And then I make the function object a member of my 'actual' class and just call that?
15:51
< celticminstrel>
Huh?
15:51
< Tarinaky>
I'm confused :/
15:52
< celticminstrel>
Okay.
15:52
< celticminstrel>
Instead of a function, you define a class.
15:52
< celticminstrel>
With me so far?
15:52
< celticminstrel>
class name(object): ...
15:52
< Tarinaky>
Yes.
15:53
< Tarinaky>
Then inside that class define __init__(self,surfaceTarget,coordinate)
15:53
< Tarinaky>
And __call__(self,surfaceTarget,coordinate)
15:53
< celticminstrel>
Something like that.
15:53
< Tarinaky>
I'm -guessing- specifying __call__ makes this class a function object?
15:54
< Tarinaky>
However Python might implement that.
15:54
< celticminstrel>
Now, if your class is called myClass (don't call it that, duh), myClass() is equivalent to myClass.__init__(). And if you do func = myClass(), then func() is equivalent to func.__call__().
15:54
< celticminstrel>
Just like overriding the function call operator in C++.
15:55
< Tarinaky>
Ahah.
15:55
< celticminstrel>
However, you can't quite use this just like you would have used the original function. You need to initialize it with the surface, then call the class instance it returns.
15:55
< Tarinaky>
So to use myClass as a component of a bigger class I'd do...
15:56
< Tarinaky>
self.draw_star_function_whatever = myClass() #in my initialise/constructor
15:56
< Tarinaky>
Then call it with self.draw_star_function_whatever(argument_list) ?
15:57
< celticminstrel>
Pretty much. I'm not entirely sure if both __init__ and __call__ need the same arguments, since I don't know exactly what you're doing.
15:58
< Tarinaky>
Exactly what I'm doing depends on what exactly python will let me do.
15:59
< Tarinaky>
I just want to initialises a function's constants.
15:59
< Tarinaky>
If that makes sense :/
16:07
< Tarinaky>
If I give both __init__ and __call__ the same signature how do I make it so that __init__ is called exactly once?
16:15
<@ToxicFrog>
__init__ is called when an instance of the class is created. It's the constructor.
16:15
< celticminstrel>
__init__ is called when you initialize the class, so it's never called more than once on a given instance.
16:15
<@ToxicFrog>
__call__ is called when you try to use that instance as a function.
16:15
< celticminstrel>
Though I think it can be called explicitly.
16:15
<@ToxicFrog>
Eg, obj = Object() # calls Object.__init__
16:16
<@ToxicFrog>
obj() # calls obj._
16:16
<@ToxicFrog>
obj() # calls obj.__call__
16:16
<@ToxicFrog>
That said, it tastes like what you're after isn't really "static" at all - you want to save starfield slices after creating them, right?
16:17
< Tarinaky>
No. That's something else.
16:17
<@ToxicFrog>
Aah.
16:17
< Tarinaky>
I just want to buffer the 8 or so pixels that make up a single star.
16:17
<@ToxicFrog>
(hmm. Does python have a builtin @memoize decorator?)
16:18
< Tarinaky>
(I'm going to worry about buffering the starfield's tiles later)
16:19
< celticminstrel>
ToxicFrog: Seems not.
16:39 Thaqui [Thaqui@27B34E.D54D49.F53FA1.6A113C] has quit [Client closed the connection]
16:44 TarinakyKai [Tarinaky@Nightstar-f349ca6d.plus.com] has joined #code
16:47 Tarinaky [Tarinaky@Nightstar-f349ca6d.plus.com] has quit [Ping timeout: 121 seconds]
16:56
< TarinakyKai>
My point is. Where would I construct the function object?
16:56
< celticminstrel>
The first time you need to call it?
16:57
< TarinakyKai>
I'm confused. Won't the previously initialised version be thrown away at the end of the proceedure that calls it though?
16:57
< TarinakyKai>
Popped off the stack.
16:57
< celticminstrel>
Yeah, if you were to do it that way.
16:58
< celticminstrel>
Does it only need to be initialized once in the entire program?
16:58
< TarinakyKai>
Yes.
16:58
< celticminstrel>
So, do one of the following.
16:58
< celticminstrel>
1. Add a line similar to 'classname = classname()' immediately following the class definition.
16:59
< celticminstrel>
2. If this class is defined in another class, add a line like 'self.classname = self.classname()' in the __init__ function.
17:00
< celticminstrel>
This is actually what a decorator abstracts away, so using a decorator for this would probably be beneficial. I'm not sure how such a decorator would work though.
17:00
< celticminstrel>
^ s/This/Number 2/
17:06
< TarinakyKai>
Right. And then I can call __call__ with classname(argumentlist)?
17:07
< TarinakyKai>
Or self. the same.
17:09 Attilla [Attilla@Nightstar-7a92f10e.threembb.co.uk] has joined #code
17:09 mode/#code [+o Attilla] by Reiver
17:44 Attilla [Attilla@Nightstar-7a92f10e.threembb.co.uk] has quit [[NS] Quit: ]
17:47
< TarinakyKai>
for i in range (a,b): gives me a warning if I don't actually use i in the body of the loop.
17:47
< TarinakyKai>
How should I adjust this to reflect my complete lack of intention to use i in the body of the loop?
17:48
< TarinakyKai>
(for(int i = a;a<=b;i++) { } )
18:01 * TheWatcher vaguely pokes for other emacs users
18:03
< TarinakyKai>
Have you tried the local asylum?~
18:03
<@TheWatcher>
I work there :P
18:03 Syloqs-AFH [Syloq@NetworkAdministrator.Nightstar.Net] has quit [[NS] Quit: ]
18:03
<@TheWatcher>
(although they call it a "university", for some reason)
18:04
<@TheWatcher>
(silly people)
18:05 * gnolam hands TheWatcher some dried frog pills.
18:08
< gnolam>
Finally.
18:08 Syloqs_AFH [Syloq@NetworkAdministrator.Nightstar.Net] has joined #code
18:09 * gnolam is starting to break Sketchup's will to resist.
18:09 Syloqs_AFH is now known as Syloqs-AFH
18:10
< gnolam>
http://www.lysator.liu.se/~gnolam/temp/intensimeter_28_WIP_1.png
18:10
< gnolam>
http://www.lysator.liu.se/~gnolam/temp/intensimeter_28_WIP_2.png
18:11
<@TheWatcher>
Looks good
18:31
< gnolam>
I'm getting pretty fed up with Sketchup's numerous bugs, I can tell you. :P
18:32
<@TheWatcher>
I bet. But the question is, is your sanity less eroded than it would be attempting it in Blender?~
18:34
< celticminstrel>
TarinakyKai: Don't worry about the warning of i not being used. I don't think there's another way to do that anyway.
18:34
< celticminstrel>
Also, this is correct. --> [Jul 21@12:06:55pm] TarinakyKai: Right. And then I can call __call__ with classname(argumentlist)?
18:35
< gnolam>
Attempting it in Blender presupposes insanity.
18:35
<@TheWatcher>
Point.
18:43 Attilla [Attilla@Nightstar-500dd5b1.threembb.co.uk] has joined #code
18:43 mode/#code [+o Attilla] by Reiver
18:43 * Vornicus-Latens eyes the Tarinaky thing.
18:44 Vornicus-Latens is now known as Vornicus
18:44
< Vornicus>
what the hell's going on
18:44
< TarinakyKai>
Eep.
18:44
< TarinakyKai>
What'd I do?
18:44
< Vornicus>
Why are you making a singleton class? Could you not do this in a module instead?
18:47
< TarinakyKai>
I don't know?
18:48
< TarinakyKai>
I just wanted a function with some constants that needed initialising.
18:48
< TarinakyKai>
(And shared between different invocations of that function)
18:49
< Vornicus>
I'm confused now.
18:49
< TarinakyKai>
I wanted a function that drew a star onto an SDL surface.
18:49
< TarinakyKai>
It needed to initialise an SDL surface containing the star itself.
18:50
< TarinakyKai>
But it only needed to initialise that surface once.
18:50
< Vornicus>
Aha, that's what you're doing.
18:51 * Vornicus fiddles
18:52
< TarinakyKai>
It runs without error but it doesn't work. :/
18:52
< Vornicus>
Okay usually the way I'd do this is: 1. set up a function that, given the name of an image, returns a surface with that image on it.
18:52
< TarinakyKai>
This is, arguably, the worst kind of error.
18:53
< TarinakyKai>
How would I go about debugging a python script?
18:54
< Vornicus>
This function first checks a dictionary to see if that image name has already been loaded.
18:54
< Vornicus>
If so, it returns the value from that dictionary. If /not/, then it loads the image, places it in the dictionary, and returns it too.
18:54
< Vornicus>
...actually, I think you can pull this off using the existing "defaultdict"
18:55
< TarinakyKai>
Using a dictionary is a little 'overkill' as I'm only considering 1 image.
18:56
< Vornicus>
Well, all right. Then we can do something slightly simpler.
18:56
< Vornicus>
How would you like to call this thing?
18:56
< Vornicus>
Remember, you don't have to put everything in a function or class.
18:57
< TarinakyKai>
At the moment I'd rather address the fact that it doesn't work rather than how I call it >.>
18:57
< Vornicus>
THe most likely reason it doesn't work right now is that it isn't built in such a way that it will ever reasonably work.
18:57
< TarinakyKai>
How do I debug a python program?
18:58
< TarinakyKai>
So I can determine what, exactly, isn't built in such a way it will ever reasonably work.
18:58
< Vornicus>
Show me the code.
18:58
< TarinakyKai>
Before you say lines 1 through to EOF >.>
18:58
< Vornicus>
There's pdb I think it is but frankly right now it looks very much like your problem is you're trying to do complicated things when something simple would do just fine.
18:59
< TarinakyKai>
Gah. Git's fallen down again.
19:00
< Vornicus>
If you're never going to change the image, why not /just load the image/.
19:01
< TarinakyKai>
Vornicus: Load it from what?
19:02
< Vornicus>
...from the file? From however you're building the surface?
19:02
< Vornicus>
Right now I look at what you say you're doing and I go, "damn, that sounds much more complicated than it needs to be"
19:03
< TarinakyKai>
http://github.com/Tarinaky/becquerel/blob/master/starfield.py
19:03
< TarinakyKai>
Any idea why eclipse has suddenly decided it can't decrypt my rsa key?
19:04
< Vornicus>
Yeah. I look at that and say "why the hell is that a class"
19:05
< TarinakyKai>
>.> I'm currently troubleshooting eclipse at the moment.
19:09
< Vornicus>
The class can be replaced with this: http://paste.pocoo.org/show/240118/
19:09
< Vornicus>
also I corrected your for loops - you were drawing a 3x3 star.
19:16
< TarinakyKai>
I thought range was inclusive?
19:17
< Vornicus>
inclusive start, exclusive end.
19:17
< TarinakyKai>
Oh.
19:17
< Vornicus>
thus range(8) gives you 0 through 7 inclusive.
19:17
< Vornicus>
(which are the forward indices for a list of len 8)
19:18
< TarinakyKai>
The modified script still fails to draw anything except black.
19:18
< Vornicus>
Okay, that means something else is wrong.
19:19
< TarinakyKai>
Technically I don't believe there was anything 'wrong' with the one before that. It just didn't look right >.>
19:20 Stalker [Z@3A600C.A966FF.5BF32D.8E7ABA] has quit [Ping timeout: 121 seconds]
19:26
< Vornicus>
and what's this prng thing?
19:27
< Vornicus>
Oh, you're building a fresh Random object. Unless you want several independent streams of random numbers you don't need to do that.
19:29
< celticminstrel>
Vornicus: Not saying it was necessarily the best way, but I was basically suggesting creating a callable class since what he wanted was a function with state.
19:29
< TarinakyKai>
Vornicus: I don't want this to effect my 'normal' random number generator.
19:30
< celticminstrel>
TarinakyKai: Oh yes, range() excludes the upper bound.
19:30
< TarinakyKai>
Otherwise the dice can be manipulated by forcing it to load particular sections of the buffer.
19:30
< TarinakyKai>
Which would be a bug.
19:30
< celticminstrel>
But randint does not.
19:31
< Vornicus>
TarinakyKai: that's a good reason.
19:31
< TarinakyKai>
(I also suspect that the MTR may not be the best algorithm for what I'm doing in this module and may replace it later)
19:32
< Vornicus>
MTR?
19:32
< TarinakyKai>
Python's Random Number Generator is a Mersenne Twister.
19:33
< TarinakyKai>
At least, that's what the documentation says.
19:35
< Vornicus>
Are you looking for cryptographically strong random number generation for a goddamn /starfield/?
19:36 Attilla_ [Attilla@Nightstar-dd52bccc.threembb.co.uk] has joined #code
19:37
< TarinakyKai>
Vornicus: No.
19:37
< TarinakyKai>
Vornicus: You misunderstand.
19:37
< TarinakyKai>
Vornicus: The Mersenne Twister uses an array to increase the length of its period.
19:37
< Vornicus>
yeah, so?
19:38
< TarinakyKai>
The array is initialised every time a seed is loaded. I don';t actually need a very long period
19:39
< Vornicus>
Okay. And you're worried about 650 small calculations now.
19:39
< TarinakyKai>
No.
19:39
< TarinakyKai>
I said suspect and later.
19:39 Attilla [Attilla@Nightstar-500dd5b1.threembb.co.uk] has quit [Ping timeout: 121 seconds]
19:39
< TarinakyKai>
The main reason I insulated it was because I didn't want to change the seed of the RNG I was using for game logic.
19:40
< Vornicus>
'k, let's see here
19:41
< TarinakyKai>
(I have a bag full of more important optimisations to do before I even think about touching the RNG >.>)
19:43 Attilla_ [Attilla@Nightstar-dd52bccc.threembb.co.uk] has quit [Ping timeout: 121 seconds]
19:44 Attilla [Obsolete@Nightstar-6535fedf.threembb.co.uk] has joined #code
19:44 mode/#code [+o Attilla] by Reiver
19:57
< TarinakyKai>
I can't see anything wrong when I step though the program in a debugger :/
19:57
< TarinakyKai>
Suggestions?
20:01 Attilla [Obsolete@Nightstar-6535fedf.threembb.co.uk] has quit [Ping timeout: 121 seconds]
20:02
< Vornicus>
Dunno. See if you can blit exactly one star.
20:02
< TarinakyKai>
Ahah! Fixed it!
20:02
< Vornicus>
What was wrong?
20:06
< TarinakyKai>
The get_field function is fucked beyond repair.
20:06
< TarinakyKai>
On the plus side - I don't actually need that function anyway.
20:07 Attilla [Obsolete@Nightstar-f58d6601.threembb.co.uk] has joined #code
20:07 mode/#code [+o Attilla] by Reiver
20:07
< TarinakyKai>
Now to figure out how to make my 'stars' look a little nicer.
20:09
< TarinakyKai>
I'm having trouble figuring out how to do logical ands/ors :/
20:09
< TarinakyKai>
s/figuring/finding
20:09
<@ToxicFrog>
As in what they mean, or as in the syntax for them?
20:10
< TarinakyKai>
if ( (x == 2 || x == 5) && ( y == 2 || y == 5) ) { }
20:11
<@ToxicFrog>
The syntax, then.
20:11
<@ToxicFrog>
Try 'and' and 'or'.
20:12
<@ToxicFrog>
The constants are True and False, the operators are and or not
20:13
< TarinakyKai>
How do I leave an if statement empty?
20:13
< TarinakyKai>
It's giving me a warning about an expected <INDENT>
20:13
< TarinakyKai>
*error about an expected...
20:14
<@ToxicFrog>
"pass", I think, but why is this useful?
20:14
< TarinakyKai>
I tend to use if (something) { } else { actual logic } a lot.
20:15
< TarinakyKai>
I know I can use negation.
20:15
<@ToxicFrog>
ghk, why?
20:15
< TarinakyKai>
ghk?
20:15
<@ToxicFrog>
When, as you say, you could just go "if not something then ..."
20:15
<@ToxicFrog>
A sound of distress.
20:16
< TarinakyKai>
I guess I just find if-else easier to parse than if-not.
20:16
< TarinakyKai>
It's -probably- a bad habit though >.>
20:16
< TarinakyKai>
(Also - brackets can get messier >.>)
20:31 Derakon [Derakon@Nightstar-1ffd02e6.ucsf.edu] has joined #code
20:31 mode/#code [+o Derakon] by Reiver
20:37
< TarinakyKai>
Any suggestions on how I can make my stars look better?
20:37
< TarinakyKai>
At the moment they kinda just look like white circles.
20:37
<@Derakon>
http://antwrp.gsfc.nasa.gov/apod/
20:37 * Derakon ducks
20:39
< TarinakyKai>
Sweet picture.
20:39 aoanla [AndChat@7C1B03.D41F62.4CB2F2.6D98F9] has joined #code
20:39
<@Derakon>
Generally speaking, stars in the night sky are rendered as small circles of pixels.
20:39
<@Derakon>
About all you can do is vary their size.
20:39
<@Derakon>
Remember, in outer space they do not twinkle.
20:41
< Vornicus>
Size, and color.
20:43
< TarinakyKai>
I was wondering if an anti-aliasing or blur effect would make them look better.
20:43
< TarinakyKai>
At least, less harsh.
20:43
< gnolam>
It does.
20:44
<@Derakon>
Stars in space are harsh, though.
20:44
<@Derakon>
Remember, no atmosphere.
20:44
<@Derakon>
So you can smooth it, but it'll be less realistic~
20:45
< TarinakyKai>
Anti-aliasing will make them at least look more like a circle.
20:46 Chi [omegaboot@Nightstar-c5f3565b.il.comcast.net] has joined #code
20:46
< gnolam>
My stars basically consist of one pixel with a very faint blur around it. I don't vary the size of the point sprite, only the color (including alpha).
20:47 Alek [omegaboot@Nightstar-c5f3565b.il.comcast.net] has quit [Ping timeout: 121 seconds]
20:49
< TarinakyKai>
http://i29.tinypic.com/6zyhb5.png << This is a sample of the current output.
20:49
< Vornicus>
Looks good to me.
20:50
<@Derakon>
I'd make some of 'em single pixels instead of 2x2 squares, but yeah, looks good.
20:52
< Vornicus>
I do like gnolam's idea though. It sounds like it'd work well.
21:20
<@Derakon>
Augh, my boss is making noises about getting a fourth display O_o
21:20
<@Derakon>
Which means I'll be spending time making GUIs for stuff to show on said display...despite the fact that last week he was saying that he wanted me to cut down the amount of time I spent working on the scope software. Whee~
21:21
< TarinakyKai>
Derakon: I was going to say. At that point aren't you better off just printing stuff out and mounting it on the wall?
21:22
<@Derakon>
I'm just wrestling with the idea of having to find stuff to use up six million pixels' worth of display.
21:22
<@Derakon>
...wait, more than that.
21:22
<@Derakon>
Eight million pixels.
21:23
< TarinakyKai>
An animated penguin?
21:24
<@Derakon>
I am not writing Clippy for Microscopes.
21:24
< TarinakyKai>
It'd serve your boss right.
21:24
< TarinakyKai>
You know it would >:D
21:25
<@Derakon>
Actually, my boss, for all that he's curmudgeonly as all get out, is very good at what he does.
21:25
<@Derakon>
The guy I have a hate-on for is Sebastian.
21:25
< TarinakyKai>
:p
21:25
<@TheWatcher>
Deservedly.
21:46 Attilla [Obsolete@Nightstar-f58d6601.threembb.co.uk] has quit [[NS] Quit: ]
21:49 aoanla [AndChat@7C1B03.D41F62.4CB2F2.6D98F9] has quit [[NS] Quit: ]
21:55 * Derakon pushes the last of his changes, now needs to figure out what can fit into the time he has left before going on vacation.
22:00 Zed [Zed@Nightstar-e4835f03.or.comcast.net] has quit [Client closed the connection]
22:00 Zed [Zed@Nightstar-e4835f03.or.comcast.net] has joined #code
22:03 Stalker [Z@3A600C.A966FF.5BF32D.8E7ABA] has joined #code
22:06 Attilla [Obsolete@Nightstar-518c9eac.threembb.co.uk] has joined #code
22:06 mode/#code [+o Attilla] by Reiver
22:09 Attilla_ [Obsolete@Nightstar-d15052a2.threembb.co.uk] has joined #code
22:10 Attilla [Obsolete@Nightstar-518c9eac.threembb.co.uk] has quit [Ping timeout: 121 seconds]
22:31
<@Derakon>
I've figured out what I find so annoying about WX's layout system.
22:31
<@Derakon>
It's almost identical to abuse of <table> tags in HTML.
22:32
<@Derakon>
Today I had a design that couldn't be solved through a simple collection of rows and columns (due to overlap) and the solution was to use a special container that basically gives access to the 'span' attribute. ?.?
22:33
< TarinakyKai>
Table abuse isn't really abuse~
22:33
<@Derakon>
(Net result: I chunked the window up into an 11x9 grid of 100x66-pixel-rectangles)
22:33
<@Derakon>
Tarinaky: it's inflexible, it's impossible for screen readers to interact with properly, it doesn't scale, it's a nightmare to edit.
22:33
<@Derakon>
It's the moral equivalent of using goto because you can't be arsed to write a proper program flow.
22:39
<@Derakon>
Oh, and WX, in classic "X means row, right?" style, specifies coordinates for this special container as (row, column) instead of (X offset, Y offset).
23:04 Derakon [Derakon@Nightstar-1ffd02e6.ucsf.edu] has quit [[NS] Quit: Leaving]
23:21 Attilla_ [Obsolete@Nightstar-d15052a2.threembb.co.uk] has quit [Ping timeout: 121 seconds]
23:22 Attilla [Obsolete@Nightstar-56f17970.threembb.co.uk] has joined #code
23:22 mode/#code [+o Attilla] by Reiver
23:27 Attilla [Obsolete@Nightstar-56f17970.threembb.co.uk] has quit [Ping timeout: 121 seconds]
23:29 Attilla [Obsolete@Nightstar-56c324a7.threembb.co.uk] has joined #code
23:29 mode/#code [+o Attilla] by Reiver
23:35
< gnolam>
Ooh, an "I have this super mega ultra awesome game design, I just need someone to do all the work in actually implementing it" post. Haven't seen one of those in a while.
23:39 Attilla [Obsolete@Nightstar-56c324a7.threembb.co.uk] has quit [Ping timeout: 121 seconds]
23:40 Attilla [Obsolete@Nightstar-824ae0c5.threembb.co.uk] has joined #code
23:40 mode/#code [+o Attilla] by Reiver
23:40
< celticminstrel>
What, gnolam?
23:47 cpux [Moo@Nightstar-20a84089.dyn.optonline.net] has joined #code
23:57 Attilla_ [Obsolete@Nightstar-5a5cbc92.threembb.co.uk] has joined #code
23:59 Attilla [Obsolete@Nightstar-824ae0c5.threembb.co.uk] has quit [Ping timeout: 121 seconds]
--- Log closed Thu Jul 22 00:00:16 2010
code logs -> 2010 -> Wed, 21 Jul 2010< code.20100720.log - code.20100722.log >