Created
March 14, 2015 05:24
-
-
Save mattharrison/c7049b8fe22efdc81806 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
=========== | |
Drone Lab | |
=========== | |
Start IDLE | |
============ | |
Run:: | |
>>> import turtle as t | |
>>> t.write('hello world') | |
Lists & Loops | |
================ | |
Create a list with some numbers in it. Loop over the list and move the turtle with each number. | |
Functions | |
========= | |
Write a function (``square``) that draws a square | |
Write a function (``move_xy``) that moves the turtle to certain coordinates | |
Call both functions like this:: | |
>>> for x, y, size in [(10, 10, 5), | |
... (-20, -20, 10)]: | |
... move_xy(t, x, y) | |
... square(t, size) | |
Conditionals | |
============ | |
Write a function (``odd_square``) that takes a number: | |
* if the number is odd it moves right and up that amount and draws a square | |
* if the number is even it moves right and down that amount and draws a square | |
Call it like thes:: | |
>>> for num in range(10): | |
... odd_square(num) | |
File io | |
======= | |
Read in a text file and have the turtle write out the contents | |
Classes | |
======= | |
Make a ``Rabbit`` subclass of ``Turtle``: | |
* when ``.pensize`` is called, double the size of the pen | |
* when ``.forward`` is called, go twice the amount | |
* when ``.backward`` is called, go back half the amount | |
Run:: | |
>>> r = Rabbit() | |
>>> t2 = t.Turtle() | |
>>> for thing in [r, t2]: | |
... for num in range(100): | |
... thing.forward(num) | |
... thing.left(2) | |
... thing.backward(num/2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment