Private myBrush As System.Drawing.SolidBrush Private formGraphics As System.Drawing.Graphics Private p2vbW As Integer Private p2vbH As Integer Private p2vbX1 As Integer Private p2vbY1 As Integer Private p2vbX2 As Integer Private p2vbY2 As Integer Private myPen as Pen ' Make a choice of colors via mouse clicks in Rectangles -- ' Demonstate loops using lists of tuples of data. ' from graphics import * Public Function isBetween(x As Object, end1 As Object, end2 As Object) ' Return True if x is between the ends or equal to either. ' The ends do not need to be in increasing order. Return end1 <= x <= end2 or end2 <= x <= end1 End Function Public Function isInside(point As Object, rect As Object) ' Return True if the point is inside the Rectangle rect. Dim pt1 As Object pt1 = rect.getP1() Dim pt2 As Object pt2 = rect.getP2() Return isBetween(point.getX(), pt1.getX(), pt2.getX()) and isBetween(point.getY(), pt1.getY(), pt2.getY()) End Function Public Function makeColoredRect(corner As Point, width As Integer, height As Integer, color As String, win As Object) ' Return a Rectangle drawn in win with the upper left corner ' and color specified. Dim corner2 As Point corner2 = corner corner2.X = corner2.X + width corner2.Y = corner2.Y + -height Dim rect As Rectangle rect = New Rectangle(corner, corner2) myBrush = New System.Drawing.SolidBrush(System.Drawing.Color.FromName(color)) formGraphics = Form1.CreateGraphics() formGraphics.FillRectangle(myBrush, rect) Return rect End Function Public Function getChoice(choicePairs As Object, default2 As String, win As Object)'NEW ' Given a list choicePairs of tuples with each tuple in the form ' (rectangle, choice), Return the choice that goes with the rectangle ' in win where the mouse gets clicked, or Return default if the click ' is in Nothing of the rectangles. Dim Python2VBArray1(,) As Object Dim rectangle As Object Dim choice As Object for Python2VBArray1(rectangle, choice)=0 To choicePairs.Length - 1 Dim point As Object if isInside(point, rectangle) Then Return choice End If Next Return default2 End Function Public Sub main() Dim winWidth As Integer winWidth = 400 Dim winHeight As Integer winHeight = 400 Form1.Text = "pick Colors" Form1.Width = winWidth + 100 p2vbW = winWidth Form1.Height = winHeight + 100 p2vbH = winHeight p2vbX1 = 0 p2vbY1 = 0 p2vbX2 = winWidth p2vbY2 = winHeight 'NEW Dim choicePairs As List(Of Object) choicePairs = New List(Of Object) Dim buttonSetup As Object buttonSetup = {{310, 350, "red"}, {310, 310, "yellow"}, {310, 270, "blue"}} Dim Python2VBArray2(,,) As Object Dim x As Object Dim y As Object Dim color As Object Dim house As Integer Dim win As Object Dim button As Integer for Python2VBArray2(x, y, color)=0 To buttonSetup.Length - 1 button = makeColoredRect(New Point(x, y), 80, 30, color, win) choicePairs.add({button, buttonSetup(color)}) Next house = makeColoredRect(New Point(60, 200), 180, 150, "gray", win) Dim door As Integer door = makeColoredRect(New Point(90, 150), 40, 100, "white", win) Dim roof As Point() = {New Point(50, 200), New Point(250, 200), New Point(150, 300)} myPen = New Pen(Drawing.Color.Black, 1) formGraphics.DrawPolygon(myPen, roof) myBrush = New System.Drawing.SolidBrush(System.Drawing.Color.black) formGraphics.FillPolygon(myBrush, roof) 'NEW Dim shapePairs As Object shapePairs = {{house, "house"}, {door, "door"}, {roof, "roof"}} Dim msg As New Label msg.Left = p2vbW * ((winWidth/2) / (p2vbX2 - p2vbX1)) msg.Top = p2vbH - (p2vbH * (( 375) / (p2vbY2 - p2vbY1))) msg.Text = "" msg.AutoSize = True Form1.Controls.Add(msg) Dim Python2VBArray1(,) As Object Dim shape As Object Dim description As Object Dim prompt As String for Python2VBArray1(shape, description)=0 To shapePairs.Length - 1 prompt = "Click to choose a " + (description).toString + " color." msg.Text = prompt color = getChoice(choicePairs, "white", win) shape.setFill(color) Next msg.Text = "Click anywhere to quit." End Sub 'main()