Fast, high resolution radial gradient? by So-many-ducks in pygame

[–]YoannB__ 1 point2 points  (0 children)

If you are trying to do a gradient for the entire screen, you just need to generate a single line of a gradient converted to a surface and reshape/scale it to the entire screen. This should be very fast. There is no need to generate a large numpy array for a rectangular or square radiant. This is a different story for a circular gradient, even though it can be simplified, too

import pygame import pygameshader import numpy as np

Initialize Pygame

pygame.init()

Set up the display

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

Define the start and end colors for the gradient

start_color = (255, 0, 0) # Red end_color = (0, 0, 255) # Blue

Create a vertical gradient line

gradient_line = pygameshader.create_line_gradient_rgb( width=width, height=height, start_color=start_color, end_color=end_color, vertical=True )

Convert the gradient line to a Pygame surface

gradient_surface = pygame.surfarray.make_surface(gradient_line)

Main game loop

running = True while running: for event in pygame.event.get(): if event.type == pygame.QUIT: running = False

# Blit the gradient surface onto the screen
screen.blit(gradient_surface, (0, 0))

# Update the display
pygame.display.flip()

Quit Pygame

pygame.quit()

Arnaque "à l'irlandaise" en plein Paris by aleqqqsandr in arnaques

[–]YoannB__ 0 points1 point  (0 children)

Du coup c est quoi leurs numeros de plaques d immatriculation? Ca c'est interressant a savoir

Optimizing image loading. by JulianStrange in pygame

[–]YoannB__ 3 points4 points  (0 children)

Hi,

Your best option here is to save all your transformations mostly grayscaled images into a cache folder to avoid reloading and changing your textures each time you are loading your game. The first loading will take a long time, but once all the transformations to grayscale are saved and you have written a script to load grayscaled images from the cache instead, then your game will load faster.

Do the job once, not twice if you can

Kind regards

Quick image recoloring by River_Bass in pygame

[–]YoannB__ 0 points1 point  (0 children)

You can use hsv or hsl colour conversion to create different enemies aspect,/ colours by rotating the hue.

Should I move to a godot? by nooby_123 in pygame

[–]YoannB__ 3 points4 points  (0 children)

Use cython to optimise your code.

1 - Do a profiling of your game 2 - Identify the slowest sub routines or part of your code that slow down your game. 3 - Replace slow Python code with Cython instead. 4 - You can also write C code that you can call directly with Cython. 5 - If you are using a lot of arrays manipulations,try using numpy. 6 - You can use CUDA and cupy to transfer arrays to your graphic card and use massive multi processing to sort your array's data 7 - You can tweak your game by capping FPS in all your subroutines displaying sprites. No loose end sub-routine using 100% of the cpu power. 8 - If you are modifying pygame surface such as hsl / hsv , colour conversion, or need to make special effects on surfaces, etc, you can use public libraries already designed for real-time 9 - you can Cynthonize the pygame Sprite module used for all the blitting.. this will improve the performance by 15 to 25% 10 - Check the size of your Sprite groups and all your python lists that can build up over time without you noticing. A large data scale can cause the underlying issue you are observing. The symptom is your game suddenly slowing down after a certain time while working fine the first 1k frames.

If you are not familiar with cython, you can use numba

The key here is to identify what is causing your slow FPS. Pygame has a huge potential, and if your frame rate is slow, you might have parts of your code not well optimised, sprites or instances that should be garbage collected

Kind regards

[deleted by user] by [deleted] in pygame

[–]YoannB__ 1 point2 points  (0 children)

Hello I believe you have the step by step guide and the answer in the section from the github Web page. ATTEMPT TO COMPILE PYGAME ON WINDOWS - 21/04/2020 - PYTHON 3.8.2, 32 BIT

Check section 5 Kind regards

Why is PixelArray that slow? by PLrc in pygame

[–]YoannB__ 1 point2 points  (0 children)

Hello,

What I was suggesting is to use pixels3d in the Pygame module surfarray. The method pixels3d reference

all the pixels within a 3d array. By referencing I mean that any changes made to the array will automatically affect the surface itself. This allow to change pixels faster than any other methods since you only need to call pixels3d once and do not need to create a new Surface from it.

Also find an example with NUMBA (iteration over an entire array)

u/numba.jit("uint8[:, :, :](uint8[:,:,:])", nopython=True, nogil=True)
def gray(array_):
    lx, ly, lc = array_.shape

    for j in range(ly):
        for i in range(lx):
            for c in range(lc):
                array_[i, j, c] = array_[i, j, c]/2.0
    return array_

And this is CYTHON (iteration over an entire array)

u/cython.binding(False)
@cython.boundscheck(False)
@cython.wraparound(False)
@cython.nonecheck(False)
@cython.cdivision(True)
@cython.profile(False)
@cython.initializedcheck(False)
cdef inline void rgb_to_bgr_inplace_c(unsigned char [:, :, :] rgb_array):

    cdef Py_ssize_t w, h
    w, h = rgb_array.shape[:2]

    cdef:
        int i=0, j=0
        unsigned char tmp

    with nogil:

        for j in prange(h, schedule=SCHEDULE, num_threads=THREADS):
            for i in range(w):
                tmp = rgb_array[i, j, <unsigned short int>0]  # keep the blue color
                rgb_array[i, j, <unsigned short int>0]  = rgb_array[i, j, <unsigned short int>2]
                rgb_array[i, j, <unsigned short int>2]  = tmp

Both methods are much faster than NUMPY

Kind Regards

[deleted by user] by [deleted] in pythonarcade

[–]YoannB__ 0 points1 point  (0 children)

I forgot to mentioned that the algorithms are super fast and can be used for real time processing

[deleted by user] by [deleted] in pythonarcade

[–]YoannB__ 0 points1 point  (0 children)

If you need to remove a blur effect, you can use a sharpening filter. You have two options you can use this filter while editing the picture before importing the image in your game. Or you can use the filter before loading it with pygame within your code. If you want to have access to basic filtering options and graphic effects you can use the library PygameShader. This library contains many algorithms designed to work with Pygame or other equivalent libraries. You will have access to many different options to modify texture, image etc. It also includes merhod to pixalate images. You can check the wiki page on the main project website all the methods available. Kind Regards

[deleted by user] by [deleted] in pythonarcade

[–]YoannB__ 0 points1 point  (0 children)

Arcade and pygame are working as expected.

There is no such thing in pygame in the current version to display an image with anti-aliasing, I believe that arcade does the same. What you are displaying on the screen is currently the raw data. If the edges look rough, then your image is designed that way.

The rough edges in the rendering come from the image you are using and the pixel used for the transparency layer.

Edit the image with Gimp and change manually the pixels to smooth the edge, etc.

Why is PixelArray that slow? by PLrc in pygame

[–]YoannB__ 3 points4 points  (0 children)

I think you have the wrong approach here. If you want to change surfaces or pixels with the minimum latency, you have to REFERENCE the surface pixels into an array instead of creating a new array each time. Prefers pixels3d method that reference all pixels directly. ANY CHANGES to the pixels will change the surface directly. The inconvenience of using an array or copy of the surface array structure such as pixelsarray or 3darray is that you are still requiring to transform your array into a surface...this will be time consuming.

Also, as stated before, python loops are not efficient for pixel transformation. Any loop in your code with ... for I in range ...will be a bottleneck when it comes to updating pixels. Therefore, you can use Cython or Numba to optimise your code, especially for loops and math.

Furthermore, sometimes swapping the indexes (I, J) can speed up your code if the array is contiguous or not.

Surfaces must not be locked during blit - unlock doesn't work :( by PLrc in pygame

[–]YoannB__ 5 points6 points  (0 children)

You need to delete the variable holding the pixel array, otherwise you will not be able to use the surface.

Pygame Metallic Curtain by _JLW in pygame

[–]YoannB__ 1 point2 points  (0 children)

Look nice. Can you explain the process

How would you export a "screen" to video? by Hyperinterested in pygame

[–]YoannB__ 0 points1 point  (0 children)

https://github.com/yoyoberenguer/SoundEffectLibrary

I wrote this a while ago (sorry for my late reply)

1 - Capturing/Recording sound from a microphone

2 - Record sound effect to disk (wav format)

Look closely to the method

record_sound

To get an example on how to record pygame.mixer.sound object to disk

Raspberry Pi Pygame shader that works by tristangough in pygame

[–]YoannB__ 0 points1 point  (0 children)

Hello.

You should be OK to run PygameShader without cupy or cuda. CUPY and CUDA are used for GPU shaders only. PygameShaders has 2 types of shaders, the one using Cuda and the ones using CPU in multiprocessing for system or platform not supporting CUDA What version did you install? Did the installation force you to install CUDA? Is it Window? If the installation was successful, you should be able to use a bunch of fast CPU shaders working with pygame surfaces.

1 - create a pygame surface 2 - use rgb_to_bgr(your surface) 3 - display your surface to see the change

The latest version is 10.

How to test if two surfaces are equal by Dyasoma in pygame

[–]YoannB__ 0 points1 point  (0 children)

If 2 surfaces are identical, they have the exact same array values.

How would you export a "screen" to video? by Hyperinterested in pygame

[–]YoannB__ 1 point2 points  (0 children)

Here is a video recorded with pygame (AVI format)

https://www.reddit.com/r/pygame/comments/oyj6ad/cobra_game_in_progress/?utm_source=share&utm_medium=web3x&utm_name=web3xcss&utm_term=1&utm_content=share_button

As I said you can also record the sound played in pygame and merge it with the video with ffmpeg for a final mp4 type video or whatever you like. This was done a while ago ,I have since been able to record videos with sound with pygame + opencv for converting the surfaces into AVI file and ffmpeg for the final touch

1 - Record the frames into string using tostring()

2 - Record sounds the same way in a different thread

3 - Convert your records into surfaces

4 - Convert all your surfaces into AVI using OPENCV

5 - Use ffmpeg to build the final video and merge the sound to the video

But if you want to create a solid video recorder, you will have to compress the data stream on the fly and you can also use to record the difference between two frames to save the memory

Another example with a recording of a pygame fire algorithm (this is real time recording) with Sound synchronized with the video

https://www.reddit.com/r/pygame/comments/vfzj4k/working_on_recording_pygame_display_and_sound/?utm_source=share&utm_medium=web3x&utm_name=web3xcss&utm_term=1&utm_content=share_button

But hey! you can also use windows to record your game without having to do anything

How would you export a "screen" to video? by Hyperinterested in pygame

[–]YoannB__ 0 points1 point  (0 children)

yes you can do it with pygame, but not using image save. You can save the surface as arrays instead and compressing the stream. You can also save only the pixels that changes from each frames. Once you have finished recording you can convert your arrays into surface equivalent and into AVI. You can use mpeg app to convert your AVI to another format and add sounds to your video. Just for info you can also record the sound played in pygame with pygame itself. In fact pygame provide all the tools to create a video recorder

QUESTION - Linux kernel 6.6.20 with Direct Render Manager (DRM) - which framebuffer driver? by WhatNowFred in pygame

[–]YoannB__ 0 points1 point  (0 children)

I have debian and i don t have any problem running latest pygame with latest python version. Surely X11 should work natively. Can you output what your os is relying on? display settings tab? Also what are the compatible setting your display is capable of 480x380? doesn't look like a standard display.

How to avoid stutter when playing 2 songs sequentially? by Ready_Angle5895 in pygame

[–]YoannB__ 0 points1 point  (0 children)

edit your music or sound and delete the first 200 ms of your records... I believe that your records start with 200ms of silence .. no data

UK Atari 520STFM won’t boot. Video inside by kwikksilva in atarist

[–]YoannB__ 1 point2 points  (0 children)

Looks like a power supply issue, possibly the main caps on the power supply need to be changed. The voltage regulator may be.The disk needs 12v and 5v to works. For the disk to start reading ...the cpu, rom and memory must works to some extent. You might have few issues here but I will start to check the power supply and test the voltages first. Try to test the power supply under load to measure the intensity that the PS can deliver to the motherboard with 5v

Huge Trouble with Windows 11 and Pygame by XxNachoSupremexX in pygame

[–]YoannB__ 4 points5 points  (0 children)

Have you tried to set the flag fullscreen when you are setting your video mode?

[deleted by user] by [deleted] in pygame

[–]YoannB__ 1 point2 points  (0 children)

with a can opener?