Week 2
This week we learn about Turtle Graphic and OOP.
Object-oriented programming is a programming paradigm that revolves around object.
Principles of OOP
1. Encapsulation
2. Inheritance.
3. Polymorphism
Encapsulation
Class : a blueprint for how to build a certain type of object. Class describes
attributes and behavior of objects instantiated from the class. Python uses the
keyword class to define a class.
Object : an instance of a class
Constructor : a special that creates an instance of the class. Constructor
initializes values of attributes of an object. In Python, constructor of a class is
defined as __init__.
Inheritance
Inheritance is the ability to define a new class that is an extension of an existing
class. The new class (derived class) inherits all of the methods of the existing
class (base class).
Example :
Person class (base class), Employee class (derived class) and Boss class
(derived class). The example shows how derived class object is initialized—how
constructors are called.
Polymorphism
Methods usually work for a specific type of objects. When a new class is defined,
methods that operate on objects of that class are included in the class.
There is another type of operations that work for many types of objects. Each
object type responds to the operation differently.
Example :
Bear and Dog classes. Both inherit from the built-in Object class. A bear and a
dog are capable of making sound. However, their sounds are different. The
example shows how polymorphism is implemented in Python.
Turtle Graphics
There are many Python packages that can be used to create graphics and GUI’s.
Two graphics modules, called turtle and tkinter, come as a part of Python’s
standard library. tkinter is primarily designed for creating GUI’s. turtle is primarily
used as a simple graphics package. It also can be used to create simple GUI’s.
This week assignment is about create a clock that using Turtle Graphics
First, we have to draw a plain clock, so make hour numbers at a clock from 1 - 12, then we could know that angle between each hour numbers is 30 degree and angle minutes numbers is 6 degree. Then, we can let them manipulate by using center of circle be a joint to draw for each hour and minute numbers. Finally, we can draw a hours hand and minutes hand by using information from above.
Object-oriented programming is a programming paradigm that revolves around object.
Principles of OOP
1. Encapsulation
2. Inheritance.
3. Polymorphism
Encapsulation
Class : a blueprint for how to build a certain type of object. Class describes
attributes and behavior of objects instantiated from the class. Python uses the
keyword class to define a class.
Object : an instance of a class
Constructor : a special that creates an instance of the class. Constructor
initializes values of attributes of an object. In Python, constructor of a class is
defined as __init__.
Inheritance
Inheritance is the ability to define a new class that is an extension of an existing
class. The new class (derived class) inherits all of the methods of the existing
class (base class).
Example :
Person class (base class), Employee class (derived class) and Boss class
(derived class). The example shows how derived class object is initialized—how
constructors are called.
Polymorphism
Methods usually work for a specific type of objects. When a new class is defined,
methods that operate on objects of that class are included in the class.
There is another type of operations that work for many types of objects. Each
object type responds to the operation differently.
Example :
Bear and Dog classes. Both inherit from the built-in Object class. A bear and a
dog are capable of making sound. However, their sounds are different. The
example shows how polymorphism is implemented in Python.
Turtle Graphics
There are many Python packages that can be used to create graphics and GUI’s.
Two graphics modules, called turtle and tkinter, come as a part of Python’s
standard library. tkinter is primarily designed for creating GUI’s. turtle is primarily
used as a simple graphics package. It also can be used to create simple GUI’s.
This week assignment is about create a clock that using Turtle Graphics
First, we have to draw a plain clock, so make hour numbers at a clock from 1 - 12, then we could know that angle between each hour numbers is 30 degree and angle minutes numbers is 6 degree. Then, we can let them manipulate by using center of circle be a joint to draw for each hour and minute numbers. Finally, we can draw a hours hand and minutes hand by using information from above.
ความคิดเห็น
แสดงความคิดเห็น