如果这是一个简单的修复,请提前道歉,但我找不到任何内容。我对pygame比较新,但我无法理解为什么当我运行这个时,第一个被绘制的条总是被切掉一半。无论如何,对我来说,我应该开始一个0,400并从0到40然后向上画。如果不是这样,请启发一个好奇的心灵
from pygame import *
import pygame, sys, random
pygame.init()
screen = pygame.display.set_mode((1000,400))
colour = (0, 255, 0)
array = []
x, y, z, b = -80, 0, 0, 0
flag = True
for c in range(5):
array.append(random.randint(100, 400));
for c in array:
print c
while True:
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit()
if len(array) == z:
flag = False
if flag == True:
b = array[z]
x += 80
z += 1
pygame.draw.line(screen, colour, (x, 400), (x, (400-b)), 40)
pygame.display.update()
答案 0 :(得分:1)
pygame 是从(0,400)到(0,400-b),画一条线,线条粗细 40。
这是一种移动线条的方法,使每个线条完全可见:
for i, b in enumerate(array):
x = i*80 + 20 # <-- add 20 to shift by half the linewidth
pygame.draw.line(screen, colour, (x, 400), (x, (400-b)), 40)
import sys
import random
import pygame
pygame.init()
screen = pygame.display.set_mode((1000,400))
colour = (0, 255, 0)
array = [random.randint(100, 400) for c in range(5)]
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
linewidth = 40
for i, b in enumerate(array):
x = i*linewidth*2 + linewidth//2
pygame.draw.line(screen, colour, (x, 400), (x, (400-b)), linewidth)
pygame.display.update()