Chapter 17 Rendering Reactive Animations. Motivation  In the previous chapter we learned just enough about advanced IO and concurrency to develop a “renderer”

Slides:



Advertisements
Similar presentations
Chapter 16 Graphical User Interfaces
Advertisements

Introduction to Macromedia Director 8.5 – Lingo
Pages and boxes Building quick user interfaces. learning objectives o Build a quick UI with pages and boxes o understand how pages and boxes work o click.
Cse536 Functional Programming 1 1/13/2015 Lecture #13, Nov. 08, 2004 Today’s Topics –Simple animations –Buffered graphics –Animations in Haskell –Complex.
Chapter 16 Graphical User Interfaces John Keyser’s Modifications of Slides by Bjarne Stroustrup
Chapter 16 Communicating With the Outside World. Motivation  In Chapter 3 we learned how to do basic IO, but it was fairly limited.  In this chapter.
Chapter 19 An Imperative Robot Language. Motivation  In the previous chapter, monads were introduced.  In particular, state monads were described as.
1 Loops. 2 Often we want to execute a block of code multiple times. Something is always different each time through the block. Typically a variable is.
Chapter 3 Simple Graphics. Side Effects and Haskell  All the programs we have seen so far have no “side-effects.” That is, programs are executed only.
1 9/28/07CS150 Introduction to Computer Science 1 Loops section 5.2, 5.4, 5.7.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Java Software Solutions Foundations of Program Design Sixth Edition by Lewis.
State Diagram. What is State Diagram?  State diagram is used to show the state space of a given class, the events that cause a transition from one state.
Advanced Programming Handout 12 Higher-Order Types (SOE Chapter 18)
Department of Computer Science and Engineering, CUHK 1 Final Year Project 2003/2004 LYU0302 PVCAIS – Personal Video Conference Archives Indexing System.
Chapter 13 A Module of Simple Animations. Motivation  In the abstract, an animation is a continuous, time-varying image.  But in practice, it is a sequence.
Cse502 Functional Programming 1 6/26/2015 Lecture #11, Nov. 4, 2002 Todays Topics –Using Calculation to prove 2 functions are equal »An example from class.
Advanced Programming Handout 10 A Module of Simple Animations (SOE Chapter 13)
Chapter 15 A Module of Reactive Animations. Motivation  The design of animations in Chapter 13 is elegant, and in fact has the feel of a small domain-specific.
Chapter 5 Polymorphic and Higher-Order Functions.
Cse536 Functional Programming 1 6/30/2015 Lecture #16, Nov. 29, 2004 Todays Topics – Files, Channels, and Handles –IO exception handling –First Class Channels.
Cse536 Functional Programming 1 7/16/2015 Lecture #15, Nov. 15, 2004 Todays Topics – Simple Animations - Review –Reactive animations –Vocabulary – Examples.
Sentinel Logic Assumes while loops and input statements.
Transactions and Recovery
Offline Performance Monitoring for Linux Abhishek Shukla.
Study Guide For Test Chapter 5, 6,& 7 Test is Friday, May 15th.
Department of Computer Science and Engineering, CUHK 1 Final Year Project 2003/2004 LYU0302 PVCAIS – Personal Video Conference Archives Indexing System.
Questions as we get started?. Getting Loopy Unplugged Activity (Course 2, Lesson 5) I need a volunteer to come up and follow my directions. I need a second.
REVIEW On Friday we explored Client-Server Applications with Sockets. Servers must create a ServerSocket object on a specific Port #. They then can wait.
Object-Oriented Programming. Object-oriented programming  First goal: Define and describe the objects of the world  Noun-oriented  Focus on the domain.
Basic Controls & Properties Chapter 2. Overview u VB-IDE u Basic Controls  Command Button  Label  Text Box  Picture Box u Program Editor  Setting.
Department of Computer Science and Engineering, CUHK 1 Final Year Project 2003/2004 LYU0302 PVCAIS – Personal VideoConference Archives Indexing System.
The Wait-Until-Event pattern Has it happened  Yes, it happened!
Lecture PowerPoint Slides Basic Practice of Statistics 7 th Edition.
CSCE 121: Introduction to Program Design and Concepts, Honors Dr. J. Michael Moore Spring 2015 Set 15: GUIs 1.
Q and A for Chapter 7 Students of CS104, and me, your benevolent professor, Victor T. Norman, PhD.
Reactive pattern matching for F# Part of “Variations in F#” research project Tomáš Petříček, Charles University in Prague
GUI development with Matlab: GUI Front Panel Components GUI development with Matlab: Other GUI Components 1 Other GUI components In this section, we will.
1 Printing in Python Every program needs to do some output This is usually to the screen (shell window) Later we’ll see graphics windows and external files.
1 Mouse Events See Figure See Example in Figure 11.28,
Interactive computability Episode 13 0 Hard-play machines (HPMs) Easy-play machines (EPMs) Definition of interactive computability The interactive version.
Pigeon Hole Device What does it resemble? What can it do? How could it be improved? Will it ever look familiar? How much ‘memory’ does it have? What kind.
Dictionaries and File I/O George Mason University.
Theory of Computation Automata Theory Dr. Ayman Srour.
C++ for Everyone by Cay Horstmann Copyright © 2012 by John Wiley & Sons. All rights reserved Chapter Eight: Streams Slides by Evan Gallagher.
Test Title Test Content.
Introduction To Repetition The for loop
Console and GUI Programs
In-situ Visualization using VisIt
Content Reading Strategy: Preview
Keyboard Input and Screen Display ––––––––––– Interactive Programming
Tsao, Lin-wei Li, Han-lin Hu, Sun-Bo
Reactive Android Development
Event loops.
Operating Systems Chapter 5: Input/Output Management
Advanced Topics in Concurrency and Reactive Programming
Module 4 Loops.
Event loops 17-Jan-19.
Graphics Animation Using Terrapin LOGO
Evolution of Humans Describe what is going on in this rendering?
CS288 Lab Exercise 2.
Compiling Real-Time Functional Reactive Programming (RT-FRP)
Event loops 8-Apr-19.
Reactive Animations Todays Topics
Event loops.
Types of loops definite loop: A loop that executes a known number of times. Examples: Repeat these statements 10 times. Repeat these statements k times.
Simple Animations Today’s Topics Reading Assignment Simple animations
Event loops.
Event loops 19-Aug-19.
Interactive computability
Presentation transcript:

Chapter 17 Rendering Reactive Animations

Motivation  In the previous chapter we learned just enough about advanced IO and concurrency to develop a “renderer” for FAL.  That renderer is called “reactimate”, and has type: reactimate :: String -> Behavior a -> (a -> IO Graphic) -> IO ()  But first, we need a way to extract an infinite stream of time-stamped user actions from the operating system. We want the values in the stream to be: “Just ua” if there is a user action “ua” present at the time we ask for it, and “Nothing” if there is not.

windowUser  The stream of user actions will be supplied by: windowUser :: Window -> IO (([Maybe UserAction],[Time]), IO ())  Executing the command: ((us,ts), addEvents) <- windowUser w yields a user action stream “us” and a time stream “ts”. also yields an IO action “addEvents” that causes the OS to update “us” with whatever user actions happen to be pending at that time, followed by a “Nothing”.  Note: “addEvents” is an IO action – it does nothing until executed. “reactimate” will call windowUser, process all user actions in “us” until it sees “Nothing”, then execute “addEvents”, and repeat.

Using First-Class Channels  “windowUser” will use first-class channels.  As a helper function, we define: makeStream :: IO ([a], a -> IO ()) makeStream = do ch <- newChan contents <- getChanContents ch return (contents, writeChan ch)  “makeStream” creates a new channel, converts its contents into a stream using “getChannelContents”, and returns that stream along with a function to write into the channel.

Definition of windowUser windowUser :: Window -> IO (([Maybe UserAction],[Time]), IO ()) windowUser w = do (evs, addEv) return () Just e -> do addEv (Just e, rt) loop rt let addEvents = do t <- timeGetTime let rt = w32ToTime (t-t0) loop rt addEv (Nothing, rt) return ((map fst evs, map snd evs), addEvents) w32ToTime t = intToFloat (word32ToInt t) / 1000

Turning Nothing into Something  Recall that the non-occurrence of an event corresponds to a time when we wish to sample the picture. So we need to convert non-occurrences into occurrences: sample :: Event () sample = Event (\(us,_) -> map aux us) where aux Nothing= Just () aux (Just _)= Nothing  Then, for a given FAL program “franProg”, we can describe the individual picture values that we want as an event stream: sample `snapshot_` franProg :: Event Picture  This leads finally to the definition of “reactimate”.

Reactimate reactimate :: String -> Behavior a -> (a -> IO Graphic) -> IO () reactimate title franProg toGraphic = runGraphics $ do w <- openWindowEx title (Just (0,0)) (Just (xWin,yWin)) drawBufferedGraphic (Just 30) (user, addEvents) <- windowUser w addEvents let drawPic (Just p) = do g <- toGraphic p setGraphic w g addEvents getWindowTick w drawPic Nothing = return () mapM_ drawPic (runEvent (sample `snapshot_` franProg) user) runEvent (Event fe) u = fe u