ling 408/508: programming for linguists lecture 23 november 25 th

25
LING 408/508: Programming for Linguists Lecture 23 November 25 th

Upload: mervin-bennett

Post on 08-Jan-2018

219 views

Category:

Documents


0 download

DESCRIPTION

graphics.py

TRANSCRIPT

Page 1: LING 408/508: Programming for Linguists Lecture 23 November 25 th

LING 408/508: Programming for Linguists

Lecture 23November 25th

Page 2: LING 408/508: Programming for Linguists Lecture 23 November 25 th

Last Time

• Library graphics.py– built on top of Tkinter (Python interface to Tk)– built on top of Tk (graphics library)– built on top of X11 (graphics library) on Ubuntu

Page 3: LING 408/508: Programming for Linguists Lecture 23 November 25 th

graphics.py

Page 4: LING 408/508: Programming for Linguists Lecture 23 November 25 th

graphics.py• Object inheritance (see graphics.py code):• GraphicsObject– Point: draw, move, clone– Text: clone, move, draw, setText, getText, setFace– Polygon: clone, getPoints, move, draw– _Bbox: move• Rectangle: draw• Oval: clone, draw–Circle: clone, getRadius

• Line: clone, draw, setArrow

Page 5: LING 408/508: Programming for Linguists Lecture 23 November 25 th

Directly in wish tcl/tk

Stylistic variation…graphics.py: use primitive object Pointtk: uses plain x,y coordinates

Page 6: LING 408/508: Programming for Linguists Lecture 23 November 25 th

Interactive Graphics

• textbook 5.7:– p = win.getMouse() returns a Point

Page 7: LING 408/508: Programming for Linguists Lecture 23 November 25 th

Interactive Graphics

Page 8: LING 408/508: Programming for Linguists Lecture 23 November 25 th

Interactive Graphics

Page 9: LING 408/508: Programming for Linguists Lecture 23 November 25 th

Interactive Graphics

• textbook 5.7:– input = Entry(center,width) creates a user-

editable text box

Page 10: LING 408/508: Programming for Linguists Lecture 23 November 25 th

Interactive Graphics

Page 11: LING 408/508: Programming for Linguists Lecture 23 November 25 th

Interactive Graphics

Page 12: LING 408/508: Programming for Linguists Lecture 23 November 25 th

graphics.py API

Page 13: LING 408/508: Programming for Linguists Lecture 23 November 25 th

graphics.py API

Page 14: LING 408/508: Programming for Linguists Lecture 23 November 25 th

graphics.py API

Page 15: LING 408/508: Programming for Linguists Lecture 23 November 25 th

graphics.py API

• Color:

• Color names: – see http://wiki.tcl.tk/37701

Page 16: LING 408/508: Programming for Linguists Lecture 23 November 25 th

graphics.py API

Page 17: LING 408/508: Programming for Linguists Lecture 23 November 25 th

graphics.py API

Page 18: LING 408/508: Programming for Linguists Lecture 23 November 25 th

graphics.py API

Page 19: LING 408/508: Programming for Linguists Lecture 23 November 25 th

graphics.py API

Page 20: LING 408/508: Programming for Linguists Lecture 23 November 25 th

graphics.py API

Page 21: LING 408/508: Programming for Linguists Lecture 23 November 25 th

Section 6.2-6.4

• Happy birthday example

• nested function calls:

Note: parameters are passed byvalue (copying)- not by reference (pointer)- (some other programming languages allow both options)

Page 22: LING 408/508: Programming for Linguists Lecture 23 November 25 th

Section 6.5

• To send a value back, use – return <Expression>

• Multiple values can be returned:

Note: None is returned when there is no return statement

Page 23: LING 408/508: Programming for Linguists Lecture 23 November 25 th

triangle2.py• Calculates the perimeter of a triangle you draw.

Page 24: LING 408/508: Programming for Linguists Lecture 23 November 25 th

triangle2.py

Note: parameters are passed byvalue (copying)- mutable objects (Point)

Page 25: LING 408/508: Programming for Linguists Lecture 23 November 25 th

triangle2.py