嗨,我只是一个初学者,我正在尝试制作摩天轮动画。
我能够推断出窗口开始崩溃的位置,它是下面的代码块。
def carriages(cx1,cy1,cx2,cy2,cx3,cy3,cx4,cy4,cx5,cy5,cx6,cy6,cx7,cy7,cx8,cy8,cx9,cy9,cx10,cy10,cx11,cy11,cx12,cy12,cx13,cy13,cx14,cy14,cx15,cy15):#gather variables for placement
carriage1 = pygame.draw.polygon(screen, yellow, [[-30+cx1,-10+cy1],[30+cx1,-10+cy1],[20+cx1,10+cy1],[-20+cx1,10+cy1]],0)#the four points of the carriages with center at 0 plus the positions they need to be placed on ferris
carriage2 = pygame.draw.polygon(screen, yellow, [[-30+cx2,-10+cy2],[30+cx2,-10+cy2],[20+cx2,10+cy2],[-20+cx2,10+cy2]],0)
carriage3 = pygame.draw.polygon(screen, yellow, [[-30+cx3,-10+cy3],[30+cx3,-10+cy3],[20+cx3,10+cy3],[-20+cx3,10+cy3]],0)
carriage4 = pygame.draw.polygon(screen, yellow, [[-30+cx4,-10+cy4],[30+cx4,-10+cy4],[20+cx4,10+cy4],[-20+cx4,10+cy4]],0)
carriage5 = pygame.draw.polygon(screen, yellow, [[-30+cx5,-10+cy5],[30+cx5,-10+cy5],[20+cx5,10+cy5],[-20+cx5,10+cy5]],0)
carriage6 = pygame.draw.polygon(screen, yellow, [[-30+cx6,-10+cy6],[30+cx6,-10+cy6],[20+cx6,10+cy6],[-20+cx6,10+cy6]],0)
carriage7 = pygame.draw.polygon(screen, yellow, [[-30+cx7,-10+cy7],[30+cx7,-10+cy7],[20+cx7,10+cy7],[-20+cx7,10+cy7]],0)
carriage8 = pygame.draw.polygon(screen, yellow, [[-30+cx8,-10+cy8],[30+cx8,-10+cy8],[20+cx8,10+cy8],[-20+cx8,10+cy8]],0)
carriage9 = pygame.draw.polygon(screen, yellow, [[-30+cx9,-10+cy9],[30+cx9,-10+cy9],[20+cx9,10+cy9],[-20+cx9,10+cy9]],0)
carriage10 = pygame.draw.polygon(screen, yellow, [[-30+cx10,-10+cy10],[30+cx10,-10+cy10],[20+cx10,10+cy10],[-20+cx10,10+cy10]],0)
carriage11 = pygame.draw.polygon(screen, yellow, [[-30+cx11,-10+cy11],[30+cx11,-10+cy11],[20+cx11,10+cy11],[-20+cx11,10+cy11]],0)
carriage12 = pygame.draw.polygon(screen, yellow, [[-30+cx12,-10+cy12],[30+cx12,-10+cy12],[20+cx12,10+cy12],[-20+cx12,10+cy12]],0)
carriage13 = pygame.draw.polygon(screen, yellow, [[-30+cx13,-10+cy13],[30+cx13,-10+cy13],[20+cx13,10+cy13],[-20+cx13,10+cy13]],0)
carriage14 = pygame.draw.polygon(screen, yellow, [[-30+cx14,-10+cy14],[30+cx14,-10+cy14],[20+cx14,10+cy14],[-20+cx14,10+cy14]],0)
carriage15 = pygame.draw.polygon(screen, yellow, [[-30+cx15,-10+cy15],[30+cx15,-10+cy15],[20+cx15,10+cy15],[-20+cx15,10+cy15]],0)
在此代码中,15个滑架的中心位于0处.cx和cy值然后将滑架移动到摩天轮上的正确位置。每辆车都有自己的价值,因为它们各自在摩天轮上都有自己的位置。
我确实尝试将值更改为全局,但它没有改变任何内容。
我确保呼叫功能在正确的位置。
在窗口崩溃之前,期间或之后不会显示错误消息。
感谢您查看此问题,如果您能帮助我,我们将不胜感激。
由于上面的代码不是问题所以我的代码的其余部分。 (我知道它有点无组织,但我仍在制作它)
import pygame # this allows program to use all the functions in Pygame module
import time
#variables
#carriage
cx = 0 #x axis
cy = 0 #y axis
pos =0 #position on wheel
carriageno= 0#carriage number 0-15
#carriage x/y placement variables (cx1 == carriage 1(x axis) etc.)
cx1=0
cy1=0
cx2=0
cy2=0
cx3=0
cy3=0
cx4=0
cy4=0
cx5=0
cy5=0
cx6=0
cy6=0
cx7=0
cy7=0
cx8=0
cy8=0
cx9=0
cy9=0
cx10=0
cy10=0
cx11=0
cy11=0
cx12=0
cy12=0
cx13=0
cy13=0
cx14=0
cy14=0
cx15=0
cy15=0
#FPS code
FPS = 3
fpsclock = pygame.time.Clock()
#colours
red = (255,0,0)
blue = (0, 0, 255)
lightblue = (51,255,255)
yellow =(255, 255, 51)
black = (0,0,0)
white = (255,255,255)
purple = (150, 0, 150)
orange = (255,158,0)
brown = (152,51,0)
grey = (129,129,129)
green= (0,204,0)
#images
def blueguy():#not in use
pygame.draw.circle(screen, blue, [10,10],8)
pygame.draw.rect(screen, blue, [5,15,10,15])
def pinkguy():#not in use
pygame.draw.circle(screen, blue, [10,10],8)
pygame.draw.rect(screen, blue, [5,15,10,15])
def ferriswheelbase():
pygame.draw.circle(screen, blue, [250,250],150, 8) #the circle
pygame.draw.polygon(screen, purple, [[250,250],[100,400],[400,400]],8)#triangle (ferris support)
def fence():
pos2 = 0
pygame.draw.line(screen, brown,[0,400],[500,400], 5)#draw bottom fence line
pygame.draw.line(screen, brown,[0,390],[500,390], 5)# draw top fence line
while pos2 < 500: #continue until the latest fence is near the end of the screen
pygame.draw.rect(screen, brown, [(0+pos2),385,5,15])#draw fence stake
pygame.draw.polygon(screen, brown, [[(0+pos2),385],[(2+pos2),380],[(4+pos2),385]],0)#draw triangle (for the sharp part of the stake)
pos2 = pos2 + 10 #where the fence is positioned
def ground():
pygame.draw.rect(screen, green, [0,400,500,100])#grass
pygame.draw.rect(screen, brown, [0,405,500,25])#path
def sky():
pygame.draw.rect(screen, lightblue, [0,0,500,400])#blue sky
def back():#draw background i.e sky, fence etc.
sky()
ground()
fence()
ferriswheelbase()
def carriages(cx1,cy1,cx2,cy2,cx3,cy3,cx4,cy4,cx5,cy5,cx6,cy6,cx7,cy7,cx8,cy8,cx9,cy9,cx10,cy10,cx11,cy11,cx12,cy12,cx13,cy13,cx14,cy14,cx15,cy15):#gather variables for placement
carriage1 = pygame.draw.polygon(screen, yellow, [[-30+cx1,-10+cy1],[30+cx1,-10+cy1],[20+cx1,10+cy1],[-20+cx1,10+cy1]],0)#the four points of the carriages with center at 0 plus the positions they need to be placed on ferris
carriage2 = pygame.draw.polygon(screen, yellow, [[-30+cx2,-10+cy2],[30+cx2,-10+cy2],[20+cx2,10+cy2],[-20+cx2,10+cy2]],0)
carriage3 = pygame.draw.polygon(screen, yellow, [[-30+cx3,-10+cy3],[30+cx3,-10+cy3],[20+cx3,10+cy3],[-20+cx3,10+cy3]],0)
carriage4 = pygame.draw.polygon(screen, yellow, [[-30+cx4,-10+cy4],[30+cx4,-10+cy4],[20+cx4,10+cy4],[-20+cx4,10+cy4]],0)
carriage5 = pygame.draw.polygon(screen, yellow, [[-30+cx5,-10+cy5],[30+cx5,-10+cy5],[20+cx5,10+cy5],[-20+cx5,10+cy5]],0)
carriage6 = pygame.draw.polygon(screen, yellow, [[-30+cx6,-10+cy6],[30+cx6,-10+cy6],[20+cx6,10+cy6],[-20+cx6,10+cy6]],0)
carriage7 = pygame.draw.polygon(screen, yellow, [[-30+cx7,-10+cy7],[30+cx7,-10+cy7],[20+cx7,10+cy7],[-20+cx7,10+cy7]],0)
carriage8 = pygame.draw.polygon(screen, yellow, [[-30+cx8,-10+cy8],[30+cx8,-10+cy8],[20+cx8,10+cy8],[-20+cx8,10+cy8]],0)
carriage9 = pygame.draw.polygon(screen, yellow, [[-30+cx9,-10+cy9],[30+cx9,-10+cy9],[20+cx9,10+cy9],[-20+cx9,10+cy9]],0)
carriage10 = pygame.draw.polygon(screen, yellow, [[-30+cx10,-10+cy10],[30+cx10,-10+cy10],[20+cx10,10+cy10],[-20+cx10,10+cy10]],0)
carriage11 = pygame.draw.polygon(screen, yellow, [[-30+cx11,-10+cy11],[30+cx11,-10+cy11],[20+cx11,10+cy11],[-20+cx11,10+cy11]],0)
carriage12 = pygame.draw.polygon(screen, yellow, [[-30+cx12,-10+cy12],[30+cx12,-10+cy12],[20+cx12,10+cy12],[-20+cx12,10+cy12]],0)
carriage13 = pygame.draw.polygon(screen, yellow, [[-30+cx13,-10+cy13],[30+cx13,-10+cy13],[20+cx13,10+cy13],[-20+cx13,10+cy13]],0)
carriage14 = pygame.draw.polygon(screen, yellow, [[-30+cx14,-10+cy14],[30+cx14,-10+cy14],[20+cx14,10+cy14],[-20+cx14,10+cy14]],0)
carriage15 = pygame.draw.polygon(screen, yellow, [[-30+cx15,-10+cy15],[30+cx15,-10+cy15],[20+cx15,10+cy15],[-20+cx15,10+cy15]],0)
def carriagemovement():
global cx1 #has to be global due to changes made inside this function, affect another function
global cy1
global cx2
global cy2
global cx3
global cy3
global cx4
global cy4
global cx5
global cy5
global cx6
global cy6
global cx7
global cy7
global cx8
global cy8
global cx9
global cy9
global cx10
global cy10
global cx11
global cy11
global cx12
global cy12
global cx13
global cy13
global cx14
global cy14
global cx15
global cy15
global cx
global cy
global pos #position on wheel
global counter #number of times looped (for each carriage)
global no #the carriage no
counter = 0
while counter < 16:
no = 0 + counter #example if (no = 1)=carriage 1
pos = counter #temporary (look at carriagepos() for real position) (this would not make the carriages move)
if pos == 0: #place on circle
cx =250
cy =100
if pos == 1:
cx =309
cy =118
if pos == 2:
cx =348
cy =140
if pos == 3:
cx =394
cy =213
if pos == 4:
cx =400
cy =250
if pos == 5:
cx =383
cy =298
if pos == 6:
cx =355
cy =355
if pos == 7:
cx =288
cy =383
if pos == 8:
cx = 250
cy = 400
if pos == 9:
cx =203
cy =383
if pos == 10:
cx =155
cy =355
if pos == 11:
cx =108
cy =288
if pos == 12:
cx =100
cy =250
if pos == 13:
cx =108
cy =188
if pos == 14:
cx =155
cy =145
if pos == 15:
cx =173
cy =118
if no == 0: #assigns the position nums to the right carriage
cx = cx1
cy = cy1
if no == 1:
cx = cx2
cy = cy2
if no == 2:
cx = cx3
cy = cy3
if no == 3:
cx = cx4
cy = cy4
if no == 4:
cx = cx5
cy = cy5
if no == 5:
cx = cx6
cy = cy6
if no == 6:
cx = cx7
cy = cy7
if no == 7:
cx = cx8
cy = cy8
if no == 8:
cx = cx9
cy = cy9
if no == 9:
cx = cx10
cy = cy10
if no == 10:
cx = cx11
cy = cy11
if no == 11:
cx = cx12
cy = cy12
if no == 12:
cx = cx13
cy = cy13
if no == 13:
cx = cx14
cy = cy14
if no == 14:
cx = cx15
cy = cy15
if no == 15:
cx = cx15
cy = cy15
def carriagepos():
global pos
if pos < 16 and pos > 0: #if the position not equal 0 or 16
pos = pos + 1
else:
if pos == 16:#if the pos equal 16 change to 0 (resets clockwise movement)
pos = 0
else: pos = pos + 1 #if the event that pos == 0, add one to turn zero to one(moves the process along)
#window
pygame.init() # this allows all the pygame modules to be inititalised - ready to be used
background_colour = white# max value of red, green and blue creates white
(width, height) = (500, 500) # sets size of the window
screen = pygame.display.set_mode((width, height)) # call function called set_mode within the display class
pygame.display.set_caption('Opening & Closing a Window') # call a function within pygame module to set caption
screen.fill(background_colour) # set background colour
pygame.display.flip()#refresh
running = True # this sets a flag (a variable that stores a value in order to make something happen)
while running == True:
back()#draw background
carriagemovement()#idenify carriage no and pos
#crashes when drawing carriages
carriages(cx1,cy1,cx2,cy2,cx3,cy3,cx4,cy4,cx5,cy5,cx6,cy6,cx7,cy7,cx8,cy8,cx9,cy9,cx10,cy10,cx11,cy11,cx12,cy12,cx13,cy13,cx14,cy14,cx15,cy15)#draw carriages in pos
'''
carriagepos() #changes the position of each carriage
'''
for event in pygame.event.get(): # each event caused by the user is checked
if event.type == pygame.QUIT: # and is someone closes the window by clicking on x, then set flag to false
running = False # which then closes the window
pygame.quit()
pygame.display.update()
fpsclock.tick(FPS)
追踪(最近一次呼叫最后一次):
追踪(最近的呼叫最后):
文件&#34;&#34;,第70行,在execInThread中 文件&#34;&#34;,第44行,致电
文件&#34; E:\ practice python \ Portable Python 3.2.1.1 \ App \ lib \ site-packages \ rpyc \ core \ netref.py&#34;,第122行,调用
返回syncreq(_self,consts.HANDLE_CALL,args,kwargs)
文件&#34; E:\ practice python \ Portable Python 3.2.1.1 \ App \ lib \ site-packages \ rpyc \ core \ netref.py&#34;,第45行,在syncreq中 return conn()。sync_request(handler,oid,* args)
文件&#34; E:\ practice python \ Portable Python 3.2.1.1 \ App \ lib \ site-packages \ rpyc \ core \ protocol.py&#34;,第343行,在sync_request中 self.serve(0.1) 文件&#34; E:\ practice python \ Portable Python 3.2.1.1 \ App \ lib \ site-packages \ rpyc \ core \ protocol.py&#34;,305行,in serve data = self._recv(timeout,wait_for_lock = True)
文件&#34; E:\ practice python \ Portable Python 3.2.1.1 \ App \ lib \ site-packages \ rpyc \ core \ protocol.py&#34;,第265行,在_recv中 data = self._channel.recv() 文件&#34; E:\ practice python \ Portable Python 3.2.1.1 \ App \ lib \ site-packages \ rpyc \ core \ channel.py&#34;,第36行,在recv中 header = self.stream.read(self.FRAME_HEADER.size) 文件&#34; E:\ practice python \ Portable Python 3.2.1.1 \ App \ lib \ site-packages \ rpyc \ core \ stream.py&#34;,第105行,读取
提出EOFError(ex)
EOFError:[Errno 10054]远程主机强行关闭现有连接