Skip to content

Instantly share code, notes, and snippets.

@rbdixon
Created January 30, 2016 13:56
Show Gist options
  • Save rbdixon/baa12be42b40af928b29 to your computer and use it in GitHub Desktop.
Save rbdixon/baa12be42b40af928b29 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"To start the program first you must load the turtle library and some math functions that will let you get a random number.\n",
"\n",
"Then you create your turtle. He will be named `bob`."
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import turtle\n",
"from random import seed, random\n",
"\n",
"bob = turtle.Turtle()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"This next box resets the canvas. You can run it any time you want to clear the canvas and start over."
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"bob.reset()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Now we will draw with Bob. Bob is going to make 25 loops. Each loop will be a random color. Before Bob starts the loop he will turn left a little bit. See if you can figure out how far he will turn. The Bob will draw a circle ending up back where he started. The last line is very important... can you figure out what would happen if that line was not there?"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"numloops = 25\n",
"loops = numloops\n",
"while (loops>0):\n",
" bob.color( random(), random(), random() )\n",
" bob.left( 360.0 / numloops )\n",
" bob.circle( 50.0 )\n",
" loops = loops - 1"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 2",
"language": "python",
"name": "python2"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.11"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment