CS 100: Roadmap to Computing

Slides:



Advertisements
Similar presentations
Graphics Shapes. Setup for using graphics You have to import the graphics library You can use either “import graphics” or “from graphics import *” or.
Advertisements

CS 100: Roadmap to Computing Fall 2014 Lecture 02: Fun With Turtles.
Modules and Objects Introduction to Computing Science and Programming I.
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.
© 2011 Delmar, Cengage Learning Chapter 9 Introduction to ActionScript 3.0.
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.
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.
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.
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.
Java is an object oriented programming language In this model of programming all entities are objects that have methods and fields Methods perform tasks.
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.
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
CRE Programming Club - Class 5 Robert Eckstein and Robert Heard.
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.
LOGO WHAT IS IT? HOW TO USE IT AND HOW USEFUL CAN IT BE?
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
Main Points: - Python Turtle - Fractals
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:
Advanced Coding Session 5
CS 100: Roadmap to Computing
turtle module Simple graphics programming How to use it ?
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
Java Programming with BlueJ
Log onto a computer first then ….
CS 100: Roadmap to Computing
Learning to Program in Python
Graphics Part I Taken from notes by Dr. Neil Moore
Main Points: - Python Turtle - Fractals
Section 3 Programming with Turtle Graphics
Introduction to Turtle Graphics
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.
CMPT 120 Lecture 16 – Unit 3 – Graphics and Animation
Background for lab: the ord() function
CMPT 120 Lecture 19 – Unit 3 – Graphics and Animation
The beginning of media computation Followed by a demo
Methods Coding in Java Copyright © Curt Hill.
Using Modules.
Presentation transcript:

CS 100: Roadmap to Computing Fall 2016 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 (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)

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 they always have parentheses >>> 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