Part 19. big-bang
We are using Dr. Racket to design interactive programs, from this day forward, this is going to be very complicated.
Imagine we have 2 interactive programs, one that counts down from 10 to 0 and some animation of a cat walking in the screen.
These programs are interactive by just pressing the space key, the program restarts.
These interactive programs change state and it affects the program behavior.
On the countdown program, it generates a number from 10 to 0 every 1 second. It is also the same with the cat program, it just changes the x coordinate of the cat every miliseconds.
These are 2 different functions, now how can we combine these 2 functions.
We combine them by using Dr. Rackets big-bang primitive.
(big-bang 0
(on-tick next-cat)
(to-draw render-cat))
We use 0 as the initial world state, then on every tick, we get the next x coordinate, we pass it to the render cat which redraws the cat's x coordinates to the new one.
We can use this to make more complex programs and help us to integrate 2 or more functions into one cohesive unit.
These are 2 different functions, now how can we combine these 2 functions.
We combine them by using Dr. Rackets big-bang primitive.
(big-bang 0
(on-tick next-cat)
(to-draw render-cat))
We use 0 as the initial world state, then on every tick, we get the next x coordinate, we pass it to the render cat which redraws the cat's x coordinates to the new one.
We can use this to make more complex programs and help us to integrate 2 or more functions into one cohesive unit.
Mga Komento
Mag-post ng isang Komento