Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

trying to make a valentine card? dont know how to do the question or what I need is to make a valentine day card. 1.

trying to make a valentine card? dont know how to do image text in transcribed
image text in transcribed
the question or what I need is to make a valentine day card.
1. needs 4 types of graphics
2. greeting of "Happy Valentines!"
3. need one animation object moving, flickering/shivering , or color changinf background.
it needs to have sleep in it. (this is restating what the sheet says)
image text in transcribed
this is the graphics.py function image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
Learning objectives: Develop a Python program that uses the author's graphics package. Assignment: Write a program called greeting.py that displays a greeting card with Valentine theme. Use the author's graphics packages, graphics.py. Since everyone likes to design their own Valentine theme (heart, arrow, candy, etc.), we will leave it up to you what the details of the finished product should look like. To make the program more fun, there should be several elements you must include: 1. At least 4 different types of graphics 2. Greeting message like: "Happy Valentine!" 3. At least one animation as followings: a. Flickering/Shivering b. Object movement C. Color changing (either background of window or object's color) The loop that makes the movement (animation) may go too fast. To slow it down, use the sleep() function from the time library that is a part of Python. You will need to import the library into your code. The line time. sleep (0.1) will make the program pause for one tenth of a second, Make sure to provide users instructions on how to interact with your greeting card. For example, the message "Click anywhere to close" will accept a user's a mouse click and gracefully close the window. Adding sound effect is optional We will have a little in-class competition for the best Valentine greeting card among those who submit this assignment by due date, A Read aloud Computer Science 220 Policies for All Programming Assignments: Programming assignment grades will be based on elegance and usibility as well as correctness of result Collaboration policy for CSC 220 signments 1. You may discuss the problem and how to solve it with others, but you may not look at, copy, or use any code that was written by anyone other than yourself. If instructor TA have evidence that you have shared program code or used code found anywhere, your grade will be zero 3. if you do discuss the problem and how to solve it with others, you must document that in the Certification of Authenticity of the program. 3. Not following these rules is in vilation of the Student Honor CodeYou will be reported to the Honor Board if you are given three warnings. Note that the Honor Board may give a grade of XF (Fail because of an honor violation) that will remain on your permanent record. Assignments are to be submitted by uploading to Im.cofcedi (OAKS) only. Do NOT submit assignments to instructor TA via email Each assignment in due by the date and time that will be stated on themsignment. Assignments will be accepted only via OAKS. Late asignment within 3 days has the penalty of 5 points deduction for each day. No laterassignment after 5 days is allowed unless reasonable excuse is approved by the instructor If you have questions about your grading comments, you may email instruct/TA. You must have a 70% average on the assignments to pass the course Identifiers naming policy 1. All identifies should be meaningful and not too wordy 2. Variable names should use lower case or lower snake case 1. Function and method names should use lower cute or lower_snake_case. 4. Class names should be named using UpperCamelCase. 5. Constant values should be named using ALL UPPER CASE Numeric data should be stored in a variable instead of referenced directly in your code. Exceptions de apply. (example: - PI radius** 2. In this code PI and radius were assigned values 2 did not need a variable) Have no more than 99 characters per linc provided that comments and docstrings are still wrapped at 72 chumacters. Please refer to PEP for other style guide . All programs should include a comment that states the purpose All programs should include information provided to the user explaining the purpose of the code. (For text based programa, this will be a printed message. For graphics based programs, this may be the window name or information provided as a text object in the graphies window) Documentation and formatting within your program The following comments should appear in your program as the first lines in the file Items in angle brackets are either to be removed or replaced with what is specified within the bracket #lan your goes her - tirst and last min p.py BELO. one of two sentence description of the problem that this program solves in your own wondo #Certification of Authenticity include one of the following tity that this is truly my own Tify that this but I und it with D Learning objectives: Develop a Python program that uses the author's graphics package. Assignment: Write a program called greeting.py that displays a greeting card with Valentine theme. Use the author's graphics packages, graphics.py. Since everyone likes to design their own Valentine theme (heart, arrow, candy, etc.), we will leave it up to you what the details of the finished product should look like. To make the program more fun, there should be several elements you must include: 1. At least 4 different types of graphics 2. Greeting message like: "Happy Valentine!" 3. At least one animation as followings: a. Flickering/Shivering b. Object movement c. Color changing (either background of window or object's color) The loop that makes the movement (animation) may go too fast. To slow it down, use the sleep() function from the time library that is a part of Python. You will need to import the library into your code. The line time. sleep(0.1) will make the program pause for one tenth of a second. Make sure to provide users instructions on how to interact with your greeting card. For example, the message "Click anywhere to close" will accept a user's a mouse click and gracefully close the window. Adding sound effect is optional We will have a little in-class competition for the best Valentine greeting card among those who submit this assignment by due date, 1 Overview The package graphics.py w a simple object oriented graphics library designed to malo it very easy for novice programmers to experiment with computer graphics in an object oriented fashion. It was written by Jolin Zelle for use with the book "Python Programming An Introduction to Computer Science (Franklin, Beedle & Associates). The most recent version of the library can obtained at http://map Wartburg edu/relle/python. This document is a reference to the functionality provided In the library See the comments in the file for installation instructions There are two kinds of objects in the library The Graphwan class implements a window where drawing can be done, and various graphics objects are provided that can be drawn into a Graphwin. As a simple example, here is a complete program to draw a circle of radius 10 centered in a 100x100 window from graphics import. def sain: vin - GraphWin("My Circle", 100, 100) - Circle(Point(50,50). 10) c.draw(in) vin.getMouno() # pause for click in window vin.clone) main() Grapain objects support coordinate transformation through the setCoorda nethod and input via monte or laryboard The library provides the following graphical objects Point, Line, Circle, Oval, Roctangle. Polygon, Text, Entry (for text-based input), and Image. Various attributes of graphical objects can be set such as outline.color, fill-color, and line width Graphical objects also support moving and andrawing for animation effects. 2 Graph Win Objects A GraphWin object represents a window on the screen where graphical images may be drawn. A program may define any number of GraphWins. A GraphiWin understands the following methods GraphWin(title, width, height) Constructs a new graphics window for drawing on the screen. The parameters are optional the default title is "Graphics Window," and the default size is 200 x 200 pixels Example: vin - GraphVin("Investnent Growth", 640, 480) plot(x, y, color) Drawn the pixel at (x,y) in the window. Color is optional block in the default Examples win.plot(35. 128, "blue") plotPixel(x, y, color) Drawn the pixel at the "raw"position (x,y) i noring any coordinate transformations set up by setCoordo. V Draw Quarterdeck at lames and LX + x D Graphic Documentation par cofc.edu/CSC1220/06_Reference/Graphics Documentation.pdf ED Page view l A Read aloud Fap vin plotPixel (35, 128, blue) hackground color) Set the window Back to the color The default Background role depends on to Se Section for Information specifying colors Example is setBackground("white") close Close the con witlow Example win.close() getMe) Pause for the worto dicka me in the window and return whether dicked Point object Example clickPoint - vinget. House) chach Mouse Similar to get out, but does not use for a click Return the last point where the mouw clickord of None if the window w must been clicked in the previous call to check mouse or get House. This is particularly fat for controlling to loops (Chapter 8). Ecumple clickPoint - win.checko) Note: chickPoint may be one gtky Paws for the user to type 4 ley on the keyboard and returns a string representing the bory that we pred Example: keyString - win getKey) checkKey() Similar to getkey, but does not paise for them to powalory Returns the last ry that work was pressed since the previous call to check Key or getKey This is particularly well for controlling simple animati looper Chapter 8). Example: keyString win.checkey) Note: keystring may be the empty string net Coorde (x1, y11, rur, yur) Sets the coordinate system of the window. The lower left comer is (ally) so the upper-right corner is (rur, yur). Currently down objects are redrawn and sequent drawing is done with respect to the new coordinate system (except for plotPixel). Ecumple: vin.setCoordo co, 0, 200, 100) 3 Graphics Objects The module provides the following classes of drawable objects Point Line Circle Oval Rectangle, Polygon, and Text. All objects are initially created filled with a black outline. All graphics ob jects support the following generic set of methods setFill(color) Sets the interior of the object to the phen color Example.com bject.etfi11"red") BetOutline(color) Set the time of the object to the given color Escumple Dject.etoutline("yellow) X Graphics Documentation pdf X Quarterdeck at James Island + edu/CSC1220/06_Reference/Graphics Documentation.pdf + ID Page view l A Read aloud Draw 31 Metre netvidta (pixela) Sets the width of the outline of the object to the desired ber of pills (Does not work for Point.) Examples object. Width(3) dra (Graphin) Draw the object into the gm Graphit and return the drawn ohjeet Example sonobject draw someGraphwan) undravo Undre the object from a wraples window. If the object is not currently drawn, do action is taken Examples objectura move(dx,dy) Mures the object dx units in the direction and dy units in the yection. If the object is currently draw, the image is adjusted to the new position Example oneObject.move(10, 15.5) close Returns a duplicate of the object. Cloor are ways in and state Other than that, they are identical to the cloned object Example objectCopy - Object clone) 3.1 Point Methods Point (x,y) Construct a point having the given coordinates Example Point - Point(3.5, 8) Kotx) Return the coordinato al point. Example Value Point.get getro Return the coordinate of a point sample yolue on getTO 3.2 Line Methods Line(pointi, point2) Constructa linement from point to point2 Esamples aline. Lise (Point(1,3), Point (7,4)) setarrow(endstring) Sets the stonbad status of a line. Arrow may be drwm at either the first point, the list point, or both Poble values of diftring are "first", "last", "both and "none". The default setting is one Examples alineatarrow("both) getCenter Returns a clone of the midpoint of the linement Example: midpoint - alin.getCenter() getP10. gtP20 Returns a clone of the cooling endpoint of the Examples atartPoint - wine.getPio C 33 Circle Methods 3.3 Circle Methods Circle(centerPoint, radius) Constructs a circle with the given center point and radius Example: aCircle - Circle(Point(3,4), 10.5) getCenter Returns a clone of the center point of the circle. Example cantar Paint Cirela gat Center get Radius() Returns the radius of the circle Example radius - Circle.getRadius gotP10. getP20 Returns a close of the corresponding corner of the circle's bounding box. These are opposite corner points of a square that circumscribes the circle Example: cornerPoint - aCircle.getP10 3.4 Rectangle Methods Rectangle(pointi, point2) Constructs a rectangle having opposite corners at points and point2. Example: Rectangle - Rectangle(Point(1,3), Point (4,7)) gwl Cuales o Return a chwuf the center point of the rectangles. Example: centerPoint - aRectangle.getCenter) getP10. gotP20 Returns a clone of the corresponding point used to construct the rectangle. Example: cornerPoint - aRectangle getP10 3.5 Oval Methods Oval (pointi, point2) Constructs an oval in the bounding base determined by pointi and point2. Example anbval - Oval (Point(1.2). Point(3,4)) get Center) Returns a clone of the point at the center of the oval. Example: centerPoint - andvalgetCenter() getP10), getP20) Returns a clone of the corresponding point used to construct the oval. Example: corner Point - anval getPIO 3.6 Polygon Methods Polygon (pointi. point2, point3, ...) Constructs a polygon with the given points as vertices Also accept a single parameter that is a list of the vertices. Examples a Polygon - Polygon (Point(1,2), Point(3,4), Point (5,6)) Example: a Polygon - Polygon ((Point(1,2), Point(3,6), Point(5,6)]) getPoints() Returns a list containing clones of the pointed to construct the polygon. Example: pointtiat - Polygon.getPoints 3.7 Text Methods Text (anchor Point, textString) Constructs a text object that displayn textString centered at anchor Point. The text is displayed horizontally Example: monnage - Text (Point(3,4). "Hello!") net Text Catring) Sets the text of the object to string Example mensage.setText("Goodbye!") get Text Returns the current string Example: magString - message.getText() get Anchor() Returns a clone of the anchor point. Example: centerPoint - message.getAnchor() netFace (family) Changes the font face to the given family. Possible values are "helvetica", "courier", "timel roman", and "arial". Example: message. setFace("arial") setSize(point) Changes the font size to the given point size. Sines from 5 to 36 points are legal. Example: nesange.setSize(18) setStyle(style) Changen font to the given style. Posable values are: "normal", "bold". italic" and "bold italic" Example: message.setStyle("bold") setTextColor(color) Sets the color of the text to color. Note: setFill us the same effect. Examples message.setTextColor("pink") 4 Entry Objects Objects of type Entry are displayed as text entry boxes that can be edited by the user of the program. Entry objects support the generic graphics methods move().draw(graphwin), undravo, setF111(color), and clone(). The Entry specific methods are given below. Entry(centerPoint, width) Constructs an Entry having the given center point and width. The width is specified in number of characters of text that can be displayed. Example: inputBox - Entry(Point(3,4), 5) get anchor () Returns a clone of the point where the entry box is centered Example: centerPoint - inputBox.getAnchor) getText Returns the string of text that is currently in the entry box. Example: inputStr - inputBox.getText() BetText(string) Sets the text in the entry box to the given string. Example: inputBox.setText(*32.0") ID Page view A Read aloud 5 Displaying in setFace (family) Change the font face to the given family. Posible values are "belvetica". courier" "times roman", and "arial" Example: InputBox.netFace("courier) petSize(point) Change the fontslae to the given point sie. Sie from 5 to 36 points are legal. Example inputBox.netSize(12) setStyle(style) Changes font to the given style. Possible values are "normal", "bold" italic", and "bold Italic Excumple: inputBox.setStyle("italic") net TextColor(color) Sets the color of the text to color Example: inputBox.setTextColor("green") 5 Displaying Images The graphics module also provides minimal support for displaying and manipulating images in a Graphin. Most platforms will support at least PPM and GIF images Display is done with an Tange object Images support the generic methods move (dx, dy), draw(graphin), undravo), and clone). Image-specific methods are given below Image CanchorPoint, filename) Constructs an image from contents of the given file, centered at the given anchor point. Can also be called with width and height parameters instead of filename. In this case, a blank (traruparent) image is created of the given width and height (in pixels) Example flower Image - Image(Point(100,100), "lover.gif"> Examples blank Image - Image (320, 240) getAnchor () Returns a clone of the point where the image is centered Excample: centerPoint - flower Image.getAnchor() gotWidth() Returns the width of the image. ExauplewidthInPixelu - flower Image.getWidth) gotHeight() Returns the height of the image. Frampler haghti Pivals - Anuar image gat. Haight getPixel(x, y) Returns a list Cred, green, blue) of the RGB values of the pixel at position (x,y). Each value in a number in the range 0 256 indicating the intensity of the corresponding RGB color. These numbers can be turned into a color string using the color rgb function (see next section) Note that piscel position is relative to the image itself, not the window where the image may be drawn. The upper-left corner of the image is always pixel (0,0) Example: red, green, blue - flover Image.getPixel(32,18) 6. Generating Colors setPixel(x, y, color) Sets the pixel at position tr.y) to the given color. Note: This is a slow operation Exampler Flower Image.setPixel(32, 18, "blue") nave(leane) Saves the image to u file. The type of the resulting file (eg. GIF PPS) determined by the extension on the filem Example: flowerinagesave"mypic.ppn) 6 Generating Colors Colors are indiented by strings. Most normal colores such as "red" "purple" "green" Keyan" etc. skllavalle. Many culon Wales, di 2-3 "red", which are increasingly darker shades of red. For a full list, look up X11 color names on the web. The graphics module also provides function for mixing your own colos numerically. The function color_rgb(red, green, blue) will return a string representing a color that is a mature of the interities of red, green and blue specified. These should be ints in the range 0-255. Thus color_rgb(255, 0, 0) is a bright red, while color.rgb(130, 0, 130) is a medium magenta Example: Circle.setFill(color.rgb(130, 0, 130)) 7 Controlling Display Updates (Advanced) Usually, the visual display of a Graphwin is updated whenever any graphics object's visible state is changed in some way. However, under some circumstances, for example when using the graphics library inside some interactive shells, it may be necessary to force the window to update in order for changes to be seen. The update() function is provided to do this update() Causes any pending graphics operations to be carried out and the results displayed For efficiency reasons, it is sometimes desirable to turn off the automatic updating of a window every time one of the objects changes. For example, in an animation, you might want to change the appearance of multiple objects before showing the next "frame of the animation. The Graphin constructor includes a special extra parameter called autoflush that controls this automatic up dating. By default, autoflush is on when a window is created. To turn it off, the autoflush parameter should be set to false, like this: wa - Graphwan("My Animat20n", 400, 400, autorius "False) Now changes to the objects in via will only be shown when the graphics system has some idle time or when the changes are forced by a call to update() The update() method also takes an optional parameter that specifies the maximum rate (per second) at which updates can happen. This is useful for controlling the speed of animations in a hardware-independent fashion. For example, placing the command update(30) at the bottom of a loop ensures that the loop will "spin" at most 30 times per second. The update command will inact an appropriate pause each time through to maintain a relatively constant rate. Of course, the rate throttling will only work when the body of the loop itself executes in less than 1/30th of second Example: 1000 frames at 30 frames per second 1. Controlling Deplay Updates (Advanced) vin - Graph Vin("Update Example", 320, 200, autof lush-Falne) for 1 in range(1000) craving commands for ith frame> update (30) TT

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Systems For Advanced Applications 17th International Conference Dasfaa 2012 Busan South Korea April 2012 Proceedings Part 1 Lncs 7238

Authors: Sang-goo Lee ,Zhiyong Peng ,Xiaofang Zhou ,Yang-Sae Moon ,Rainer Unland ,Jaesoo Yoo

2012 Edition

364229037X, 978-3642290374

More Books

Students also viewed these Databases questions

Question

Evaluate the integral. x cos (x*)/sin(x) dx

Answered: 1 week ago

Question

Explain the various collection policies in receivables management.

Answered: 1 week ago

Question

What are the main objectives of Inventory ?

Answered: 1 week ago

Question

Explain the various inventory management techniques in detail.

Answered: 1 week ago