Lecture Materials

Questions & Answers


Q: Hello, the lecture slides are still not on the website, it gives an error saying " object not found"

A1:  Working on this! Thanks!


Q: What is the best way to copy/duplicate an image?

A1:  You can make another image from the same filename.


Q: Do we not have an assignment #4 this week?

A1:  It comes out on Wednesday!


Q: when is this data from

A1:  Not positive, but I believe it is from a few years ago


Q: If you submit an assignment late on the due date, does that count as an entire late day?

A1:  Yes. Anything that comes in after the time that the assignment is due is considered late.


Q: When we make another image from the same filename, how exactly do we copy it onto the blank canvas we make? I am having some trouble

A1:  You can copy an image pixel by pixel into a new blank image.


Q: how do we copy an image to another blank image/slate?

A1:  You can copy the image pixel by pixel (in a loop). For example, you might want to check out the mirror example from class last week.


Q: I missed the beginning, are diagnostic scores going to available after class? Where do I check this?

A1:  There will be an announcement posted on the course website at the end of class.


Q: What outside resources/tools do you reccommend we use to practice coding?

A1:  You could check out parlante.org. It has practice problems in Python and was developed by Nick Parlante (lecturer at Stanford)


Q: why did pixel.red have to add (R*proportion + G*proportion + B*proportion) and not just the R*proportion?

A1:  That's just the way the sepia filter is defined to get the right effect. You can find out more here: https://www.techrepublic.com/blog/how-do-i/how-do-i-convert-images-to-grayscale-and-sepia-tone-using-c/


Q: does it matter whether you nest your loops by x or y first?

A1:  It is convention to loop over y in the outer list. But you can also loop over with x as the outer list.


Q: So as opposed to matrices in math, pixels are (col, row) since it’s (x,y)?

A1:  In lists of lists, we think of the rows as the first index and columns as the second index.


Q: For the warhol image problem, is it ok to import random library to use?

A1:  Yes


Q: when will we be able to make insta

A1:  You're getting closer!


Q: can you store an image in a global variable?

A1:  You can, but using global variables is generally bad style.


Q: what's the best way to iterate through a list while simultaneously removing elements in the list?

A1:  This is actually a dangerous thing to do. You generally want to create a new list that only contains the elements of the original list that you care about.


Q: Is there a way to change the border color?

A1:  Yes. Use outline= parameter.


Q: can we use a canvas for the warhol assignment?

A1:  You should not need to.


Q: The fill and outline parameters are imported using one of the libraries right?

A1:  They are part of the create_rectangle (and other functions) that are part of the library tkinter.


Q: what’s the purpose of the ‘hello rect’?

A1:  Just to show you a simple example of graphics.


Q: is 600, 600 the endpoint or the distance from the specified origin?

A1:  Endpoint


Q: Is there a way to draw these shapes rotated on an angle?

A1:  You'd need to figure out the coordinates for the rotated object manually (but there are libraries to help with that).


Q: How come the line does not go through the blue squre or red oval

A1:  The square and the circle are on top of the line.


Q: how frequently are the mouse positions updating? or can we specify a framerate?

A1:  Its set by how often the operating system notifies python of mouse movement.


Q: How is Chris getting negative y-coordinates when mousing over the graphic? like occasionally y = -1 will pop up

A1:  Didn't see that, but it might be an artifact of the window bounds.


Q: Does the console showing the x and y values of where the mouse is happen automatically? Or does that need to be programmed?

A1:  That needs to be programmed.


Q: sorry, I missed what the anchor means?

A1:  It is which point on the object you want to specify the x and y location. So if you want to specify the NW corner, or the SW corner, or just the West point.


Q: Do peple in industry typically use python for graphics or another language?

A1:  Depends on the application. But heavy graphics (e.g., movie making) uses other languages (sometime specialized for the application).


Q: When we take the next diagnostic, can we use these SimpleImage/tkinter reference sheets or must we remember all the functions eventually?

A1:  You can use these reference sheets!


Q: Is there a way to see the potential arguments of a function while your defining it?

A1:  Some development environments may provide that information, but the documentation is always the best source to go to.

A2:  You can checkout this handout for a list of helpful graphics functions. It shows the parameters. http://web.stanford.edu/class/cs106a/handouts/graphics-reference.html


Q: is the border for all shapes automatically black? or is that hiding in the code somewhere? thank you!

A1:  The border color defaults to black.


Q: For coding graphics is it again standard to declare numbers as global constants or can we just use numbers in the body of code?

A1:  Declare them as constants!


Q: How do we to write a Python library tkinter or simpleimage?

A1:  Come chat about this at office hours!


Q: Can you shut off the chat?

A1:  You can close the chat panel by clicking on the "Chat" icon in zoom. Sometimes the instructors use the chat to get feedback from the class.


Q: why aren’t the global variables n_rows and n_cols being used in the example?

A1:  They were just added.


Q: why do we need to minus 1 for the constant SIZE? for furture questions, is that always the case we should do? thx for answering!

A1:  Depends on the application. It was done here so the last square wouldn't go off the end of the canvas (since we start counting from location 0,0)


Q: can y = row * size be moved to be below for row and above for col?

A1:  Yes!


Q: I’m trying to run Canvas in Python, but it appears that there is a package missing. Do I need to download Canvas, tkinter, or graphics, or is there something else I’m missing? Thanks!

A1:  you need some import statements. import tkinter and from graphics import Canvas


Q: how max long a variable or method name can be?

A1:  Longer than you'd actually want to use. It depends on the interpretter you're using. But it's as long as you need for practical purposes.


Q: is it bad if we set each patch individually in assignment 3 for the warhol program?

A1:  This might be a good question for Ed! We can help give you a more complete answer.


Q: are we allowed to use the "not in" operator to compare lists?

A1:  Yes


Q: what was the type command for creating our own function

A1:  Higlight code, right click, refactor, extract method


Q: Is canvas an immutable or mutable type?

A1:  Mutable


Q: Can you please define binding again?

A1:  Check out this handout: http://web.stanford.edu/class/cs106a/handouts/mutation.html


Q: How does this apply to mutable vs immutable variables? Is this "url" type thing what happens with integers and floats and stuff?

A1:  Ints and floats are immutable. Lists are mutable. Check out the handout on binding and mutation.


Q: for the warhol assignment how do you pass images into a list and then transfer it to an x,y coord on the canvas? would you use a for loop and append each image to a list? ty!

A1:  This might be better answered on Ed! Post on there so that we can provde a more in depth answer.


Q: Can we use list.clear() to clear lists after an iteration?

A1:  It might be better style to instead create a new list at the beginning of each iteration.


Q: where can we see our scores for the diagnostic?

A1:  There will be a link on the class website soon where you can see your grade.


Q: Where can we see our diagnostic grade?

A1:  There will be a link on the class website soon where you can see your grade.


Q: where do we see the diagnostic results?

A1:  On an announcement on the course website


Q: If we want to know where we’re at in the class, do we talk to our section leader?

A1:  Or you can talk to Juliette