CS 100: Roadmap to Computing Fall 2014 Lecture 02: Fun With Turtles.

Slides:



Advertisements
Similar presentations
Python Turtle Mini-Course. Operations go( n ) # n est un nombre turn ( d ) # d est longle color (green) width ( n ) invisible ( ) visible ( ) pen_up.
Advertisements

Noadswood Science,  To understand the flow procedure when writing programs Thursday, January 15, 2015.
Lecture 04 – Classes.  Python has a number of classes built-in  lists, dictionaries, sets, int, float, boolean, strings  We can define our own classes.
TOPIC 12 CREATING CLASSES PART 1 1 Notes adapted from Introduction to Computing and Programming with Java: A Multimedia Approach by M. Guzdial and B. Ericson,
Cosc 1P02 Week 2 Lecture slides
Modules and Objects Introduction to Computing Science and Programming I.
1 Python Programming: An Introduction to Computer Science Chapter 3 Objects and Graphics.
Compilers and Interpreters. Translation to machine language Every high level language needs to be translated to machine code There are different ways.
Introduction to TouchDevelop
Yr 9 a computer science Nice to meet you variable challenge! 1.Variable assessment Looping in python 2.Looping assessment Drawing in python using turtle.
Computer Science 111 Fundamentals of Programming I Introduction to Programmer-Defined Classes.
Chapter 9 Introduction to ActionScript 3.0. Chapter 9 Lessons 1.Understand ActionScript Work with instances of movie clip symbols 3.Use code snippets.
Introduction to Programming Writing Java Beginning Java Programs.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 6 Value- Returning Functions and Modules.
Modules. A module is a file containing Python definitions and statements intended for use in other Python programs. There are many modules as part of.
School of Computer Science & Information Technology G6DICP - Lecture 22 The Theory of Object Oriented Programming.
Programming Training kiddo Main Points: - Python Statements - Problems with selections.
1 CSC 221: Computer Programming I Fall 2011 Fun with turtle graphics  turtle module  relative motion (setup, reset, left, right, forward, backward) 
Main Points: - Python Turtle - Fractals
You SHOUD HAVE.. C:\100 folder A desktop shortcut to “IDLE (Python34)”
A SIMPLE COMPUTER LANGUAGE LOGO. LOGO Introduction Logo is the simplest programming language. It.
Art 321 Lecture 7 Dr. J. Parker. Programming In order to ‘make things happen’ on a computer, you really have to program it. Programming is not hard and.
Class 2 Introduction to turtle graphics
Agent P, I have been hearing some rumours about a Python Turtle.
1 Turtle Graphics and Math Functions And how you can use them to draw cool pictures!
Introduction to TouchDevelop
Hello, little turtles. Hello, little turtles! There are many modules in Python that provide very powerful feature that we can use in our own program.
An introduction to Logo Mike Warriner Engineering Director, Google Note: This course is not an endorsement of Logo by Google. All views in this document.
Java is an object oriented programming language In this model of programming all entities are objects that have methods and fields Methods perform tasks.
The Hare Raising Experience of Logo in the Classroom
Loops & Graphics IP 10 Mr. Mellesmoen Recall Earlier we wrote a program listing numbers from 1 – 24 i=1 start: TextWindow.WriteLine(i) i=i+1 If.
Introduction to Programming Writing Java Beginning Java Programs.
OCR GCSE Computing © Hodder Education 2013 Slide 1 OCR GCSE Computing Python programming 1: Introduction.
Programming for GCSE 1.0 Beginning with Python T eaching L ondon C omputing Margaret Derrington KCL Easter 2014.
CSC 1010 Programming for All Lecture 7 Input, Output & Graphics.
1 Graphics CSCI 343, Fall 2015 Lecture 3 Introduction to WebGL.
Microsoft® Small Basic Exploring Shapes Estimated time to complete this lesson: 1 hour.
Getting started with the turtle Find the latest version of this document at
CRE Programming Club - Class 5 Robert Eckstein and Robert Heard.
Programming Training kiddo Main Points: - Python Statements - Problems with selections.
Let’s Learn 3. Modules Saenthong School, January – February 2016
Introduction to: Python and OpenSesame FOR PROS. OpenSesame In OpenSesame you can add Python in-line codes which enables complex experiment. We will go.
Turtle Graphics Let’s see what we can draw on Python!
Turtle Graphics Lesson 2 1. There are 3 homeworks to complete during the six lessons of this unit. Your teacher will let you know when a homework has.
Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 9: Arrays; Revision Session.
Today… The for loop. Introducing the Turtle! Loops and Drawing. Winter 2016CISC101 - Prof. McLeod1.
Search for it on your computer
LOGO WHAT IS IT? HOW TO USE IT AND HOW USEFUL CAN IT BE?
Introducing the turtle
Introduction to Computing Science and Programming I
Python Turtle Graphics
Graphics CIS 40 – Introduction to Programming in Python
For vs. While loop count=0 while count< 5: for count in range(5):
Introduction to Python
CMPT 120 Topic: Python Modules.
Graphics Part I Taken from notes by Dr. Neil Moore
Paddle Ball! We will begin creating, in steps, a video game similar to ‘brick breaker’ or ‘pong’, were we can move paddles to hit a bouncing ball. I hope.
Agent P, I have been hearing some rumours about a Python Turtle.
Graphics Part I Taken from notes by Dr. Neil Moore
CS 100: Roadmap to Computing
CS 100: Roadmap to Computing
Let's Learn Python and Pygame
Graphics Part I Taken from notes by Dr. Neil Moore
Main Points: - Python Turtle - Fractals
Topics Introduction to Value-returning Functions: Generating Random Numbers Writing Your Own Value-Returning Functions The math Module Storing Functions.
Introduction to Turtle Graphics
Introduction to Value-Returning Functions: Generating Random Numbers
Background for lab: the ord() function
Using Modules.
Presentation transcript:

CS 100: Roadmap to Computing Fall 2014 Lecture 02: Fun With Turtles

Introduction to Computing Using Python Python Data Types (3): Turtle Graphics  Objects and Classes  Python Standard Library  Turtle Graphics

Introduction to Computing Using Python Python Standard Library In addition to built-in data types (number, Boolean, string, list) Python has a large library of other data types – the Python Standard Library You can find a list of these ‘modules’ here Help -> Python docs -> Global Module Index Each module is a file of Python code that contains definitions of one (or more) data type(s), functions (methods) that you can perform on objects of that type, and possibly data (like the value of pi) Quick task: Look up three modules that have names that interest you and see what data types and functions they contain. Hint: you might try random, urllib or pickle, for example Share the one you like best with the person sitting next to you. Quick task: Look up three modules that have names that interest you and see what data types and functions they contain. Hint: you might try random, urllib or pickle, for example Share the one you like best with the person sitting next to you.

Introduction to Computing Using Python Turtle Graphics Module Find and open the documentation for the turtle module Look up turtle info in this document as we discuss turtle graphics Turtle graphics are a simple but powerful way to draw things on a coordinate plane To get started, import the turtle module. The Python Standard Library is contained in the standard distribution, but you must import any module that you want to use >>> import turtle

Introduction to Computing Using Python Turtle Graphics Module Turtle graphics are a simple but powerful way to draw things on a coordinate plane, using a drawing pen (a turtle) Open the documentation for the turtle module, and refer to it as we discuss turtle graphics The Python Standard Library is contained in the standard distribution, but you must import any module in it before you can use it To get started, import the turtle module (below) >>> import turtle >>> >>> import turtle >>>

Introduction to Computing Using Python Turtle Graphics Module The turtle module defines a some new classes of graphical things Once you’ve imported the turtle module, you can create a graphics screen and a turtle (a whimsical name for a drawing pen), using their constructors Note: The constructor syntax is variableName = moduleName.ClassName() >>> import turtle >>> aScreen = turtle.Screen() >>> shelly = turtle.Turtle() >>> import turtle >>> aScreen = turtle.Screen() >>> shelly = turtle.Turtle() Screen constructor Turtle constructor

Introduction to Computing Using Python Moving a Turtle A turtle has a position and an orientation on a graphics screen Change shelly’s position with a forward (or back) statement Change shelly’s orientation with a right or left statement >>> import turtle >>> aScreen = turtle.Screen() >>> shelly = turtle.Turtle() >>> shelly.forward(100) >>> shelly.right(90) >>> import turtle >>> aScreen = turtle.Screen() >>> shelly = turtle.Turtle() >>> shelly.forward(100) >>> shelly.right(90)

Introduction to Computing Using Python A Fancier Turtle A turtle also has color and width attributes that you can change A method (function) that applies to a particular object uses the dot operator, with the syntax objectName.method(parameterList) >>> shelly.color('blue') >>> shelly.width(10) >>> shelly.color('blue') >>> shelly.width(10)

Introduction to Computing Using Python A Fat Blue Triangle Save this example as a Python file and run it blueT = Turtle() blueT.color('blue') blueT.width(10) blueT.forward(100) blueT.right(120) blueT.forward(100) blueT.right(120) blueT.forward(100) blueT.right(120)

Introduction to Computing Using Python Some turtle methods UsageExplanation forward() | bk()move the turtle right() | left()rotate the turtle circle()lstdraw a circle up() | down()raise/lower the drawing pen goto()move to x, y coordinate setheading()set turtle orientation showturtle() | hideturtle()set turtle visibility color()set drawing color width()set line width

What we have learned A Python module is a file that Python code – usually defining one or more related new types of things ('classes'). Each class has a constructor method to create new objects in that class Each class will have methods (functions) for doing things with objects of that type. A method is invoked using the dot ('.') operator. By convention, a class name is capitalized, object and method names are lower case