Wednesday, November 30, 2016

Reflection of class on Nov 29th
  At the beginning of this chapter 5, there is a similar interface of drawing app which I have created in last class, but the difference is that a line of various buttons is added below the bottom of the original surface. So what are these buttons used for?
  As the basic instructions of this chapter says, these buttons can change the line color and line thickness by attaching functions to them instead of key presses, and the size of these buttons can be adjusted easily as well. So how to do that?
  In order to save time, I downloaded the source code from the dedicated coding website and copied them to the new text editing interface, what I need to do is adding relative codes to the preset blanks which were highlighted by red color and run the whole procedure to see what will happen on the app canvas. Absolutely, I need try to change some codes to customize my own app canvas.
  I defined some new functions about line colors and bind them with relative keys by implementing ‘window.bind’ statement just like the last chapter. Then, following to the steps of the example, I added buttons to my application by typing codes of loading images for buttons and attached functions which include necessary variables to buttons.
  I didn’t understand completely why I need to remove ‘event’ from between the brackets of pen color functions so that the procedure could work normally, but I found that I couldn’t change the pen color by pressing preset keys anymore when I run the program. Actually, I found the solution for this item from the later content of this chapter, all I need to do was removing these useless codes from the procedure because their functions were already replaced by codes of buttons. Well, I got a feel suddenly that the author was a fantastic magician who could read my mind and predict my behavior. Just for fun.
  At last, I did the same operation as color button to plus and minus button to change line size and try to change the value of side from LEFT to RIGHT of ‘Button’ function to see what could be changed when I run it as the idea 1 said. Well, all things are correct except the position of buttons. These buttons were arranged from the right side of the bottom of the canvas. What’s more, I added another button to choose a random color which I preset before by implementing random import and ‘random.randint’ command.
  All is well! Now I can draw more fabulous images by my new drawing application!

  

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.

Tuesday, November 15, 2016

Reflection of class on Nov 15th
  As this chapter 3 says, it’s the final turtle chapter which can provide a few ideas about creating our own images by using a minimum of code and many loops. Well, I did really get some new fabulous ideas like “fractal tree” and practice them in turtle module in class, but actually I took a long time to understand them and converted them to my own ideas.
  In this chapter, I find that the “import turtle” and “t=turtle” commands are used in all the examples and I should add extra “t.” before every needed function as the prefix of function name to make sure relative codes can work normally, that is, it’s the better way to use particular functions which have the same name in different modules although it’s a little inconvenient.
  When I finished the whole procedure by complex coding, I always need to examine which image it can output and back to the procedure to modify relative inappropriate code according to the image. Sometimes the image appears too fast that I cannot monitor the track of formation immediately so that I should run the procedure again and again to try my best to follow the little turtle. But I won’t worry it anymore because the “speed()” command can help me a lot because I can set the speed of picture drawing between 0 to 10 to fit my different purpose by using it. And, argument 0 represents that the computer can go as fast as it can.
  To be honest, I met a big problem on understanding the procedure of the “fractal tree” although I knew the major point here was recursion where a function calls itself from within itself just as the instruction says in the beginning of this example. I inputted all codes of example in Python 3 and run it in the lowest speed to monitor the track of turtle in order to clarify the meaning of important components. Well, I still couldn’t understand why the whole procedure could output a fractal tree although I had known how the fractal tree was formed. I don’t know how many times the main function would be called from within itself and when the calling would be broken by which code. I discussed the whole procedure with my classmates but we were still confused about it.

  So I skipped this “fractal tree” and practiced other creative ideas because I didn’t want to waste the whole morning on it and get the failed feed. Because of the limited class time I had no time to ask you about the “fractal tree” procedure, and I’ll try my best to figure it out in my spare time. If possible, I’ll ask for your help in next class.