At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.
How far did you get? Can you post what you have done so we can take a look?
I have no idea how to execute def animate(). Variants of the execution command contained in the below code don't seem to work. from graphics import * class Wheel(): def __init__(self, center, wheel_radius, tire_radius): self.tire_circle = Circle(center, tire_radius) self.wheel_circle = Circle(center, wheel_radius) def draw(self, win): self.tire_circle.draw(win) self.wheel_circle.draw(win) def move(self, dx, dy): self.tire_circle.move(dx, dy) self.wheel_circle.move(dx, dy) def set_color(self, wheel_color, tire_color): self.tire_circle.setFill(tire_color) self.wheel_circle.setFill(wheel_color) def undraw(self): self.tire_circle .undraw() self.wheel_circle .undraw() def get_size(self): return self.tire_circle.getRadius() def get_center(self): return self.tire_circle.getCenter() # Define a main function; if you want to display graphics, run main() # after you load code into your interpreter def main(): # create a window with width = 700 and height = 500 new_win = GraphWin('Wheel', 700, 500) # What we'll need for the wheel... wheel_center = Point(200, 200) # The wheel center is a Point at (200, 200) tire_radius = 100 # The radius of the outer tire is 100 # Make a wheel object new_wheel = Wheel(wheel_center, 0.6*tire_radius, tire_radius) # Set its color new_wheel.set_color('red', 'black') # And finally, draw it new_wheel.draw(new_win) def animate(self, win, dx, dy, n): if n > 0: self.move(dx, dy) win.after(100, self.animate, win, dx, dy, n-1) # Run the window loop (must be the *last* line in your code) new_win.mainloop() # Comment this call to main() when you import this code into # your car.py file - otherwise the Wheel will pop up when you # try to run your car code. main() animate(win, 1,0,5)
Addition to the above: From Codecademy practice to Ch.16 in "How to Think Like Computer Scientist" to now something like this in the MIT homework strikes me as a big leap. Week 1 to 6 of Intro to Gentle Python/MOOC more or less made sense with the materials we were given by MOOC. Now, many of the concepts concerning the above code are not explained in any of the Week 7 MOOC study materials. For beginners like me, I don't know how the heck we're expected to proceed. Everything up to Classes in this course can be supplemented by Googling for Python help. But I can find very little above importing graphics modules to get them to work with Classes, so I'm at a loss. Let's just call it the MOOC version of Skyfall.
Should def animate not be part of your class Wheel? What error messages are you getting? I think with a rough glance over the code that it will probably relate to self.move not existing or some such. Week 6 had us reading 3 chapters on classes. This should be building on that. But yes there were times when I felt that things had changed fairly quickly too. I thought that I had lost focus a bit.
OK, here is my car with wheels that move it across the window. should be in same directory as graphics.py and wheel.py. Make sure that you follow the directions in wheel.py and comment out the last line ( the call to main() )
@Screech: I think you're one homework lesson ahead of me. I will look at your attachment later. I'm first trying to get the wheel to move in wheel.py. The car/wheel movement is, I believe, the next homework assignment, which I haven't yet examined. @Andrew Higgs: "Should def animate not be part of your class Wheel?" What you say sounds about right, now that I think about it and study other Python issues on the Web. Unfortunately, the MIT instructions (in 6.189 Homework 4) are unclear They state both "#add any functions or classes you might define here" and "# add your code below this point". I was concentrating more on the latter (since that's the homework instruction), and now realize that def animate() probably has to be included with the other defs, while the code to run def animate() has to go below new_win = GraphWin.
Odd!!?? I just noticed that the Screech and Andrew Higgs messages, and my reply, are appearing in the Computer Science OpenStudy section. Why are these messages not being channeled to the Gentle Intro to Python OpenStudy section, which is where I placed my post and Andrew Higgs replied about 12 hours ago?
@Screech and Andrew Higgs: OK, I managed to animate (i.e. move) the wheel in wheel.py. Success! But what new interesting, important thing have I/we learned about Python Classes? I guess we learned where to place inside a Class a) functions that define animated objects and b) some about where to place code to execute the animation, based fundamentally on the GraphWin template. Important, I guess, but is that it?
About half the time, the Open Study comes up with some course OTHER THAN MIT 6,189. I don't know why.
@JohnM: here's what I did to do the animate, and I don't know any coding but what I've learned here: ## 6.189 HW 4, ex. 4.1 section 3: animate Wheel def animate(self, win, dx, dy, n): if n > 0: self.move(dx,dy) win.after(100, self.animate, win, dx, dy, n-1)
They told us at the beginning that it's an experiment! Also there are random obstacles added in order to encourage teamwork.
@exchaoordo: Thanks. Have taken a break for about a week and will move on later. @KLEEDS: Ah, yes. Another in a long list of comments I've seen online at various programming websites, along the lines of people either passively accepting or taking perverse pride in suffering through a sado-masochistic process in order to learn programming. Such an approach would not be acceptable in learning, say, linear algebra or organic chemistry, but is de rigeur for many when learning coding.
@JohnM That was intended humorously, ironically! Sorry to hear that you have been sadomasochistically subjecting yourself to long lists of bitter comments. Perhaps you could try taking up a more enjoyable hobby, like programming!
To encourage teamwork is an excellent goal. There are several ways how the MOOC team could have helped shorten the path from the weekly MOOC mail to the actual course material, and there are several helpful features that this forum could have, but it doesn't. In both cases, the added benefit inefficiency is more discussion among ourselves. That is rude to call someone passive-aggressive when you don't know the person, even if it might be true at times.
Hi @JohnM. I took some time off too, but am now back trying to get to Tetris and to the car animation. Did you call your animate method on your new wheel? I think your problem above is that after the ##draw it comment, you need this: #Move the wheel new_wheel.animate(new_win, 1,0,250)