INTRODUCTION TO PYTHON PART 5 - GRAPHICS CSC482 Introduction to Text Analytics Thomas Tiahrt, MA, PhD.

Slides:



Advertisements
Similar presentations
Copyright 2006 by Pearson Education 1 Building Java Programs Supplement 3G: Graphics.
Advertisements

Topic 9 more graphics Based on slides bu Marty Stepp and Stuart Reges from
Building Java Programs Supplement 3G Graphics Copyright (c) Pearson All rights reserved.
Building Java Programs Supplement 3G Graphics Copyright (c) Pearson All rights reserved.
Copyright 2008 by Pearson Education Building Java Programs Graphics Reading: Supplement 3G.
Copyright 2006 by Pearson Education 1 Building Java Programs Supplement 3G: Graphics.
Week 3 parameters, return, math, graphics Special thanks to Scott Shawcroft, Ryan Tucker, and Paul Beck for their work on these slides. Except where otherwise.
Week 3 parameters and graphics Special thanks to Scott Shawcroft, Ryan Tucker, and Paul Beck for their work on these slides. Except where otherwise noted,
Copyright 2008 by Pearson Education Building Java Programs Graphics reading: Supplement 3G videos: Ch. 3G #1-2.
Week 3 parameters, return, math, graphics Special thanks to Scott Shawcroft, Ryan Tucker, and Paul Beck for their work on these slides. Except where otherwise.
Copyright 2008 by Pearson Education Building Java Programs Graphics reading: Supplement 3G videos: Ch. 3G #1-2.
Copyright 2006 by Pearson Education 1 Building Java Programs Supplement 3G: Graphics.
INTRODUCTION TO PYTHON PART 3 - LOOPS AND CONDITIONAL LOGIC CSC482 Introduction to Text Analytics Thomas Tiahrt, MA, PhD.
1 Graphical objects We will draw graphics in Java using 3 kinds of objects: DrawingPanel : A window on the screen. Not part of Java; provided by the authors.
INTRODUCTION TO PYTHON PART 2 INPUT AND OUTPUT CSC482 Introduction to Text Analytics Thomas Tiahrt, MA, PhD.
Fundamentals of Python: From First Programs Through Data Structures
METHODS AND SCOPE CSCE More on Methods  This is chapter 6 in Small Java.
Copyright 2010 by Pearson Education Building Java Programs Graphics reading: Supplement 3G.
Making Python Pretty!. How to Use This Presentation… Download a copy of this presentation to your ‘Computing’ folder. Follow the code examples, and put.
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.
1 Building Java Programs Supplement 3G: Graphics These lecture notes are copyright (C) Marty Stepp and Stuart Reges, They may not be rehosted, sold,
Week 3 parameters and graphics Special thanks to Scott Shawcroft, Ryan Tucker, and Paul Beck for their work on these slides. Except where otherwise noted,
GRAPHICS MODULE 14 STUDY BOOK. Graphic commands SCREEN - puts the screen into graphics mode WINDOW - allows scaling of the screen LINE - 3 formats –LINE.
CSC 1010 Programming for All Lecture 7 Input, Output & Graphics.
Building Java Programs Supplement 3G Graphics Copyright (c) Pearson All rights reserved.
Introduction to Programming with Python
Video in Macromedia Flash (Optional) – Lesson 121 Video in Macromedia Flash (Optional) Lesson 12.
Parameters, return, math, graphics nobody expects the spanish inquisition!
1 Introduction to Programming with Python: overview.
Building Java Programs Graphics Reading: Supplement 3G.
CS305j Introduction to Computing Simple Graphics 1 Topic 11 Simple Graphics "What makes the situation worse is that the highest level CS course I've ever.
Introduction to Graphics. Graphical objects To draw pictures, we will use three classes of objects: –DrawingPanel : A window on the screen. –Graphics.
Copyright 2008 by Pearson Education Building Java Programs Graphics reading: Supplement 3G videos: Ch. 3G #1-2.
Introduction to Programming Python Lab 8: Loops 26 February PythonLab8 lecture slides.ppt Ping Brennan
Basic Graphics 03/03/16 & 03/07/16 Imagine! Java: Programming Concepts in Context by Frank M. Carrano, (c) Pearson Education - Prentice Hall, 2010.
CompSci 4 Java 4 Apr 14, 2009 Prof. Susan Rodger.
Introduction to Programming
Adapted from slides by Marty Stepp and Stuart Reges
Building Java Programs
Introduction to Programming
Building Java Programs
Building Java Programs
Building Java Programs
Introduction to Programming
Building Java Programs
CSc 110, Autumn 2017 Lecture 5: The for Loop and user input
CSc 110, Spring 2017 Lecture 6: Parameters (cont.) and Graphics
CSc 110, Autumn 2017 Lecture 31: Dictionaries
Topic 8 graphics "What makes the situation worse is that the highest level CS course I've ever taken is cs4, and quotes from the graphics group startup.
Building Java Programs
CSc 110, Spring 2018 Lecture 9: Parameters, Graphics and Random
1/22/2008.
Building Java Programs
CSc 110, Autumn 2017 Lecture 9: Graphics and Nested Loops
CSE 142 Lecture Notes Graphics with DrawingPanel Chapter 3
Topics Graphical User Interfaces Using the tkinter Module
Building Java Programs
CSc 110, Spring 2018 Lecture 10: More Graphics
Building Java Programs
Building Java Programs
CSc 110, Autumn 2017 Lecture 8: More Graphics
Building Java Programs
Topic 9 More Graphics Based on slides bu Marty Stepp and Stuart Reges from
Building Java Programs
Building Java Programs
Building Java Programs
Making a Smile Face Pepper.
Graphics Reading: Supplement 3G
Building Java Programs
Introduction to Programming with Python
Presentation transcript:

INTRODUCTION TO PYTHON PART 5 - GRAPHICS CSC482 Introduction to Text Analytics Thomas Tiahrt, MA, PhD

Graphics

To create a window create a drawingpanel and its graphical pen, called g : from drawingpanel import * panel = drawingpanel( width, height) g = panel.get_graphics()... (draw shapes here)... panel.mainloop() The window has nothing on it, but we can draw shapes and lines on it by sending commands to g. Example: g.create_rectangle(10, 30, 60, 35) g.create_oval(80, 40, 50, 70) g.create_line(50, 50, 90, 70) Drawing Shapes

Graphic Shape Drawing commands can accept optional outline & fill colors g.create_rectangle(10, 40, 22, 65, fill="red", outline="blue") The coordinate system is y-inverted: (0, 0) (200, 100)

Commands for Drawing Shapes CommandDescription g.create_line( x1, y1, x2, y2 ) a line between (x1, y1), (x2, y2) g.create_oval( x1, y1, x2, y2 ) the largest oval that fits in a box with top-left corner at (x1, y1) and bottom-left corner at (x2, y2) g.create_rectangle( x1, y1, x2, y2 ) the rectangle with top-left corner at (x1, y1), bottom-left at (x2, y2) g.create_text( x, y, text= "text" ) the given text at (x, y)

Drawing Shapes We can draw many repetitions of the same item at different x/y positions with for loops. The x or y assignment expression contains the loop counter, i, so that in each pass of the loop, when i changes, so does x or y. from drawingpanel import * window = drawingpanel(500, 400) g = window.get_graphics() for i in range(1, 11): x = * i y = * i g.create_oval(x, y, x + 50, y + 50, fill="red") window.mainloop()

Python Exercise 7 Exercise: Draw the figure at right. Be sure to place the drawingpanel.py code somewhere in your path so that you can import it: from drawingpanel import *

Free Book that uses Python This is a handy (and free) book that uses Python. How to Think Like a Computer Scientist

Thanks for many of the slides go to: Marty Stepp Lecturer, Stanford University

Exercises  Exercise 1: Evaluate the quadratic equation for a given a, b, and c using Python.  Exercise 2: Write the code for the "99 Bottles of Beer" song  Exercise 3: Write a Python program that computes the factorial of an integer using a loop and the range operator.  Exercise 4: Count and display the factors of a number.  Exercise 5: Write a program that performs a rotation cypher.  Exercise 6: Compute the percentage of C and G nucleotides in a DNA file  Exercise 7: Draw the figure shown as a stack of rectangles.

Exercises  N.B. these must all appear in one file, and allow the user to work through all of the exercises. Be sure to provide prompts explaining which exercise is the current exercise. Note that you must perform error checking for reasonableness (e.g. do not allow square roots of negative numbers, and do not compute factorials of large numbers).  This is a 35 point exercise collection. Place your name at the start of the file name and append _Ex01.py to your name.  Be sure to get the drawpanel.py module and place it where Python can find it. You can use show path in IDLE to see where it searches.

Conclusion of the Python Sequence  The end of the end has come.