Computer Science
Gilmour AcademyLancerTech
  • Our Curriculum and Department
  • Intro to Programming
    • 1: Parts of a Computer
    • 2: Parts of Python
    • 3: DRY Turtle
    • 4: Turtle Design App
    • Wordle with Turtles
    • 5: Interactive Turtles
    • OLD 5: Replit, GitHub, and repositories (Oh my!)
    • 6: Raspberry Pi / GoPiGo
    • 7: Kivy
  • Intro to Web Design
    • 1: Internet?
    • 2: Websites?
    • 3: Bootstrap Template
    • 4: Graphics and Branding
    • 5: Collaboration
    • 6: Advanced Editing
    • Publish Static HTML
  • AP Computer Science
    • 1: Logic & Instances
    • 2: How Java Works
    • 3: Data Types & Flow
    • 4: Strings
    • 5: Objects & References
    • 6: Inheritance & Algorithms
    • 7: Data Structures
    • 8: Sorting
    • 9: Review
    • Data Science
  • Web App Dev
    • 1: Core Concepts
    • 2: MVT Pattern
    • 3: Hello Flask
    • 4: Install Flaskinni
    • 5: Tour Flaskinni
    • 6: Visualize Your App
    • 7: Theme & Blueprint
    • 8: Standup Your DB
    • 9: Advanced Topics
    • 10: Deployment
  • 2D Game Design
    • Class Overview
    • Gamemaker Studio 2 and Github Setup
    • Game 1: Bouncing Ball
    • Turning in your games
    • Game 2: Maze
    • Game 3: Ping Pong
    • Game 4: Breakout
    • Game 5: Tank Battle
    • Game 6 Highlights
    • DO NOT DO:
    • Game 7: Final Project
    • Publish to Opera
    • FAQ
  • 3D Game Design
    • 1: Class Overview
    • 2: Installation
    • 3: Exploring the Unity UI
    • Game 1: Rolling Ball
    • Game 2: Tanks
    • Game 3: Third Person Platformer
    • Game 4: Final project
    • FAQs
    • OLD: Distance Learning Setup
    • OLD: GIT
  • 3D Modeling & Fabrication
    • Installation
    • Fusion 360 Interface and Sketch Modeling
    • Primitive Modeling
    • Patterns
    • Appearances and Rendering
    • Building Community Gallery Page 2023
    • Parametric Modeling
    • 3D Printing Concerns
    • Assemblies and Mechanical Design
    • Laser Cutting
    • Sculpt Tools
    • Milling Concerns
  • Robotics 7
    • Software Installation
    • Python basics (trinket.io)
    • Python Turtle
    • Programming for the Ev3
    • Setting up for clarity
  • Robotics 8
    • Replit
    • Python review
    • Kivy Basics
    • Calculator
  • Competitive Robotics
    • Hardware Team
      • CAD Examples
      • Elevators
    • Software Team
      • Command Pattern
      • Example Command
      • Subsystem
      • Running Your Code
      • Under the Hood
      • RoadRunner
      • Vision Processing
  • Archives
    • Adiletta Archives
      • Old Web
        • Ex: WordPress CMS
      • ItP
        • OLD: Parts of Python (old -- Mr. A)
        • OLD: 5: Raspberry Pi
        • OLD: 6: Deploying Code
        • OLD 7: Nav Algorithm
    • Vanek Archives
      • OLD Robotics 8
        • OLD: End of Class Project
      • OLD Competitive Robotics
        • Untitled
        • Webots Videos
      • OLD Robotics 7
        • Trinket Introduction
        • Lists: x/y position
        • Functions: Math program
        • Lists: Grocery List
        • Study Guide Program
        • Tic Tac Toe Game
        • Dice Roller Program
        • Visualization
        • Dice Roller + Visualization
        • OpenSCAD: Installation
        • OpenSCAD: Command Sheet and Intro
        • OpenSCAD: Difference
        • OpenSCAD: Variables
        • OpenSCAD: Union
        • OpenSCAD: For Loops
        • OpenSCAD: Final Project
      • OLD Art I - Blender Sculpting
        • Class Overview
        • Installation
        • Lesson 1 - Tools
        • Lesson 2 - Detail
        • Lesson 3 - Base Mesh: Metaballs
        • Lesson 4: Converting metaballs and adding detail
        • Lesson 5: Masking, Hiding, and Working with Multiple Objects
        • Lesson 6: Joining Objects & Basing
        • Lesson 7: Sculpture Painting
        • Student Gallery: Animal Sculpts
        • Lesson 8: 3D Compositon
        • Lesson 9: The Project - Putting it all together
        • Lesson 10: Developing the image further
        • Lesson 11: Layout the base metaball mesh.
        • Lesson 12: Final Detail
        • Lesson 13: Basing and Painting
        • Final Project Gallery
      • OLD Fab
        • OLD Building Community Project Gallery
        • Copy of Building Community Project Gallery
        • old Building Community Project Gallery
      • OLD: Turtle Design App
      • OLD Arduino Robotics 8
        • Arduino Basic Commands Cheat Sheet
        • Logging into Tinkercad
        • Arduino, Circuits, LEDs and Resistors
        • Functions and Variables
        • Serial Monitor
        • Buttons and Interrupts
        • Traffic Light Project
        • Potentiometers + Servos
        • Piezo Buzzer and Tone();
        • Sequencer Project
        • Arrays and for loops
        • Extra Loop Practice
        • Refining the Sequencer
        • Servos
        • Ultrasonic Sensors
        • Final Project
Powered by GitBook
On this page
  • Class Videos
  • 2/1
  • 2/7
  • 2/7 assignment PT 2
  • 2/8
  • 2/15 -- Extending the SuperTurtle APP Assignment
  • Building an App
  • SuperTurtle file
  • helper file
  • Wiring them together
  • Main file
  • Now go play!

Was this helpful?

Export as PDF
  1. Archives
  2. Vanek Archives

OLD: Turtle Design App

Previousold Building Community Project GalleryNextOLD Arduino Robotics 8

Last updated 3 years ago

Was this helpful?

Class Videos

2/1

2/7

2/7 assignment PT 2

2/8

2/15 -- Extending the SuperTurtle APP Assignment

To finish off the superturtle app, we are going to add the following to our program:

Move the printing of the menu options to the helper function, but run it in main.py

Add at least 3 new methods to the SuperTurtle class (whatever you want, but they should be obviously different than the things we wrote together.

Building an App

Let's get a little crazy here and build a pretty sophisticated app. We're building a SuperTurtle class with lots of methods. We've built some helper functions to provide random colors or print welcome messages. And we're building an interactive menu structure to run the whole app. But if we put all of this stuff in one file it gets to be a real mess. So let's split everything up like professional software developers.

SuperTurtle file

Let's make a new Python Trinket. Call it Final Turtle and save it. Then create a new file called superturtle.py. Notice that we don't include capitals or spaces in the names of our module file.

Now let's add our SuperTurtle class to this file. You can start with my copy below and then add in additional methods you may have built in our previous Trinkets.

from turtle import Turtle
from random import randint

class SuperTurtle(Turtle):
  """
  Our wrapper class of the turtle.Turtle object
  """
  
  def __init__(self, shape='turtle'):
    """
    This is the turtle's constructor with a default shape of "turtle"
    """
    Turtle.__init__(self)
    self.color(rancolor())
    self.shape(shape)
    self.penup()
    self.speed(9999)
    self.goto_random()
  
  def goto_random(self):
    """
    Simple function that sends a turtle to a random location on
    a 400x400 canvas
    """
    self.goto(randint(-200,200), randint(-200,200))
    
  def triangle(self, length=50):
    """
    Draws an equilateral triangle with a default length of 50
    """
    self.pendown()
    self.forward(length)
    self.left(120)
    self.forward(length)
    self.left(120)
    self.forward(length)

  def square(self, length=120):
    """
    Draws a square with a default length of 120
    """
    self.pendown()
    for x in range(4):
      self.forward(length)
      self.left(90)
    
  def home(self):
    """
    Returns to center position
    """
    self.goto(0,0)

  def star(self):
    """
    Draws a 5-point star with a fixed length of 140
    """
    self.pendown()
    for x in range(5):
      self.forward(140)
      self.left(145)

helper file

We're going to make a file with a bunch of helpful functions. Let's call it helper.py

And let's add this code:

from random import choice

def welcome():
  for x in range(3):
    print("**************")
    if x == 0:
      print("** WELCOME ***")
      
def print_options():
  print("--- MENU ---")
  print("1: Add turtle to gang")
  print("2: Draw a picture")
  print("Any other key will quit")

def rancolor():
  """ This method returns a string from a list of colors available to Turtle's .color() method """
  colors = ["brown", "darkorange", "maroon", "crimson", "navy", "salmon", "tomato", "khaki", "gold", "hotpink", "springgreen", "blue", "cyan", "purple", "green", "red", "pink", "yellow", "teal"]
  return choice(colors)

Wiring them together

In order to access the rancolor() function from helper.py, we could import that specific function with from helper import rancolor

But what'd I'd rather do, is just import helper at the top and then change the rancolor line to helper.rancolor()

Main file

Let's add a basic menu to our app:

from superturtle import SuperTurtle
import helper

# our collection of turtles
gang = []

# welcome message
helper.welcome()

# menu loop
while True:
  helper.print_options()
  selection = input("You selection: ")
  # analyize the selection
  if "one" in selection or "1" in selection:
    gang.append(SuperTurtle())
  elif "two" in selection or "2" in selection:
    # loop through all our turtles
    for t in gang:
      t.star()
  # quit if no option is recognized 
  else:
    break

Now go play!

Try changing this project. Add options and features. I'm here to help, too.

What if I want the help file to command my turtles?

The gang of turtles is in the main file. If we want to use it in the helper.py file, we need to pass it as a parameter. For example, I could add this method to my helper file that will make each turtle draw 100 stars:

def super_star(gang):
  for x in range(100):
    for t in gang:
      t.star()

And perhaps I want to add this super_star option to my menu. So I'll add it to my print_options and to my main.py's if statements:

  elif "three" in selection or "3" in selection:
    helper.super_star(gang) # pass the gang over to helper
  • 1pt - separate SuperTurtle class and module

  • 1pt - separate helper module

  • 2pts - multiple adds to menu

  • 2pts - first added method

  • 2pts - second added method

  • 2pts - third added method

  • 2pts - creative display