Showing posts with label faq. Show all posts
Showing posts with label faq. Show all posts

Friday, March 2, 2007

Lab7 FAQ (part I)

Lab7 FAQ (part I)

Q1: A snowflake looks like a (fancy) triangle. But each smaller part is not a triangle. How do I use recursion to solve the problem?
Answer:
We do not draw a big triangle. Instead, we call the method 3 times (with different vertices as argument) to draw 3 segments of the snowflake.

Q2: What is really being executed? If we call ourselves all the way down to the littlest point, we don't really have a reason to come back up(up the call ladder) because we are just drawing small lines.
Answer:
At the bottom level of recursion, we know what to draw, so draw. For this program, we do not start drawing anything until we get to the bottom. What's the point of backing up the "call ladder"? So we can draw other small segments that make up for other parts of the snowflake. Even though the upper (non-bottom) levels of recursion do not draw anything, they actually calculate the positions and make calls to the lower level.

Q3: How would recursion work with the snowflake? How does recursion draw the lines and cuts out the old section?
Answer:
Again, there is no "cutting out" any lines here. It's unlike the spiral (or the Sierpinski Gasket) where we performs a draw at each level. For this lab, we only draw at the bottom level (base case of recursion).

Q4: I write a class called SnowflakeSegment. What should be the arguments to the constructor?
Answer:
Up to you. I have 2 suggestions for you. Choose either one or come up with your own. There is no right or wrong.
  1. SnowflakeSegment(Point p1, Point p2);
  2. SnowflakeSegment(Point p1, double length, double angle);
Both options would give sufficient information to the SnowflakeSegment on what to draw. Which one should you pick? ... whatever. You will need to calculate the points of subdivision from the arguments. It's a little work on geometry. Both options give you enough information for the calculation.
If you have more questions, post them here (be sure to put your name) or email me.

- Mock

Thursday, January 25, 2007

Common Questions for Lab 2

Question:

Hi, I have a problem for cs10 Lab 2. Not a big problem, but I just
realized that whenever I run my program, it draws a red circle in the
middle of the frame...
Its no big deal, because everything else runs fine, but is there a way
to get rid of it?

Michael

Answer:

Hi Michael,

Yes, there is. It will be easy once I tell you how. But I should also
tell you why it works.

When you make the Alien class extends Ellipse, that means the Alien
itself is an Ellipse .. with some extra ellipses and maybe some
rectangles/lines. Inside the Alien constructor, you probably have a
statement like this...

face = new Ellipse();
face.setSize(...);
face.setLocation(...);

which creates a new Ellipse for variable face, resizes it, and puts it
at some location.

If you didn't call setSize() and setLocation(), what would happen?
Yes, the face will just be a red dot at the middle of the screen...

and that is exactly what is happening to your Alien's ellipse. So, to
fix this problem, you can make use of a special variable called "this"
(without the quotes) .. this refers to the class itself.

Since "this" is already an Ellipse, you do not need to create a new
Ellipse for the face. So, instead of saying

face = new Ellipse();

you can just say
face = this;

and then anything you do with the face, will be performed to the Alien
itself (which is initially a red dot).

Hope this helps!
- Mock

Contributors