1 / 11

Events and interactivity

Events and interactivity. IP 10 Mr. Mellesmoen 2014. How are events useful?. So far all we have create some interactive programs, but nothing too fancy….yet. Today we will learn about events and interactivity. Looking at a simple program first. Try this:

van
Download Presentation

Events and interactivity

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Events and interactivity IP 10 Mr. Mellesmoen 2014

  2. How are events useful? So far all we have create some interactive programs, but nothing too fancy….yet. Today we will learn about events and interactivity

  3. Looking at a simple program first Try this: Graphics.Window.MouseDown = OnMouseDown Sub OnMouseDown GraphicsWindow.ShowMessage(“You Clicked.”, “Hello”) EndSub

  4. Clicking So that was pretty basic, whenever you clicked on the graphic window you got your message. Let’s try something else…see the next slide…

  5. A bunch of dots GraphicsWindow.BrushColor="Blue" GraphicsWindow.MouseDown= OnMouseDown Sub OnMouseDown x= GraphicsWindow.mouseX-10 y= GraphicsWindow.mouseY-10 GraphicsWindow.FillEllipse(x, y, 20, 20) EndSub Try changing SHAPES (I.E. Fillrectangle)

  6. Multiple events You can create subroutines in this program that will change what a program does if the user performs a specific action. The next program illustrates this by using Key Strokes.

  7. Random colors GraphicsWindow.BrushColor="Red" GraphicsWindow.MouseDown= OnMouseDown GraphicsWindow.KeyDown = OnKeyDown Sub OnKeyDown GraphicsWindow.BrushColor=GraphicsWindow.GetRandomColor() EndSub Sub OnMouseDown x= GraphicsWindow.MouseX-10 y= GraphicsWindow.MouseY-10 GraphicsWindow.FillEllipse(x, y, 20, 20) EndSub

  8. A paint program Now we can create a program that allows the user to draw with the mouse in the graphics window. On the next slide is the information you need

  9. A paint program GraphicsWindow.MouseMove = OnMouseMove Sub OnMouseMove x = GraphicsWindow.MouseX y = GraphicsWindow.MouseY GraphicsWindow.DrawLine (prevX, prevY, x, y) prevX = x prevY = y EndSub

  10. Did you notice… Every time you run the program your drawing starts in the top left corner (0, 0) You should have also noticed that you just need to move the mouse and really can’t ever stop drawing. Adding a MouseDown and IsLeftButtonDown property will fix this up. See next slide…

  11. A better paint program GraphicsWindow.MouseMove = OnMouseMove GraphicsWindow.MouseDown= OnMouseDown Sub OnMouseDown PrevX = GraphicsWindow.MouseX PrevY= GraphicsWindow.MouseY EndSub Sub OnMouseMove x = GraphicsWindow.MouseX y = GraphicsWindow.MouseY If (Mouse.IsLeftButtonDown) Then GraphicsWindow.DrawLine (prevX, prevY, x, y) EndIf prevX = x prevY = y EndSub

More Related