Lab 7 CSE 15L Winter 2009 Scott B. Baden UCSD 3/1/09 Scott B. Baden /CSE 15L / Winter '09 2 Announcements • No Lab next time • We will have our usual weekly quiz • Final Exam Review 3/1/09 Scott B. Baden /CSE 15L / Winter '09 3 Filled, named polygons • This time we will draw polygons using more powerful constructs – java Lab7 shapes.in • Copies of named polygons may be drawn at arbitrary places – Define polygons with P – Add the polygon to the canvas with A • M, R, L, U, D as before P tri 50 50 0 0 50 0 50 25 P sq 50 50 10 10 10 40 40 40 40 10 M 10 10 A tri R 50 C red A sq 3/1/09 Scott B. Baden /CSE 15L / Spring '08 4 Jz.in M 14 5 A jd C red M 14 0 A jd C green M 14 0 A jd C blue M 14 0 A jd M -42 21 A jd C red M 14 21 A jd C green M 14 21 A jd C blue M 14 21 P jd 14 20 6 10 0 10 0 12 6 12 6 14 4 16 4 18 6 20 8 20 10 18 10 16 8 14 8 12 10 12 10 14 12 14 12 10 8 10 8 8 10 0 8 0 7 4 6 0 4 0 6 8 3/1/09 Scott B. Baden /CSE 15L / Winter '09 5 Other files • Inputs together with screenshots of the image in the Lab7 directory – tri.in – JDs.in • Error input: odd number of points in a polygon: oddError.in Odd number of coordinate points 3/1/09 Scott B. Baden /CSE 15L / Winter '09 6 Miscellany • You will need the GraphicsUtil Library – Co-located with the lab source – Compile GraphicsUtil.java – http://www.apl.jhu.edu/~hall/java/GraphicsUtil.html • Global origin (0,0) is at the upper left corner – Pen’s initial position is at the center – Program scales coordinates so output is easier to view – Reports out of bound coordinates • As before – Each polygon has a defined bounding box – Coordinates within the bounding box are relative to the lower left corner P tri 50 50 0 0 50 0 50 25 M 10 10 A tri (0,0) (10,10) 50 50 3/1/09 Scott B. Baden /CSE 15L / Winter '09 7 Sidebar on Hash Tables • A hash table is a data structure that maps keys onto records • In our case the keys are polygon names, the records are the polygon descriptions • An array is a special case http://en.wikipedia.org/wiki/Hash_table 3/1/09 Scott B. Baden /CSE 15L / Winter '09 8 Başla !