2

Here's the code, i'm working on Atom. I've been using pygame for a lot of time, and that rarely happens. I never knew what the problem was, but i never needed to, until now.

import pygame
from random import randint as rnd
from colorama import Cursor
import math
import os
os.environ['SDL_VIDEO_WINDOW_POS'] = "%d,%d" % (600,90)


pygame.init()
xsize, ysize = 700, 700
screen = pygame.display.set_mode((xsize, ysize))
screen.fill((0, 0, 0))

def dis(p1, a1):
    return math.sqrt((p1[0] - a1[0])**2 + (p1[1] - a1[1])**2)

inner = 0
tot = 0
pygame.draw.circle(screen, (255, 255, 255), (350, 350), 350, 2)

while True:
    pos = (rnd(0, xsize), rnd(0, ysize))
    if dis((350, 350), pos) < 350:
        color = (50, 255, 50)
        inner += 1
    else:
        color = (50, 50, 250)
    tot += 1
    pygame.draw.circle(screen, color, pos, 2)
    print(" pi = " + str(4 * inner / tot) + "\nnº dots: " + str(tot), Cursor.UP(2))
    pygame.display.flip()
0

1 Answer 1

2

The window freeze, because you do not handle the events. You have to handle the events by either pygame.event.pump() or pygame.event.get(), to keep the window responding.

Add an event loop, for instance:

run = True
while run:

    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            run = False

    # [...]
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.