CS 100: Roadmap to Computing

Slides:



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

Lecture 04 – Classes.  Python has a number of classes built-in  lists, dictionaries, sets, int, float, boolean, strings  We can define our own classes.
Modules and Objects Introduction to Computing Science and Programming I.
Objects Interaction and Source Code Week 2. OBJECT ORIENTATION BASICS REVIEW.
1 Python Programming: An Introduction to Computer Science Chapter 3 Objects and Graphics.
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.
Turtle Graphics Victor Norman CS104 Calvin College.
Introduction to Python
Introduction to Programming Writing Java Beginning Java Programs.
TOPIC 3 INTRODUCTION TO PROGRAMMING 1 Notes adapted from Introduction to Computing and Programming with Java: A Multimedia Approach by M. Guzdial and B.
Peter Andreae Python for Level 3 CS4HS see website: ecs.vuw.ac.nz/Main/PythonForSchools.
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.
1 CSC 221: Introduction to Programming Fall 2012 Functions & Modules  standard modules: math, random  Python documentation, help  user-defined functions,
Programming Training kiddo Main Points: - Python Statements - Problems with selections.
PYTHON: PART 2 Catherine and Annie. VARIABLES  That last program was a little simple. You probably want something a little more challenging.  Let’s.
COSC 1P02 Introduction to Computer Science 3.1 Cosc 1P02 Week 3 Lecture slides Birthdays are good for you. Statistics show that the people who have the.
Graphics Concepts CS 2302, Fall /3/20142 Drawing Paths.
David Streader Computer Science Victoria University of Wellington Copyright: David Streader, Victoria University of Wellington Java Programing Basics COMP.
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)”
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.
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.
Classes 1 COMPSCI 105 S Principles of Computer Science.
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.
CSC 1010 Programming for All Lecture 7 Input, Output & Graphics.
Lecture 71 CS110 Lecture 8 February 19, 2004 Announcements –hw3 due tonight –hw4 available, due Thursday February 26 –exam Tuesday March 2 Agenda –questions.
1 Graphics CSCI 343, Fall 2015 Lecture 3 Introduction to WebGL.
Introduction to Python Dr. José M. Reyes Álamo. 2 Three Rules of Programming Rule 1: Think before you program Rule 2: A program is a human-readable set.
Getting started with the turtle Find the latest version of this document at
1.1: Objects and Classes msklug.weebly.com. Agenda: Attendance Let’s get started What is Java? Work Time.
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.
Chapter 5 Introduction to Defining Classes Fundamentals of Java.
Introduction to Computing Science and Programming I
Fundamentals of Programming I Overview of Programming
Python Turtle Graphics
Computer Programming.
Graphics CIS 40 – Introduction to Programming in Python
Introduction to Python
Introduction to Programming: Module #2 Python, Trinket, and Turtle Graphics Lois Delcambre.
Do it now activity Last lesson we used Flowol to create a solution to a problem a computer could solve. Identify what each symbol does:
CS 100: Roadmap to Computing
Chapter 8 Objects.
JavaScript: Functions.
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.
Learning to program with Logo
Graphics Part I Taken from notes by Dr. Neil Moore
CS 100: Roadmap to Computing
Java Programming with BlueJ
Learning to Program in Python
Graphics Part I Taken from notes by Dr. Neil Moore
Chapter 8 Objects.
Python Primer 1: Types and Operators
Using Logo and Logic This presentation uses a version of Logo called StarLogo available through MIT. It can be downloaded for free and installed on your.
Class 6 using the math library
CMPT 120 Lecture 16 – Unit 3 – Graphics and Animation
Methods Coding in Java Copyright © Curt Hill.
Using Modules.
Presentation transcript:

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

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

Python Standard Library Introduction to Computing Using Python 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. In addition to built-in data types (e.g., int, float, 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), methods (functions) that operate on objects of that type, and possibly data (like the value of pi)

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

Turtle Graphics Module Introduction to Computing Using Python The turtle module defines 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 The constructor syntax is variableName = moduleName.ClassName() A constructor is a method, which is a kind of function. Like every function it takes a parameter list enclosed in parentheses Hint: notice that the name of a class (Screen, Turtle) is upper case, while the name of a variable or file (shelly, turtle) is lower case. This is a Python convention, meaning that Python does not force you to do it, but we always follow this rule to make our code clear and readable. Screen constructor >>> import turtle >>> aScreen = turtle.Screen() >>> shelly = turtle.Turtle() Turtle constructor

Moving a Turtle Introduction to Computing Using Python 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 Note: forward, back, right and left are all methods in the Turtle class, and when you invoke (call) them, you must include all of these: an object (instance) of the class (for example, shelly) the dot operator the name of the method (e.g., forward)] parentheses for the parameter list (even if the list is empty) >>> import turtle >>> aScreen = turtle.Screen() >>> shelly = turtle.Turtle() >>> shelly.forward(100) >>> shelly.right(90)

A Fancier Turtle Introduction to Computing Using Python 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)

A Fat Blue Triangle Save this example as a Python file and run it Introduction to Computing Using Python Save this example as a Python file and run it t_size = 100 blueT = turtle.Turtle() blueT.color('blue') blueT.width(10) blueT.forward(t_size) blueT.right(120) blueT.forward(t_size) blueT.right(120) blueT.forward(t_size) blueT.right(120) Engage in some turtle play by changing the size, color or width of the turtle Use turtle graphics to draw some other shapes

Some turtle methods Usage Explanation forward() | bk() move the turtle Introduction to Computing Using Python Usage Explanation forward() | bk() move the turtle right() | left() rotate the turtle circle() draw a circle up() | down() raise/lower the 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 contains Python code – usually defining one or more related new types of things (a class). Each class defines a type of object and a constructor method to create new objects of that type Each class defines methods (functions) for doing things with an object of that type. A method is invoked (or called) using the dot ('.') operator. By convention, a class name is capitalized; object and method names are lower case