Python奇怪的交互

时间:2013-05-03 17:33:15

标签: python pygame

这里很新,我想一般编程,决定向其他人寻求帮助。

import sys,os
import pygame

black = ( 0, 0, 0)
white = ( 255, 255, 255)
green = ( 0, 255, 0)
red = ( 255, 0, 0)
blue = ( 0, 0, 255 )
pygame.init()
# Set the width and height of the screen [width,height]
size=[700,500]
screen=pygame.display.set_mode(size)
pygame.display.set_caption("DN[A]")
#Loop until the user clicks the close button.
done=False
# Used to manage how fast the screen updates
clock=pygame.time.Clock()
FPS=60
#Loading images below.
n=1
z=1
maxint=10
minint=-maxint
# -------- Main Program Loop -----------
while done==False:
     for event in pygame.event.get(): # User did something
         if event.type == pygame.QUIT: 
             done=True 
     # above this, or they will be erased with this command.
     screen.fill(black)
     x,y=pygame.mouse.get_pos()
     for i in range(size[1]):
         screen.set_at((x,y),blue)
         x+=1
         y+=n
         n+=z
         if n==maxint or n==minint:
             z=-z
     pygame.display.flip()
     clock.tick(FPS)
pygame.quit ()

所以基本上如果maxint是10则得到反射。我的目标是当maxint为5时的结果。任何人都知道为什么会这样做?

当它是6或任何其他数字时,它甚至变得更奇怪。

1 个答案:

答案 0 :(得分:2)

你看到两个正弦的原因是因为我们的愿景。我们每隔几毫秒就会看到一个图像,所以我们看到两个正弦,而不是它们交替出现。

如果你有10,因为你的maxint将以负z结束,所以下次我们绘制时我们将绘制下半部分。你可以通过在while循环中放入n和z来解决这个问题。

此外,它使用得更好而不是完成==错误。