2013-05-03 56 views
0

這裏頗爲新穎,我想一般的編程,決定要求其他人的幫助。Python奇怪的互動

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或任何其他數字它變得更加陌生。

+0

友情提示以備日後參考:不要忘記標記你所使用的所有模塊,例如Pygame在這種情況下的問題:) – Torxed 2013-05-03 17:36:15

+0

將這樣做,謝謝。 – user2347832 2013-05-03 17:40:22

回答

2

你看到兩個正弦的原因是因爲我們的願景。我們每隔幾毫秒只看到一張圖片,因此我們看到兩個正弦,而不是交替。

當你有10個,因爲你的maxint將以負z結束,所以下一次我們將繪製下半部分。你可以通過在while循環中放置n和z來解決這個問題。

此外,它更好地使用不做,而不是完成==假。