Graphics CIS 40 – Introduction to Programming in Python

Slides:



Advertisements
Similar presentations
Computer Science 1000 LOGO I. LOGO a computer programming language, typically used for education an old language (1967) the basics are simple: move a.
Advertisements

Introduction to TouchDevelop
B.A. (Mahayana Studies) Introduction to Computer Science November March Logo (Part 1) An introduction to Logo: drawing, moving,
Slides adapted from: Bjarne Stroustrup, Programming – Principles and Practice using C++ Chapter 12 A display model Hartmut Kaiser
Mini Project II – Drawing Machine
LOGO SOFTWARE BY: SAVE 9S. INTRODUCTION Logo is a software that can be found at : Shared area> High School > ICT > take home software > LOGO32. This is.
Programming Training kiddo Main Points: - Python Statements - Problems with selections.
Microsoft® Small Basic
1 CSC 221: Computer Programming I Fall 2011 Fun with turtle graphics  turtle module  relative motion (setup, reset, left, right, forward, backward) 
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
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.
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.
Graphics Concepts CS 2302, Fall /17/20142 Drawing in Android.
Slides adapted from: Bjarne Stroustrup, Programming – Principles and Practice using C++ Chapter 12 A display model Hartmut Kaiser
Let’s Learn 3. Modules Saenthong School, January – February 2016
Intro to Turtle Graphics (Part 2)
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.
Today… The for loop. Introducing the Turtle! Loops and Drawing. Winter 2016CISC101 - Prof. McLeod1.
CS 115 Lecture 6 Graphics Taken from notes by Dr. Neil Moore.
LOGO WHAT IS IT? HOW TO USE IT AND HOW USEFUL CAN IT BE?
Turtle Graphics Just keep swimming …. Fill Shapes turtle.fillcolor(“#color_code”) turtle.begin_fill() turtle.end_fill() ■You must tell turtle when to.
ENGINEERING 1D04 Tutorial 4. What are we doing today? Focus Functions Scope of Variables Returning Values Objects Graphics library Aliasing Events Mouse.
Using the Python Turtle
Computers and Programming
Development Environment
Introduction to Python
LOGO BY Kaotip 9S.
Main Points: - Python Turtle - Fractals
Going Green By Ima Librarian
Containers and Lists CIS 40 – Introduction to Programming in Python
General Form for a Conditional
Variables, Expressions, and IO
Functions CIS 40 – Introduction to Programming in Python
PowerPoint Day 1 Credibility Builder
Graphics Part I Taken from notes by Dr. Neil Moore
Chapter 16 – Programming your App’s Memory
Object Oriented Programming
Tie to LO Are the following triangles congruent? Why or why not?
A Tiny Look at the Graphics Window
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
Working with Text and Numbers in Java
Introduction to.
Selection CIS 40 – Introduction to Programming in Python
Microsoft® Small Basic
البرمجة مع لغة PYTHON TURTLE
Number and String Operations
File IO and Strings CIS 40 – Introduction to Programming in Python
CS 100: Roadmap to Computing
An Introduction to VEX IQ Programming with Modkit
Creating Functions with Parameters
Loops CIS 40 – Introduction to Programming in Python
Graphics Part I Taken from notes by Dr. Neil Moore
Sketching Techniques and Practice!
Suppressing print Newline
Main Points: - Python Turtle - Fractals
Section 3 Programming with Turtle Graphics
Winter 2019 CISC101 2/17/2019 CISC101 Reminders
Introduction to Turtle Graphics
CISC101 Reminders Assignment 2 due this Friday.
A Tiny Look at the Graphics Window
Getting started with LEGO EV3 Mindstorms software
Presentation transcript:

Graphics CIS 40 – Introduction to Programming in Python De Anza College Clare Nguyen

Intro In this module we use our knowledge of functions to work with the basic graphics module called turtle. The turtle module is made up of many methods, which are a type of functions, to help us draw on screen. Therefore we will get a lot of practice working with functions. The turtle module introduces us to some concepts of object oriented programming (such as methods, mentioned above). Object oriented programming is a popular concept in software engineering and will be covered more in-depth later in the course.

What Is Graphics? Up to this point our Python code has produced text based output: all the data printed to screen are lines of words and numbers. Text based output is the earliest form of program output and it is the standard form of output for most programming languages. Text output is still widely used today in all areas of technology and is often used by skilled tech professionals. However, most common applications now have graphics output or a graphical user interface (or GUI) because it is more visually interesting. A graphics output allows us to draw shapes and use different colors in the output.

The turtle Module turtle is a Python module, which is a package of data and functions that work together to provide a particular kind of service. The turtle module provides us with basic graphics capabilities. turtle is not a built-in part of the Python language, so before we can use turtle, we need to add it to our development environment. In other words, we need to import all the data and functions of the turtle module. At the top of your code, type: from turtle import * (the * symbol means “all”) Python and many other languages use the concept of modules to make it easier to ‘customize’ the language. The language comes with a standard package that supports basic functionalities, and then users can import specific modules that support their specific needs.

The turtle Object (1 of 2) The turtle module package is an object oriented (OO) package. This means that the software works with data that are objects. Objects are data that: Have the class data type. Recall that int or str is a data type. Python lets us define our own data type, similar to how we define our own functions. The data type that we define is a class data type. Come with multiple methods that work with the objects. A method is a function that belongs to a class data type. Up to this point, our functions are global functions that don’t belong to a class. Therefore, the way we call a method is slightly different than the way we call a function. **All this might seem abstract now, but as we use turtle it will be clearer. And we will discuss more OO concepts later.**

The turtle Object (2 of 2) After importing the turtle package, when we want graphics output, we need to create a turtle object. The turtle object has methods such as: draw a circle, change color to red, etc. which we can call to produce graphics output. To create the turtle object: t = Turtle() Turtle() is the first method that we use, it creates a turtle object. Recall that num = 5 creates a memory space that stores 5 and has the name num. Similarly, memory space is created for the turtle data and has the name t (for turtle). We now say that t is a turtle object. When we want to call a turtle method (or a function that belongs in the turtle class), the format is: object_name.method_name() For our turtle object, to draw a circle: t.circle(10)

Demo Click for a video demo of how to use turtle to draw shapes. The methods covered in the video are discussed in the next slides.

Methods For Pen Control (1 of 2) The “pen” is the cursor where the drawing takes place. To change the shape of the pen: shape(“shape_name”) where the shape_name can be: “turtle”, “circle”, “square”, “triangle”, “classic”, “arrow” To change the color of the pen: color(“color_name”) where common color_names are: or click for a complete list of more colors than you’ll know what to do with. To change the width of the pen: pensize(number) where number is a positive number.

Methods For Pen Control (2 of 2) Similar to when we draw with pen and paper, if we want to draw 2 shapes that are far apart from each other, we need to lift the pen up from the paper in between the 2 shapes. To lift the pen up: penup() or up() Likewise, when the pen is already up, to set the pen down to continue to draw: pendown() or down() Make a mark in the shape of the pen: stamp()

Methods To Move (1 of 2) With the pen down, the move methods will draw on the screen. Set the pen to the middle of the screen: home() Move to a particular location: goto(x_coord, y_coord) where x_coord and y_coord are the (x, y) position on the screen. The screen uses Cartesian coordinates and the center of the screen is (0,0). Move forward: forward(number) or fd(number) Move backward: back(number) or bk(number) where number can be positive or negative, and the larger the number, the larger the distance. Turn left: left(number) or lt(number) Turn right: right(number) or rt(number) where number is the degrees of the turn angle, and number can be positive or negative.

Methods To Move (2 of 2) Move in a circle: circle(radius) where radius is a positive number. Move in an arc: circle(radius, extent) where radius is a positive number, extent is the angle that the arc covers. For example, extent of 180 means half a circle. Undo the last move: undo()

Methods To Fill a Shape To fill a shape, we need to let turtle know before drawing a shape, and then we need to tell turtle to stop after the shape is drawn: begin_fill() code to draw a shape end_fill() Change fill color: fillcolor(“color_name”) where color_name is the same as with the pencolor method.

Administrative Methods These methods are called “administrative” methods because they support the graphics output. Go back to the start screen: reset() This is equivalent to running the 2 methods: home() and clear() The pen goes back to the (0, 0) position and the screen is cleared. Print text on screen: write(“text string”, font = number) where text string is the text that is printed to screen, and number is a positive number and is the size of the font. Find more information on a turtle method: help(method_name) where method_name is the method we need information on. Exit graphics mode: bye() No need to use the turtle object name with this method.

What’s Next We will continue to use turtle graphics as well as text output for our programs. Moving forward, in the next module our programs will use conditional processing to make decisions and give the user choices.