[pygame] a little help

2012-01-14 Thread Silver
Oops, got my rect width argument wrong... Never mind.


[pygame] A little help please

2012-01-14 Thread Silver
I need some help with a program that I'm trying to write with pygame.

I am having two issues:
* the squares aren't being drawn 1 px small so that they leave a black 
grid
* the squares on the edges are extending, even though I don't think I
told them to.

anyone know how to fix it?
import pygame
import math


squaresize = 64
sqsz = squaresize

width = 799
height = width

radius = .5*sqsz

pygame.init()

screen = pygame.display.set_mode((width,height))

while True:
pygame.event.get()
mousex = pygame.mouse.get_pos()[0]
mousey = pygame.mouse.get_pos()[1]
screen.fill((0,0,0))
for x in xrange(width/squaresize):
for y in xrange(height/squaresize):
hx = x
hy = y
hx *= sqsz
hy *= sqsz
#print hx,hy,sqsz, sqsz
nx = hx+(sqsz/2)-mousex
ny = hy+(sqsz/2)-mousey
nz = ((nx**2)+(ny**2))**.5
if nz == 0:
nz = .001#print nz
n = radius / nz
if n == 0:
n = .001
if n > 1:
n = 1

#print n
color = n*255
#print (color,color,color)
#print hx, hy, hx+15, hy+15
pygame.draw.rect(screen, (color,color,color), 
(hx,hy,hx+sqsz-1,hy+sqsz-1))
pygame.display.update()


Re: [pygame] Capabilities of Pygame

2012-01-14 Thread Lenard Lindstrom

On 14/01/2012 8:36 PM, Greg wrote:

--- On Sat, 1/14/12, Ryan Strunk  wrote:

The only audio-only game I've seen written in Pygame, Sound
RTS, has a bit
of noticeable lag when playing sounds.


I don't know about music, but the latency of (non-streamed)
sounds can be reduced by specifying a smaller buffer size
when you initialise the mixer module.

I remember there was a tradeoff though, with poor playback if the buffer 
was too small. Maybe that is no longer a problem.


Lenard



Re: [pygame] Capabilities of Pygame

2012-01-14 Thread Lenard Lindstrom

On 14/01/2012 2:22 AM, Christopher Night wrote:
On Fri, Jan 13, 2012 at 9:15 PM, Lenard Lindstrom > wrote:


On 13/01/12 01:43 PM, Julian Marchant wrote:

--- On Fri, 1/13/12, Lenard Lindstrommailto:le...@telus.net>>  wrote:

Also,
though SDL does support streaming, Pygame does not.
Everything must be loaded before played.

Um... that's not true.  pygame.mixer.music is Pygame's
streaming module.

Oh right, I forgot about file like objects. Has anyone managed to
use the music module to play streaming audio?


I feel like I'm misunderstanding you, but yes I use pygame.mixer.music 
to stream audio from an OGG file all the time. I've never had a 
problem with it. Is that what you're asking?


-Christopher

I was vague. I was referring to streaming audio from a remote server, 
such as over the internet. If Ryan Strunk intends to develop a web based 
multiplayer game--he did mention World of Warcraft--then he would want 
streaming audio, especially if the game is audio only. Pygame has no 
code specific to remote streaming. I did search if an audio stream could 
be fed to the music module through a socket or pipe. I found no answer.


If I am reading too much into Ryan's intentions then I apologize for 
sidetracking the discussion.


Lenard Lindstrom



Re: [pygame] Capabilities of Pygame

2012-01-14 Thread Greg

--- On Sat, 1/14/12, Ryan Strunk  wrote:

The only audio-only game I've seen written in Pygame, Sound
RTS, has a bit
of noticeable lag when playing sounds.


I don't know about music, but the latency of (non-streamed)
sounds can be reduced by specifying a smaller buffer size
when you initialise the mixer module.

--
Greg


RE: [pygame] Capabilities of Pygame

2012-01-14 Thread Julian Marchant
--- On Sat, 1/14/12, Ryan Strunk  wrote:
> So if you were to stream audio, would that eliminate the
> potential delay.
> The only audio-only game I've seen written in Pygame, Sound
> RTS, has a bit
> of noticeable lag when playing sounds. Is there a way to
> program such that
> sounds would play instantly when told to do so?

Streaming is for music, not sound effects.


RE: [pygame] Capabilities of Pygame

2012-01-14 Thread Ryan Strunk
--- On Fri, 1/13/12, Lenard Lindstrom  wrote:

> > Also,
> > though SDL does support streaming, Pygame does not.
> > Everything must be loaded before played.

> Um... that's not true.  pygame.mixer.music is Pygame's streaming module.

So if you were to stream audio, would that eliminate the potential delay.
The only audio-only game I've seen written in Pygame, Sound RTS, has a bit
of noticeable lag when playing sounds. Is there a way to program such that
sounds would play instantly when told to do so?
Thanks for everyone's help thus far.
Ryan



Re: [pygame] Capabilities of Pygame

2012-01-14 Thread Greg

R. Alan Monroe wrote:

How does a C command
that gets compiled to a CPU's MUL instruction differ in any way from a
Fortran command that also gets compiled to that same CPU's same MUL
instruction?


Fortran has various rules that prevent aliasing, i.e. having
two different names for the same thing. This allows the compiler
to perform various optimisations that can't safely be performed
in C, where you can get aliasing of just about anything using
pointers.

Various arcane anti-aliasing rules have been introduced into
recent versions of C, but there's still a lot more room for
aliasing than there is in Fortran.

--
Greg


Re: [pygame] Capabilities of Pygame

2012-01-14 Thread ANKUR AGGARWAL
You can check put my repository for  pygame examples
https://github.com/ankur0890/Pygame-Examples-For-Learning

On Sat, Jan 14, 2012 at 4:33 AM, R. Alan Monroe wrote:

> > FORTRAN is still used in some circles because it's
> > still very fast for number crunching.
>
> A bit off topic, but I've seen this bit of folk wisdom repeated online
> for a long time and have always been skeptical. How does a C command
> that gets compiled to a CPU's MUL instruction differ in any way from a
> Fortran command that also gets compiled to that same CPU's same MUL
> instruction? Honest question.
>
> Alan
>
>


Re: [pygame] Capabilities of Pygame

2012-01-14 Thread René Dudfield
On Sat, Jan 14, 2012 at 12:03 AM, R. Alan Monroe wrote:

> > FORTRAN is still used in some circles because it's
> > still very fast for number crunching.
>
> A bit off topic, but I've seen this bit of folk wisdom repeated online
> for a long time and have always been skeptical. How does a C command
> that gets compiled to a CPU's MUL instruction differ in any way from a
> Fortran command that also gets compiled to that same CPU's same MUL
> instruction? Honest question.
>
> Alan
>
>

Theoretically, the compiler has more information about the fortran code
than the C code, so can make more optimizations.  So in C, the compiler can
not be sure about pointer aliasing, and such things... so it has to be a
little safer about the optimizations.  In practice, you can provide hints
to the C compiler to get pretty much the same performance.  For a modern C
compiler like gcc, you have things like 'pure', 'restrict', openmp hints,
function level optimization optimizations, and various other vectorisation
hints that let you do lots of optimizations that fortran can do.

See this for more info:
http://stackoverflow.com/questions/146159/is-fortran-faster-than-c
Also see here that fortran is still speedy:

http://shootout.alioth.debian.org/u64q/which-programming-languages-are-fastest.php


cheers,


Re: [pygame] Capabilities of Pygame

2012-01-14 Thread R. Alan Monroe
> FORTRAN is still used in some circles because it's
> still very fast for number crunching.

A bit off topic, but I've seen this bit of folk wisdom repeated online
for a long time and have always been skeptical. How does a C command
that gets compiled to a CPU's MUL instruction differ in any way from a
Fortran command that also gets compiled to that same CPU's same MUL
instruction? Honest question.

Alan



Re: [pygame] Capabilities of Pygame

2012-01-14 Thread Sean Wolfe
ogg streaming + sound effects together, works fine for me on both
pygame windows + android phone. Worked like a charm actually. I love
python.

On Sat, Jan 14, 2012 at 1:13 AM, Zack Baker  wrote:
> Thanks guys!!
>
> -Zack
>
>
> On Jan 13, 2012, at 10:45 PM, Ian Mallett  wrote:
>
> On Fri, Jan 13, 2012 at 7:36 PM, Zack Baker  wrote:
>>
>> I use it for my 'soundtracks' in the games. The only problem I run into
>> with it is it takes a 'loop' argument, which is how many times the song
>> should loop, I wish you could set this too infinite but I usually set it too
>> 500 and that seems to work. Assuming no one will play my game for mor than
>> 26 hours in a row...
>>
>> -Zack
>
> If I recall, try -1



-- 
A musician must make music, an artist must paint, a poet must write,
if he is to be ultimately at peace with himself.
- Abraham Maslow