Saturday, November 30, 2013

Chapter 4: The Second Day of Project #2 (fractal)

          The second problem Fractal cost me almost 2 hours to define, test and finish. The jobs are to finish two definitions in the program. The first definition was bull-eyes that we have seen in the lecture and tutorial #8. So I easily retrieved the tutorial sheet and type in the definition on that. The idea about the definition was totally the same, so I thought that as long as I copied all the elements of the definition would be okay to pass. I was wrong! I simply copy the overlay sentence "(overlay (circle 10 "outline" "blue"))" on the definition which caused the problem afterward. Since the tests about the definition passed, I moved on to the second definition.
          The second definition was very similar to the fx problem, defining the key-press expression. This time, I was expected to press direction keys to increase or decrease the depth or radius of the bull-eyes. This definition has already started with a given statement, which indicate that I could use the same formula of fx. I need to figure out a new one. I started to analyse the goal of this definition, and I found that was as simple as just to change the depth and radius according to the different direction keys. This means that when I press one key there will be a new bull-eyes formed. Therefore, the structure of the definition has to be (make-param depth radius). However, the depth and radius are dynamic which has to use the conditional command to regulate two of them. According to the given check-expect and description, I can now write the definition as follows:
(define (key-press rp k)
  (make-param
   (cond
      [(key=? k "up") (add1 (param-depth rp))]
      [(key=? k "down") (sub1 (param-depth rp))]
      [else (param-depth rp)])
   (cond
     [(key=? k "left") (sub1 (param-radius rp))]
     [(key=? k "right") (add1 (param-radius rp))]
     [else (param-radius rp)]
     )))
          When I finished both definitions, I need to test them. The problem came across when I press "right" and "left" keys. The picture did not have any change as I pressed the keys. Then I re-examined the definition of key-press k again, and there was no error showed. I confirmed that the problem would be first definitions. I found out that my definition about bull-eyes radius was not dynamic because I restricted to 10. Finally, I changed my definition of bull-eyes to:
(define (eyes rp)
  (cond
    [(> (param-depth rp) 0)
     (overlay
      (circle (image-width (eyes (make-param (sub1 (param-depth rp)) (param-radius rp)))) "outline" "blue")
      (rotate
       90
       (beside
        (eyes (make-param (sub1 (param-depth rp)) (param-radius rp)))
        (eyes (make-param (sub1 (param-depth rp)) (param-radius rp))))))]
    [else
     (circle (param-radius rp) "outline" "blue")]
Works done!

Chapter 4: Second Day of Project #2 (Fx)

            Today is my second of finishing the project #2. I have finished the 2 problem in one day since I have learned something from the Racket video and website Racket documents.
            For the first problem, fx.rkt, the most important and difficult part of the question is to define the "toggle-band". Since this is the key press expression which we don't have video on the course website. However, the logics about the definition was very similar to the conditional commands. According to the given check expectations, it is easily to figure three function keys, "r" "g" "b". Each of them exert the function of averaging the colour. However, the question is how to right three things in one definition statements. The conditional command would be useful to do that. Because I can assume the key expression k equals to "r", then right on the job if it does. As following:
(define (toggle-band ac k)
    (cond
      [(equal? k "r")
       (cond
         [(avcol-r ac) (make-avcol false (avcol-g ac) (avcol-b ac))]
         [else (make-avcol true (avcol-g ac) (avcol-b ac))])]
But this is only one of three parts of the definition as we have three keys to define. I opened another window of DrRacket to test my definition and then cut and paste to the fx file. This problem did not cost me too much time, because the formula of the definition was fixed. All I need to do is changing the variables in the formula to achieve the goal. Since the assignment is due, I can post my whole definition for the record,
(define (toggle-band ac k)
    (cond
      [(equal? k "r")
       (cond
         [(avcol-r ac) (make-avcol false (avcol-g ac) (avcol-b ac))]
         [else (make-avcol true (avcol-g ac) (avcol-b ac))])]
      [(equal? k "g")
       (cond
         [(avcol-g ac) (make-avcol (avcol-r ac) false (avcol-b ac))]
         [else (make-avcol (avcol-r ac) true (avcol-b ac))])]
      [(equal? k "b")
       (cond
         [(avcol-b ac) (make-avcol (avcol-r ac) (avcol-g ac) false)]
         [else (make-avcol (avcol-r ac) (avcol-g ac) true)])]
      [else (make-avcol (avcol-r ac) (avcol-g ac) (avcol-b ac))]
  ))

Tuesday, November 19, 2013

Chapter 3: The First Day of Project #2

             Programming program varies from time to time and function to function. I have found that DrRacket is a smart program that different from the program that I learned in my high school. I used to use Visual Basic which is every elementary tool compared to the programming. 
             The difference I found in those two different program was that they are used for distinct purpose. The Dr.Racket seems has more availabilities when there is fixed functions which is not going to be changed during the process of running. For this kind of program, it is more helpful when the programmer wants to analyse some given data or stimulating a situation based on the data. However, in the latter program Visual Basics seems designed for visual usage. For example, the basic task that I did on Visual Basics was to design a dialogue window for the users to type in their name, age, or other information for computer to memorize and retrieve the information when the user type in their names again. Although the DrRacket could do graphic outcome as well, the difference between them is obvious. Learning difference is always good!
              Today is my first to do the project number 2 which has been released for several day. I wish to do it as early as possible. The first step for me is to understand the problem as said in class. Understanding is always the first step, then making a plan and thinking about alternatives, the final step is to implement the plan and give the feedback. The first problem named fx.rkt that I downloaded from the website. The problem is about to fix some definitions about a program related to the expression of colours in terms of rgb system. This problem is exploring the outcome of picture when we dissolve the picture and reassign them in different colour intensities. In this case, we take the average of three colour intensities. The second problem is named fractal.rkt. The problem is to extend the discussion of tutorial #8 the bull-eyes. Fixing the program definitions in order to check the expectation of that and make sure the depth. Another possibles for the assignment was to cycle the colours which I wish to do in the tutorial. In the next day, I want to finish up the first assignment with a blog entry. 

Thursday, October 31, 2013

Chapter 2: Project and Obstacle

           This is my second entry of sLOG. Today I would like to talk about our first project "Sneeze Infection". This is a very interesting topic for a student programmer. The project is basically about to generate some definition command to DrRacket, based on what has been given. Professor has generated a whole rkt file on the situation that he suggested. I have found some difficulties in doing this projects.
The first obstacle is that I do not fully understand all command he made in the file, although I have go through the whole file. For example, there are some commands such as "local" which is not appeared on our textbook yet. I have found that I could omit those "unknown" commands, then go to the exact question about in the file.
            Among four jobs in the file, the first one is creating a definition on "left-cycle", that makes the first element of the list at the back of the new list. For this request, I have went through all the videos of list and aggregation. Finally, I decided to separate the list and then merge together into one list. "Append" command is my choice, however, the "check-expect" cannot go through for hundreds of times. Then I use a new draft window on DrRacket to try my definition again and again. Finally, I found the problem of my definition. I first time use the seen the reverse as a list, which is not. Then I put a list out of the bracket to make it as a list. It worked!
            The second job is more complicated than the first one although it looks similar. "Right-cycle" is the one definition about put the last element in front of the rest of list. This is the one with a lot of logic cycle and use many "reverse" "rest" and "first" command on list. I figured it out to use the way of "in-to-out". I dissolved the list in to elements, then I found the last element of a list is the first element of reverse list. Using the same logic, I found the way to claim the definition. The following two question was not that difficult for me, since I can get the hint from "check-expect" sentence to define the other two variables.
            The last part of this project is to change the variables which has been indicated in the first lines of the document to see what will happen on the expected result. I found it is fun when I change the three variables - VIRULENCE, DURATION and IMMUNITY. I changed those variables to their maximum value indicate in the assignment. This model is really like the real one with only three variables which can influence the effects of infection. The virulence is the idea how the virus spread into the public and the ability to infect other people. Duration is the variable to indicate the period of people who has been infected. The immunity is when people already recovered from the infection, they will have immunity to such a virus for a period. Those can influence the course differently. To find out the change and effects of the change, I keep other parameters the same as before, change the specific parameter into its extreme value to see how to influence the model. I found this project is very interesting and challenged for students.

Tuesday, October 22, 2013

Chapter 1: Pilot

          This is my first time to get into Blogger! I am very interested in this idea about creating a blog for a course as a record of what I learned and think! It is so excited for me to write an entry to talk about something related to the course in a university! Bravo! I do think blog is a place where people like to share and communicate their opinions about the world and minds. I'd like to share what I think about the course frankly, but I am hoping to read your entry and comments at the same time. 
         First of all, there are some opinions that why I choose this course in the first place. To be honest, I think some of you have heard some rumours about the course, like myself, which is an "easy course" designed for people who are at the basic level of computer. I am a fourth year student, who like to make my CGPA as high as possible. That is why I believed the rumours and chose the course as soon as I can. However, when I took the first lecture. I hate to say, but this is absolutely not an "easy course" as I thought in the first place. I didn't regret about my choice, because I found fun in this course. There, indeed, is something really attracting me to continue work on computer science.
         Then I went to the first class, this is my second change that caused by this course. I changed my thought on computer science. Before that, I thought that computer science or computer is just as easy as a calculator. That computer is a giant smart machine which can do everything was my definition of computer. I did not know anything about computational thinking. When I went to the first class, I did learn that computational thinking is a precise process just like our brain does. Prof said that there was a long history for algorithms, which is a base of computational thinking. We all believe that the first computer ENIAC was born in Pennsylvania State in 1942, yet we don't know that the first programmer was a female! Those are something really shock me.
        Those are my first feeling about this course. Interesting and getting fun from the process of learning! I still want to work out the formula about that problem of folding paper! Having fun encourages me to move forward. Looking forward to having something new and interesting tomorrow!