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 ' Test animation of a group of objects making a face. ' Combine the face elements in a function, and use it twice. ' Have an extra level of repetition in the animation. ' ' from graphics import * ' import time Public Sub moveAll(shapeList As Object, dx As Object, dy As Object) ' Move all shapes in shapeList by (dx, dy). for shape= 0 To shapeList.Length - 1 shapeList(shape).X = shapeList(shape).X + dx shapeList(shape).Y = shapeList(shape).Y + dy Next End Sub Public Sub moveAllOnLine(shapeList As Object, dx As Object, dy As Object, repetitions As Object, delay As Object) ' Animate the shapes in shapeList along a line. ' Move by (dx, dy) each time. ' Repeat the specified number of repetitions. ' Have the specified delay (in seconds) after each repeat. ' for i = 0 To repetitions - 1 moveAll(shapeList, dx, dy) Threading.Thread.Sleep(delay * 1000) Next End Sub Public Function makeFace(center As Point, win As Object) ' display face centered at center in window win. ' Return a list of the shapes in the face. ' Dim head As RectangleF formGraphics = Form1.CreateGraphics() myPen = New Pen(Drawing.Color.Black, 1) head.X = center.X head.Y = center.Y head.Width = 25 head.Height = 25 formGraphics.DrawEllipse(myPen, head) myBrush = New System.Drawing.SolidBrush(System.Drawing.Color.yellow) formGraphics.FillEllipse(myBrush, head) Dim eye1Center As Point eye1Center = center ' face positions are relative to the center eye1Center.X = eye1Center.X + -10 eye1Center.Y = eye1Center.Y + 5 ' locate further points in relation to others Dim eye1 As RectangleF myPen = New Pen(Drawing.Color.Black, 1) eye1.X = eye1Center.X eye1.Y = eye1Center.Y eye1.Width = 5 eye1.Height = 5 formGraphics.DrawEllipse(myPen, eye1) myBrush = New System.Drawing.SolidBrush(System.Drawing.Color.blue) formGraphics.FillEllipse(myBrush, eye1) Dim eye2End1 As Point eye2End1 = eye1Center eye2End1.X = eye2End1.X + 15 eye2End1.Y = eye2End1.Y + 0 Dim eye2End2 As Point eye2End2 = eye2End1 eye2End2.X = eye2End2.X + 10 eye2End2.Y = eye2End2.Y + 0 Dim eye2 As Integer myPen = New Pen(Drawing.Color.Black, 3) formGraphics.DrawLine(myPen, eye2End1.X, eye2End1.Y, eye2End2.X, eye2End2.Y) Dim mouthCorner1 As Point mouthCorner1 = center mouthCorner1.X = mouthCorner1.X + -10 mouthCorner1.Y = mouthCorner1.Y + -10 Dim mouthCorner2 As Point mouthCorner2 = mouthCorner1 mouthCorner2.X = mouthCorner2.X + 20 mouthCorner2.Y = mouthCorner2.Y + -5 Dim mouth As Rectangle mouth = New Rectangle(mouthCorner1, mouthCorner2) myPen = New Pen(Drawing.Color.Black, 1) formGraphics.DrawEllipse(myPen, mouth) myBrush = New System.Drawing.SolidBrush(System.Drawing.Color.red) formGraphics.FillEllipse(myBrush, mouth) Return New List(Of Object)({head, eye1, eye2, mouth}) End Function Public Sub main() Dim winWidth As Integer winWidth = 300 Dim winHeight As Integer winHeight = 300 Dim win As Integer Form1.Text = "Back and Forth" Form1.Width = winWidth + 100 p2vbW = winWidth Form1.Height = winHeight + 100 p2vbH = winHeight p2vbX1 = 0 p2vbY1 = 0 p2vbX2 = winWidth p2vbY2 = winHeight ' make right side up coordinates! Dim rect As Rectangle rect = New Rectangle(New Point(200, 90), New Point(220, 100)) myPen = New Pen(Drawing.Color.Black, 1) formGraphics.DrawRectangle(myPen, rect) myBrush = New System.Drawing.SolidBrush(System.Drawing.Color.blue) formGraphics.FillRectangle(myBrush, New Rectangle(200, 90, 220, 100)) Dim faceList As Integer faceList = makeFace(New Point(40, 100), win) Dim faceList2 As Integer faceList2 = makeFace(New Point(150,125), win) Dim stepsAcross As Integer stepsAcross = 46 Dim dx As Integer dx = 5 Dim dy As Integer dy = 3 Dim wait As Integer wait = .05 for i = 0 To 2 moveAllOnLine(faceList, dx, 0, stepsAcross, wait) moveAllOnLine(faceList, -dx, dy, stepsAcross/2, wait) moveAllOnLine(faceList, -dx, -dy, stepsAcross/2, wait) Next Dim Control1 As New Label Control1.Left = p2vbW * ((winWidth/2) / (p2vbX2 - p2vbX1)) Control1.Top = p2vbH - (p2vbH * (( 20) / (p2vbY2 - p2vbY1))) Control1.Text = "Click anywhere to quit." Control1.AutoSize = True Form1.Controls.Add(Control1) End Sub 'main()