#!/usr/bin/env python # coding: utf-8 # In[2]: import turtle import time # Make turtle appear turtle.showturtle() # initial direction it points is to right time.sleep(2) # Moving "forward" in direction that turtle is pointing turtle.forward(30) time.sleep(2) # Can rotate turtle so many degrees right or left turtle.right(90) turtle.forward(30) time.sleep(2) # We can move the turtle anywhere we want, if # we understand the coordinate system. # We can track coordinates for every movement. print("The turtle is currently at",turtle.pos()) time.sleep(2) turtle.forward(30) print("The turtle is currently at",turtle.pos()) time.sleep(2) # How do we move to a specified coordinate? turtle.penup() # this causes the turtle to stop writing turtle.goto(0,0) # this moves us back to the origin # pointing the same direction as before time.sleep(2) # We can tell turtle to point in a certain direction # by specifying the angle that we want it to point: turtle.setheading(135) time.sleep(2) # Change color of the pen turtle.pencolor("#600060") turtle.pendown() turtle.forward(40) time.sleep(2) # Can also change background color: turtle.bgcolor("red") time.sleep(2) turtle.bgcolor("blue") time.sleep(5) # In[ ]: import turtle import time turtle.showturtle() # circle demonstration #turtle.setheading(180) #turtle.circle(50,extent=200) # move turtle to top left of the "T" # without drawing anything turtle.penup() time.sleep(1) turtle.goto(-125,175) time.sleep(2) # change color turtle.pencolor('#600060') time.sleep(1) # drop the pen turtle.pendown() time.sleep(1) # move forward ("right") 100 pixels turtle.forward(100) time.sleep(2) # move turtle now to the middle of # the horizontal line we just made turtle.goto(-75,175) time.sleep(2) # turn turtle 90 degrees to the right turtle.right(90) time.sleep(2) # move forward ("down") 175 pixels turtle.forward(100) time.sleep(2) # Pick pen up turtle.penup() # move to (100,0) turtle.goto(100,0) time.sleep(2) # put pen back down turtle.pendown() #up and left part of the C turtle.setheading(135) turtle.forward(50) time.sleep(2) #down and left part of the C turtle.setheading(225) turtle.forward(50) time.sleep(2) # vertical part of the C turtle.setheading(270) turtle.forward(75) time.sleep(2) # down and right piece of the C turtle.setheading(315) turtle.forward(50) time.sleep(2) # up and right part of the C turtle.setheading(45) turtle.forward(50) time.sleep(5)