SlideShare a Scribd company logo
1 of 2
#Simulate bouncing ball in pygame
# Bouncing ball
import sys, pygame
pygame.init()
size = width, height = 700, 300
speed = [1, 1]
background = 255, 255, 255
screen = pygame.display.se t_mode(size)
pygame.display.set_ca ption("Bounc ing ball")
ball = pygame.image.loa d("ba ll.jpg")
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(background)
screen.blit(ba ll, ballrect)
pygame.display.flip()
Ball.jpg
Output:

More Related Content

What's hot

IIT Kanpur Fresher's Tech Quiz
IIT Kanpur Fresher's Tech QuizIIT Kanpur Fresher's Tech Quiz
IIT Kanpur Fresher's Tech QuizAnshul Roy
 
Structure and validity in oral evidence
Structure and validity in oral evidenceStructure and validity in oral evidence
Structure and validity in oral evidenceMhervz Espinola
 
IIT Kanpur Arts & Etymology Quiz
IIT Kanpur Arts & Etymology QuizIIT Kanpur Arts & Etymology Quiz
IIT Kanpur Arts & Etymology QuizAnshul Roy
 
General quiz 01
General quiz 01General quiz 01
General quiz 01qfrathbtu
 
Amdavad Quiz Club Business Quiz
Amdavad Quiz Club Business QuizAmdavad Quiz Club Business Quiz
Amdavad Quiz Club Business Quizkushal94
 
Anokha tech quiz 2014 Finals
Anokha tech quiz 2014 FinalsAnokha tech quiz 2014 Finals
Anokha tech quiz 2014 FinalsRohit Sridhar
 
LSD Quiz - NSIT QUIZ FEST 2016
LSD Quiz - NSIT QUIZ FEST 2016LSD Quiz - NSIT QUIZ FEST 2016
LSD Quiz - NSIT QUIZ FEST 2016nsitqc
 
The Inquizition Open Quiz Finals , Dhishna 2017
The Inquizition Open Quiz Finals , Dhishna 2017The Inquizition Open Quiz Finals , Dhishna 2017
The Inquizition Open Quiz Finals , Dhishna 2017Edwin Muriyaden Wilson
 

What's hot (12)

IIT Kanpur Fresher's Tech Quiz
IIT Kanpur Fresher's Tech QuizIIT Kanpur Fresher's Tech Quiz
IIT Kanpur Fresher's Tech Quiz
 
Structure and validity in oral evidence
Structure and validity in oral evidenceStructure and validity in oral evidence
Structure and validity in oral evidence
 
IIT Kanpur Arts & Etymology Quiz
IIT Kanpur Arts & Etymology QuizIIT Kanpur Arts & Etymology Quiz
IIT Kanpur Arts & Etymology Quiz
 
General quiz 01
General quiz 01General quiz 01
General quiz 01
 
Mythology quiz
Mythology quizMythology quiz
Mythology quiz
 
Amdavad Quiz Club Business Quiz
Amdavad Quiz Club Business QuizAmdavad Quiz Club Business Quiz
Amdavad Quiz Club Business Quiz
 
Shaastra Main Quiz 2016
Shaastra Main Quiz 2016Shaastra Main Quiz 2016
Shaastra Main Quiz 2016
 
S08_04: Boycott Bollywood.pptx
S08_04: Boycott Bollywood.pptxS08_04: Boycott Bollywood.pptx
S08_04: Boycott Bollywood.pptx
 
Anokha tech quiz 2014 Finals
Anokha tech quiz 2014 FinalsAnokha tech quiz 2014 Finals
Anokha tech quiz 2014 Finals
 
LSD Quiz - NSIT QUIZ FEST 2016
LSD Quiz - NSIT QUIZ FEST 2016LSD Quiz - NSIT QUIZ FEST 2016
LSD Quiz - NSIT QUIZ FEST 2016
 
The Inquizition Open Quiz Finals , Dhishna 2017
The Inquizition Open Quiz Finals , Dhishna 2017The Inquizition Open Quiz Finals , Dhishna 2017
The Inquizition Open Quiz Finals , Dhishna 2017
 
Saarang 2015 Biz Quiz Finals
Saarang 2015 Biz Quiz FinalsSaarang 2015 Biz Quiz Finals
Saarang 2015 Biz Quiz Finals
 

Recently uploaded

Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Celine George
 
ROOT CAUSE ANALYSIS PowerPoint Presentation
ROOT CAUSE ANALYSIS PowerPoint PresentationROOT CAUSE ANALYSIS PowerPoint Presentation
ROOT CAUSE ANALYSIS PowerPoint PresentationAadityaSharma884161
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceSamikshaHamane
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxDr.Ibrahim Hassaan
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Mark Reed
 
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxGrade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxChelloAnnAsuncion2
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for BeginnersSabitha Banu
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersSabitha Banu
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
Quarter 4 Peace-education.pptx Catch Up Friday
Quarter 4 Peace-education.pptx Catch Up FridayQuarter 4 Peace-education.pptx Catch Up Friday
Quarter 4 Peace-education.pptx Catch Up FridayMakMakNepo
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...JhezDiaz1
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPCeline George
 
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfphamnguyenenglishnb
 

Recently uploaded (20)

Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17
 
ROOT CAUSE ANALYSIS PowerPoint Presentation
ROOT CAUSE ANALYSIS PowerPoint PresentationROOT CAUSE ANALYSIS PowerPoint Presentation
ROOT CAUSE ANALYSIS PowerPoint Presentation
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in Pharmacovigilance
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptx
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)
 
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxGrade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for Beginners
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginners
 
Rapple "Scholarly Communications and the Sustainable Development Goals"
Rapple "Scholarly Communications and the Sustainable Development Goals"Rapple "Scholarly Communications and the Sustainable Development Goals"
Rapple "Scholarly Communications and the Sustainable Development Goals"
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
Quarter 4 Peace-education.pptx Catch Up Friday
Quarter 4 Peace-education.pptx Catch Up FridayQuarter 4 Peace-education.pptx Catch Up Friday
Quarter 4 Peace-education.pptx Catch Up Friday
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERP
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
 

Simulate bouncing ball in pygame

  • 1. #Simulate bouncing ball in pygame # Bouncing ball import sys, pygame pygame.init() size = width, height = 700, 300 speed = [1, 1] background = 255, 255, 255 screen = pygame.display.se t_mode(size) pygame.display.set_ca ption("Bounc ing ball") ball = pygame.image.loa d("ba ll.jpg") 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(background) screen.blit(ba ll, ballrect) pygame.display.flip() Ball.jpg