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. ' User graphically shows the initial direction and speed of the ball. ' Control the animation with a while loop. ' 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) ' Animate a shape moving in jumps (dx, dy), bouncing when ' its center reaches the low and high x and y coordinates. ' The animation stops when the mouse is clicked. Dim delay As Integer delay = .001 ' win.clearLastMouse() while win.getLastMouse() = Nothing: 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 or x > xHigh Then dx = -dx End If if y < yLow or y > yHigh Then dy = -dy End If Threading.Thread.Sleep(delay * 1000) End While End Sub Public Function makeDisk(center As Object, radius As Object, win As Object) ' 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 Function getShift(point1 As Object, point2 As Object)' NEW utility function ' Returns a tuple (dx, dy) which is the shift from point1 to point2. Dim dx As Object dx = point2.getX() - point1.getX() Dim dy As Object dy = point2.getY() - point1.getY() Return {dx, dy} End Function Public Function getUserShift(point As Object, prompt As Object, win As Object)'NEW direction selection ' Return the change in position from the point to a mouse click in win. ' First display the prompt string under point. Dim text As New Label text.Left = p2vbW * ((point.getX()) / (p2vbX2 - p2vbX1)) text.Top = p2vbH - (p2vbH * (( 60) / (p2vbY2 - p2vbY1))) text.Text = prompt text.AutoSize = True Form1.Controls.Add(text) Dim userPt As Object Return getShift(point, userPt) End Function Public Sub bounceBall() ' Make a ball bounce around the screen. The user sets the initial speed. Dim winWidth As Integer winWidth = 290 Dim winHeight As Integer winHeight = 290 Form1.Text = "Ball Bounce" 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 of 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 = New Point(winWidth/2, winHeight/2) 'NEW central starting point Dim ball As Integer ball = makeDisk(center, radius, win) 'NEW interactive direction and speed setting Dim prompt As String prompt = "Click to indicate the direction and" + vbNewLine + "speed of the ball: The further you" + vbNewLine + "click from the ball, the faster it starts." Dim Python2VBArray(,) as Object Dim dx As Object Dim dy As Object Python2VBArray(dx, dy) = getUserShift(center, prompt, win) Dim scale As Integer scale = 0.01 ' to reduce the size of animation steps bounceInBox(ball, dx*scale, dy*scale, xLow, xHigh, yLow, yHigh, win) End Sub Public Sub Routine2 bounceBall() End Sub