1
1
Aaron Stevens
9 February 2009
CS108 Lecture 11: Objects and Graphics
Objects and Classes Graphics Concepts
2
Overview/Questions What are objects, and how do they help us - - PDF document
CS108 Lecture 11: Objects and Graphics Objects and Classes Graphics Concepts Aaron Stevens 9 February 2009 1 Overview/Questions What are objects, and how do they help us program more effectively? An overview of computer graphics
1
2
3
4
5
6
7
8
9
http://mcsp.wartburg.edu/zelle/python/graphics/graphics/index.html
10
/Library/Frameworks/Python.framework/Versions/2.5/ lib/python2.5/site-packages/ on Mac.
11
12
13
14
15
>>> from graphics import * >>> win = GraphWin() >>> p = Point(50,50) >>> p.draw(win) >>> win = GraphWin() >>> center = Point(100,100) >>> circ = Circle(center, 30) >>> circ.setFill("red") >>> circ.draw(win) >>> line = Line(Point(150,50),Point(150,150)) >>> line.draw(win) >>> text = Text(Point(100,20), "Witty remark.") >>> text.draw(win)
16
17
– This actually describes an engineering specification from which an entire class of identical cars could be created.
18
19
20
<object>.<method-name>(<param1>, <param2>,…)
p.draw(win)
21
<object>.<method-name>(<param1>, <param2>,…)
>>> circ.draw(win) >>> circ.setFill("green") >>> circ.move(10,10)
22
– Provide the correct number of parameters. – Provide the correct types of parameters. – Provide the correct order of parameters.
http://mcsp.wartburg.edu/zelle/python/graphics/graphics/index.html
23
>>> p.getX() >>> p.getY() >>> circ.undraw()
24
25