For this lab, you are going to write code to make your Scribbler robot be able to go to certain locations on the whiteboard, using some classes.
Open Eclipse and make sure you are in the workspace S:\workspace
. Make a lab11
folder. Then ***copy*** the move.py
file over from your lab7
folder into your lab11
folder. (move.py
should be unchanged from lab7
.)
Make a new file called scribpoint.py
. Put this new class definition into it:
class ScribPoint: def __init__(self): self.x = 0 self.y = 0
This class will represent an (x, y) coordinate on a whiteboard on the floor where the Scribbler is, or will go to. Initially, the point being represented is (0, 0).
Now, add the getter and setter methods for x
and y
. Call them, getX()
, getY()
, setX()
, and setY()
.
Open the move.py
file. At this point, I recommend that you only have one move.py
file open in Eclipse. If you have two of them open (one from lab11
) you might edit the wrong one.
Now, in move.py
, at the top by the other imports, put this:
from scribpoint import *
In move.py
, we are going to add a new function, goToPoint()
, to make a Scribbler robot go to a point on the x,y coordinate plane.
move.py
, after the last function, create a new function definition called goToPoint():
Name | goToPoint |
Makes a Scribbler robot move from where it is (located in start ), to a new point end. |
---|---|---|
Parameters |
|
|
Return Value | None |
atan2()
function from the math package. Look up atan2()
in the math
package on Google now. Notice the order of the arguments!math
's degrees()
function to convert radians to degrees, because our current API uses degrees. (To use math
you'll have to import it... hint, hint...)goToPoint()
function should leave the scribbler facing in the correct orientation -- i.e., "looking" at the positive X axis. That way if you call goToPoint()
multiple times in a row, you can always assume it is oriented correctly.goToPoint(start, end)
. Your code should:
deltaX
and deltaY
, based on start
's and end
's x
and y
values. (Recall, start
and end
are ScribPoint
objects.) Hint: You get the x value from start
by calling start.getX()
.atan2(deltaY, deltaX)
and then convert the results to degrees, and store in a variable angle
.(deltaX, deltaY)
relative to where the Scribbler is now).turnDegrees()
and travelForw()
.Now, create a file lab11.py
. At the top of that, add the magic code to import __future__ stuff. Then, add the line to import move
, like we've been doing.
Add code to lab11.py
to:
ScribPoint
object (which by default initializes it to location (0, 0)).ScribPoint
object. After creation, set its x
and y
attributes to 16 and 12, respectively. Thus, the object will represent point (16, 12) on the whiteboard.goToPoint()
to make the Scribbler move to location (16, 12) -- i.e. the location represented by this second ScriptPoint
object. Remember, that you have to pass in two ScribPoint
objects to the function: the first is where the Scribbler is (i.e., (0, 0)), and the 2nd is where you want the Scribbler to go to.goToPoint()
to make the Scribbler move back to (0, 0).Put a marker in your Scribbler and run your code. See if your line segment is close to the 20 cm. It should be.
Create more ScribPoint()
objects and to test your goToPoint()
to make sure it really works.
***Replace*** the code you have in lab11.py
with code to draw a 5-pt star with these points
Remember that where ever you put the Scribbler down is point (0, 0), and whichever direction you have it facing is the +x axis. Also, you don't really want to draw a line from (0, 0) to (5, 20). So, you'll have to make some adjustments to get this to work.
Clean up any code in lab11.py
that isn't relevant anymore (old print statements, etc.) Make sure your code is well-documented, indented, hospitable, etc. Make sure you have the correct information in it about you, the author.
To submit your final version of lab11.py
and move.py
, you’ll need to use Windows Explorer.
lab11.py, scribpoint.py,
and move.py
files down in your lab11
folder.lab11.py, scribpoint.py,
and move.py
.T:\CS104\current\<yourid>\
.lab11
. (Do NOT call it Lab11
or lab 11
or Lab 11
or VivaLaFrance
. Call it lab11
.)lab11
? If not, do something silly, and then rename the folder lab11
.lab11.py
, scribpoint.py
and move.py
) into that folder.Grading Rubric: 15 points total
10 points: program that runs correctly. There are many parts to handle in this program, so make sure all work correctly.
1 points: correct comments at the top of the file.
4 points: code is clean and neat and uses good comments and variable names. I.e., the code is hospitable.