Private myPen as Pen Private formGraphics As System.Drawing.Graphics Private myBrush As System.Drawing.SolidBrush Private p2vbW As Integer Private p2vbH As Integer Private p2vbX1 As Integer Private p2vbY1 As Integer Private p2vbX2 As Integer Private p2vbY2 As Integer ' ' Show a ball bouncing off the sides of the window,stoping when the mouse is clicked. ' ' from graphics import * ' import time, random Public Sub bounceInBox(shape As Object, dx As Object, dy As Object, xLow As Object, xHigh As Object, yLow As Object, yHigh As Object, win As Object)'NEW add wi ' Animate a shape moving in jumps (dx, dy), bouncing when ' its center reaches the low and high x and y coordinates,stopping at the first mouseclick in win. ' Dim delay As Integer delay = .005 ' win.clearLastMouse() 'NEW while win.getLastMouse() = Nothing: 'NEW shape.X = shape.X + dx shape.Y = shape.Y + dy Dim center As Object center = shape.getCenter() Dim x As Integer x = center.getX() Dim y As Integer y = center.getY() if x < xLow Then dx = -dx ElseIf x > xHigh Then dx = -dx End If if y < yLow Then dy = -dy ElseIf y > yHigh Then dy = -dy End If Threading.Thread.Sleep(delay * 1000) End While End Sub Public Function getRandomPoint(xLow As Object, xHigh As Object, yLow As Object, yHigh As Object)'NEW add wi ' Return a random Point with coordinates in the range specified. Dim x As Integer x = Int(Rnd * (xHigh+1 - xLow) + xLow) Dim y As Integer y = Int(Rnd * (yHigh+1 - yLow) + yLow) Return New Point(x, y) End Function Public Function makeDisk(center As Object, radius As Object, win As Object)'NEW add wi ' Return a red disk that is drawn in win with given center and radius. Dim disk As RectangleF formGraphics = Form1.CreateGraphics() myPen = New Pen(System.Drawing.Color.red, 1) disk.X = center.X disk.Y = center.Y disk.Width = radius disk.Height = radius formGraphics.DrawEllipse(myPen, disk) myBrush = New System.Drawing.SolidBrush(System.Drawing.Color.red) formGraphics.FillEllipse(myBrush, disk) Return disk End Function Public Sub bounceBall(dx As Integer, dy As Integer)'NEW add wi ' Make a ball bounce around the screen, initially moving by (dx, dy) ' at each jump. Dim winWidth As Integer winWidth = 290 Dim winHeight As Integer winHeight = 290 Dim win As Integer Form1.Text = "Ball Bounce - Click to stop" Form1.Width = winWidth + 100 p2vbW = winWidth Form1.Height = winHeight + 100 p2vbH = winHeight p2vbX1 = 0 p2vbY1 = 0 p2vbX2 = winWidth p2vbY2 = winHeight Dim radius As Integer radius = 10 Dim xLow As Integer xLow = radius ' center is separated from the wall by the radius at a bounce Dim xHigh As Integer xHigh = winWidth - radius Dim yLow As Integer yLow = radius Dim yHigh As Integer yHigh = winHeight - radius Dim center As Point center = getRandomPoint(xLow, xHigh, yLow, yHigh) Dim ball As Integer ball = makeDisk(center, radius, win) bounceInBox(ball, dx, dy, xLow, xHigh, yLow, yHigh, win) 'NEW add win End Sub Public Sub Routine2 bounceBall(2, 3) End Sub