Difference between revisions of "CSC111 Homework 10 2015"

From dftwiki3
Jump to: navigation, search
(Problem 1 (60 points))
Line 18: Line 18:
 
You have been hired for the summer by a company that makes wrapping paper.  The company has a Web form where customers can pick different colors, a general theme, and a message to print in the middle of the page.  Then a Python program generates an image that is printed by a large format printer.
 
You have been hired for the summer by a company that makes wrapping paper.  The company has a Web form where customers can pick different colors, a general theme, and a message to print in the middle of the page.  Then a Python program generates an image that is printed by a large format printer.
  
The image above shows one particular output, for somebody who has selected ''Cars'' as the theme, ''Blue'' as the background, and "Happy Easter" as the message.
+
The image above shows one particular output, for somebody who has selected ''Cars'' as the theme, ''Blue'' as the background, and "CSC111 HOMEWORK 10" as the message.
 
<br />
 
<br />
 
==Your assignment==
 
==Your assignment==
 
<br />
 
<br />
  
You must demonstrate that you should be hired for the programming job by writing a program that generates a sample output, with a predefined color, a predefined scheme, and a predefined message.  Your program will '''NOT''' ask the user for any information.
+
You must demonstrate that you should be hired for the programming job by writing a program that generates a sample output, with a predefined color, a predefined scheme, and a predefined message.  Your program will '''NOT''' ask the user for any information, but instead will generate the information internally, on its own.
  
 
<br />
 
<br />
Line 36: Line 36:
 
==Requirements==
 
==Requirements==
 
<br />
 
<br />
* Your program should print rows of cars.  The color of the cars should be '''randomly generated'''.
+
* Your program should print the cars using two nested for-loops.  Programs that create the cars using code not repeated by loops will be given only 10 points.
 +
* The cars are not movingThey are generated at a particular location, and do not move.  Your program does not use an ''animation loop.''
 +
* The color of the cars should be '''randomly generated'''.
 
* Your program organizes the cars in rows, one above the other.  The car may or may not align vertically (the image above shows them aligned vertically).
 
* Your program organizes the cars in rows, one above the other.  The car may or may not align vertically (the image above shows them aligned vertically).
* You are free to design the shape of your car.  It must contain at least 2 rectangles and at least two wheels.
+
* You are free to design the shape of your car.  It must contain at least 2 rectangles (or other shapes) and at least two wheels.
* A given  car can have differently colored rectangles, or the same color for all its rectangles.  It is your design decision.
+
* A given  car can have differently colored shapes, or the same color for all its shapes.  It is your design decision.
* Cars are not allowed to extend past the boundaries of the window.
+
* Cars are '''not allowed to extend''' past the boundaries of the window.
 
* The message in the middle should appear inside a rectangle that hides the cars underneath it.  It is ok to have cars partially covered by the box with the message.
 
* The message in the middle should appear inside a rectangle that hides the cars underneath it.  It is ok to have cars partially covered by the box with the message.
 
* The message should be centered in the rectangle.
 
* The message should be centered in the rectangle.
 
* The message should be large enough to be easily readable.
 
* The message should be large enough to be easily readable.
* The actual text of the message should be your name: either your first name, your last name, or both.
+
* The actual text of the message should be '''your name, consisting of your first name, and your last name''', so that the images can be easily assigned to you and accordingly graded.
 
* Your program should have a main() function defined at the end, and one final call to main() at the end of the program.   
 
* Your program should have a main() function defined at the end, and one final call to main() at the end of the program.   
 +
* The image you submit should not show a "click to stop" or "click to start" message.
 
<br />
 
<br />
  
 
==Hints==
 
==Hints==
 
<br />
 
<br />
* To set the color of the background, you can use the '''setBackground()''' canvas method:
+
* The document [http://cs.smith.edu/dftwiki/images/1/17/ZelleGraphicsDescription.pdf Graphic Module Reference], authored by Zelle, provides all the information you need for figuring out:
<br />
+
::* How to set the background of the window
:::<source lang="python">
+
::* How to set the size, or face (family), of the font used to display the message.
win = GraphicsWindow(MAXWIDTH, MAXHEIGHT)
+
* Do not hesitate to give your classes additional methods that can make your life easier in your main program.   
canvas = win.canvas()
+
* The colors available can be found on this [[Tk_Color_Names|page]].
   
 
canvas.setBackground( 0, 250, 250 )
 
</source>
 
<br />
 
* Printing text can be used using two other canvas methods: '''setTextFont()''' and '''drawText()''':
 
<br />
 
:::<source lang="Python">
 
 
 
canvas.setTextFont( 'arial', 40, 'bold' )
 
canvas.drawText( 100, 100,  "CSC111 Homework 11" )
 
 
 
</source>
 
<br />
 
* Do not hesitate to give your classes extra methods that can make your life easier in your main program.  For example, I used a '''setRandomColor()''' method for my Car class.  This way I can generate a black car, then ask it to pick its own random color:
 
<br />
 
:::<source lang="Python">
 
# generate a black car by default
 
c = Car( x, y, w, h, (0, 0, 0) )
 
 
 
# make it pick a random color for itself
 
c.setRandomColor()
 
</source>
 
 
 
<br />
 
* Colors can also be specified by name, as in
 
<br />
 
:::<source lang="Python">
 
canvas.setFill( "yellow" )
 
</source>
 
<br />
 
In case you wanted to limit the colors to a specific set, you may find this [[Color_Charts_for_TKinter | chart of color names]] useful. In this case you could pick a random color this way:
 
<br />
 
:::<source lang="Python">
 
color = choice[ 'snow', 'ghost white', 'white smoke', 'gainsboro', 'floral white', 'old lace',
 
    'linen', 'antique white', 'papaya whip', 'blanched almond', 'bisque', 'peach puff',
 
    'navajo white', 'lemon chiffon' ]
 
canvas.setFill( color )
 
</source>
 
<br />
 
(Remember that '''choice''' must be ''imported'' from random before it can be understood by Python!)
 
 
<br />
 
<br />
  

Revision as of 20:01, 4 April 2015

--D. Thiebaut (talk) 20:19, 4 April 2015 (EDT)





This assignment is due Tuesday night (4/14/15) at 11:55 p.m.


WrappingPaper.png


Problem 1 (60 points)



You have been hired for the summer by a company that makes wrapping paper. The company has a Web form where customers can pick different colors, a general theme, and a message to print in the middle of the page. Then a Python program generates an image that is printed by a large format printer.

The image above shows one particular output, for somebody who has selected Cars as the theme, Blue as the background, and "CSC111 HOMEWORK 10" as the message.

Your assignment


You must demonstrate that you should be hired for the programming job by writing a program that generates a sample output, with a predefined color, a predefined scheme, and a predefined message. Your program will NOT ask the user for any information, but instead will generate the information internally, on its own.


Submission


You must submit 2 files on Moodle:

  • Your program, which should be called hw10_1.py
  • An image of the output generated by your program. It should be called hw10_1.png or hw11_1.jpg


Requirements


  • Your program should print the cars using two nested for-loops. Programs that create the cars using code not repeated by loops will be given only 10 points.
  • The cars are not moving. They are generated at a particular location, and do not move. Your program does not use an animation loop.
  • The color of the cars should be randomly generated.
  • Your program organizes the cars in rows, one above the other. The car may or may not align vertically (the image above shows them aligned vertically).
  • You are free to design the shape of your car. It must contain at least 2 rectangles (or other shapes) and at least two wheels.
  • A given car can have differently colored shapes, or the same color for all its shapes. It is your design decision.
  • Cars are not allowed to extend past the boundaries of the window.
  • The message in the middle should appear inside a rectangle that hides the cars underneath it. It is ok to have cars partially covered by the box with the message.
  • The message should be centered in the rectangle.
  • The message should be large enough to be easily readable.
  • The actual text of the message should be your name, consisting of your first name, and your last name, so that the images can be easily assigned to you and accordingly graded.
  • Your program should have a main() function defined at the end, and one final call to main() at the end of the program.
  • The image you submit should not show a "click to stop" or "click to start" message.


Hints


  • How to set the background of the window
  • How to set the size, or face (family), of the font used to display the message.
  • Do not hesitate to give your classes additional methods that can make your life easier in your main program.
  • The colors available can be found on this page.


Submission


Remember that you must submit 2 files, the program and a screen capture of your window. The submission URL is http://cs.smith.edu/~thiebaut/111b/submit11.php


Optional and Extra-Credits: Problem 2 (20 points)


CSCcarsAndTrucks.png


20 extra points = 10 points for program, 10 points for image
This second problem requires you to use two different types of cars. They should be different enough to be easily distinguished from one another.

The program must generate rows of cars, alternating between the two types of car. The first row should have cars of Type 1, the second row cars of Type 2, and continuing alternating between the two.

The program must use a for-loop to display the rows of cars!

You need to submit two files, a program called hw11b.py and a screen copy of your image, called hw11b.jpg or hw11b.png (all lower-case). Submit both to the same URL as above.