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.