Exercise 1.3.1 - PowerPoint PPT Presentation

About This Presentation
Title:

Exercise 1.3.1

Description:

Exercise 1.3.1 A) Find out how tock in that figure works manually. Enter expression expressions such as (tock 0) and (tock 1) into DrScheme's Interactions window and ... – PowerPoint PPT presentation

Number of Views:30
Avg rating:3.0/5.0
Slides: 7
Provided by: labu420
Learn more at: https://home.adelphi.edu
Category:

less

Transcript and Presenter's Notes

Title: Exercise 1.3.1


1
Exercise 1.3.1
  • A) Find out how tock in that figure works
    manually. Enter expression expressions such as
    (tock 0) and (tock 1) into DrScheme's
    Interactions window and see what their results
    and their effects on the canvas are. Hint
    Execute the animation but comment out the
    expression (on-tick-event tock).
  • B) Make the UFO animation slower and/or faster.
  • C) Render the UFO as a yellow shape. Add an
    antenna. Make the background blue.
  • D) Swap the two drawing actions in tock. Does
    this make a difference? Why? Why not?

2
1.3.1.A Solution / Explanation
  • Type in some example of tock manually
  • (tock 0) erases the 0th UFO and draws the 1st
    UFO.
  • (tock 1) erases the 1st UFO and draws the 2nd
    UFO.
  • In general, tock erases the current UFO and draws
    the next one.
  • Since we do not want to sit at the computer and
    keep typing (tock 2), (tock 3), (tock 4), etc.,
    we use a predefined function called
    on-tick-event.
  • The on-tick-event function takes another function
    (like tock) and automatically runs it after every
    clock tick.

3
1.3.1B,C Solution / Explanation
  • To slow down the animation, increase the time
    between clock ticks. For example, (big-bang 1
    0).
  • To speed up the animation, decrease the time
    between clock ticks. For example, (big-bang .3
    0).
  • To make the UFO yellow, change the color in the
    ufo-draw function (from green) to yellow.
  • To make the background blue, we will simply draw
    a solid blue rectangle the same size as the
    canvas
  • (draw-solid-rect0 0 0 100 200 blue)

4
1.3.1C Solution / Explanation
  • To add an antenna, we add a line (say, 15 pixels
    long) that extends from the top of the circle.
  • Since the center is (X, Y) and the radius is 10,
    the top point on the circle is (X, Y 10).
  • ---In Scheme, that is (X t) and (- (Y t) 10).
  • Since we draw the line 15 pixels up from that
    point, the line goes up to (X, Y 25).
  • ---In Scheme, that is (X t) and (- (Y t) 25).
  • So we have,
  • (draw-solid-line0 (X t) (- (Y t) 10) (X t) (- (Y
    t) 25) yellow)

5
1.3.1D Solution / Explanation
  • (define (tock t)
  • (draw (ufo-draw ( t 1))
  • (ufo-erase t)
  • produce ( t 1)))
  • Swapping the 2 drawing actions causes
  • --part of the antenna may get erased
  • --if the clock ticks are slow enough, you will
    be able to (incorrectly) have 2 UFOs on the
    screen at the same time
  • There is no other difference as the 2 actions
    occur simultaneously, at least to human eyes.

6
In conclusion
  • We have written an animation program for moving
    the UFO across the screen.
  • This program includes several Scheme functions
    that we wrote, like X, Y, ufo-paint, and tock.
    It also includes several predefined functions
    like , , draw-solid-rect0, big-bang, and
    on-tick-event.
  • In HW4, you will write an animation for moving
    the shots across the screen.
  • Then, you will combine the two animations, and
    complete the UFO game.
  • For the rest of the semester, we will write
    shorter programs (each with only one, or a few,
    Scheme functions).
Write a Comment
User Comments (0)
About PowerShow.com