Search
  • Rachael Kim

Our Fifth Class!

Updated: Aug 2, 2020

July/29 was our fifth class, and we finally started to learn about Python Turtle library.

Below is the powerpoint we used for class!

Class 5, July 29, 2020
.pptx
Download PPTX • 2.30MB

Review of our fifth class:


1. What is Python Turtle?

Python Turtle is a built-in Python library that lets users create shapes and drawings using vector graphics.

In order to use the pre-defined functions in Turtle library, you need to import the library.

In Python, import is as simple as this:

import turtle

Then, you can create an instance of turtle object by doing:

t = turtle.Turtle()

You can still run your functions without creating the object, but if you want to make use of multiple turtle objects, it is useful to do so.

NOTE: object in computer science refers to anything with values. Functions, variables, etc. are all objects.

This is similar to giving names to individual human beings. For example, there is Rachael, who is one instance of humans, and there is humans, which is a bigger class like turtle.


2. Running Python Turtle

Put the two lines into a new file and run it.

You should see a new window popping up. The window should say "Python Turtle Graphics," and you would see a small arrow at the center of a square window.


3. Python Turtle functions

There are numerous functions you can run using Turtle library.

Below are just some examples.

When you want to run these functions on specific instance of turtle object, you do:

t.shape("turtle")
t.forward(100)
t.xcor()

If you haven't declared your own instance, you can also simply run it on turtle itself:

turtle.shape("turtle")

4. Setting background color

By creating an instance of Screen object, you can set the background color.

import turtle
s = turtle.Screen()
s.bgcolor("orange")

5. Filling your shape

You can tell Turtle to fill your shape.

Specify color with .fillcolor("color") and .color("color"). Tell Python to start filling using .begin_fill(). and to stop using .end_fill().

t.color("yellow")
t.fillcolor("yellow")
t.begin_fill()
for x in range(3):
    t.forward(100)
    t.left(120)
t.end_fill()

There is also a good article for you to read, thanks to Mana!

https://realpython.com/beginners-guide-python-turtle/

Check it out!

13 views0 comments

Recent Posts

See All

End of our Summer Program

Our Summer Program has officially ended on August 19, 2020. Our girls presented their final projects that they have worked on for a couple of weeks. We were impressed by their creativity and improveme

Phillips Exeter Academy Girls Who Code

Phillips Exeter Academy

20 Main Street

Exeter, NH 03833

Quick Links

© 2020 by Exeter Girls Who Code

This site was designed with the
.com
website builder. Create your website today.
Start Now