Python Forum
Trying to make a white circle appear and disappear
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Trying to make a white circle appear and disappear
#1
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
Reply
#2
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.
Reply
#3
thank you
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020