2013-05-03 7 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

+0

감사합니다. – user2347832

답변

2

두 개의 사인을 보는 이유는 우리의 비전 때문입니다. 우리는 단지 몇 ms마다 이미지를 볼 수 있습니다. 그래서 우리는 두 개의 사인을 교대로 보는 대신에 보았습니다.

maxint가 음수 인 z로 끝날 때 10을 가질 때 다음 번에 그릴 때 우리는 아래쪽 절반을 그릴 것입니다. while 루프 안에 n과 z를 넣으면 문제를 해결할 수 있습니다.

또한, 사용하기가 좋지 않은 대신 done == False가 사용됩니다.