Python: pygame-based ball elasticity effect (source code)

Source: Internet
Author: User
This article mainly introduces the pygame-based stretch ball effect in Python, involves techniques related to pygame graphics dynamic operations, and comes with a complete source code for readers to download and reference, if you need it, refer to the example in this article to describe the effect of the pygame-based stretch ball in Python. We will share this with you for your reference. The details are as follows:

Running effect:

The Code is as follows:

#A bouncing ballimport sys, pygame__author__ = {'name' : 'Hongten',       'mail' : 'hongtenzone@foxmail.com',       'QQ'  : '648719819',       'Version' : '1.0'}pygame.init()size = width, height = 600, 500speed = [1, 1]black = 249, 130, 57screen = pygame.display.set_mode(size)ball = pygame.image.load('c:\\py\\ball.png')ballrect = ball.get_rect()while 1:  for event in pygame.event.get():    if event.type == pygame.QUIT:      sys.exit()  ballrect = ballrect.move(speed)  if ballrect.left < 0 or ballrect.right > width:    speed[0] = -speed[0]  if ballrect.top < 0 or ballrect.bottom > height:    speed[1] = - speed[1]  screen.fill(black)  screen.blit(ball, ballrect)  pygame.display.flip()

Click here to download the complete instance code.

I hope this article will help you with Python programming.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.