Re: [pygame] New way for drawing an arc

2012-01-05 Thread Ian Mallett
The presented code definitely has room for a lot of optimization.

My solution for drawing arcs was to either render it with two circles to a
surface, and then crop/cut it out, or to just use OpenGL.  The idea would
be to use many small subdivisions just as with the polygon drawing method
for PyGame.

I suppose the absolute fastest thing to do (short of just doing it in your
favorite paint program and just drawing it as an image) would be to write a
fragment program and run it on the GPU.  'Course, that's overkill . . .
right?

Ian


Re: [pygame] cx_Freeze and Pygame Font module

2012-01-05 Thread Zack Baker
Ok so I want to create an executable but one of my files is basically import 
game and then game.play(). Can I execute the file that has like 2 lines or 
should I put everything into one file and build and execute that. Btw I'm on a 
Mac with python 2.7 do which 'compiler' should I use? The Build Applet tool 
that comes with it doesn't seem to work

-Zack


On Jan 5, 2012, at 7:31 PM, Lenard Lindstrom  wrote:

> Hi,
> 
> On 05/01/12 02:16 PM, Nick Arnoeyts wrote:
>> Hey everyone
>> 
>> I'm trying to get to know cx_freeze as an alternative to py2exe but I've run 
>> into some problems. There don't seem to be any errors in creating the exe, 
>> however when running the exe there are complaints about missing modules and 
>> DLL Load Errors (see below for the error message).
>> 
>> I am using Python 2.7 (32-bit) on Windows 7 SP1 (64-bit). Tell me if there 
>> is anything else I have to post and I will do my best.
>> 
>> Thanks in advance for your help.
>> 
>> --
>> 
>> D:\home\Dropbox\code\eclipse-workspace\TestGame01\build\exe.win32-2.7>main
>> main:1: RuntimeWarning: import display: No module named _view
>> (ImportError: No module named _view)
>> main:1: RuntimeWarning: import draw: No module named _view
>> (ImportError: No module named _view)
>> main:1: RuntimeWarning: import image: No module named _view
>> (ImportError: No module named _view)
>> main:1: RuntimeWarning: import pixelcopy: No module named _view
>> (ImportError: No module named _view)
>> main:1: RuntimeWarning: import transform: No module named _view
>> (ImportError: No module named _view)
>> main:10: RuntimeWarning: use font: DLL load failed: %1 is not a valid Win32 
>> appl
>> ication.
>> (ImportError: DLL load failed: %1 is not a valid Win32 application.)
>> Traceback (most recent call last):
>>  File "C:\Python27\lib\site-packages\cx_Freeze\initscripts\Console.py", line 
>> 27
>> , in 
>>exec code in m.__dict__
>>  File "main.py", line 10, in 
>>  File "C:\Python27\lib\site-packages\pygame\__init__.py", line 70, in 
>> __getattr
>> __
>>raise NotImplementedError(MissingPygameModule)
>> NotImplementedError: font module not available
>> (ImportError: DLL load failed: %1 is not a valid Win32 application.)
> Oops, I better add a token _view import to the Pygame package __init__.py.
> 
> In lib\__init__.py, near the bottom, is a "def package_imports():" with a 
> bunch of import statements in the body. Add an import "pygame._view" to the 
> end of the list. This should be picked up by cx_freeze and get _view included 
> in the package. I will fix this in the repository soon.
> 
> Module _view adds a wrapper class that exposes Surface data with a NumPy 
> style array interface. It is used by surfarray.
> 
> Lenard Lindstrom
> 


Re: [pygame] cx_Freeze and Pygame Font module

2012-01-05 Thread Lenard Lindstrom

Hi,

On 05/01/12 02:16 PM, Nick Arnoeyts wrote:

Hey everyone

I'm trying to get to know cx_freeze as an alternative to py2exe but 
I've run into some problems. There don't seem to be any errors in 
creating the exe, however when running the exe there are complaints 
about missing modules and DLL Load Errors (see below for the error 
message).


I am using Python 2.7 (32-bit) on Windows 7 SP1 (64-bit). Tell me if 
there is anything else I have to post and I will do my best.


Thanks in advance for your help.

--

D:\home\Dropbox\code\eclipse-workspace\TestGame01\build\exe.win32-2.7>main
main:1: RuntimeWarning: import display: No module named _view
(ImportError: No module named _view)
main:1: RuntimeWarning: import draw: No module named _view
(ImportError: No module named _view)
main:1: RuntimeWarning: import image: No module named _view
(ImportError: No module named _view)
main:1: RuntimeWarning: import pixelcopy: No module named _view
(ImportError: No module named _view)
main:1: RuntimeWarning: import transform: No module named _view
(ImportError: No module named _view)
main:10: RuntimeWarning: use font: DLL load failed: %1 is not a valid 
Win32 appl

ication.
(ImportError: DLL load failed: %1 is not a valid Win32 application.)
Traceback (most recent call last):
  File 
"C:\Python27\lib\site-packages\cx_Freeze\initscripts\Console.py", line 27

, in 
exec code in m.__dict__
  File "main.py", line 10, in 
  File "C:\Python27\lib\site-packages\pygame\__init__.py", line 70, in 
__getattr

__
raise NotImplementedError(MissingPygameModule)
NotImplementedError: font module not available
(ImportError: DLL load failed: %1 is not a valid Win32 application.)

Oops, I better add a token _view import to the Pygame package __init__.py.

In lib\__init__.py, near the bottom, is a "def package_imports():" with 
a bunch of import statements in the body. Add an import "pygame._view" 
to the end of the list. This should be picked up by cx_freeze and get 
_view included in the package. I will fix this in the repository soon.


Module _view adds a wrapper class that exposes Surface data with a NumPy 
style array interface. It is used by surfarray.


Lenard Lindstrom



Re: [pygame] New way for drawing an arc

2012-01-05 Thread Silver
Just worked on trying to use AA. turns out the way I'm checking
locations, pixel-to-pixel, very few locations actually get caught by my
secondary checks. The effect is pretty much invisible.

Another way to do an arc would be to calculate the minimum outer circle
width between points, using a combination of the pythagorean theorem and
trigonometry, but I won't do it now. Maybe in the future.




Re: [pygame] New way for drawing an arc

2012-01-05 Thread Silver
On 1/5/2012 3:41 PM, Christopher Night wrote:
> Cool! When I needed to draw an arc more than a couple of pixels wide, I
> approximated it with a polygon. I think it gave pretty good results. I'm
> not sure how it would compare performance-wise, but it should involve a lot
> fewer trig function calls. Have you tried this method?
> 
> -Christopher
> 

Not yet, but currently I'm trying to incorporate antialiasing into my
function. This function in C should run at the speed the current
rotation function runs :).


Polygons.. Say, you could use an altered version of my function to
calculate the exact accuracy of polygon you'd need to get full
reproduction. Maybe you could use this idea?


Re: [pygame] New way for drawing an arc

2012-01-05 Thread Christopher Night
Cool! When I needed to draw an arc more than a couple of pixels wide, I
approximated it with a polygon. I think it gave pretty good results. I'm
not sure how it would compare performance-wise, but it should involve a lot
fewer trig function calls. Have you tried this method?

-Christopher

On Thu, Jan 5, 2012 at 6:36 PM, Silver  wrote:

> I recently figured out how to draw an arc in pygame without moire holes
> and allowing stuff like antialiasing. Just if any of your are interested.
>
> The script is a little slow.
> Also: atan issues where the arc starts out from the left instead of top.
> I can't seem to fix it.
>
>
> --Rockachu2
>


[pygame] New way for drawing an arc

2012-01-05 Thread Silver
I recently figured out how to draw an arc in pygame without moire holes
and allowing stuff like antialiasing. Just if any of your are interested.

The script is a little slow.
Also: atan issues where the arc starts out from the left instead of top.
I can't seem to fix it.


--Rockachu2
import math

def draw_arc_matrix(matrix, pos, radius, color, width, angle1, angle2):
#print "Drawing arc at", pos, "with radius of ", radius
for x in xrange(getmatrixwidth(matrix)):
for y in xrange(getmatrixheight(matrix)):
n = ((x-pos[0])**2 )+ ((y-pos[1])**2 )
if n > (radius-width)**2:
if n < (radius)**2:
## now to check arc
#print x,y
#setpoint(matrix, [x,y], color)
angle = math.atan2(y-pos[1], x-pos[0])
angle = math.degrees(angle)+180
#print angle, angle1, angle2
if angle1 > angle2:
if angle < angle1:
if angle > angle2:
setpoint(matrix, [x,y], color)
#print x,y
else:
if angle > angle1:
if angle < angle2:
#print x,y
setpoint(matrix, [x,y], color)
def setpoint(matrix, pos, color):
matrix.set_at(pos, color)

#matrix[pos[0]][pos[1]] = color
#return matrix

def getmatrixwidth(matrix):
# reurn len(matrix)
return matrix.get_rect().width

def getmatrixheight(matrix):
# return len(matrix[0])
return matrix.get_rect().height

if __name__ == "__main__":
import pygame
pygame.init()
screen = pygame.display.set_mode((200,200))
angle = 0
anglec = 1
while True:
anglec += .1
anglec %= 360
screen.fill((0,0,0))
draw_arc_matrix(screen, (100,100), 80, (255,255,255), 10, angle, anglec)
pygame.display.update()
pygame.event.get()

[pygame] cx_Freeze and Pygame Font module

2012-01-05 Thread Nick Arnoeyts
Hey everyone

I'm trying to get to know cx_freeze as an alternative to py2exe but I've
run into some problems. There don't seem to be any errors in creating the
exe, however when running the exe there are complaints about missing
modules and DLL Load Errors (see below for the error message).

I am using Python 2.7 (32-bit) on Windows 7 SP1 (64-bit). Tell me if there
is anything else I have to post and I will do my best.

Thanks in advance for your help.

--

D:\home\Dropbox\code\eclipse-workspace\TestGame01\build\exe.win32-2.7>main
main:1: RuntimeWarning: import display: No module named _view
(ImportError: No module named _view)
main:1: RuntimeWarning: import draw: No module named _view
(ImportError: No module named _view)
main:1: RuntimeWarning: import image: No module named _view
(ImportError: No module named _view)
main:1: RuntimeWarning: import pixelcopy: No module named _view
(ImportError: No module named _view)
main:1: RuntimeWarning: import transform: No module named _view
(ImportError: No module named _view)
main:10: RuntimeWarning: use font: DLL load failed: %1 is not a valid Win32
appl
ication.
(ImportError: DLL load failed: %1 is not a valid Win32 application.)
Traceback (most recent call last):
  File "C:\Python27\lib\site-packages\cx_Freeze\initscripts\Console.py",
line 27
, in 
exec code in m.__dict__
  File "main.py", line 10, in 
  File "C:\Python27\lib\site-packages\pygame\__init__.py", line 70, in
__getattr
__
raise NotImplementedError(MissingPygameModule)
NotImplementedError: font module not available
(ImportError: DLL load failed: %1 is not a valid Win32 application.)