#๐Ÿ”’ need help with making glowing effect in pygame

12 messages ยท Page 1 of 1 (latest)

rapid agate
#

Guys can somebody help im not being able to figure this out

So i created a method which enables to make a circle transparent:

        trans_surface = pygame.Surface(self.rect, pygame.SRCALPHA)

        pygame.draw.circle(surface= trans_surface,
                            center= self.center,
                            color= self.color,
                            radius= self.radius)
        
        self.screen.blit(trans_surface, (0 ```

Now i made another method which basically  creates bigger circle each iteration and the alpha value which i set as self.color[3]
so it decreases and it should make the circle as it gets biggers the less  the alpha value 

```def outer_glow(self):
        

        alpha_value = self.color[3]
        
        for i in range(10):
            if self.radius < 300:
                self.radius += 2
            if alpha_value > 0:
                alpha_value -= 20
                print(alpha_value)
            self.trans_circle()
        
        self.trans_circle() ```

but when i run in my main file it runs but the bigger circle doesnt appear to transparent or the fade effect is missing

for clarity this is a class Circle and receives the following arguments

```self.circle = Circle(rect= self.rect,
                             center= self.center,
                             color= [252, 166, 28, 255],
                             radius= 150,
                             screen= self.screen) ```

can anybody help me whats wrong with this logic


My plan was to make a base circle with radius 150 and as more circles are iterated circles will get larger and alpha decreases giving in a fade out kind of glow
ornate heraldBOT
#

@rapid agate

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

cinder rain
#

I think there is something about a flag in the blit method

wheat geyser
#

you are making a new surface every time you draw, i have never used pygame that way but wouldnt that just erase everything every time you call that method? usually you define a single surface at the start of the program and just pass it to everything that needs it

cinder rain
#

I mean, both work

#

In both cases you need to be careful to not draw circles over and over again without using a fresh undrawn surface

rapid agate
#

@karma the issue is i cant seem to manipulate the idea that as radius grows alpha decreases creating a fade glow

wheat geyser
#

alpha = 255/rwould give you that

#

where r is the radius of each circle that's part of the glow

#

that's linear though and maybe not fast enough of a decline. you can try something like alpha = 255/(k*r) where k is some number you mess with to get the right alpha fall-off speed, or alpha = 255/(r**2) for exponential fall off, or combine both alpha = 255/(k*(r**2))

ornate heraldBOT
#
Python help channel closed for inactivity

This help channel has been closed. Feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.