[pygame] Perlin Noise Function

2008-07-29 Thread Knapp
I have been thinking about writing a function do to Perlin Noise. Is there
any interest in pygame having this?

http://www.cs.cmu.edu/~mzucker/code/perlin-noise-math-faq.html
http://mrl.nyu.edu/~perlin/noise/

-- 
Douglas E Knapp

http://sf-journey-creations.wikispot.org/Front_Page


[pygame] PATCH: Merging in my branch, changes to transform

2008-07-29 Thread Nirav Patel
Hello all,

Since 1.8.1 has been released, René suggested it is a good time to
merge what I've been working on into the 1.9 trunk.  Over the next few
days, I will be sending in patches of the changes I've made in my
branch.

The attached diff covers the changes I've made to the transform
module.  That is:

Increased performance in threshold and average_surfaces

A new function, average_color.  This one doesn't really belong in
transform, but it belongs even less in the other modules.  Perhaps it
could fit in Color?

Nirav
diff --git a/docs/ref/index.html b/docs/ref/index.html
index fe86eb6..da22a97 100644
--- a/docs/ref/index.html
+++ b/docs/ref/index.html
@@ -534,6 +534,7 @@
 
 pygame.transform - pygame module to transform surfaces
 
+pygame.transform.average_color - finds the average color of a surface
 pygame.transform.average_surfaces - find the average surface from many surfaces.
 pygame.transform.chop - gets a copy of an image with an interior area removed
 pygame.transform.flip - flip vertically and horizontally
diff --git a/docs/ref/transform.html b/docs/ref/transform.html
index 7951b63..e1bf5d7 100644
--- a/docs/ref/transform.html
+++ b/docs/ref/transform.html
@@ -57,6 +57,7 @@
   pygame.transform.chop - gets a copy of an image with an interior area removedgets a copy of an image with an interior area removed
   pygame.transform.laplacian - find edges in a surfacefind edges in a surface
   pygame.transform.average_surfaces - find the average surface from many surfaces.find the average surface from many surfaces.
+  pygame.transform.average_color - finds the average color of a surfacefinds the average color of a surface
   pygame.transform.threshold - finds which, and how many pixels in a surface are within a threshold of a color.finds which, and how many pixels in a surface are within a threshold of a color.
 
 A Surface transform is an operation that moves or resizes the pixels. All these functions take a Surface to operate on and return a new Surface with the results. 
@@ -153,13 +154,23 @@
 
 
 
+
+pygame.transform.average_color
+  finds the average color of a surface
+  pygame.transform.average_color(Surface, Rect = None): return Color
+Finds the average color of a Surface or a region of a surface specified by a Rect, and returns it as a Color. 
+   
+
+
+
 
 pygame.transform.threshold
   finds which, and how many pixels in a surface are within a threshold of a color.
-pygame.transform.threshold(DestSurface, Surface, color, threshold = (0,0,0,0), diff_color = (0,0,0,0), change_return = True, Surface =None): return num_threshold_pixels 
-It can set the destination surface where all of the pixels not within the threshold are changed to diff_color. 
+  pygame.transform.threshold(DestSurface, Surface, color, threshold = (0,0,0,0), diff_color = (0,0,0,0), change_return = True, Surface = None, inverse = False): return num_threshold_pixels
+Finds which, and how many pixels in a surface are within a threshold of a color. 
+It can set the destination surface where all of the pixels not within the threshold are changed to diff_color. If inverse is optionally set to True, the pixels that are within the threshold are instead changed to diff_color. 
+If the optional second surface is given, it is used to threshold against rather than the specified color. That is, it will find each pixel in the first Surface that is within the threshold of the pixel at the same coordinates of the second Surface. If change_return is set, the pixels set in DestSurface will be those from the first Surface. 
 Or it can be used to just count the number of pixels within the threshold if you set change_return to False. 
-When given the optional third surface, it will use the colors in that rather than the 3rd position "color" arg. 
 You can use a threshold of (r,g,b,a) where the r,g,b can have different thresholds. So you could use an r threshold of 40 and a blue threshold of 2 if you like. 
 New in pygame 1.8 
    
diff --git a/src/pygamedocs.h b/src/pygamedocs.h
index ec16be6..49cdff9 100644
--- a/src/pygamedocs.h
+++ b/src/pygamedocs.h
@@ -851,5 +851,7 @@
 
 #define DOC_PYGAMETRANSFORMAVERAGESURFACES "pygame.transform.average_surfaces(Surfaces, DestSurface = None): return Surface\nfind the average surface from many surfaces."
 
-#define DOC_PYGAMETRANSFORMTHRESHOLD "finds which, and how many pixels in a surface are within a threshold of a color."
+#define DOC_PYGAMETRANSFORMAVERAGECOLOR "pygame.transform.average_color(Surface, Rect = None): return Color\nfinds the average color of a surface"
+
+#define DOC_PYGAMETRANSFORMTHRESHOLD "pygame.transform.threshold(DestSurface, Surface, color, threshold = (0,0,0,0), diff_color = (0,0,0,0), change_return = True, Surface = None, inverse = False): return num_threshold_pixels\nfinds which, and how many pixels in a surface are within a threshold of a color."
 
diff --git a/src/transform.c b/src/transform.c
index 01288ab..1d8f568 100644
--- a/src/transform.c
+++ b/src/transform.c
@@ -1956,1

[pygame] No pygame.mixer.Sound.get_current()?

2008-07-29 Thread Tyler Distad
There is no function in pygame.mixer.Sound to return the current
position in the track. A get_length() function is available, so I
would assume that a get_current() position would be a simple addition.

Of course, I could be wrong. I looked at the code to see about adding
it, but in a few minutes of looking, was unable to easily find a
position marker.

Tyler Distad


Re: [pygame] Re: [OLPC-Games] PyQNet project on Launchpad

2008-07-29 Thread kschnee
On Tue, 29 Jul 2008 11:06:15 +1000, "René Dudfield" <[EMAIL PROTECTED]>
wrote:
> For the pygame 1.9+ release we would really like to get networking
> library routines in :)  Something that's simple, and has been used
> successfully in at least 2 games( 1 by the author, and 1 by someone
> else) would be nice.  Getting your library ready for ludumdare.com
> (august 8-10), and pyweek.org (sept 31st) would allow other people to
> try it out by making games.


I'm interested in the idea of Pygame getting some sort of networking
library that's as easy to set up as existing Pygame tools. Being able to
pass along messages through the event stack, as suggested, would be nice.

What would you suggest if I wanted to try a simple networked board game
with Pygame, something in which:
-Speed/lag is unimportant
-The license is public domain, GPL, or similar
-The code is simple to work with (ideally "import server; IP =
server.StartServer()")
-It supports having a non-dedicated server with multiple clients, so that I
can say "I'm hosting a game at IP 127.0.0.1:; join in!" and have people
join by typing that in and hitting a "Connect" button; and
-Setting up a server is as simple for the user as hitting a "Start Server"
button and telling people where to connect.

I'm thinking of the "Setlers of Catan" board game clone "Sea3D," which has
such an easy-to-use networking interface. Is there code out there that can
meet those requirements?



Re: [pygame] pygame and bulletml

2008-07-29 Thread Paulo Silva
thanks!  - i have now this code stored in my Pygame folder for testing
them as far i can get at least as comfortable with Pygame as i think i
were being on sdlBasic - really thanks - i'm really very curious about
how easy on Pygame we can get those shower of bullets as from Kenta
Cho games! :-)

--

On Tue, Jul 29, 2008 at 6:18 PM, Paul Pigg <[EMAIL PROTECTED]> wrote:
> I don't know bulletML and don't have plans for using it, but xml didn't seem
> to hard to work with when I needed to.  Here's a quick contrived example
> based on the "fire" example xml on the website, just to give you a quick
> idea of the api.  On it's own, it's not too useful.
>
> --Paul
>
> import xml.dom.minidom
>
> # Note that I put some whitespace in the XML, which is parsed as Text
> s='  270  2
>   '
>
> dom = xml.dom.minidom.parseString(s)
> doc = dom.documentElement
> assert doc.tagName == 'fire'
>
> print doc.tagName
>
> for child in doc.childNodes:
> if hasattr(child, 'tagName'): # isinstance(child,
> xml.dom.minidom.Element) also works...
>
> if child.tagName == 'direction':
> outstr = '  direction = ' + child.childNodes[0].data
> if child.hasAttribute('type'):
> outstr += ', type = ' + child.getAttributeNode('type').value
> print outstr
>
> elif child.tagName == 'speed':
> print '  speed = ' + child.childNodes[0].data
>
> elif child.tagName == 'bulletRef':
> if child.hasAttribute('label'):
> print '  bulletRef label = ' +
> child.getAttributeNode('label').value
>
>
> """
> prints:
>
> fire
>   direction = 270, type = absolute
>   speed = 2
>   bulletRef label = rocket
>
> """
>
>
>
>
> On Tue, Jul 29, 2008 at 1:31 AM, Paulo Silva <[EMAIL PROTECTED]> wrote:
>>
>> thanks, but if someone may have some ready snippet, please let us know...
>> :-)
>>
>> On Tue, Jul 29, 2008 at 4:37 AM, Jake b <[EMAIL PROTECTED]> wrote:
>> > Python can read xml. I don't know of a bulletml specific python lib.
>> >
>> >
>> > --
>> > Jake
>> >
>
>


Re: [pygame] pygame and bulletml

2008-07-29 Thread Paul Pigg
I don't know bulletML and don't have plans for using it, but xml didn't seem
to hard to work with when I needed to.  Here's a quick contrived example
based on the "fire" example xml on the website, just to give you a quick
idea of the api.  On it's own, it's not too useful.

--Paul

import xml.dom.minidom

# Note that I put some whitespace in the XML, which is parsed as Text
s='  270  2
  '

dom = xml.dom.minidom.parseString(s)
doc = dom.documentElement
assert doc.tagName == 'fire'

print doc.tagName

for child in doc.childNodes:
if hasattr(child, 'tagName'): # isinstance(child,
xml.dom.minidom.Element) also works...

if child.tagName == 'direction':
outstr = '  direction = ' + child.childNodes[0].data
if child.hasAttribute('type'):
outstr += ', type = ' + child.getAttributeNode('type').value
print outstr

elif child.tagName == 'speed':
print '  speed = ' + child.childNodes[0].data

elif child.tagName == 'bulletRef':
if child.hasAttribute('label'):
print '  bulletRef label = ' +
child.getAttributeNode('label').value


"""
prints:

fire
  direction = 270, type = absolute
  speed = 2
  bulletRef label = rocket

"""




On Tue, Jul 29, 2008 at 1:31 AM, Paulo Silva <[EMAIL PROTECTED]> wrote:

> thanks, but if someone may have some ready snippet, please let us know...
> :-)
>
> On Tue, Jul 29, 2008 at 4:37 AM, Jake b <[EMAIL PROTECTED]> wrote:
> > Python can read xml. I don't know of a bulletml specific python lib.
> >
> >
> > --
> > Jake
> >
>


Re: [pygame] Crackle and static with pygame.mixer.music

2008-07-29 Thread Tyler Distad
On Tue, Jul 29, 2008 at 9:28 AM, 12 Dogs <[EMAIL PROTECTED]> wrote:
> try:
>
> pygame.mixer.pre_init(44100, -16, 2, 4096)
>
> before you init

*grins delightedly* I don't quite believe it. After all the pain I've
been through on this project, it almost doesn't seem right that the
solution to this should be so simple. Thank you very much.


Re: [pygame] Crackle and static with pygame.mixer.music

2008-07-29 Thread 12 Dogs
try:

pygame.mixer.pre_init(44100, -16, 2, 4096)

before you init


On Tue, Jul 29, 2008 at 4:12 PM, Tyler Distad <[EMAIL PROTECTED]>wrote:

> I am attempting to play .ogg files with pygame, but my playback is
> static-filled. Sample script follows:
> ---
> import pygame.mixer
> pygame.mixer.init()
> pygame.mixer.music.load('sample.ogg')
> pygame.mixer.music.play()
>
> import time
> while 1:
>  time.sleep(1)
> ---
>
> I have tested this with the Ubuntu 8.04 distribution of pygame 1.7.1,
> version 1.8.0 from the home page, and the latest 1.8.1 release on the
> CVS. All versions produce identical results.
>
> All tested .ogg files work perfectly in other media players.
>


Re: [pygame] pygame and bulletml

2008-07-29 Thread Paulo Silva
thanks, but if someone may have some ready snippet, please let us know... :-)

On Tue, Jul 29, 2008 at 4:37 AM, Jake b <[EMAIL PROTECTED]> wrote:
> Python can read xml. I don't know of a bulletml specific python lib.
>
>
> --
> Jake
>