DOC PREVIEW
UW CSE 341 - Homework Assignment

This preview shows page 1 out of 3 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 3 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 3 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

CSE 341, Winter 2008, Assignment 7Due: 14 March, 8:00AMLast updated: March 5, 2008Overview: We provide a skeleton ∼270 lines of code for drawing Faceb ook-style “friend wheels.” You willneed to read, understand and extend this code (∼130 more lines) to complete its functionality. Some notes:• A contact list is represented as an array of Contacts.• Friendship is not symmetric—if Contact a is friends with b, that doesn’t imply b is friends with a.• Drawing friend wheels requires generating social networks, done by subclasses of ContactsGenerator,laying out each person on screen, done by subclasses of ContactLayoutManager, and coloring eachperson, done by subclasses of ContactColorManager. You will need to complete the skeletons we’veprovided, and implement additional subclasses of each of these three classes.• We’ve provided two debugging routines to aid printing the social networks you create:– debugPrintContactNames takes a contact list and prints the name of each person followed by thenames of their friends. If a person has secret admirers, those names are printed in parentheses.– namesOnly takes an array of (Contacts or arrays of (Contacts or arrays of . . . )), and produces anew array of just the names of the contacts, with the same nesting structure as the original array.• The RGB class provides three mechanisms to create colors: from_str takes a named color; from_rgbtakes a (red, green, blue) triple (each component is b etween 0 and 1); and from_hue takes a hue (from0 to 1) and returns a color from purple to red.• The skeleton code we provide you supports five key-bindings:– Press ‘l’ to change the layout manager of the current contacts, without changing colors.– Press ‘c’ to change the color manager of the current contacts, without changing layouts.– Press ‘n’ to change to another contact list, using the same color and layout managers.– Press ‘p’ to take a screenshot of your program. It will create a PostScript file of the namehlayoutmanageri hcolormanager i hgenerator i.ps in your current directory.– Press ‘q’ to quit.1. Naming contacts: Currently, all contacts display their names as “hnamei”. Redefine one method tochange how all contacts display their names, to “hnamei (hnumber of friendsi)”. Sample solution is 5lines (counting all boilerplate: def/end, class lines, etc.). Do not modify the top half of the file!2. Coloring contacts: Contacts are colored by subclasses of ContactColorManager, which are responsiblefor setting the color field of contacts. We’ve provided two example color managers: one assigns colorsrandomly; the other assigns colors by contact type.(a) Complete the color method of ContactColorByDegree to assign a color to every contact by theirout-degree (the number of people they have as contacts). Colors should span the rainbow withcooler colors (purple and blue) for lower degrees and warmer colors (red and orange) for higherdegrees. Specifically, if your social network has a maximum degree of n and a minimum degreeof m, and some person has degree d, then you should generate a color of hue (d − m)/(n − m).See Fig. 1 for how the colors look for ContactsGenCircle and ContactColorByDegree, laid outby ContactLayoutInCircle (when complete). Sample solution is 8 lines counting all boilerplate.(b) Create a ContactColorByDegreeSym class that assigns colors as above, except it treats friendshipas symmetric when computing degrees. See Fig. 2 for how the same contact list appears with thiscolor manager and ContactLayoutInCircle. Sample solution is 9 lines counting all boilerplate.13. Creating contact lists: We’ve provided a single contact list generator, ContactsGenCircle, whichgenerates n people where person i is friends with person n and all people 0 through i − 1. Create threemore contact lists by subclassing ContactsGenerator, looking like:(a) A “fan”: this creates n people, where person 0 is friends with everyone, and person i is friendswith i − 1, i + 1 and 0. See Fig. 3. Sample solution is 20 lines counting boilerplate.(b) A “double-circle”: this creates 2n people, which split into two circles of friends (as in the example),but neither circle is friends with the other. See Fig. 4. Sample solution is 11 lines with boilerplate.(c) A “tree”: this creates 2npeople, where person i is friends with person i/2 (his “parent”) and 2iand 2i + 1 (his “children”). See Fig. 5. Sample solution is 11 lines counting boilerplate.NOTE: until you complete problem 5 (laying out contacts), your displayed result will not look likethe diagrams. Until then, you should test your routines with either the debugging routines or withvery small group sizes, so as to make sense of the random layout. . .4. New contact types: Define a SecretAdmirer class that does not draw lines connecting it to anyoneelse, but that does affect the number of friends of all of its contacts: if a secret admirer s likes a personp, and p isn’t a friend of s, then p’s friend count is increased but no line is drawn. If p is a friend of salso, then a line is drawn and the friend count isn’t affected. Note that p could be a SecretAdmirer,too. To do this, create a new subclass of Contact, then figure out which other classes may need tobe modified or extended. (Hints: how can contacts keep count of their secret admirers? Look indebugPrintContactNames for some ideas. Also, you may want to define a new contact list generatorthat creates multiple types of people, including secret admirers, so you can test your approach.) Samplesolution is 30 lines counting all boilerplate.5. Laying out contacts: Layout managers are responsible for setting the x, y, tx and ty fields to lay outthe contact and its name. We’ve provided one layout manager that lays out contacts randomly.(a) Complete ContactLayoutInCircle to lay out contacts as seen in Figre 1. Using the providedpolarToRect method will make points on the unit circle fill the available canvas space, where θstarts at the right and turns clockwise. Sample solution is 6 lines counting all boilerplate.(b) Complete ContactLayoutInTree to lay out contacts as seen in Fig.5. Make sure your solutionfills the available space (see polarToRect for how to get the canvas’ size). Sample solution is 15lines counting all boilerplate.(c) Challenge Problem: Implement ContactLayoutInTreeCentered, another layout manager thatis similar to ContactLayuoutInTree, but where each level of the


View Full Document

UW CSE 341 - Homework Assignment

Documents in this Course
Macros

Macros

6 pages

Macros

Macros

6 pages

Macros

Macros

3 pages

Mutation

Mutation

10 pages

Macros

Macros

17 pages

Racket

Racket

25 pages

Scheme

Scheme

9 pages

Macros

Macros

6 pages

Load more
Download Homework Assignment
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Homework Assignment and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Homework Assignment 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?