Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

CS106A Pawprint exercise  RSS feed

 
Bruno Ribeiro
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there,

I'm a learning how to program in Java. As a newbie I have some questions in some exercises provided by the course material of CS106A (Stanford).
I have searched everywhere and no one did this one, apparently. So if you could give me some hints I would appreciate. It's the Part Three of the file attached (Pawprints). So far I have managed to draw the Paw, but I can't change it's place or duplicate it.



Thank you so much for you help!
Pawprint.png
[Thumbnail for Pawprint.png]
Exercise
 
Campbell Ritchie
Marshal
Posts: 55772
163
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

I think your question would fit better in our GUIs forum, so I shall move it.

You have a method taking doubles as parameters to draw the toes, but I can see no sign of your using those parameters.
I presume you are familiar with the coordinate system on a screen? If not, you can read about it in the Java┬« Tutorials. The top left of your Component is (0, 0), and the first number (=x) gets bigger if you go right and the second number (=y) gets bigger if you go down. You have your paw offsets, and what you want to do is draw them at a position (x + X_OFFSET, y + Y_OFFSET). So you need to find some way of adding the coordinates of the top left of the paw to your offsets, and you should be all right. If you don't manage to get those different positions, you end up drawing several footprints all on top of one another and you cannot see that they are separate.
 
Campbell Ritchie
Marshal
Posts: 55772
163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are those bear footprints? We have our own resident Bear on this Ranch already .
You may find the footprints easier to handle if you work in whole numbers of pixels and do all your arithmetic with ints rather than doubles. Even better, create a Footprint class with ToePrint and SolePrint fields, and you can use the location as a field.
 
Campbell Ritchie
Marshal
Posts: 55772
163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You might be stuck with doubles if the question specifies them.
 
Bruno Ribeiro
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Campbell Ritchie,

Thanks, it worked perfectly, I never thought of that. It was a really simple thing!
 
Campbell Ritchie
Marshal
Posts: 55772
163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome

It's all practice and practice and practice, and having done it before.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!