Presentation is loading. Please wait.

Presentation is loading. Please wait.

Some Graphics CS303E: Elements of Computers and Programming.

Similar presentations


Presentation on theme: "Some Graphics CS303E: Elements of Computers and Programming."— Presentation transcript:

1 Some Graphics CS303E: Elements of Computers and Programming

2 Announcements Test NEXT Wednesday, May 1st Test NEXT Wednesday, May 1st –Same time (regular class time) –Place: UTC 2.112A Study guide, sample exams up later today Study guide, sample exams up later today

3 Some Graphics Very Brief Introduction Very Brief Introduction Uses Zelle’s graphics module Uses Zelle’s graphics module –Download from his website: –http://mcsp.wartburg.edu/zelle/python/ –Put in same directory as your program

4 Graphics Objects Recall that in object-oriented programming objects consist of: Recall that in object-oriented programming objects consist of: –Data –Actions on that data (methods) To use the graphics packages you: To use the graphics packages you: –Create objects –Perform actions on those objects

5 Example: A Possible Circle Object Data Data –center = (20,20) –radius = 10 –interior_color = “blue” –outline_color = “green” Operations Operations –Draw myself –Move myself –Set interior color –Set outline color

6 Windows Graphics objects are drawn on windows Graphics objects are drawn on windows –Windows are also objects –A single program can create multiple windows Created using the GraphWin() object Created using the GraphWin() object

7 GraphWin() Objects GraphWin(title, width, height) GraphWin(title, width, height) –Constructs a new graphics window –All parameters are optional –Default size is 200x200 setBackground(color) setBackground(color) –Sets window’s background to a color –Options: red, cyan, green, blue, purple, yellow getMouse() getMouse() –Pause for a mouse click in the window, and return the Point at which it was clicked close() close()

8 Example: Creating a Window from graphics import * win = GraphWin() win2 = GraphWin(“Second”,300,300)

9 Point Objects Often used to define the position of other objects Often used to define the position of other objects Can also be drawn on the window Can also be drawn on the window

10 Points Objects: Operations Point(x,y) Point(x,y) –Construct a point with the specified coordinates x and y getX() getX() –Returns the x coordinate of the point getY() getY() –Returns the y coordinate of the point AND all the operations for drawable objects AND all the operations for drawable objects

11 Drawable Objects A category of objects that are drawable A category of objects that are drawable All drawable objects implement all the drawable operations All drawable objects implement all the drawable operations Includes: Point, Line, Circle, Oval, Rectangle, … Includes: Point, Line, Circle, Oval, Rectangle, …

12 Drawable Objects: Operations MethodDescription setFill(color) Sets the interior color of the object to the specified color setOutline(color) Sets the outline of the object to the specified color setWidth(pixels) Sets the width of the object’s outline to the specified number of pixels draw(graphicWindow) Draws the object on the specified graphics window undraw() Undraws the object move(dx,dy) Moves the object dx units in the horizontal direction and dy units in the vertical directions

13 Example: Point Objects pt=Point(15,55) #construct a #point with #x=15, y=55 pt.setOutline(“purple”) pt.draw(win) #draw point on #the window win

14 Question Which is a Boolean value? A. True B. true C. “True” D. “true”

15 Circle Objects A Circle is defined by its center coordinates (given as a Point ) and its radius A Circle is defined by its center coordinates (given as a Point ) and its radius Operations: Operations: –Circle(centerPoint, radius) Constructs a circle with a specified center point and radius Constructs a circle with a specified center point and radius –getRadius() Returns the radius of the circle Returns the radius of the circle

16 Example: Circle Objects cir=Circle(Point(50,100), 25) #center=(50,100), radius=25 #center=(50,100), radius=25 cir.setFill(“yellow”) #set #interior to yellow cir.draw(win) #draw circle on #window win

17 Line Objects Specified by two points Specified by two points Operations: Operations: –Line(point1, point2) Construct a line from point1 to point2 Construct a line from point1 to point2 –setArrow( ) Set arrow status of the line. Set arrow status of the line. Possible values for are: first, last, both, or none. Possible values for are: first, last, both, or none.

18 Example: Line Objects diag = Line(Point(0,0),Point(200,200)) #line from top left to bottom right diag.setWidth(15) #increase thickness diag.setOutline(“blue”) #make it blue diag.draw(win) #draw line on window win

19 Rectangle Objects Draws a rectangle Draws a rectangle Operations Operations –Rectangle(point1, point2) Constructs a Rectangle with opposite corners point1 and point2 Constructs a Rectangle with opposite corners point1 and point2

20 Example: Rectangle Objects rec1 = Rectangle(Point(3,4),Point(8,10)) rec1.setFill(“green”)rec1.draw(win)

21 Exercise

22 Exercise

23 Question I’ll come to class Monday, 4/29, prepared to: A. Take an exam B. Ask questions to review for the exam C. Sleep


Download ppt "Some Graphics CS303E: Elements of Computers and Programming."

Similar presentations


Ads by Google