Pages

Se afișează postările cu eticheta module. Afișați toate postările
Se afișează postările cu eticheta module. Afișați toate postările

sâmbătă, 8 aprilie 2023

PyGame : ovoid with a random pattern.

Here's how to create an ovoid with a random pattern. Run the script several times to see the differences:
import pygame
import random
pygame.init()

# Set up the display window
screen_size = (400, 400)
screen = pygame.display.set_mode(screen_size)
# Set window title
pygame.display.set_caption("Ovoid with Random Pattern")
# Define the ovoid
ovoid_pos = (150, 100)
ovoid_size = (100, 200)

# Create the ovoid surface
ovoid_surface = pygame.Surface(ovoid_size, pygame.SRCALPHA)

# Define the pattern
pattern_size = (random.randint(1, 9), random.randint(1, 9))
pattern_surface = pygame.Surface(pattern_size)
pattern_surface.fill((255, 255, 255))
pygame.draw.line(pattern_surface, (0, 0, 0), (0, 0), pattern_size)

# Create the mask surface
mask_surface = pygame.Surface(ovoid_size, pygame.SRCALPHA)
pygame.draw.ellipse(mask_surface, (255, 255, 255), mask_surface.get_rect(), 0)

# Apply the pattern to the ovoid surface
for x in range(0, ovoid_size[0], pattern_size[0]):
    for y in range(0, ovoid_size[1], pattern_size[1]):
        ovoid_surface.blit(pattern_surface, (x, y))

# Apply the mask to the ovoid surface
ovoid_surface.blit(mask_surface, (0, 0), special_flags=pygame.BLEND_RGBA_MULT)

# Draw the ovoid to the screen
screen.blit(ovoid_surface, ovoid_pos)

# Update the display
pygame.display.flip()

# Wait for the user to close the window
done = False
while not done:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            done = True

# Quit pygame properly
pygame.quit()

joi, 25 mai 2017

PyGame : Fix error install pygame module on python 3.4.

Today I started to install pygame with python 3.4.1.
I got a lot of errors first with pip tool, see all errors.
C:\Python34\Scripts>pip install pygame
Downloading/unpacking pygame
  Running setup.py (path:C:\Users\mythcat\AppData\Local\Temp\pip_build_mythcat\
pygame\setup.py) egg_info for package pygame


    WARNING, No "Setup" File Exists, Running "config.py"
    Using WINDOWS configuration...

    Path for SDL not found.
    Too bad that is a requirement! Hand-fix the "Setup"
    Path for FONT not found.
    Path for IMAGE not found.
    Path for MIXER not found.
    Path for PNG not found.
    Path for JPEG not found.
    Path for PORTMIDI not found.
    Path for COPYLIB_tiff not found.
    Path for COPYLIB_z not found.
    Path for COPYLIB_vorbis not found.
    Path for COPYLIB_ogg not found.

    If you get compiler errors during install, doublecheck
    the compiler flags in the "Setup" file.


    Continuing With "setup.py"
    Error with the "Setup" file,
    perhaps make a clean copy from "Setup.in".
    Traceback (most recent call last):
      File "", line 17, in 
      File "C:\Users\mythcat\AppData\Local\Temp\pip_build_mythcat\pygame\setup.py", line 165, in 
        extensions = read_setup_file('Setup')
      File "C:\Python34\lib\distutils\extension.py", line 164, in read_setup_file
        line = expand_makefile_vars(line, vars)
      File "C:\Python34\lib\distutils\sysconfig.py", line 423, in expand_makefile_vars
        s = s[0:beg] + vars.get(m.group(1)) + s[end:]
    TypeError: Can't convert 'NoneType' object to str implicitly
    Complete output from command python setup.py egg_info:

WARNING, No "Setup" File Exists, Running "config.py"

Using WINDOWS configuration...

Path for SDL not found.

Too bad that is a requirement! Hand-fix the "Setup"

Path for FONT not found.

Path for IMAGE not found.

Path for MIXER not found.

Path for PNG not found.

Path for JPEG not found.

Path for PORTMIDI not found.

Path for COPYLIB_tiff not found.

Path for COPYLIB_z not found.

Path for COPYLIB_vorbis not found.

Path for COPYLIB_ogg not found.

If you get compiler errors during install, doublecheck

the compiler flags in the "Setup" file.

Continuing With "setup.py"

Error with the "Setup" file,

perhaps make a clean copy from "Setup.in".

Traceback (most recent call last):

  File "", line 17, in 

  File "C:\Users\mythcat\AppData\Local\Temp\pip_build_mythcat\pygame\setup.py", line 165, in 

    extensions = read_setup_file('Setup')

  File "C:\Python34\lib\distutils\extension.py", line 164, in read_setup_file

    line = expand_makefile_vars(line, vars)

  File "C:\Python34\lib\distutils\sysconfig.py", line 423, in expand_makefile_vars

    s = s[0:beg] + vars.get(m.group(1)) + s[end:]

TypeError: Can't convert 'NoneType' object to str implicitly

----------------------------------------
Cleaning up...
Command python setup.py egg_info failed with error code 1 in C:\Users\mythcat\AppData\Local\Temp\pip_build_mythcat\pygame
Storing debug log for failure in C:\Users\mythcat\pip\pip.log

C:\Python34\Scripts>pip install pygame-1.9.3-cp34-cp34m-win_amd64.whl
pygame-1.9.3-cp34-cp34m-win_amd64.whl is not a supported wheel on this platform.
Storing debug log for failure in C:\Users\mythcat\pip\pip.log

C:\Python34\Scripts>pip3 install pygame-1.9.3-cp34-cp34m-win_amd64.whl
pygame-1.9.3-cp34-cp34m-win_amd64.whl is not a supported wheel on this platform.
Storing debug log for failure in C:\Users\mythcat\pip\pip.log
The solution come with the executable pygame-1.9.2a0-hg_8d9e6a1f2635%2B.win-amd64-py3.4.msi from here and now working very well.

duminică, 12 martie 2017

PyGame : How play ogg file.

Let's see how to play file.ogg file with pygame python module.
import pygame
import time
pygame.init()
pygame.mixer.music.load('file.ogg')
pygame.mixer.music.play()
time.sleep(1.5)

luni, 24 iunie 2013

PyGame : The pygame module come without font module.

Today I try to see some old python source code.
I got this error and seam many python users have the same error.
NotImplementedError: font module not available
(ImportError: No module named font)
It's the last release of pygame.
When I try to config the pygame I got this
pygame-1.9.1release]$ python2.7 config.py
Using UNIX configuration...


Backup existing "Setup" file [Y/n]:

Hunting dependencies...
sh: smpeg-config: command not found
WARNING: "smpeg-config" failed!
SDL     : found 1.2.13
FONT    : not found
IMAGE   : found
MIXER   : not found
SMPEG   : not found
PNG     : found
JPEG    : found
SCRAP   : found
PORTMIDI: not found
PORTTIME: not found


Warning, some of the pygame dependencies were not found. Pygame can still
compile and install, but games that depend on those missing dependencies
will not run. Would you like to continue the configuration? [Y/n]:
Not only the FONT is not here. I will try to fix this issue.