0

Hi I am just a beginner and I am trying to make a Ferris wheel animation.

I was able to deduce where the window started crashing and it is the block of code below.

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)

In this code, the 15 carriages are draw with their centre at 0. The cx and cy values then move the carriage to the right position on the ferris wheel. Each carriage has their own value because they each have their own spot on the ferris wheel.

I did try changing the value to global but it didn't change anything.

I have made sure that the call function is in the right place.

No error message appears before, during or after the window crashes.

Thank you for looking at this question and it would be greatly appreciated if you can help me out.

Here is the rest of my code due to the code above not being the problem. (I know it is a bit unorganized but I am still making it)

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)

Traceback (most recent call last):

Traceback (most recent call last):
File "", line 70, in execInThread
File "", line 44, in call
File "E:\practice python\Portable Python 3.2.1.1\App\lib\site-packages\rpyc\core\netref.py", line 122, in call
return syncreq(_self, consts.HANDLE_CALL, args, kwargs)
File "E:\practice python\Portable Python 3.2.1.1\App\lib\site-packages\rpyc\core\netref.py", line 45, in syncreq
return conn().sync_request(handler, oid, *args)
File "E:\practice python\Portable Python 3.2.1.1\App\lib\site-packages\rpyc\core\protocol.py", line 343, in sync_request
self.serve(0.1) File "E:\practice python\Portable Python 3.2.1.1\App\lib\site-packages\rpyc\core\protocol.py", line 305, in serve
data = self._recv(timeout, wait_for_lock = True)
File "E:\practice python\Portable Python 3.2.1.1\App\lib\site-packages\rpyc\core\protocol.py", line 265, in _recv
data = self._channel.recv() File "E:\practice python\Portable Python 3.2.1.1\App\lib\site-packages\rpyc\core\channel.py", line 36, in recv header = self.stream.read(self.FRAME_HEADER.size) File "E:\practice python\Portable Python 3.2.1.1\App\lib\site-packages\rpyc\core\stream.py", line 105, in read
raise EOFError(ex)
EOFError: [Errno 10054] An existing connection was forcibly closed by the remote host

sloth
  • 99,095
  • 21
  • 171
  • 219
Meerfall the dewott
  • 209
  • 1
  • 4
  • 19
  • For me, the code runs just fine. What operating system are you using? Does this happen when running other programs? Also, you should learn how to use lists, because your code is very hard to read. – Tetsudou Oct 09 '14 at 20:07
  • Windows and it doesn't happen on any other code. I will try to make it a list but I just want to get it working first. I will add the rest of my code because if that code is not the problem then I don't know what is. – Meerfall the dewott Oct 09 '14 at 20:11
  • Yes, adding the rest of the code will help. Just click "edit" and replace your old code with your full code. – Tetsudou Oct 09 '14 at 20:14
  • opps, I just added it at the end, oh well. – Meerfall the dewott Oct 09 '14 at 20:20
  • One mistake that I just found is that you never increase the counter in `carriagemovement`. Try fixing that and let me know if it still crashes, because I might find more problems. – Tetsudou Oct 09 '14 at 20:45
  • I added 'counter = counter + 1' at the end of carriagemovement() but it is still crashing. Thanks – Meerfall the dewott Oct 09 '14 at 20:48
  • Try adding `pygame.display.flip()` at the end of the `while` loop. You need to update the screen every frame. Let me know if it still crashes. – Tetsudou Oct 09 '14 at 20:50
  • that's a lot better, it displays back() and the carriages appear at the top left corner (with their center at zero), it then crashes. So I think it has something to do with carriagemovement() – Meerfall the dewott Oct 09 '14 at 20:53
  • What is carriagemovement supposed to do? – Tetsudou Oct 10 '14 at 00:55
  • Basically, their are 15 position that a carriage can land. The 15 points are placed on the ferris wheel. pos is the position that the carriage should go on. Then the next part of the code should make sure that the x and y variables go to the right carriage. 'no' should symbolise the right carriage and give it the x and y variables i.e CX1 and CY1. – Meerfall the dewott Oct 10 '14 at 06:31
  • Wait, it started crashing when I just run back() or carriages(). That is strange, it just crashing no matter what function I am running. Here is the traceback call, I have no idea what it is and I have to keep forcibly closing it to stop pygame from crashing. Traceback (most recent call last): File "", line 70, in execInThread File "", line 44, in __call__ File "E:\practice python\Portable Python 3.2.1.1\App\lib\site-packages\rpyc\core\netref.py", line 122, in __call__ return syncreq(_self, consts.HANDLE_CALL, args, kwargs) (continue) – Meerfall the dewott Oct 10 '14 at 06:48
  • (continued) File "E:\practice python\Portable Python 3.2.1.1\App\lib\site-packages\rpyc\core\netref.py", line 45, in syncreq return conn().sync_request(handler, oid, *args) File "E:\practice python\Portable Python 3.2.1.1\App\lib\site-packages\rpyc\core\protocol.py", line 343, in sync_request self.serve(0.1) File "E:\practice python\Portable Python 3.2.1.1\App\lib\site-packages\rpyc\core\protocol.py", line 305, in serve data = self._recv(timeout, wait_for_lock = True) (continue) – Meerfall the dewott Oct 10 '14 at 06:52
  • (continued) File "E:\practice python\Portable Python 3.2.1.1\App\lib\site-packages\rpyc\core\protocol.py", line 265, in _recv data = self._channel.recv() File "E:\practice python\Portable Python 3.2.1.1\App\lib\site-packages\rpyc\core\channel.py", line 36, in recv header = self.stream.read(self.FRAME_HEADER.size) File "E:\practice python\Portable Python 3.2.1.1\App\lib\site-packages\rpyc\core\stream.py", line 105, in read raise EOFError(ex) EOFError: [Errno 10054] An existing connection was forcibly closed by the remote host – Meerfall the dewott Oct 10 '14 at 06:53

0 Answers0