1 / 13

Turtle Graphics and Abstract Data Types

Turtle Graphics and Abstract Data Types. Denison University, CS 111: Foundations of Computing Guest Lecture 01/29/2014 Hernando Bermudez. Objectives. Introduce Turtle Graphics as a way of visualizing data.

aviva
Download Presentation

Turtle Graphics and Abstract Data Types

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Turtle Graphics and Abstract Data Types Denison University, CS 111: Foundations of Computing Guest Lecture 01/29/2014 Hernando Bermudez

  2. Objectives Introduce Turtle Graphics as a way of visualizing data. Describe the concept of an Abstract Data Type(ADT) and illustrate the main ideas via the turtle.

  3. Turtle Graphics Turtle Graphics are created by moving an abstract “turtle” with directional commands. As the turtle moves, its “tail” leaves behind a trail. If we lift the turtle’s tail it can move without leaving a trace. The turtle moniker comes from a type of robot which could be used to trace out on paper the picture which is drawn by the “turtle” on the screen.

  4. The Valiant Turtle Robot Picture from Wikipedia

  5. Abstract Data Types The turtle is an example of an Abstract Data Type(ADT). An ADT is an implementation independent description of some abstract object. The ADT consists of the information about the entity and the functions required to change said information.

  6. Example of ADT: A Graph Information Functions Edge: Is there an edge between two vertices? Add vertex Add edge Remove vertex Remove edge • Vertices • Edges

  7. Adjacency Matrix Implementation The Petersen Graph Vertex Pair Implementation (1,2),(1,5),(1,6),(2,3),(2,7),(3,4),(3,8),(4,9), (4,5),(5,10),(6,8),(6,9),(7,9),(7,10),(8,10)

  8. The Turtle as an ADT Information Functions Move Forward Turn Right Turn Left Change Color Lift Tail • Position • Orientation • Color • Tail status (Up or Down)

  9. Classes in Python ADT’s are implemented in Python with a class. A class holds the information in instance variables which can be changed via methods. The instance variables are typically interacted with via the methods and not directly.

  10. The Turtle Class Instance Variables Methods left(angle):modify _orient by rotating angle degrees to the left right(angle) forward(distance): change _position by moving distance units in _orient direction pencolor(‘color’): set _pencolor to ‘color’ up(): lift the tail etc • _position • _pencolor • _orient • etc

  11. Instances To utilize the turtle class we begin by creating an instance of the class. The class is the description of a type of object, each actual object is an instance of the class. This allows us to have more than one object of the same type in a program.

  12. A Quick Overview of Polynomial Geometry • For a regular n-gon: • The inner angles measure 180*(n-2)/n degrees. • If d is the diameter of the circumscribed circle then the length of the d_k diagonal is d*sin(180*k/n)

More Related