user2347832
user2347832

Reputation: 1

Python weird interactions

quite new here and to programming in general I suppose, deciding to ask other people for help.

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 ()

So basically if maxint is 10 it gets a reflection. What I'm aiming for is the result when maxint is 5. Anyone knows why it does that?

Also when it's 6 or any other number it gets even stranger.

Upvotes: 0

Views: 172

Answers (1)

Bartlomiej Lewandowski
Bartlomiej Lewandowski

Reputation: 11180

The reason why you see two sines, is because of our vision. We only see an image every few ms, so we see both sines, instead of them alternating.

When you have 10 as your maxint will end with a negative z, so the next time we draw we will draw the bottom half. You can fix this by putting n and z inside the while loop.

Also, its nicer to use not done instead of done==False.

Upvotes: 2

Related Questions