Startsidan  ▸  Texter  ▸  Teknikblogg

Anders Hesselbom

Programmerare, skeptiker, sekulärhumanist, antirasist.
Författare till bok om C64 och senbliven lantis.
Röstar pirat.

Monkeybone: The Spline instruction


Using notepad
The Spline instruction has syntax similar to the Line instruction when named arguments are used, but each value has a magnet attached to it. The line will bend to the magnet. This will draw a red line on a black image, from the upper left to the lower right:

Line #ff0000 X1:0 Y1:0 X2:200 Y2:200

This will draw a green line, also from the upper left to the lower right, but it will be bent, like an S (but mirrored).

Spline #00ff00 X1:0+100 Y1:0+0 X2:200-100 Y2:200+0

Not how X1 has its value set to 0 and its magnet set to +100. This means that the curve will bend off 100 pixels to the left. Note that I don’t want to use the magnet on Y1, so I just add +0. I want X2 to bend 100 pixels to the left, so -100 is added.

This is a working example:

//Create a black picture.
Clear 200x200 #000000

//Set line thikness.
Set Line Thikness To 3

//Draw a red line.
Line #ff0000 X1:0 Y1:0 X2:200 Y2:200

//Draw a green spline.
Spline #00ff00 X1:0+100 Y1:0+0 X2:200-100 Y2:200+0

And this is the result:

Using the .NET library
If you are using the .NET library, this Visual Basic code below, the output will be a .MOB file with exactly the same image. This requires a reference to Monkeybone.dll.

Dim OutputPath As String = System.IO.Path.Combine( _
   System.Environment.GetFolderPath(Environment.SpecialFolder.Desktop), _
Using Sw As New Monkeybone.MonkeyboneWriter(OutputPath, 200, 200, _

   'Set line thikness to 3.

   'Draw a red line across the picture.
   Dim Line As New Monkeybone.Instructions.Line(0, 0, 200, 200)
   Line.Color = System.Drawing.Color.FromArgb(255, 0, 0)

   'Draw a green spline
   Dim Spline As New Monkeybone.Instructions.Spline(0, 100, 0, 0, 200, _
      -100, 200, 0)
   Spline.Color = System.Drawing.Color.FromArgb(0, 255, 0)

End Using

Using the Monkeybox control
The Monkeybox control (resides in Monkeybox.dll) is capable of displaying the image on screen and exporting the image to a .MOB file. Given that you are writing a Windows Forms application in Visual Basic, and you have a Monkeybox control named MBox1 on your form, this code will produce the exact same image as shown above:

Private Sub Form1_Shown(ByVal sender As Object, ByVal e As System.EventArgs) _
   Handles Me.Shown
   'Size is normaly set in the designer, but here I set it manually.
   MBox1.Width = 200
   MBox1.Height = 200

   'Set the background color and the line thikness.
   MBox1.BackColor = Color.Black

   'Draw a red line.
   MBox1.AddLine(Color.FromArgb(255, 0, 0), 0, 0, 200, 200)

   'Draw a green spline.
   MBox1.AddSpline(Color.FromArgb(0, 255, 0), 0, 100, 0, 0, 200, -100, 200, 0)

   'Redraw is not trigged by adding and instruction.
End Sub

Categories: Programs

Tags: Monkeybone

Leave a Reply

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

En kopp kaffe!

Bjud mig på en kopp kaffe (20:-) som tack för bra innehåll!

Bjud på en kopp kaffe!


Kontaktuppgifter, med mera, finns här.

Följ mig

Twitter Instagram
GitHub RSS

Public Service

Folkbildning om public service.

Hem   |   |   |   |   Filmtips