Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/363.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python pygame新手。这";对于“范围内的i”;不';行不通_Python - Fatal编程技术网

Python pygame新手。这";对于“范围内的i”;不';行不通

Python pygame新手。这";对于“范围内的i”;不';行不通,python,Python,我想让程序画100个圆圈,每个圆圈都有随机的颜色,随机的X,Y坐标和随机的大小。我正在使用范围为(100)的for I,但它不起作用。这个程序只画了一个所有东西都是随机的圆。你画了100个圆,你只是把它们都画在同一个精确的位置上 from random import randint import pygame, sys pygame.init() ekraan = pygame.display.set_mode([800, 600]) valge = [255, 255, 255] ekraan

我想让程序画100个圆圈,每个圆圈都有随机的颜色,随机的X,Y坐标和随机的大小。我正在使用范围为(100)的for I,但它不起作用。这个程序只画了一个所有东西都是随机的圆。

你画了100个圆,你只是把它们都画在同一个精确的位置上

from random import randint
import pygame, sys
pygame.init()
ekraan = pygame.display.set_mode([800, 600])
valge = [255, 255, 255]
ekraan.fill(valge)
pygame.display.set_caption("Ülesanne 6")
pygame.display.flip()


värv1 = randint(0, 255)
värv2 = randint(0, 255)
värv3 = randint(0, 255)
asukoht_x = randint(0, 800)
asukoht_y = randint(0, 600)
suurus = randint(5, 100)

i = 1
for i in range(100):
    pygame.draw.circle(ekraan, (värv1, värv2, värv3), [asukoht_x, asukoht_y], suurus, 0) 
    pygame.display.flip()
    i = i + 1



running = True
while running:
    for i in pygame.event.get():
        if i.type == pygame.QUIT:
            running = False
            pygame.quit()

你画了100个圆,你只是在同一个精确的位置画了所有的圆

from random import randint
import pygame, sys
pygame.init()
ekraan = pygame.display.set_mode([800, 600])
valge = [255, 255, 255]
ekraan.fill(valge)
pygame.display.set_caption("Ülesanne 6")
pygame.display.flip()


värv1 = randint(0, 255)
värv2 = randint(0, 255)
värv3 = randint(0, 255)
asukoht_x = randint(0, 800)
asukoht_y = randint(0, 600)
suurus = randint(5, 100)

i = 1
for i in range(100):
    pygame.draw.circle(ekraan, (värv1, värv2, värv3), [asukoht_x, asukoht_y], suurus, 0) 
    pygame.display.flip()
    i = i + 1



running = True
while running:
    for i in pygame.event.get():
        if i.type == pygame.QUIT:
            running = False
            pygame.quit()

你不是用这个代码在同一个地方画了100个圆吗?你需要在每个循环中重新随机排列它。你不就是用这个代码在同一个地方画100个圆吗?您需要在每个循环中重新随机化它。非常感谢!非常感谢你!