From 6745e7cc80df1b77e25020faf9470eb97dc9526b Mon Sep 17 00:00:00 2001 From: Kevin Chou Date: Wed, 7 Mar 2018 10:40:44 -0500 Subject: [PATCH 1/5] / --- src/m2_functions.py | 39 +++++++++++++++++++++++++++++++-------- 1 file changed, 31 insertions(+), 8 deletions(-) diff --git a/src/m2_functions.py b/src/m2_functions.py index 9e19204..dc51c70 100644 --- a/src/m2_functions.py +++ b/src/m2_functions.py @@ -3,12 +3,12 @@ FUNCTIONS Authors: David Mutchler, Dave Fisher, Valerie Galluzzi, Amanda Stouder, - their colleagues and PUT_YOUR_NAME_HERE. -""" # TODO: 1. PUT YOUR NAME IN THE ABOVE LINE. + their colleagues and Kevin Chou. +""" # DONE: 1. PUT YOUR NAME IN THE ABOVE LINE. ############################################################################### # -# TODO: 2. +# DONE: 2. # Allow this module to use the rosegraphics.py module by marking the # src # folder in this project as a "Sources Root", as follows: @@ -32,6 +32,8 @@ def main(): window = rg.TurtleWindow() turtle1() + turtle4() + turtle5() turtle3() turtle2() turtle2() @@ -104,9 +106,30 @@ def turtle3(): maja.end_fill() +def turtle4(): + bob = rg.SimpleTurtle('turtle') + bob.pen = rg.Pen('antique white', 10) + bob.forward(10) + bob.right(40) + bob.backward(100) + + +def turtle5(): + joe = rg.SimpleTurtle('triangle') + joe.pen = rg.Pen('yellow', 20) + joe.forward(50) + joe.left(60) + joe.backward(100) + + steven = rg.SimpleTurtle('circle') + steven.pen = rg.Pen('blue', 30) + steven.backward(100) + steven.left(200) + steven.forward(30) + ############################################################################### # -# TODO: 3. +# DONE: 3. # READ the code above. Be sure you understand: # -- How many functions are defined above? # (Answer: 4) @@ -138,7 +161,7 @@ def turtle3(): ############################################################################### # -# TODO: 4. +# DONE: 4. # Define another function, # immediately below the end of the definition of turtle3 above. # Name your new function turtle4. @@ -168,7 +191,7 @@ def turtle3(): ############################################################################### # -# TODO: 5. +# DONE: 5. # Add a line to main that CALLS your new function immediately # AFTER main calls turtle1. So: # -- the SimpleTurtle from turtle1 should move, @@ -184,7 +207,7 @@ def turtle3(): ############################################################################### # -# TODO: 6. +# DONE: 6. # The previous two TODOs IMPLEMENTED a function (TO-DO 4) # and TESTED that function (TO-DO 5). # @@ -211,7 +234,7 @@ def turtle3(): ############################################################################### # -# TODO: 7. +# DONE: 7. # COMMIT-and-PUSH your work (after changing this TO-DO to DONE). # # As a reminder, here is how you should do so: From e7b85d9b229f941668fe65f82bfa5346a4938d87 Mon Sep 17 00:00:00 2001 From: Kevin Chou Date: Wed, 7 Mar 2018 10:58:52 -0500 Subject: [PATCH 2/5] / --- src/m3_practice_fixing_errors.py | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/src/m3_practice_fixing_errors.py b/src/m3_practice_fixing_errors.py index 8bb7c6c..91f308b 100644 --- a/src/m3_practice_fixing_errors.py +++ b/src/m3_practice_fixing_errors.py @@ -2,8 +2,8 @@ This module lets you practice correcting SYNTAX (notation) errors. Authors: David Mutchler, Dave Fisher, Valerie Galluzzi, Amanda Stouder, - their colleagues and PUT_YOUR_NAME_HERE. -""" # TODO: 1. PUT YOUR NAME IN THE ABOVE LINE. + their colleagues and Kevin Chou. +""" # DONE: 1. PUT YOUR NAME IN THE ABOVE LINE. ############################################################################### # @@ -32,21 +32,22 @@ ############################################################################### import rosegraphics as rg +import math def main(): """ Calls the other functions in this module to demo them. """ print_math() - tutle_fn() + turtle_fun() -def print_math: +def print_math(): """ Prints some calculated values. """ - x = cos(pi) + x = math.cos(math.pi) print(x) - y = sin(pi) - print(The sine of PI is, y) + y = math.sin(math.pi) + print('The sine of PI' is y) def turtle_fun(): @@ -58,19 +59,21 @@ def turtle_fun(): window = rg.TurtleWindow() alan = rg.SimpleTurtle() -alan.pen = rg.Pen('blue', 30) + alan.pen = rg.Pen('blue', 30) alan.paint_bucket = rg.PaintBucket('yellow') - alan.back(3 * (47 + 16) - al.begin_fill() - alan.circle(25) + alan.backward(3 * (47 + 16)) + alan.begin_fill() + alan.draw_circle(25) alan.end_fill() - forward(200) + alan.forward(200) window.close_on_mouse_click() # ----------------------------------------------------------------------------- # Calls main to start the ball rolling. # ----------------------------------------------------------------------------- + + main() From 77692274c0f989bb7ae234999dbeafcd1a7b4ac3 Mon Sep 17 00:00:00 2001 From: Kevin Chou Date: Wed, 7 Mar 2018 11:21:44 -0500 Subject: [PATCH 3/5] / --- src/m4_functions_vs_methods.py | 37 ++++++++++++++++++++++++++++------ 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/src/m4_functions_vs_methods.py b/src/m4_functions_vs_methods.py index 1411f19..f779a25 100644 --- a/src/m4_functions_vs_methods.py +++ b/src/m4_functions_vs_methods.py @@ -4,12 +4,12 @@ -- how they differ. Authors: David Mutchler, Dave Fisher, Valerie Galluzzi, Amanda Stouder, - their colleagues and PUT_YOUR_NAME_HERE. -""" # TODO: 1. PUT YOUR NAME IN THE ABOVE LINE. + their colleagues and Kevin Chou. +""" # DONE: 1. PUT YOUR NAME IN THE ABOVE LINE. ############################################################################### # -# TODO: 2. +# DONE: 2. # READ this comment, ASKING QUESTIONS as needed to understand it. # # Part 1: CONSTRUCTING objects, applying ** METHODS ** to them: @@ -82,7 +82,9 @@ def main(): draw_many_squares(turtle, 3, 75, 15) turtle3() - + try_methods() + try_functions() + try_methods_and_functions() ########################################################################### # When the TODOs ask you to test YOUR code, put YOUR tests below this: ########################################################################### @@ -181,9 +183,15 @@ def try_methods(): -- backward 100 units """ ########################################################################### - # TODO: 3. Implement and test this function, per its doc-string above. + # DONE: 3. Implement and test this function, per its doc-string above. # (To test it, put a statement in main that calls this function.) ########################################################################### + bob = rg.SimpleTurtle('turtle') + bob.pen = rg.Pen('brown', 5) + bob.forward(150) + bob.left(90) + bob.forward(50) + bob.backward(100) def try_functions(): @@ -195,7 +203,7 @@ def try_functions(): -- One jumps to (-50, 50), then moves (while drawing) to (100, 100) """ ########################################################################### - # TODO: 4. Implement and test this function, per its doc-string above. + # DONE: 4. Implement and test this function, per its doc-string above. # (To test it, put a statement in main that calls this function.) # # NOTE: This function requires @@ -204,6 +212,9 @@ def try_functions(): # HINT: see jump_and_move_turtle above. # ########################################################################### + jump_and_move_turtle(200, 100, 300, 30) + jump_and_move_turtle(100, 200, 0, 0) + jump_and_move_turtle(-50, 50, 100, 100) def try_methods_and_functions(): @@ -248,6 +259,20 @@ def try_methods_and_functions(): # function defined above. If you don't see why, ** ASK FOR HELP. ** # ########################################################################### + steven2 = rg.SimpleTurtle('turtle') + steven2.pen = rg.Pen('blue', 5) + steven2.speed = 1 + draw_many_squares(steven2, 2, 100, 30) + steven2.speed = 5 + steven2.pen.color = 'red' + draw_many_squares(steven2, 10, 50, 15) + steven2.speed = 100 + steven2.pen.thickness = 35 + draw_many_squares(steven2, 8, 300, 60) + steven2.pen = rg.Pen('black', 3) + steven2.backward(200) + steven2.draw_circle(30) + steven2.draw_square(50) # ----------------------------------------------------------------------------- From 5fbd3076e8342483aafe3a760e32e6e25012a6b9 Mon Sep 17 00:00:00 2001 From: Kevin Chou Date: Wed, 7 Mar 2018 11:39:22 -0500 Subject: [PATCH 4/5] / --- src/m5r_using_rosegraphics_objects.py | 33 +++++++++++++++------------ 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/src/m5r_using_rosegraphics_objects.py b/src/m5r_using_rosegraphics_objects.py index 0989f04..1e1d436 100644 --- a/src/m5r_using_rosegraphics_objects.py +++ b/src/m5r_using_rosegraphics_objects.py @@ -5,61 +5,61 @@ -- accessing their DATA via INSTANCE VARIABLES. Authors: David Mutchler, Dave Fisher, Valerie Galluzzi, Amanda Stouder, - their colleagues and PUT_YOUR_NAME_HERE. -""" # TODO: 1. PUT YOUR NAME IN THE ABOVE LINE. + their colleagues and Kevin Chou. +""" # DONE: 1. PUT YOUR NAME IN THE ABOVE LINE. ######################################################################## # -# TODO: 2. +# DONE: 2. # RUN this program. Then answer the following, # GETTING HELP AS NEED! (Ask questions!!!) # # a. For the RoseGraphics coordinate system: # # -- Where is the (0, 0) point on the screen? -# WRITE_YOUR_ANSWER_HERE,_REPLACING_THIS +# Top left corner # # -- In what direction on the screen does the positive X-axis point? -# WRITE_YOUR_ANSWER_HERE,_REPLACING_THIS +# Right # # -- In what direction on the screen does the positive Y-axis point? -# WRITE_YOUR_ANSWER_HERE,_REPLACING_THIS +# Down # # b. Write a line of code that constructs a basic RoseWindow object: -# WRITE_YOUR_ANSWER_HERE,_REPLACING_THIS +# test_window = rg.RoseWindow(100, 80, 'basic window') # # c. What is the default height of a RoseWindow? # Type into main the code shown in your answer above. That will # ask PyCharm will help you figure out the answer to this question. # Hint: After you type the ( in the line of code, # if you wait a moment PyCharm will add the ) and has a popup. -# WRITE_YOUR_ANSWER_HERE,_REPLACING_THIS +# 400x300 # # d. Write a line of code that constructs a RoseWindow object whose # height is 100 with any width you choose. # Again try to use PyCharm's hints to help you figure this out. -# WRITE_YOUR_ANSWER_HERE,_REPLACING_THIS +# test_window2 = rg.RoseWindow(100, 30, 'test2') # # e. Use the DOT trick to answer the following: # # -- Write the names of two types of graphics objects # that you can construct OTHER than Circle and Point: -# WRITE_YOUR_ANSWER_HERE,_REPLACING_THIS +# Arc, Ellipse # # -- Write the names of three METHODs that Circle objects have: # Hint: Use the circle from the example3 function below with # the dot trick to let PyCharm help you. -# WRITE_YOUR_ANSWER_HERE,_REPLACING_THIS +# clone, move by self, move to center # # -- Write the names of three INSTANCE VARIABLEs # that Circle objects have: -# WRITE_YOUR_ANSWER_HERE,_REPLACING_THIS +# center, radius, self # # f. What does a RoseWindow RENDER method do? -# WRITE_YOUR_ANSWER_HERE,_REPLACING_THIS +# render draws your objects onto the window # # g. When is a RoseWindow close_on_mouse_click method call necessary? Why? -# WRITE_YOUR_ANSWER_HERE,_REPLACING_THIS +# so that after the window is draw, the user can close the window by clicking it # # ASK QUESTIONS ** NOW ** if you do not understand how the # RoseGraphics graphics system works. @@ -83,6 +83,7 @@ def main(): example1() example2() example3() + #test_window = rg.RoseWindow() def example1(): @@ -98,12 +99,14 @@ def example2(): # ------------------------------------------------------------------------- window = rg.RoseWindow() + # ------------------------------------------------------------------------- # Construct some rg.Point objects. # Note: the y-axis goes DOWN from the TOP. # ------------------------------------------------------------------------- point1 = rg.Point(100, 150) point2 = rg.Point(200, 50) + #point3 = rg.Point(20,20) # ------------------------------------------------------------------------- # A RoseGraphics object is not associated with a window, @@ -111,6 +114,7 @@ def example2(): # ------------------------------------------------------------------------- point1.attach_to(window) point2.attach_to(window) + #point3.attach_to(window) # ------------------------------------------------------------------------- # And they still are not DRAWN until you RENDER the window. @@ -141,6 +145,7 @@ def example3(): circle.fill_color = 'green' circle.attach_to(window) + # ------------------------------------------------------------------------- # Rectangle: needs two opposite corners. # ------------------------------------------------------------------------- From e5e2b307835821b2ff278dfaa03b52ebda706476 Mon Sep 17 00:00:00 2001 From: Kevin Chou Date: Thu, 8 Mar 2018 02:00:18 -0500 Subject: [PATCH 5/5] / --- src/m6_using_objects.py | 68 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 63 insertions(+), 5 deletions(-) diff --git a/src/m6_using_objects.py b/src/m6_using_objects.py index 6ca2c34..d91c4dd 100644 --- a/src/m6_using_objects.py +++ b/src/m6_using_objects.py @@ -5,8 +5,8 @@ -- accessing their DATA via INSTANCE VARIABLES Authors: David Mutchler, Dave Fisher, Valerie Galluzzi, Amanda Stouder, - their colleagues and PUT_YOUR_NAME_HERE. -""" # TODO: 1. PUT YOUR NAME IN THE ABOVE LINE. + their colleagues and Kevin Chou. +""" # DONE: 1. PUT YOUR NAME IN THE ABOVE LINE. import rosegraphics as rg @@ -14,6 +14,9 @@ def main(): """ Calls the other functions to demonstrate and/or test them. """ # Test your functions by putting calls to them here: + two_circles() + circle_and_rectangle() + lines() def two_circles(): @@ -27,12 +30,23 @@ def two_circles(): -- Waits for the user to press the mouse, then closes the window. """ # ------------------------------------------------------------------------- - # TODO: 2. Implement this function, per its doc-string above. + # DONE: 2. Implement this function, per its doc-string above. # -- ANY two rg.Circle objects that meet the criteria are fine. # -- File COLORS.txt lists all legal color-names. # Put a statement in main to test this function # (by calling this function). # ------------------------------------------------------------------------- + window = rg.RoseWindow(400, 300) + center1 = rg.Point(200, 150) + center2 = rg.Point(100, 200) + circle1 = rg.Circle(center1, 20) + circle2 = rg.Circle(center2, 45) + circle2.fill_color = 'blue' + circle1.attach_to(window) + circle2.attach_to(window) + + window.render() + window.close_on_mouse_click() def circle_and_rectangle(): @@ -66,8 +80,33 @@ def circle_and_rectangle(): 75.0 150.0 """ + window2 = rg.RoseWindow(800, 600) + center = rg.Point(150, 150) + circle2 = rg.Circle(center, 50) + circle2.fill_color = 'blue' + corner1 = rg.Point(300, 400) + corner2 = rg.Point(400, 500) + rectangle = rg.Rectangle(corner1, corner2) + rectangle.attach_to(window2) + circle2.attach_to(window2) + + window2.render() + print(circle2.outline_thickness) + print(circle2.fill_color) + print(circle2.center) + print(center.x) + print(center.y) + print(rectangle.outline_thickness) + print(rectangle.fill_color) + print(rectangle.get_center()) + rectangle_x = rectangle.get_center().x + print(rectangle_x) + rectangle_y = rectangle.get_center().y + print(rectangle_y) + + window2.close_on_mouse_click() # ------------------------------------------------------------------------- - # TODO: 3. Implement this function, per its doc-string above. + # DONE: 3. Implement this function, per its doc-string above. # -- ANY objects that meet the criteria are fine. # Put a statement in main to test this function # (by calling this function). @@ -78,6 +117,25 @@ def circle_and_rectangle(): def lines(): + window3 = rg.RoseWindow(800, 800) + start = rg.Point(200, 200) + end = rg.Point(400, 400) + line1 = rg.Line(start, end) + start2 = rg.Point(500, 300) + end2 = rg.Point(700, 500) + line2 = rg.Line(start2, end2) + line2.thickness = 10 + line1.attach_to(window3) + line2.attach_to(window3) + window3.render() + midpoint = line2.get_midpoint() + midx = line2.get_midpoint().x + midy = line2.get_midpoint().y + print(midpoint) + print(midx) + print(midy) + window3.close_on_mouse_click() + """ -- Constructs a rg.RoseWindow. -- Constructs and draws on the window two rg.Lines such that: @@ -100,7 +158,7 @@ def lines(): -- Waits for the user to press the mouse, then closes the window. """ # ------------------------------------------------------------------------- - # TODO: 4. Implement and test this function. + # DONE: 4. Implement and test this function. # -------------------------------------------------------------------------