You are on page 1of 41

Vasantdada Patil Pratishthan's College of

Engineering & Visual Arts, Sion Mumbai - 400 022

A
MINI PROJECT REPORT
ON
“BOUNCE-BALL GAME”
Submitted in partial fulfillment of the requirements of the degree
BACHELOR OF ENGINEERING IN COMPUTER ENGINEERING

Submitted By:
Ayush Singh (VU1F2021027)
Ayush Patel (VU1F2021030)
Shankendu Kunti (VU1F2021031)

Under the guidance of


Prof. Shrikant Bagewadi

Department of Computer Engineering


Vasantdada Patil Pratishthan's College of Engineering &
Visual Arts, Sion Mumbai - 400 022

University of Mumbai
(AY 2021-22)
CERTIFICATE

This is to certify that the Mini Project entitled “Bounce-Ball Game” is a bonafide

work of Shankendu Kunti (VU1F2021031) submitted to the University of Mumbai

in partial fulfillment of the requirement for the award of the degree of “Bachelor of

Engineering” in “Computer Engineering” .

(Prof. )
Supervisor

(Prof. ) (Prof. )
Head of Department Principal
INSTITUTE VISION & MISSION

VISION:

To educate, encourage and explore students by facilitating conducive environment to


achieve professional goals

MISSION:

To kindle the zeal among the student and promote their quest for academic excellence with
industry interaction to enhance their career opportunities

COMPUTER ENGINEERING DEPARTMENT

VISION:

To inculcate skills for overall development of students to be a leader in the world of


computer engineering and contributes in favor of society.

MISSION:
1. To provide students with a fundamental knowledge of theory, practical and problem-
solving skills with an exposure to emerging technologies.
2. Provide platform for overall growth and adapting challenges in rapidly changing
technology.
3. To produce globally competent computer professionals with moral values and leadership
abilities for sustainable development of the society.
PROGRAM EDUCATIONAL OBJECTIVES (PEO's)
1. To create graduates with sound fundamental knowledge of computer engineering &
enhance their skillset towards emerging technologies.
2. To inculcate the skills among students to formulate, analyze and propose the solutions
to engineering problems.
3. To make the students aware of professional ethics of the software industry.
4. To motivate the students for life-long self-learning.

PROGRAM SPECIFIC OUTCOMES (PSOs)


1. Graduates of programme will be able to provide effective and efficient real time
solutions using practical knowledge in Computer Engineering domain.
2. Graduate of programme will be able to use engineering practices, strategies and tactics
for the development, operation and maintenance of software system.

PROGRAM OUTCOMES (POs)


1) Engineering knowledge: Apply the knowledge of mathematics, science, engineering
fundamentals, and an engineering specialization to the solution of complex
engineering problems.

2) Problem analysis: Identify, formulate complex engineering problems reaching


substantiated conclusions using principles of Computer Engineering.

3) Design / development of solutions: Design / develop solutions for complex


engineering problems and design system components or processes that meet the
specified needs with appropriate consideration for the society.

4) Conduct investigations of complex problems: Use knowledge for the design of


experiments, analysis and interpretation of data, and synthesis of the information to
provide valid conclusions.

5) Modern tool usage: Create, select and apply appropriate techniques and modern
engineering tools, including predictions and modelling to complex engineering
activities with an understanding of the limitations.

6) The engineer and society: Apply the knowledge to assess social issues and the
responsibilities relevant to engineering practices.

7) Environment and sustainability: Understand the impact of the professional


engineering solutions in social and environmental contexts, and demonstrate the
knowledge for sustainable development.
8) Ethics: Apply ethical principles and commit to professional ethics and responsibilities
and norms of the engineering practice.

9) Individual and team work: Function effectively as an individual, and as a member


or leader in diverse teams, and in multidisciplinary settings.

10) Communication: Communicate effectively such as, being able to comprehend and
write effective reports and design documentation, make effective presentations.

11) Project management and finance: Demonstrate knowledge and understanding of


the engineering and management skills and apply these skills to manage projects
effectively.

12) Life-long learning: Recognize the need for, and have the preparation and ability to
engage in independent and life-long learning in the broadest context of technological
change.
Mini Project Approval

This Mini Project entitled “Bounce-Ball Game” by Shankendu Kunti

(VU1F2021031) is approved for the degree of Bachelor of Engineering in

Computer Engineering.

Examiners

1………………………………………
(Internal Examiner Name & Sign)

2…………………………………………
(External Examiner name & Sign)

Date:

Place

:
Sr . Content Pg .
No No
1 Introduction to Python 8 - 13
1.1 Explanation about Mini Project 14 - 16
1.2 List of Python Concepts used in Mini Project 17
1.3 Explanation of Each & Every Python Concept 18 - 30
used in Mini Project
1.4 Objective 31
1.5 Application 32
2 Coding / Implementation 33 - 37
3 Output 38 - 39
4 Conclusion 40
5 Refrence 41
1.Introduction to Python

What is Python? History ?


Python is a popular programming language. It was created by Guido van
Rossum, and released in 1991.

It is used for:

● web development (server-side),


● software development,
● mathematics,
● system scripting.

What can Python do?


● Python can be used on a server to create web applications.
● Python can be used alongside software to create workflows.
● Python can connect to database systems. It can also read and modify
files.
● Python can be used to handle big data and perform complex
mathematics.
● Python can be used for rapid prototyping, or for production-ready
software development.

Why Python?
● Python works on different platforms (Windows, Mac, Linux, Raspberry
Pi, etc).
● Python has a simple syntax similar to the English language.
● Python has syntax that allows developers to write programs with
fewer lines than some other programming languages.
● Python runs on an interpreter system, meaning that code can be
executed as soon as it is written. This means that prototyping can be
very quick.
● Python can be treated in a procedural way, an object-oriented way or
a functional way.

Good to know
● The most recent major version of Python is Python 3, which we shall
be using in this tutorial. However, Python 2, although not being
updated with anything other than security updates, is still quite
popular.
● In this tutorial Python will be written in a text editor. It is possible to
write Python in an Integrated Development Environment, such as
Thonny, Pycharm, Netbeans or Eclipse which are particularly useful
when managing large collections of Python files.

Python Syntax compared to other programming


languages
● Python was designed for readability, and has some similarities to the
English language with influence from mathematics.
● Python uses new lines to complete a command, as opposed to other
programming languages which often use semicolons or parentheses.
● Python relies on indentation, using whitespace, to define scope; such
as the scope of loops, functions and classes. Other programming
languages often use curly-brackets for this purpose.

Applications of Python Programming:


1) Web Development: Python offers different frameworks for web development
like Django, Pyramid, Flask. This framework is known for security, flexibility,
and scalability.

2) Game Development: PySoy and PyGame are two python libraries that are used
for game development

3) Artificial Intelligence and Machine Learning: There is a large number of open-


source libraries which can be used while developing AI/ML applications.

4) Desktop GUI: Desktop GUI offers many toolkits and frameworks using which
we can build desktop applications.PyQt, PyGtk, PyGUI are some of the GUI
frameworks.

Real-World Examples:
1) NASA (National Aeronautics and Space Agency): One of Nasa’s Shuttle Support
Contractors, United Space Alliance developed a Workflow Automation System
(WAS) which is fast. Internal Resources Within critical project stated that:

“Python allows us to tackle the complexity of programs like the WAS without
getting bogged down in the language”.

Nasa also published a website (https://code.nasa.gov/) where there are 400 open
source projects which use python.

2) Netflix: There are various projects in Netflix which use python as follow:

● Central Alert Gateway


● Chaos Gorilla
● Security Monkey
● Chronos
Amongst all projects, Regional failover is the project they have as the system
decreases outage time from 45 minutes to 7 minutes with no additional cost.

3) Instagram: Instagram also uses python extensively. They have built a photo-
sharing social platform using Django which is a web framework for python. Also,
they are able to successfully upgrade their framework without any technical
challenges.

Python is a high-level, general-purpose and a very popular programming language.


Python programming language (latest Python 3) is being used in web development,
Machine Learning applications, along with all cutting edge technology in Software
Industry. Python Programming Language is very well suited for Beginners, also for
experienced programmers with other programming languages like C++ and Python.

Below are some facts about Python Programming Language:

1. Python is currently the most widely used multi-purpose, high-level


programming language.
2. Python allows programming in Object-Oriented and Procedural
paradigms.
3. Python programs generally are smaller than other programming
languages like Python. Programmers have to type relatively less and the
indentation requirement of the language makes them readable all the
time.
4. Python language is being used by almost all tech-giant companies like –
Google, Amazon, Facebook, Instagram, Dropbox, Uber… etc.
5. The biggest strength of Python is huge collection of standard library
which can be used for the following:
○ Machine Learning
○ GUI Applications (like Kivy, Tkinter, PyQt etc. )
○ Web frameworks like Django (used by YouTube, Instagram,
Dropbox)
○ Image processing (like OpenCV, Pillow)
○ Web scraping (like Scrapy, BeautifulSoup, Selenium)
○ Test frameworks
○ Multimedia
○ Scientific computing
○ Text processing and many more..
Features of Python ?

Advantages / Disadvantages of Python ?


1.1 Explanation About Mini Project

Bouncing Ball Game is developed using Python Programming Language . The


Bouncing Ball Game in Python is designed using tkinter and graphical user
interface(GUI) and it is a desktop application. This Bouncing Ball Game uses
Canvas for drawing objects and random modules in Python. Canvas is a rectangular
area intended for drawing pictures or other complex layouts. We can place graphics,
text, widgets or frames on Canvas.

This Bouncing Ball Game in Python could be very simple to control for the users.
There is one bar at the lowest of the game window which may be moved left or right
for the proper usage of the buttons which are in the game window.

The goal of the Bouncing Ball Game is to hit all targets as many times as you can to
earn the highest score. Every time the ball hits the Target you earn 1 point, and if it
hits 2 targets you earn 2 points, respectively. If the player fails to catch the ball on
the bar then it will appear the game over on the game window.

Before you start on How to Make Bouncing Ball Game in Python,


make sure that you have PyCharm IDE installed on your computer.

This are the steps on How to Make


Bouncing Ball Game in Python
How to Make Bouncing Ball Game in Python With Source Code

● Step 1: Create a project name


First when you finish installing the Pycharm IDE in your computer, open it
and then create a “project name” after creating a project name, click the
“create” button.
● Step 2: Create a python file.
● Second, after creating a project name, “right click” your project name and
then click “new” after that click the “python file“.
● Step 3: Name your python file.
Third, after creating a python file, Name your python file after that click
“enter“.

● Step 4: The actual code


Now you have to write the code which is shown further but following are some
steps
THE STEPS TO WRITE CODE IN :

Importing Tkinter Module .

Importing Random Module .

Designing the Main Window .

Module for Starting a Game .

Module for the Class Function Use .

Module for Left and Right Key .

Complete the Source Code on How to Make a Bouncing Ball Game in Python .
1.2 List of python concept used in project

Python Functions
Function Calling
The return statement
Arguments in function
Required arguments
Keyword arguments
Default arguments
Variable-length arguments
Scope of variables

Python Module / Libraries


TensorFlow
Matplotlib
Pandas
Numpy
SciPy
Scrapy
Scikit-learn
PyGame
PyTorch
PyBrain
1.3 Explanation Of concept used in Project

Python Function
Functions are the most important aspect of an application. A function can be defined as the
organized block of reusable code, which can be called whenever required.

Python allows us to divide a large program into the basic building blocks known as a
function. The function contains the set of programming statements enclosed by {}. A
function can be called multiple times to provide reusability and modularity to the Python
program.

The Function helps programmers to break the program into smaller parts. It organizes the
code very effectively and avoids the repetition of the code. As the program grows, function
makes the program more organized.

Python provides us various inbuilt functions like range() or print(). Although, the user can
create its functions, which can be called user-defined functions.

There are mainly two types of functions.

● User-defined functions - The user-defined functions are those defined by the user
to perform the specific task.
● Built-in functions - The built-in functions are those functions that are pre-defined in
Python.

In this tutorial, we will discuss the user defined functions.

Advantage of Functions in Python


There are the following advantages of Python functions.

● Using functions, we can avoid rewriting the same logic/code again and again in a
program.
● We can call Python functions multiple times in a program and anywhere in a
program.
● We can track a large Python program easily when it is divided into multiple
functions.
● Reusability is the main achievement of Python functions.
● However, Function calling is always overhead in a Python program.

Creating a Function
Python provides the def keyword to define the function. The syntax of the define function is
given below.

Syntax:
1. def my_function(parameters):
2. function_block
3. return expression

Let's understand the syntax of functions definition.

● The def keyword, along with the function name is used to define the function.
● The identifier rule must follow the function name.
● A function accepts the parameter (argument), and they can be optional.
● The function block is started with the colon (:), and block statements must be at the
same indentation.
● The return statement is used to return the value. A function can have only one
return

Function Calling
In Python, after the function is created, we can call it from another function. A function must
be defined before the function call; otherwise, the Python interpreter gives an error. To call
the function, use the function name followed by the parentheses.

Consider the following example of a simple example that prints the message "Hello World".

1. #function definition
2. def hello_world():
3. print("hello world")
4. # function calling
5. hello_world()

Output:

hello world

The return statement


The return statement is used at the end of the function and returns the result of the function.
It terminates the function execution and transfers the result where the function is called. The
return statement cannot be used outside of the function.

Syntax

1. return [expression_list]

It can contain the expression which gets evaluated and value is returned to the caller
function. If the return statement has no expression or does not exist itself in the function
then it returns the None object.

Consider the following example:

Example 1
1. # Defining function
2. def sum():
3. a = 10
4. b = 20
5. c = a+b
6. return c
7. # calling sum() function in print statement
8. print("The sum is:",sum())

Output:

The sum is: 30

In the above code, we have defined the function named sum, and it has a statement c = a+b,
which computes the given values, and the result is returned by the return statement to the
caller function.

Example 2 Creating function without return statement


1. # Defining function
2. def sum():
3. a = 10
4. b = 20
5. c = a+b
6. # calling sum() function in print statement
7. print(sum())

Output:

None

In the above code, we have defined the same function without the return statement as we
can see that the sum() function returned the None object to the caller function.

Arguments in function
The arguments are types of information which can be passed into the function. The
arguments are specified in the parentheses. We can pass any number of arguments, but they
must be separate them with a comma.

Consider the following example, which contains a function that accepts a string as the
argument.

Example 1
1. #defining the function
2. def func (name):
3. print("Hi ",name)
4. #calling the function
5. func("Devansh")

Output:

Hi Devansh
Example 2
1. #Python function to calculate the sum of two variables
2. #defining the function
3. def sum (a,b):
4. return a+b;
5.
6. #taking values from the user
7. a = int(input("Enter a: "))
8. b = int(input("Enter b: "))
9.
10. #printing the sum of a and b
11. print("Sum = ",sum(a,b))

Output:

Enter a: 10
Enter b: 20
Sum = 30

Call by reference in Python


In Python, call by reference means passing the actual value as an argument in the function.
All the functions are called by reference, i.e., all the changes made to the reference inside
the function revert back to the original value referred by the reference.

Example 1 Passing Immutable Object (List)


1. #defining the function
2. def change_list(list1):
3. list1.append(20)
4. list1.append(30)
5. print("list inside function = ",list1)
6.
7. #defining the list
8. list1 = [10,30,40,50]
9.
10. #calling the function
11. change_list(list1)
12. print("list outside function = ",list1)

Output:

list inside function = [10, 30, 40, 50, 20, 30]


list outside function = [10, 30, 40, 50, 20, 30]

Example 2 Passing Mutable Object (String)


1. #defining the function
2. def change_string (str):
3. str = str + " Hows you "
4. print("printing the string inside function :",str)
5.
6. string1 = "Hi I am there"
7.
8. #calling the function
9. change_string(string1)
10.
11. print("printing the string outside function :",string1)

Output:

printing the string inside function : Hi I am there Hows you


printing the string outside function : Hi I am there

Types of arguments
There may be several types of arguments which can be passed at the time of function call.

1. Required arguments
2. Keyword arguments
3. Default arguments
4. Variable-length arguments

Required Arguments
Till now, we have learned about function calling in Python. However, we can provide the
arguments at the time of the function call. As far as the required arguments are concerned,
these are the arguments which are required to be passed at the time of function calling with
the exact match of their positions in the function call and function definition. If either of the
arguments is not provided in the function call, or the position of the arguments is changed,
the Python interpreter will show the error.

Consider the following example.

Example 1

1. def func(name):
2. message = "Hi "+name
3. return message
4. name = input("Enter the name:")
5. print(func(name))

Output:

Enter the name: John


Hi John

Example 2
1. #the function simple_interest accepts three arguments and returns the simple
interest accordingly
2. def simple_interest(p,t,r):
3. return (p*t*r)/100
4. p = float(input("Enter the principle amount? "))
5. r = float(input("Enter the rate of interest? "))
6. t = float(input("Enter the time in years? "))
7. print("Simple Interest: ",simple_interest(p,r,t))

Output:

Enter the principle amount: 5000


Enter the rate of interest: 5
Enter the time in years: 3
Simple Interest: 750.0

Example 3

1. #the function calculate returns the sum of two arguments a and b


2. def calculate(a,b):
3. return a+b
4. calculate(10) # this causes an error as we are missing a required arguments b.

Output:

TypeError: calculate() missing 1 required positional argument: 'b'

Default Arguments
Python allows us to initialize the arguments at the function definition. If the value of any of
the arguments is not provided at the time of function call, then that argument can be
initialized with the value given in the definition even if the argument is not specified at the
function call.

Example 1

1. def printme(name,age=22):
2. print("My name is",name,"and age is",age)
3. printme(name = "john")

Output:

My name is John and age is 22

Example 2

1. def printme(name,age=22):
2. print("My name is",name,"and age is",age)
3. printme(name = "john") #the variable age is not passed into the function however
the default value of age is considered in the function
4. printme(age = 10,name="David") #the value of age is overwritten here, 10 will be
printed as age

Output:

My name is john and age is 22


My name is David and age is 10

Variable-length Arguments (*args)


In large projects, sometimes we may not know the number of arguments to be passed in
advance. In such cases, Python provides us the flexibility to offer the comma-separated
values which are internally treated as tuples at the function call. By using the variable-length
arguments, we can pass any number of arguments.

However, at the function definition, we define the variable-length argument using the *args
(star) as *<variable - name >.

Consider the following example.

Example

1. def printme(*names):
2. print("type of passed argument is ",type(names))
3. print("printing the passed arguments...")
4. for name in names:
5. print(name)
6. printme("john","David","smith","nick")

Output:

type of passed argument is <class 'tuple'>


printing the passed arguments...
john
David
smith
nick

In the above code, we passed *names as variable-length argument. We called the function
and passed values which are treated as tuple internally. The tuple is an iterable sequence
the same as the list. To print the given values, we iterated *arg names using for loop.

Keyword arguments(**kwargs)
Python allows us to call the function with the keyword arguments. This kind of function call
will enable us to pass the arguments in the random order.

The name of the arguments is treated as the keywords and matched in the function calling
and definition. If the same match is found, the values of the arguments are copied in the
function definition.

Consider the following example.

Example 1
1. #function func is called with the name and message as the keyword arguments
2. def func(name,message):
3. print("printing the message with",name,"and ",message)
4.
5. #name and message is copied with the values John and hello respectively
6. func(name = "John",message="hello")

Output:

printing the message with John and hello

Example 2 providing the values in different order at the calling

1. #The function simple_interest(p, t, r) is called with the keyword arguments the order
of arguments doesn't matter in this case
2. def simple_interest(p,t,r):
3. return (p*t*r)/100
4. print("Simple Interest: ",simple_interest(t=10,r=10,p=1900))

Output:

Simple Interest: 1900.0

If we provide the different name of arguments at the time of function call, an error will be
thrown.

Consider the following example.

Example 3

1. #The function simple_interest(p, t, r) is called with the keyword arguments.


2. def simple_interest(p,t,r):
3. return (p*t*r)/100
4.
5. # doesn't find the exact match of the name of the arguments (keywords)
6. print("Simple Interest: ",simple_interest(time=10,rate=10,principle=1900))

Output:

TypeError: simple_interest() got an unexpected keyword argument 'time'

The Python allows us to provide the mix of the required arguments and keyword arguments
at the time of function call. However, the required argument must not be given after the
keyword argument, i.e., once the keyword argument is encountered in the function call, the
following arguments must also be the keyword arguments.

Consider the following example.

Example 4

1. def func(name1,message,name2):
2. print("printing the message with",name1,",",message,",and",name2)
3. #the first argument is not the keyword argument
4. func("John",message="hello",name2="David")

Output:

printing the message with John , hello ,and David

The following example will cause an error due to an in-proper mix of keyword and required
arguments being passed in the function call.

Example 5

1. def func(name1,message,name2):
2. print("printing the message with",name1,",",message,",and",name2)
3. func("John",message="hello","David")

Output:

SyntaxError: positional argument follows keyword argument

Python provides the facility to pass the multiple keyword arguments which can be
represented as **kwargs. It is similar as the *args but it stores the argument in the dictionary
format.

This type of arguments is useful when we do not know the number of arguments in advance.

Consider the following example:

Example 6: Many arguments using Keyword argument

1. def food(**kwargs):
2. print(kwargs)
3. food(a="Apple")
4. food(fruits="Orange", Vagitables="Carrot")

Output:

{'a': 'Apple'}
{'fruits': 'Orange', 'Vagitables': 'Carrot'}

Scope of variables
The scopes of the variables depend upon the location where the variable is being declared.
The variable declared in one part of the program may not be accessible to the other parts.

In python, the variables are defined with the two types of scopes.

1. Global variables
2. Local variables

The variable defined outside any function is known to have a global scope, whereas the
variable defined inside a function is known to have a local scope.

Consider the following example.

Example 1 Local Variable


1. def print_message():
2. message = "hello !! I am going to print a message." # the variable message is
local to the function itself
3. print(message)
4. print_message()
5. print(message) # this will cause an error since a local variable cannot be
accessible here.

Output:

hello !! I am going to print a message.


File "/root/PycharmProjects/PythonTest/Test1.py", line 5, in
print(message)
NameError: name 'message' is not defined

Example 2 Global Variable


1. def calculate(*args):
2. sum=0
3. for arg in args:
4. sum = sum +arg
5. print("The sum is",sum)
6. sum=0
7. calculate(10,20,30) #60 will be printed as the sum
8. print("Value of sum outside the function:",sum) # 0 will be printed Output:

Output:

The sum is 60
Value of sum outside the function: 0
Python Libraries

Normally, a library is a collection of books or is a room or place where many books


are stored to be used later. Similarly, in the programming world, a library is a
collection of precompiled codes that can be used later on in a program for some
specific well-defined operations. Other than pre-compiled codes, a library may
contain documentation, configuration data, message templates, classes, and values,
etc.A Python library is a collection of related modules. It contains bundles of code
that can be used repeatedly in different programs. It makes Python Programming
simpler and convenient for the programmer. As we don’t need to write the same
code again and again for different programs. Python libraries play a very vital role
in fields of Machine Learning, Data Science, Data Visualization, etc.

Working of Python Library ; As is stated above, a Python library is simply a


collection of codes or modules of codes that we can use in a program for specific
operations. We use libraries so that we don’t need to write the code again in our
program that is already available. But how it works. Actually, in the MS Windows
environment, the library files have a DLL extension (Dynamic Load Libraries).
When we link a library with our program and run that program, the linker
automatically searches for that library. It extracts the functionalities of that library
and interprets the program accordingly. That’s how we use the methods of a library
in our program. We will see further, how we bring in the libraries in our Python
programs.

Python standard library : The Python Standard Library contains the exact
syntax, semantics, and tokens of Python. It contains built-in modules that provide
access to basic system functionality like I/O and some other core modules. Most of
the Python Libraries are written in the C programming language. The Python
standard library consists of more than 200 core modules. All these work together to
make Python a high-level programming language. Python Standard Library plays a
very important role. Without it, the programmers can’t have access to the
functionalities of Python. But other than this, there are several other libraries in
Python that make a programmer’s life easier. Let’s have a look at some of the
commonly used libraries:

TensorFlow: This library was developed by Google in collaboration with the Brain
Team. It is an open-source library used for high-level computations. It is also used
in machine learning and deep learning algorithms. It contains a large number of
tensor operations. Researchers also use this Python library to solve complex
computations in Mathematics and Physics.

Matplotlib: This library is responsible for plotting numerical data. And that’s why
it is used in data analysis. It is also an open-source library and plots high-defined
figures like pie charts, histograms, scatterplots, graphs, etc.

Pandas: Pandas are an important library for data scientists. It is an open-source


machine learning library that provides flexible high-level data structures and a
variety of analysis tools. It eases data analysis, data manipulation, and cleaning of
data. Pandas support operations like Sorting, Re-indexing, Iteration, Concatenation,
Conversion of data, Visualizations, Aggregations, etc.

Numpy: The name “Numpy” stands for “Numerical Python”. It is the commonly
used library. It is a popular machine learning library that supports large matrices
and multi-dimensional data. It consists of in-built mathematical functions for easy
computations. Even libraries like TensorFlow use Numpy internally to perform
several operations on tensors. Array Interface is one of the key features of this
library.

SciPy: The name “SciPy” stands for “Scientific Python”. It is an open-source


library used for high-level scientific computations. This library is built over an
extension of Numpy. It works with Numpy to handle complex computations. While
Numpy allows sorting and indexing of array data, the numerical data code is stored
in SciPy. It is also widely used by application developers and engineers.
Scrapy: It is an open-source library that is used for extracting data from websites. It
provides very fast web crawling and high-level screen scraping. It can also be used
for data mining and automated testing of data.

Scikit-learn: It is a famous Python library to work with complex data. Scikit-learn


is an open-source library that supports machine learning. It supports variously
supervised and unsupervised algorithms like linear regression, classification,
clustering, etc. This library works in association with Numpy and SciPy.

PyGame: This library provides an easy interface to the Standard Directmedia


Library (SDL) platform-independent graphics, audio, and input libraries. It is used
for developing video games using computer graphics and audio libraries along with
Python programming language.

PyTorch: PyTorch is the largest machine learning library that optimizes tensor
computations. It has rich APIs to perform tensor computations with strong GPU
acceleration. It also helps to solve application issues related to neural networks.

PyBrain: The name “PyBrain” stands for Python Based Reinforcement Learning,
Artificial Intelligence, and Neural Networks library. It is an open-source library
built for beginners in the field of Machine Learning. It provides fast and easy-to-use
algorithms for machine learning tasks. It is so flexible and easily understandable
and that’s why is really helpful for developers that are new in research fields.

There are many more libraries in Python. We can use a suitable library for our
purposes. Hence, Python libraries play a very crucial role and are very helpful to the
developers
1.4 Objective

The main objective of the bouncing ball game is to let children have
fun . Having fun is great to relieve stress and be healthy . That's why
this game is the simplest and the best . It spreads Joy and happiness
when you are yourself happier .

Nowadays even having fun can cost you money but this game won't
, it'll only help you be more joyful .

it also increases hand to eye coordination , reflexes and much more


o
1.5 Applications
The Application Of the bouncy ball game is :

1. Reflexes
2. Hand to eye Coordination
3. Have fun
4. Doesn't cost you a penny
2 . Coding / Implementation .

from tkinter import *


import time
import random

root = Tk()
root.title("Bounce Ball Game")
root.geometry("500x570")
root.resizable(0, 0)
root.wm_attributes("-topmost", 1)
canvas = Canvas(root, width=500, height=500, bd=0, highlightthickness=0,
highlightbackground="Red", bg="Black")
canvas.pack(padx=10, pady=10)
score = Label(height=50, width=80, text="Score: 00", font="Calibri 14 italic")
score.pack(side="left")
root.update()

class Ball:
def __init__(self, cvs, clr, pole, stones, scre):
self.stones = stones
self.cvs = cvs
self.pole = pole
self.scre = scre
self.bottom_hit = False
self.hit = 0
self.id = canvas.create_oval(10, 10, 25, 25, fill=clr, width=1)
self.cvs.move(self.id, 230, 461)
start = [4, 3.8, 3.6, 3.4, 3.2, 3, 2.8, 2.6]
random.shuffle(start)

self.a = start[0]
self.b = -start[0]
self.cvs.move(self.id, self.a, self.b)
self.cvs_height = canvas.winfo_height()
self.cvs_width = canvas.winfo_width()

def stone_strike(self, push):


for stone_line in self.stones:
for stone in stone_line:
stone_push = self.cvs.coords(stone.id)

try:
if push[2] &gt;= stone_push[0] and push[0] &lt;= stone_push[2]:
if push[3] &gt;= stone_push[1] and push[1] &lt;= stone_push[3]:
canvas.bell()
self.hit += 1
self.scre.configure(text="Score: " + str(self.hit))
self.cvs.delete(stone.id)
return True
except:
continue
return False

def pole_strike(self, push):


pole_push = self.cvs.coords(self.pole.id)
if push[2] &gt;= pole_push[0] and push[0] &lt;= pole_push[2]:
if push[3] &gt;= pole_push[1] and push[1] &lt;= pole_push[3]:

return True
return False

def draw(self):
self.cvs.move(self.id, self.a, self.b)
push = self.cvs.coords(self.id)
# print(pos)
start = [4, 3.8, 3.6, 3.4, 3.2, 3, 2.8, 2.6]
random.shuffle(start)
if self.stone_strike(push):
self.b = start[0]
if push[1] &lt;= 0:
self.b = start[0]
if push[3] &gt;= self.cvs_height:
self.bottom_hit = True
if push[0] &lt;= 0:
self.a = start[0]
if push[2] &gt;= self.cvs_width:
self.a = -start[0]
if self.pole_strike(push):
self.b = -start[0]
class Pole:
def __init__(self, cvs, clr):
self.cvs = cvs
self.id = canvas.create_rectangle(0, 0, 100, 10, fill=clr)
self.cvs.move(self.id, 200, 485)
self.a = 0
self.pauseSeconds = 0
self.cvs_width = canvas.winfo_width()
self.cvs.bind_all("&lt;Left&gt;", self.turn_left)
self.cvs.bind_all("&lt;Right&gt;", self.turn_right)
self.cvs.bind_all("&lt;space&gt;", self.pauseSeconds)

def draw(self):
push = self.cvs.coords(self.id)
# print(pos)
if push[0] + self.a &lt;= 0:
self.a = 0
if push[2] + self.a &gt;= self.cvs_width:
self.a = 0
self.cvs.move(self.id, self.a, 0)

def turn_left(self, event):


self.a = -3.5

def turn_right(self, event):


self.a = 3.5

def pause(self, event):


self.pauseSeconds += 1
if self.pauseSeconds == 2:
self.pauseSeconds = 0

class Stone:
def __init__(self, cvs, clr):
self.cvs = cvs
self.id = canvas.create_oval(5, 5, 25, 25, fill=clr, width=2)

playing = False

def start_game(event):
global playing
if playing is False:
playing = True
score.configure(text="Score: 00")
canvas.delete("all")
BALL_COLOR = ["blue", "green", "violet"]
STONE_COLOR = ["green", "dark blue", "red", "pink", "violet", "yellow",
"orange", "gray", "brown", "white", "blue", "yellow green",
"navajo white", "dark gray", "violet red", "powder blue", "blue violet"]
random.shuffle(BALL_COLOR)
pole = Pole(canvas, "yellow")
stones = []
for i in range(0, 5):
b = []
for j in range(0, 19):
random.shuffle(STONE_COLOR)
tmp = Stone(canvas, STONE_COLOR[0])
b.append(tmp)
stones.append(b)

for i in range(0, 5):


for j in range(0, 19):
canvas.move(stones[i][j].id, 25 * j, 25 * i)

ball = Ball(canvas, BALL_COLOR[0], pole, stones, score)


root.update_idletasks()
root.update()

time.sleep(1)
while 1:
if pole.pauseSeconds != 1:
try:
canvas.delete(m)
del m
except:
pass
if not ball.bottom_hit:
ball.draw()
pole.draw()
root.update_idletasks()
root.update()
time.sleep(0.01)
if ball.hit == 95:
canvas.create_text(250, 250, text="YOU WON !!", fill="yellow",
font="Calibri 24 ")
root.update_idletasks()
root.update()
playing = False
break
else:
canvas.create_text(250, 250, text="GAME OVER!!", fill="red", font="Calibri
24 ")
root.update_idletasks()
root.update()
playing = False
break
else:
try:
if m == None: pass
except:
m = canvas.create_text(250, 250, text="PAUSE!!", fill="green", font="Calibri
24 ")
root.update_idletasks()
root.update()

root.bind_all("&lt;Return&gt;", start_game)
canvas.create_text(250, 250, text="Press Enter to start Game!!", fill="yellow",
font="Calibri 18")
j = canvas.find_all()
root.mainloop()
3 . Output / Result
First Output
Second Output
4. Conclusion

FROM A PROPER ANALYSIS OF POSITIVE POINTS AND CONSTRAINTS ON


THE COMPONENT IT CAN BE SAFELY CONCLUDED THAT THE PRODUCT

IS AN EFFICIENT GUI BASED SYSTEM . THIS APPLICATION IS WORKING


PROPERLY AND MEETING ALL OF THE USER REQUIREMENTS . IT CAN
BE EASILY USED IN ANY OTHER SYSTEMS . THIS CONCLUDES OUR
BOUNCY BALL PROJECT .
5 . References

1. https://www.geeksforgeeks.org/
2. https://www.w3schools.com/
3. https://www.python.org/
4. https://www.tutorialspoint.com/

You might also like