Lecture Materials

Questions & Answers


Q: Will it be recorded? I have class then…

A1:  We’re waiting to hear from Pixar as to whether or not we can record it!


Q: Why is canvas height capitalized

A1:  It’s a constant


Q: What happens if you put in a pixel which is not an integer? For example is SQUARE_SIZE = 15; 15 / 2 = 7.5000

A1:  What happens if you put in a pixel which is not an integer? For example is SQUARE_SIZE = 15; 15 / 2 = 7.5000

A2:  Good question. I don’t remember from the top of my head - try it out!


Q: Is SQUARE_SIZE a constant values defined above main?

A1:  Yep


Q: When I try to move a square or brick on my screen by moving x,y values I have as argumetns, it changes the dimensions as opposed to the location. Might this be because the function parameters need to be altered?

A1:  Which function are you calling?


Q: if you named the canvas something other than ‘canvas’ could you still use canvas.create_rectangle or how would you adjust accordingly?

A1:  If the canvas variable is called mycanvas, you’d call mycanvas.create_rectangle


Q: Is SQUARE_SIZE basically the area of the square so width * height?

A1:  It’s the length of the square’s side


Q: i’m calling a function I wrote for the def create_brick task in pyramid

A1:  Well, it depends on how you ultimately use your parameters. I’m guessing you’re passing them into the wrong place.


Q: how do computers count time?

A1:  Stop by OH if you want to find out how this works on the level of hardware and software!

A2:  They have an internal clock. You can wait at a resolution of milliseconds.


Q: the dealy in time.sleep counts in seconds?

A1:  yes


Q: time.sleep(DELAY) is DELAY in seconds?

A1:  Yep

A2:  yes


Q: or how do we pick the measure

A1:  Decimal places!


Q: are end_y and start_y functions or variables?

A1:  Variables


Q: how do we decide to pass 1/50 t0 sleep()?

A1:  It's a reasonable amount of time between frames in the animation.

A2:  It’s how long you want between frames - 1/50 means 50 frames a second


Q: Wouldn’t we still get the same result/animation without time.sleep?

A1:  Kind of, but things would move so quickly you wouldn’t see them at all.

A2:  All the moves would happen so fast, you couldn't see it.


Q: When we say canvas.move, is canvas the name we gave the canvas? If we called the canvas “cat” for example, would we write cat.move?

A1:  Yep!


Q: But isn’t it gonna go forever? with the while True

A1:  live answered


Q: Did the square move off the canvas?(is it not bounded by it)

A1:  Yes


Q: when you are getting left x is that the x-coordinate of the top left corner of the rectangle?

A1:  It's the coordinate of the left hand side.

A2:  The whole left side of the rectangle, yeah


Q: Is get_left_x measured to the center of the rectangle or upper left?

A1:  They have the same x coordinate!


Q: what happens when you move by more than 1 pixel? does it make it move faster?

A1:  Yep


Q: Why did we add the canvas.update() and time.sleep() functions? What do they do and when do we add them?

A1:  update() causes the canvas to update the drawing to reflect the move. sleep() make the computer wait between updates -- otherwise all the updates would happen so fast, you couldn't see them (the square would just jump to it's final location).

A2:  canvas.update actually moves stuff around on the screen, and time.sleep adds a pause in between frames so you can see each frame. They go after you’ve updated all the locations of stuff on your canvas


Q: What does the return line in get_left_x tell us? What is the [0] for?

A1:  We’ll get there on Monday!


Q: is rect a variable now that you can always get information from no matter where it ends up on the canvas?

A1:  Yep


Q: when an object moves off screen, what canvas object does it exist on?

A1:  The same one

A2:  it's still on the same canvas. it's just in a place that you can't see.


Q: would chris’ code still work if he used an if statement in his is_rect_left_of_center as opposed to using return curr_x <= max_x

A1:  It depends on what you’d want to do inside that if statement - try it out using the lecture code we’ve posted!


Q: when defining the size of a canvas, does that mean its just a window into a bigger canvas i can;t see?

A1:  Yeah, that’s a good way of thinking about it!


Q: what if we didn’t pause?

A1:  all the updates would happen so fast, you couldn't see them

A2:  The rectangle would move *really* fast


Q: the numbers just change the slope of the diagonal direction, right?

A1:  live answered


Q: how are graphics objects stored, the luggage of the object is so much bigger than an integer or a float so is the luggage tag bigger?

A1:  We’re going to get there very very soon :)


Q: is there supposed to be a period after time.sleep(1/50.)

A1:  That’s just to indicate that 50 is a float (it’s a decimal place)


Q: What is the true referring to?

A1:  In the while loop? That just makes it go forever


Q: Is there any reason the ball looks kind of cut off

A1:  Zoom being weird!

A2:  It's just how it renders on the video.


Q: When is it false?

A1:  The loop is an infinite loop.

A2:  It’s not - that loop will always execute


Q: does canvas get deleted and called for every frame? that seems like a lot of function calls

A1:  Nope, what makes you think it would?


Q: What location within the ball is the reference (x,y)?

A1:  upper left hand corner of bounding box for the circle


Q: why is there a period after 1/50 in the sleep function?

A1:  Just to indicate it’s a float


Q: How did Chris know select the parameters canvas and ball?

A1:  You need access to both those variables inside the function


Q: Is ball_top_y a ready made command in Python?

A1:  That command is something that Chris wrote previously. It would be, for example, a function we might give you in the starter code (if we gave you an animation assignment).

A2:  No, it’s a variable


Q: how could you get ball_bottom_y?

A1:  If you know the top Y, you could just add the height of the ball to it


Q: Where did top_y come from in get_top_y?

A1:  tk has a function to do give you.


Q: is there a way to keep the ball round as it’s moving?

A1:  It actually is round. It jusy looks like a wedge due to video rendering issues.

A2:  It is - Zoom is just being weird about it


Q: why is that the ball changes its shape when moving? because the speed of the move?

A1:  It’s just Zoom being weird, it actually doesn’t change shape.


Q: If you put a lower value as the parameter in time.sleep(…), like 1/100, do you get a higher frame rate?

A1:  Yep, but at some point your computer screen won’t be able to keep up with it.


Q: ok..maybe a dumb question. How is a top left point on a ball defined? Based on Chris’s code, that point correpsond to the northern pole

A1:  Not a dumb question! Imagine a box drawn around the ball. The top left point is the top left corner of that box.


Q: How are objects stored in the heap different from global variables in their usage?

A1:  Those ideas are unrelated - the heap is where a variable is stored in your memory, and a global variable is where a variable is declared in your code.


Q: does this sharing variables only happen in graphs and animations?

A1:  Nope - we’ll talk about other applications of this in later lectures


Q: what if you don't want changes to be saved to large variables?

A1:  Python makes that pretty difficult but you’ll have to make a copy!

A2:  Then you'd need to manually make a copy. We'll talk more about this next week.


Q: if there wasn’t a URL, we would have to add return at the end of make_ball, right?

A1:  It’s more a question of where the URL actually points


Q: are heaps bigger than stacks? do new heaps get allocated for every program like a stack and then get stacked up on each other like a stack but fatter?

A1:  We'll talk more about memory in a few weeks. But there is generally one stack and one heap in Python programs.


Q: So do you not need a return line in make_ball(canvas)?

A1:  live answered


Q: when does your computer clear the information stored in heap?

A1:  When it detects you are done using the object and clears it from the heap. When the program ends, anything left on the heap is also cleared.


Q: So this means we don’t have to return the canvas?

A1:  Yep

A2:  Yes.


Q: Is there a way to get the information about the location of all the pixels in a drawing like a circle?

A1:  You can compute that because you know the size and location of the circle. But there are ways to determine if a particular pixel is contained in an object like a circle.


Q: so you don't have to return variables that act like URLs

A1:  Yes, because changes are being made to the actual variable, not a copy.


Q: How do we let our mouse control the pad?

A1:  live answered


Q: This is so cool! Will we learn in this class how to “export” the python code into a stand-alone software that people can install and play games?

A1:  Stop by office hours and we can talk about it!


Q: This is somewhat unrelated, but is there a way to import an image to be used as an object?

A1:  live answered


Q: where will the link to the Pixar event be posted?

A1:  It’s already on the website in the announcements.