2014-02-18 3 views
0

이 코드에서는 화면에서 7 개의 사인파가 움직이는 것을 볼 수 있습니다. 또한 오른쪽에서 4 개의 난수 그룹을 볼 수 있습니다 (@Bartlomiej Lewandowski 덕분에). 문제는 숫자가 깜박이고, 사인파가 움직이는 동안 그 숫자가 멈추는 것뿐입니다. 그렇다면 공식적인 질문은 이 코드에 숫자를 그대로 두는 방법은 무엇입니까?파이 게임에서 숫자가 깜박임을 멈 춥니 다.

import pygame 
import time 
import math 
# Some config width height settings 
canvas_width=1308 
canvas_height=720 
canvas_s=1004 
# Just define some colors we can use 
rojo=pygame.Color(255,0,0) 
verde=pygame.Color(0,255,0) 
azul=pygame.Color(0,0,255) 
amarillo=pygame.Color(255,255,0,0) 
marron=pygame.Color(85,65,0) 
morado=pygame.Color(255,0,255) 
naranja=pygame.Color(255,128,0) 
lin=pygame.Color(255,255,255) 
background_color=pygame.Color(0,0,0) 

pygame.init() 
#initialization of font module and creating a font to draw with 
pygame.font.init() 
fontdir = pygame.font.match_font('TimesNewRoman', False, False) 
myfont = pygame.font.Font(fontdir,16) 
# Set the window title 
pygame.display.set_caption("Monitor Signos Vitales") 
# Make a screen to see 
screen=pygame.display.set_mode((canvas_width,canvas_height)) 
screen.fill(background_color) 
# Make a surface to draw on 
surface=pygame.Surface((canvas_width,canvas_s)) 
surface.fill(background_color) 
#creating the random list and their corresponding surfaces 
random_list = [random.randrange(0,1000) for x in range(5)] 
text_list = [myfont.render(str(x),True,lin) for x in random_list] 

# Simple main loop 
running=True 
while running: 
    pos = (1220,0) 
    for text in text_list: 
     screen.blit(text,pos) 
     pos = (pos[0],pos[1]+180) 
    for event in pygame.event.get(): 
     if event.type==pygame.QUIT: 
      running=False 

    # Redraw the background and some guide lines 
    surface.fill(background_color) 

    pygame.draw.line(surface, lin, (0, 90), (1004, 90)) 
    pygame.draw.line(surface, lin, (0, 180), (1004, 180)) 
    pygame.draw.line(surface, lin, (0, 270), (1004, 270)) 
    pygame.draw.line(surface, lin, (0, 360), (1004, 360)) 
    pygame.draw.line(surface, lin, (0, 450), (1004, 450)) 
    pygame.draw.line(surface, lin, (0, 540), (1004, 540)) 
    pygame.draw.line(surface, lin, (0, 630), (1004, 630)) 
    pygame.draw.line(surface, lin, (1004, 0), (1308, 720)) 
    pygame.draw.line(surface, lin, (1004, 180), (1308, 180)) 
    pygame.draw.line(surface, lin, (1004, 360), (1308, 360)) 
    pygame.draw.line(surface, lin, (1004, 540), (1308, 540)) 

    # Update sine wave 
    frecuency=2;frecuency0=4;frecuency1=8;frecuency2=16;frecuency3=5;frecuency4=10 
    frecuency5=15 
    amplitude=30 # in pixels 
    speed=2 
    for x0 in range(0,canvas_s): 
     y0=int((canvas_height/2)+amplitude*math.sin(frecuency*((float(x0)/canvas_s)* (2*math.pi)+(speed*time.time()))+270)-270) 
     surface.set_at((x0,y0),amarillo) 
    for x1 in range(0,canvas_s): 
     y1=int((canvas_height/2)+amplitude*math.sin(frecuency0*((float(x1)/canvas_s)*(2*math.pi)+(speed*time.time()))+180)-180) 
     surface.set_at((x1,y1),verde) 
    for x2 in range(0,canvas_s): 
     y2=int((canvas_height/2)+amplitude*math.sin(frecuency1*((float(x2)/canvas_s)*(2*math.pi)+(speed*time.time()))+90)-90) 
     surface.set_at((x2,y2),naranja) 
    for x3 in range(0,canvas_s): 
     y3=int((canvas_height/2)+amplitude*math.sin(frecuency2*((float(x3)/canvas_s)*(2*math.pi)+(speed*time.time())))) 
     surface.set_at((x3,y3),azul) 
    for x4 in range(0,canvas_s): 
     y4=int((canvas_height/2)+amplitude*math.sin(frecuency3*((float(x4)/canvas_s)*(2*math.pi)+(speed*time.time()))-90)+90) 
     surface.set_at((x4,y4),rojo) 
    for x5 in range(0,canvas_s): 
     y5=int((canvas_height/2)+amplitude*math.sin(frecuency4*((float(x5)/canvas_s)*(2*math.pi)+(speed*time.time()))-180)+180) 
     surface.set_at((x5,y5),marron) 
    for x6 in range(0,canvas_s): 
     y6=int((canvas_height/2)+amplitude*math.sin(frecuency5*((float(x6)/canvas_s)*(2*math.pi)+(speed*time.time()))-270)+270) 
     surface.set_at((x6,y6),morado) 

    # Put the surface we draw on, onto the screen 
    screen.blit(surface,(0,0)) 
    # Show it. 
    pygame.display.flip() 

답변

2

그러나 당신은 내가 for 루프의 위치를 ​​변경 I는 않았다 그래서 적절한 순서로 모든 것을 그릴 수있는 당신은 기본적으로 그것을 채우기 다음 표면에 무언가를 그리려고하고 있었다 그래서, 이 텍스트를 화면에 그리면 모든 텍스트가 그려 지지만 여전히 이상한 깜박임/깜박임을 제거해야합니다.

import pygame 
import time 
import math 
# Some config width height settings 
canvas_width=1308 
canvas_height=720 
canvas_s=1004 
# Just define some colors we can use 
rojo=pygame.Color(255,0,0) 
verde=pygame.Color(0,255,0) 
azul=pygame.Color(0,0,255) 
amarillo=pygame.Color(255,255,0,0) 
marron=pygame.Color(85,65,0) 
morado=pygame.Color(255,0,255) 
naranja=pygame.Color(255,128,0) 
lin=pygame.Color(255,255,255) 
background_color=pygame.Color(0,0,0) 

pygame.init() 
#initialization of font module and creating a font to draw with 
pygame.font.init() 
fontdir = pygame.font.match_font('TimesNewRoman', False, False) 
myfont = pygame.font.Font(fontdir,16) 
# Set the window title 
pygame.display.set_caption("Monitor Signos Vitales") 
# Make a screen to see 
screen=pygame.display.set_mode((canvas_width,canvas_height)) 
screen.fill(background_color) 
# Make a surface to draw on 
surface=pygame.Surface((canvas_width,canvas_s)) 
surface.fill(background_color) 
#creating the random list and their corresponding surfaces 
random_list = [random.randrange(0,1000) for x in range(5)] 
text_list = [myfont.render(str(x),True,lin) for x in random_list] 

# Simple main loop 
running=True 
while running: 
    pos = (1220,0) 
    for event in pygame.event.get(): 
     if event.type==pygame.QUIT: 
      running=False 

    # Redraw the background and some guide lines 
    surface.fill(background_color) 

    #--------------------------# 
    #-------FIX POSITION-------# 
    #--------------------------# 
    for text in text_list: 
     surface.blit(text,pos) 
     pos = (pos[0],pos[1]+180) 
    pygame.draw.line(surface, lin, (0, 90), (1004, 90)) 
    pygame.draw.line(surface, lin, (0, 180), (1004, 180)) 
    pygame.draw.line(surface, lin, (0, 270), (1004, 270)) 
    pygame.draw.line(surface, lin, (0, 360), (1004, 360)) 
    pygame.draw.line(surface, lin, (0, 450), (1004, 450)) 
    pygame.draw.line(surface, lin, (0, 540), (1004, 540)) 
    pygame.draw.line(surface, lin, (0, 630), (1004, 630)) 
    pygame.draw.line(surface, lin, (1004, 0), (1308, 720)) 
    pygame.draw.line(surface, lin, (1004, 180), (1308, 180)) 
    pygame.draw.line(surface, lin, (1004, 360), (1308, 360)) 
    pygame.draw.line(surface, lin, (1004, 540), (1308, 540)) 

    # Update sine wave 
    frecuency=2;frecuency0=4;frecuency1=8;frecuency2=16;frecuency3=5;frecuency4=10 
    frecuency5=15 
    amplitude=30 # in pixels 
    speed=2 
    for x0 in range(0,canvas_s): 
     y0=int((canvas_height/2)+amplitude*math.sin(frecuency*((float(x0)/canvas_s)* (2*math.pi)+(speed*time.time()))+270)-270) 
     surface.set_at((x0,y0),amarillo) 
    for x1 in range(0,canvas_s): 
     y1=int((canvas_height/2)+amplitude*math.sin(frecuency0*((float(x1)/canvas_s)*(2*math.pi)+(speed*time.time()))+180)-180) 
     surface.set_at((x1,y1),verde) 
    for x2 in range(0,canvas_s): 
     y2=int((canvas_height/2)+amplitude*math.sin(frecuency1*((float(x2)/canvas_s)*(2*math.pi)+(speed*time.time()))+90)-90) 
     surface.set_at((x2,y2),naranja) 
    for x3 in range(0,canvas_s): 
     y3=int((canvas_height/2)+amplitude*math.sin(frecuency2*((float(x3)/canvas_s)*(2*math.pi)+(speed*time.time())))) 
     surface.set_at((x3,y3),azul) 
    for x4 in range(0,canvas_s): 
     y4=int((canvas_height/2)+amplitude*math.sin(frecuency3*((float(x4)/canvas_s)*(2*math.pi)+(speed*time.time()))-90)+90) 
     surface.set_at((x4,y4),rojo) 
    for x5 in range(0,canvas_s): 
     y5=int((canvas_height/2)+amplitude*math.sin(frecuency4*((float(x5)/canvas_s)*(2*math.pi)+(speed*time.time()))-180)+180) 
     surface.set_at((x5,y5),marron) 
    for x6 in range(0,canvas_s): 
     y6=int((canvas_height/2)+amplitude*math.sin(frecuency5*((float(x6)/canvas_s)*(2*math.pi)+(speed*time.time()))-270)+270) 
     surface.set_at((x6,y6),morado) 

    # Put the surface we draw on, onto the screen 
    screen.blit(surface,(0,0)) 
    # Show it. 
    pygame.display.flip()