Monday, November 28, 2016

Reflection of class on Nov 17th
  I have learnt about how to create colorful and fabulous images which are usually combined by loops of various regular shapes and lines by implementing Python’s turtle module, and I can also let the little title write down my Chinese name by typing relative codes in text editing interface. The turtle module is not interactive which means that I cannot control it when I run it, just wait for the result.
  But now, I can set and customize my own canvas by tkinter module and draw some personal images by creating various red lines which can be controlled by pressing ‘up’ ‘back’ ‘left’ and ‘right’ keys.
  At first, I should set necessary variables like height, width and color for my own canvas by following the example of this chapter 4. Then, I need to edit the corresponding function to move red lines. It’s not difficult to understand relative codes showed in the example, but I met a problem that I did not know where was the original point of canvas and the correct direction of ‘y’ coordinate. Fortunately, I figured it out by changing different position of anchor. As you know, I need to press different direction keys to control the creating of red lines so it’s important to connect these keys with dedicated functions that they can be called successfully. And, the ‘window.bind’ statement works perfectly here.
  As I can see, the background of my own canvas is black and it looks not so good to me so that I want to change it to my favorite picture just like changing the background of my computer, that is, I can use ‘PhotoImage’ statement to do this but I need ensure that the format of picture I want to implement should be gif, not jpg or jpeg. What’s more, I need to add ‘anchor=NW’ at the end of ‘canvas.create_image’ statement inside to make sure the new background I added could cover the canvas completely.

  In the rest of this chapter, I learned how to lift and lower and keep track of the pen, the concept here is similar with turtle module so I could understand and implement them in my own drawing app. And I found a useful way inspired by the challenge 3 of this chapter to cancel the last line what I have created by adding ‘erase(current_line)’ statement. It works much better than the ‘erase_all()’ statement.

1 comment: