Lecture 9 Zoom Q&A


Q: Do you need the last ā€˜elseā€™ block as a matter of style?

A1: live answered

A2: No, you donā€™t really need it.

A3: Functionally no change, but the style question is more subtle. Putting the recursive case in else means taht body is indented at same position as base case and there is a nice symmetry there. But if the recursive case is more involved, it means an extra layer of indent for the whole body which can be displeasing. No right or wrong answer, just food for thoughtā€¦


Q: What does the const after isPalindrome mean?

A1: It indicates that you canā€™t change the parameter that has been passed in


Q: Would this catch if the first and last letters were different but middle was palindromic?

A1: Yes it should

A2: Yes, the first and last characters would be different in the very first function call, which would cause the base case to immediately return false.


Q: is the auxillary spindle always B?

A1: live answered

A2: Whatever spindle is ā€œleftoverā€ (not the source nor destination) is used as the auxiliary


Q: what is ther difference between const and static cosnt

A1: The ā€œstaticā€ modifier makes the declaration only visible here in this file (not accessible to code in other file in same project)

A2: We use static const for ā€œglobalā€ variables to identify them as constants (only acceptable use of global variables). const on its own can be used to indicate that reference params should not be modified


Q: How much easier/faster would the problem become if we add one spindle?

A1: Meaning we had an extra auxiliary spindle?


Q: what is n?

A1: The number of disks in the starting tower


Q: Yep, what if we had four spindles?

A1: Hmmmā€¦. I am going to have to think about that one for a bit. Come to my office hours today and we can brainstorm together!


Q: are cantor fractals related to cantor sets?

A1: live answered


Q: why does 500 mean 0.5s in pause(500)?

A1: The argument to pause is expressed in the number of milliseconds


Q: How do you change the thickness?

A1: Change the value of w

A2: You can check the contents of the provided drawThickLine function, thereā€™s a line in there that actually draws the line itself, and it takes a configurable width param in number of pixels

A3: See the function drawThickLine, it depends on the constant RECT_HEIGHT


Q: How does getLoweredPoint work?

A1: It creates a new point with the same x coordinate but a different y coordinate (lower down the scnreen)

A2: (The code is in the Cantor.zip if you want to check it outt)


Q: So does each line get redrawn every time the function is called?

A1: No, only the lines at the next level

A2: Each call draws one line and then makes a recursive call which draws the smaller lines underneath

A3: *current level


Q: is the cantor fractal code accessible?

A1: Yes! Lecture code projects are is linked onto lecture page

A2: https://web.stanford.edu/class/cs106b/lectures/09-fractals/


Q: Canā€™t figure the diff between depth 1 and 2

A1: What was previously a straight line has a triangular bend in it

A2: Depth 1 is a single straight line segment. Depth 2 is a line segment with a triangle showing up halfway through


Q: Thanks


Q: so is level 0 = depth 1?

A1: live answered


Q: how do we add the ā€˜open documentsā€™ tab in qt creator?

A1: Along top edge of window are controls for this ā€” letā€™s you select what the pane is showing and one that lets you add a new pane

A2: Icon that looks like two squares stacked on top of one another with + to the right lets you add new panes


Q: Wouldn't you also need to erase a part of the line each time

A1: only the base case is drawing the line, in the recursive case we draw the snowflake version of the line (this is bit different than Cantor where every level was drawing the line and then adding on to drawing with recursive call)

A2: No, the length of each line changes depending on the number of total levels. So whe you finally reach the base case the lines will be of the correct length


Q: thanks!


Q: Could you add a pause with a lower level to show the process of drawing it recursively?

A1: Grab the project zip off of the lecture page and you can run that experiment for yourself, (or hang around til lecture end and we can get Chris to do it)


Q: What stanford library is the pause function in?

A1: console.h


Q: Does G window / G point assume top left is 0,0 ?

A1: yes

A2: yes


Q: Could you explain how we drew the beginning triangle? Meaning, how did we complete the snowflake instead of just making one side

A1: live answered


Q: Since the drawSnowflakeLine fn is being called recursively segment by segment, why is it that each set of lines is drawn collectively rather than all (start, a) segments followed by all (a, t) segments, etc?

A1: You have the right intuition! It is indeed true that all the segements that are part of the first (start, a) segment are drawn before all the segments of the (a,t) part, and that holds true at all levels.


Q: How are terrain-generating fractals in computer graphics made? Since they look very asymmetrical

A1: live answered


Q: does the 1/3 being used have to do with the fact that the triangle has 3 sides?

A1: live answered


Q: I meant how we drew the entire snowflake. Like, the snowflake is closed fractal. So how did we establish the beginning points?

A1: The beginning left and right are just chosen as arbitrary starting points in the window in the main function