Python Forum
Trying to make a white circle appear and disappear - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Game Development (https://python-forum.io/forum-11.html)
+--- Thread: Trying to make a white circle appear and disappear (/thread-35522.html)



Trying to make a white circle appear and disappear - CompleteNewb - Nov-12-2021

I'm exploring the pixelarray in pygame. I started by drawing a white circle with a pixelarray and then i thought it might be fun to animate it and make it gradually appear and disappear so i thought that those lines of codes would work but....

import pygame, math, sys, time
from pygame.locals import *

white = (255, 255, 255)
black = (0,0,0)
pygame.init()
DISPLAYSURF = pygame.display.set_mode((1200,900))

FPS = 30
fpsclock = pygame.time.Clock()

#degree
ang = 0
hyp = 100
x = 0
y = 0
conti = True

while conti == True:
    for f in range(1, 100):

        for d in range(0, 360):
            pixObj = pygame.PixelArray(DISPLAYSURF)
            x = 100*math.cos(math.radians(d)) + 600
            y = 100*math.sin(math.radians(d)) + 450
            x = int(x)
            y = int(y)
            pixObj[x][y] = white
            del pixObj
    
    
    
        for d in range(0, 360):
            pixObj = pygame.PixelArray(DISPLAYSURF)
            x = 100*math.cos(math.radians(d)) + 600
            y = 100*math.sin(math.radians(d)) + 450
            x = int(x)
            y = int(y)
            pixObj[x][y] = black
            del pixObj
    conti = False

while True:
    for event in pygame.event.get():
        if event.type == QUIT:
            pygame.quit()
            sys.exit()
    pygame.display.update()
Keep in mind that I am new at programming and I know they are better ways to do it, but I want to do it with pixelarrays in pygame to understand their possibilities. So if you can help me understand it would be really appreciated


RE: Trying to make a white circle appear and disappear - nilamo - Nov-25-2021

You have two different while loops. The color switching is in the first loop, and is completely done when the second loop starts... and the second loop is when the window is updated.


RE: Trying to make a white circle appear and disappear - CompleteNewb - Nov-26-2021

thank you