'my pygame window opened and closed instantly
import math
import random
import pygame
# static variables
MAX_ANTS = 100
FPS = 60
HEIGHT = 1080
WIDTH = 1920
SIZE = 5
ANT_COLOR = (255, 255, 255)
Win = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption("ANTS")
def move(x, y, speed):
direction = random.randint(0, 360)
x += speed * math.acos(direction)
y += speed * math.asin(direction)
return x, y
def draw(x, y):
Win.fill((150, 100, 125))
center = (x, y)
pygame.draw.circle(Win, ANT_COLOR, center, SIZE)
pygame.display.update()
class Ant:
def __init__(self, id):
self.id = id
self.speed = 3
self.direction = (360 / MAX_ANTS) * self.id
self.x = WIDTH/2 + math.acos(self.direction) * SIZE
self.y = HEIGHT/2 + math.asin(self.direction) * SIZE
self.size = 5
if __name__ == '__main__':
main(self.x, self.y, self.speed)
def main(x, y, speed):
clock = pygame.time.Clock()
run = True
while run:
clock.tick(FPS)
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
ants = []
for i in range(MAX_ANTS):
ants.append(Ant(i))
x, y = move(x, y, speed)
draw(x, y)
pygame.quit()
if anyone could find out the hell i did wrong XD i'm new i'd like to learn from my errors so please tell me what i did wrong(if you can) INFO:There is no errors in my program i want to make little circle(ANTS) that move around randomly with this code
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
