Monkeybone: The Line instruction

There are two alternative ways to use the Line instruction in a Monkeybone image (a text file with .mob ending). You can either use named arguments or a list of coordinates. This example demonstrates both alternatives. The first V symbol is drawn using named arguments, the rest of the symbols are drawn using coordinate lists.

Clear 290x200 #a0a0a0
//Draw a V symbol using named arguments.
Line #000000 X1:10 Y1:10 X2:40 Y2:190
Line #000000 X1:40 Y1:190 X2:70 Y2:10
//Draw a V symbol using a polyline.
Line #000000 (80,10) (110,190) (140,10)
//A closed triangle.
Line #000000 (150,10) (180,190) (210,10) AutoClose
//A filled triangle.
Line #000000 (220,10) (250,190) (280,10) Filled

If you are using the Monkeybone .NET library, this code is used to produce a .mob file that contains one simple line and a polyline. To view the picture, open the output file in Monkeybone Viewer. The code requires a reference to the Monkeybone.dll.

Using Sw As New Monkeybone.MonkeyboneWriter("C:\Lines.mob", 200, 200, Drawing.Color.White)

   'Create a line by passing X1, Y1, X2 and Y2 to the constructor of the Line class.
   Dim SimpleLine As New Monkeybone.Instructions.Line(10, 190, 190, 190)
   SimpleLine.Color = Drawing.Color.Black

   'Create a line by passing an array of coordinates to the constructor.
   Dim Points() As System.Drawing.Point = {New System.Drawing.Point(20, 20), _
      New System.Drawing.Point(180, 20), _
      New System.Drawing.Point(180, 180)}
   Dim PolyLine As New Monkeybone.Instructions.Line(Points)
   PolyLine.Color = Drawing.Color.Red

End Using

Finally, if you are using the Monkeybox control (named MBox1 in the example below) to display graphics directly on the screen, the following code displays one simple line on screen, together with the Monkeybone source code in a message box.

'Set the background color.
MBox1.BackColor = Color.White

'Add a red line to the monkeybox.
MBox1.AddLine(Color.Red, 10, 10, 90, 90)

'Redraw is not trigged by adding and instruction.

'Display the source code.

Leave a Reply

Your email address will not be published. Required fields are marked *