Class 6 using the math library

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

18/2/00SEM107 - © Kamin & Reddy Class 7 - LineList - 1 Class 7 - Line Drawings  The LineList data type r Recursive methods to construct line drawings.
Review of Math Class Methods abssqrt minmax powround ceilfloor.
Introduction to Programming
Processing Lecture. 1 What is processing?
1 Python Programming: An Introduction to Computer Science Chapter 3 Objects and Graphics.
Chapter 4 Objects and Graphics
Chapter 5 Graphics.  We’ve been doing command line programming, but now it’s time to try GUI programming—programming in a graphical user interface, using.
Computer Science 111 Fundamentals of Programming I Basic Program Elements.
Programming Training kiddo Main Points: - Python Statements - Problems with selections.
Introduction to Computation and Problem Solving Class 9: Static Methods and Data Members Prof. Steven R. Lerman and Dr. V. Judson Harward.
Programming games Show your version of Bo the dog. Start cannonball Preview: video, audio work session (cannonball) Homework: Cannonball with ball in a.
1 Turtle Graphics and Math Functions And how you can use them to draw cool pictures!
Some Graphics CS303E: Elements of Computers and Programming.
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.
Xiaojuan Cai Computational Thinking 1 Lecture 5 Objects and Graphics Xiaojuan Cai (蔡小娟) Fall, 2015.
Graphics and Java2D Chapter Java Coordinate System Origin is in _____________ corner –Behind title bar of window X values increase to the ________.
Python Programming, 2/e1 Python Programming: An Introduction to Computer Science Chapter 4 Objects and Graphics.
5. COMPUTING WITH GRAPHICS OBJECTS Dennis Y. W. Liu and Rocky K. C. Chang October 8, 2015 (Adapted from John Zelle’s slides)
CS 115 Lecture 7 Graphics – coordinate systems, Text, Entry, aliases Taken from notes by Dr. Neil Moore.
VG101 RECITATION 5 By TAs. CONTENTS How to read Vg101Class.h Samples about graphics About assignment 5 Array.
1 Sections 5.1 – 5.2 Digital Image Processing Fundamentals of Java: AP Computer Science Essentials, 4th Edition Lambert / Osborne.
CS 115 Lecture 6 Graphics Taken from notes by Dr. Neil Moore.
3. Drawing Let’s Learn Saengthong School, June – August 2016 Teacher: Aj. Andrew Davison, CoE, PSU Hat Yai Campus
ENGINEERING 1D04 Tutorial 4. What are we doing today? Focus Functions Scope of Variables Returning Values Objects Graphics library Aliasing Events Mouse.
Graphics Michael Liut ( ) Ming Quan Fu( ) Brandon Da Silva(
CSC 108H: Introduction to Computer Programming Summer 2011 Marek Janicki.
Foundations of Programming: Java
Graphics Taken from notes by Dr. Neil Moore & Dr. Debby Keen
Fundamentals of Programming I Overview of Programming
Python Turtle Graphics
Some Assignments  Write a program which prints the following information about at least 5 persons: NAME MAIL-ID EMPLOYEE-CODE PHONE Eg. Umesh
GUI in Python Ismail Abumuhfouz.
Object - CIS 1068 Program Design and Abstraction
Scratch for Interactivity
Agenda Warmup Prep for Core #1 Lesson G2 (RGB, Loops in Graphics)
Introduction to Programming: Module #2 Python, Trinket, and Turtle Graphics Lois Delcambre.
9. Drawing.
Python Programming: An Introduction to Computer Science
Catapult Python Programming Thursday Session
Do Now Find the value of each expression. Sin 60 ° Cos 30 ° Tan 270 °
Python: Simple Graphics and Event-driven Programming
9. Drawing Let's Learn Python and Pygame
Graphics Part I Taken from notes by Dr. Neil Moore
Learning to program with Logo
Graphics Part I Taken from notes by Dr. Neil Moore
Basic Graphics Drawing Shapes 1.
CS 115 Lecture Graphics II – coordinate systems, Text, Entry, aliases
CS 100: Roadmap to Computing
CompSci 101 Introduction to Computer Science
Section 6.2 Classes & Objects.
Using Objects 21-Nov-18.
CS 115 Lecture Graphics II – coordinate systems, Text, Entry, aliases
CSc 110, Spring 2018 Lecture 9: Parameters, Graphics and Random
CS 100: Roadmap to Computing
CSC240 Computer Science III
Graphics Part I Taken from notes by Dr. Neil Moore
6.1 Angles and Radian Measure
A look at Python Programming Language 2018.
Which best describes the relationship between classes and objects?
Class 7 coordinates: pixel and with setCoords aspect ratio Rectangle
class 5 retrieving a previous statement in Thonny or IDLE // %
MATLAB Introduction MATLAB can be thought of as a powerful graphing calculator but with a lot more buttons! It is also a programming language, commands.
Terminal-Based Programs
Announcements How to save your work? Quiz solution 5/5/2019
Computation as an Expressive Medium
A circle with center at (0, 0) and radius 1 is called a unit circle.
Using Modules.
Getting Started in Python
Presentation transcript:

Class 6 using the math library using sin and cos – converting from degrees to radian. factorial – accumulating a product float vs int Preview of Objects graphics.py the graphics window Point, Circle, ...

From Lab 5: I.B. angleInRadians = angleInDegree * π/180 math.cos() and math.sin() use angles in radians. If angle in degrees, must convert to radians to use with sin and cos. angleInRadians = angleInDegree * π/180

Why math. ? import math math.sin(), math.cos(), math.pi I don't have to worry about using a variable or function with the same name but a different meaning.

Why math. ? import math math.sin(), math.cos(), math.pi (If we had said from math import * we wouldn't need the math. Could say sin(theta), pi ...)

From Lab 5: I.B. print(deg, sin(deg*π/180), cos(deg*π/180)) or nicer formatting print(deg, "\t", sin(deg*π/180), "\t", cos(deg*π/180))

From Lab 5: I.B. arithmetic is not exact: π ≠ math.pi Computer does calculations to compute sin(theta) – not exact.

computing factorial: accumulating a product. prod=1 for i in range(1,11): prod=prod*i print(prod) 1 2 6 24 120 720 5040 40320 362880 3628800

computing factorial: print in the loop prod=1 for i in range(1,11): prod=prod*i print(prod) 1 2 6 24 120 720 5040 40320 362880 3628800

computing factorial: print after the loop prod=1 for i in range(1,11): prod=prod*i print(prod) 3628800

difference in float and int of 100! prod=1 for i in range(1,101): prod=prod*i print(prod) fprod=1.0 fprod=fprod*float(i) print(fprod)

What is the digit after ...441? 93326215443944152681699238856266700490715968264381621468592963895217599993229915608941463976156518286253697920827223758251185210916864000000000000000000000000 9.33262154439441e+157

What is the digit after ...441? 93326215443944152681699238856266700490715968264381621468592963895217599993229915608941463976156518286253697920827223758251185210916864000000000000000000000000 9.3326215443944100000000000000000....

Preview of Objects Data types we have seen: int, float, string We can make "instances" of each: age=10 #int price = 57.23 #float They have data – their values. They can do things: + * print

Downloading .py files from my website trouble downloading some .py files instead, download .txt file, change the extension to .py note this doesn't work for all kinds of files. Can't just change .docs to .txt. Can save a word file: "Save as" plain text, .txt

Preview of Objects Object Oriented Programming: We can make "data types" of our own – called Objects, and package them with functions (methods)– things they can do. We will build our own objects later.

Preview of Objects There are packages of predesigned Objects. We will get used to the idea by working with a package for graphics.

Introduction to graphics.py Some of the objects we can use: GraphWin (windows for drawing in) Circles Polygons Points

Introduction to graphics.py Each Circle we make is an "instance" of a Circle. Each instance of a Circle has its own data: its center its color its radius ...

Introduction to graphics.py Each Circle we make is an "instance" of a Circle. Each instance of a Circle can do things: draw itself in a window change color report the x coordinate of its center clone itself ...

The Graphics Window Made up of pixels – picture elements. (0,0) is upper left corner. x increases to the right y increases down

The Graphics Window

Sample code #SampleWindow2.py #Baruch #Demonstrate some graphics objects # and what they can do. #Import the graphics library, graphics.py. #Don't need to use graphics. prefix. from graphics import *

Sample code #Create a graphics window with the GraphWin constructor sw=GraphWin("Sample Window",600, 400) #Create and display a Point dot=Point(50,100) #Constructor - builds a Point object dot.draw(sw) #The Point draws itself to the sw window. #Wait for a mouse click sw.getMouse() #The window waits for a mouse click

Sample code #Create and display a circle circ=Circle(dot,30) #Construct a circle circ.setFill("red") #Change its color circ.draw(sw) #The circle draws itself. #Wait for a mouse click sw.getMouse() #The window waits for a mouse click sw.close() #close the window

Things to try. Change the circle to blue and redraw it. Create another circle rtCirc=Circle(Point(500,300),60) Make it green. Do they both turn green?