- This event has passed.
6 PM – Intro To Python – Darin
February 27 @ 6:00 pm - 7:00 pm
Today We Do
- Continued on the RobotBuilder project, where we further connected the shapes together using a bit of math and logic.
- Introduced creating a function for creating the right arm, where we used more x and y parameters for the function as a way to change the location of the arm every time we call the makeRightArm() function
Homework
- Continue on the same file called Feb20_RobotBuilder.py, and submit it into the google drive when you finish
- Create the makeLeftArm() function that takes in 2 parameters, x and y
a) The very first thing you want to do is make the left arm without using a function.
b) After you’ve made it work without a function, you want to turn into a function with these 2 parameters x and y so that we can specify where we want our left arm to be made.
c) In order to make this work, you need to use x and y as the starting coordinates of the first shape being made inside of the function (as seen in with the makeRightHand() function
d) Every other shape that is made inside of the function must use
(x + or – {the difference between the first shape’s value and the current shape})
e) Now that you have a function for the left arm, go ahead and make 2 left arms similar to the 2 right arms.
an example of how to turn any shape into a function:
code below draws a + shape:
makeRectangle(0, 0, “blue”, 10, 40)
makeRectangle(-15, -15, “blue”, 40, 10)
If we want to make it a function, it would look like this:
def makePlus(x, y):
makeRectangle(x, y, “blue”, 10, 40)
makeRectangle(x-15, y-15, “blue”, 40, 10)
See that in the example above, we made every other shape after the first shape inside of the function use x and y added/subtracted with the difference between the first shape coordinate and the next shape coordinate from the original code before it became a function.
Notes:
If you have any questions, email me at ddjapri@ayclogic.com