Clicky Turtlehack

by Elliott Hauser

06 Oct 2022

Submit a well-formatted pull request to our class website with embedded Trinket program(s) for the assignment below. Complete this on your own, using any class materials you need (including the additional resources on the syllabus). Do not look at other students’ submissions until after you’ve completed your work.

Include a thoughtful reflection, and use Markdown as needed to make your writing about your code clear and understandable to others. Your reflection should articulate what you think you’ve learned and any concepts that are still fuzzy to you. Did you encounter frustrating situations? Did you feel a lightbulb turn on?

In your program, remember to leave comments via Python’s # or using Trinket’s inline comments as needed to orient your reader.

After your programs are done, check other students’ work and other resources online if you had questions.


Write a turtle program that:

  • Has a setup() function that sets up your screen visually. For instance, you could draw green grass and blue sky using the .fill() method.
  • Has two forms of user interface: clicks and keypresses. Remember, Turtles can listen for click events, and Screens can listen for click and key events.

Option 1: Clicks

  • Uses the screen.onclick() function method to call clicky() function you create
  • Within clicky, do something cool. Think outside the .goto(x, y) box :)
  • Within clicky, call one or more helper functions you’ve created
  • Within clicky or helper functions, use logic to change your program’s behavior based on the turtle’s x and/or y coordinates. For instance, you could vary the turtle’s color, speed, or call different helper functions.

Option 2: Keys

  • Listen for at least the 4 arrow keys and one more key to control the turtle’s position and one other aspect of its state.
  • Call a helper function in at least one of your click functions

  • Does one of the following:
    • Allows the user to make something creative interactively
    • Has a ‘win’ condition. Make sure to give instructions!
    • Implements a narrative animation. import time, time.sleep(x) and tina.clear() will probably be helpful. You’ll also need to remember your interface elements!

Advanced

If you’d like to stretch yourself, try these:

  • Add other functions to animations.py, import them and use them in your main program.
  • Create a second turtle other than tina and have him/her also do something in your clicky function.
  • Explore the screen.update() and screen.tracer() methods to change how often the screen updates and fix the zigzag artifacts.
  • Add your own new module (i.e. mymodule.py) and import something from it. You could even put your clicky function there to keep your code clean and readable.
  • Read ahead on lists, loops, or dictionaries and use some of these in your code.

Ideas

You could make:

  • A drawing program
  • A treasure hunt game: ‘hide’ a treasure at an X, Y coordinate, and tell the user whether they’re hot and cold as they move the turtle.
  • An animation that waits for a user’s interaction to continue
  • Multiple turtles that have different clicky functions!

Starter Code

Use this Clicky starter code unless you feel like coding from scratch:

Small changes to the functions in this code can yield big results! And by understanding the patterns within it, you can create an entirely unique program. Good luck!

Elliott Hauser is an Assistant Professor at the UT Austin iSchool. He's hacking education as one of the cofounders of Trinket.io. Find Elliott Hauser on Twitter, Github, and on the web.