Tag: Monkeybone

  • Drawing a HTML5 heart with Monkeybone

    This demonstration shows how you can create a Monkeybone picture from scratch and to export it as a HTML5 vector image. The required software is Monkeybone Viewer version 1.5 or later.

    Step 1: Create the file. To do this in Windows, you must make sure that you can see the file ending of known file types. Right click on an empty area on your desktop, create a text file, change the file ending from .txt to .mob. Start Notepad and drag the file to Notepad.

    Another way to accomplish this, is to start Notepad, click File and Save as, change to “All files” in the filter box, and finally, type in a file name with a .mob ending. Click the Save button.

    Step 2: Initialize the picture and open it in the Monkeybone Viewer. Enter a Clear instruction as the first line in the text file. The Clear instruction will specify the image background color and the size of the image. I will make it 300 x 300 pixels and pink. This is the source:

    Clear 300x300 #ff9999

    Save it using Notepad, drag it from the desktop to the Monkeybone Viewer (version 1.5 or later). Now you should see a pink square 300 pixels wide and 300 pixels high in the viewer.

    Step 3: Define the heart. Add Spline instructions to your document. You can re-save it in Notepad, switch to the viewer and press Ctrl+Shift+F5 to make the changes appear. Adjust your code and repeat until you are satisfied. This is my code (including the first Clear instruction):

    Clear 300x300 #ff9999
    Spline #ff0000 X1:150-100 Y1:50-100 X2:10+0 Y2:70-10
    Spline #ff0000 X1:10-20 Y1:70+60 X2:150+10 Y2:290+0
    Spline #ff0000 X1:150+100 Y1:50-100 X2:290+0 Y2:70-10
    Spline #ff0000 X1:290+20 Y1:70+60 X2:150-10 Y2:290+0

    Step 4: Export the picture. In Monkeybone Viewer, click File and Save as. Change the format to HTML5. Click the Save button. To view, double click the HTML file to open it in your default browser or drag it to a open web browser. If you are using Internet Explorer, version 9 or later is required. This is the result:

    Download the Monkeybone Viewer from this page.

  • Monkeybone Viewer 1.4

    The Monkeybone Viewer (1.4) has improved HTML5 export support and a new slideshow feature. The slideshow can display png, mob and jpg images in a specific folder.

    Download link on this page.

  • Export HTML5 Canvas images

    The latest addition to the Monkeybone Viewer (1.3) is the ability to save images as HTML5 Canvas images. This feature is not working perfect yet – there are still features that the Monkeybone image format can render, but not export correct. This feature should be correct in the next release.

    Download link on this page.

  • 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), _
       "Spline.mob")
    Using Sw As New Monkeybone.MonkeyboneWriter(OutputPath, 200, 200, _
       Drawing.Color.Black)
    
       'Set line thikness to 3.
       Sw.WriteLineThikness(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)
       Sw.WriteLine(Line)
    
       '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)
       Sw.WriteLine(Spline)
    
    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
       MBox1.SetLineThikness(3)
    
       '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.
       MBox1.Invalidate()
    End Sub
  • 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
       Sw.WriteLine(SimpleLine)
    
       '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
       Sw.WriteLine(PolyLine)
    
    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.
    MBox1.Invalidate()
    
    'Display the source code.
    MessageBox.Show(MBox1.GetSource())

  • Monkeybone Viewer improvements, March 2010

    The Monkeybone file format is frozen and a description of the format is added to the Help menu. Direct download.

  • Monkeybone: The Bar instruction

    The Bar instruction, as it appears in a Monkeybone Image (a text file with .mob ending) is a line with at least five parameters. The color of the bar, the X and Y position of the bar, the width and height of the bar. The following lines in a .mob file creates a green rectangular image with a centered yellow box in it:

    Clear 200x200 #337733
    Bar #ffff00 X:50 Y:50 W:100 H:100

    Optionally, you can set the percentage of the fill in either horizontal or vertical direction using HFill or VFill, followed by a percent value. The following code will give a 50 pixel high box. The specified height is 100 (pixels) but VFill:50% tells Monkeybone Viewer to only display half height of the box:

    Clear 200x200 #337733
    Bar #ffff00 X:50 Y:50 W:100 H:100 VFill:50%

    One way of producing an image like this, is to use Notepad to create a text file that ends with .mob instead of .txt. Using Notepad is not the easiest way, and rather impossible if you want to generate dynamic images. For dynamically generate Monkeybone Images, the Monkeybone .NET library or the Monkeybone .NET control can be used.

    The Monkeybone .NET library is a class library that contains a writer with the capability of streaming Monkeybone instructions to a file. The following Visual Basic code requires a reference to Monkeybone.dll, and produces a file called “Bars.mob” that can be opened using the Monkeybone Viewer.

    Using Sw As New Monkeybone.MonkeyboneWriter("C:\Bars.mob", 200, 200, _
          System.Drawing.Color.FromArgb(51, 119, 51))
       Dim Bar As New Monkeybone.Instructions.Bar(50, 50, 100, 100)
       Bar.BarFillPercent = 50
       Bar.Color = System.Drawing.Color.FromArgb(255, 255, 0)
       Bar.Orientation = Monkeybone.Instructions.Bar.BarOrientation.Vertical
       Sw.WriteLine(Bar)
    End Using

    If you want your image to display on a form, you can use the Monkeybox control. The Monkeybox control displays your image directly on screen, with an option to save it as a .mob file that can be opened in Monkeybone Viewer. The following code is written in the Shown event of a form that has a Monkeybox control on it, called MBox1. Here, I do not actually save the image, just displays the source in a messagebox. The messagebox will contain exactly the same two instructions as the last example produces. Also, on the screen, you will see a green Monkeybone image with a yellow box in it.

    Public Class Form1
    
        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.
            MBox1.BackColor = System.Drawing.Color.FromArgb(51, 119, 51)
    
            'Add a bar.
            MBox1.AddBar(Color.FromArgb(255, 255, 0), 50, 50, 100, 100, 50, _
               Monkeybox.Bar.BarOrientation.Vertical)
    
            'Redraw is not trigged by adding and instruction.
            MBox1.Invalidate()
    
            MessageBox.Show(MBox1.GetSource())
        End Sub
    
    End Class

  • Tint, Noise and Blur

    This image simply demonstrates the filters that are available in Monkeybone. Tint overlays a color, Noise adds noise to the image and Blur decreases focus. This is the content of the .mob file:

    //Initialize the image.
    Clear 400x300 #707070
    
    //Draw a background.
    Bar #4477ff X:0 Y:150 W:400 H:150
    Set Line Thikness To 3
    Line #ffff00 (0,0) (400,300)
    Set Line Thikness To 2
    Line #000000 (0,150) (400,150)
    
    //Show off the filters tint, noise and blur.
    
    //Show tint.
    Region (10,10) (30,10) (30,290) (10,290)
    Tint O:50% #00ffff
    //Outline it.
    Line #000000 Region
    
    //Show noise.
    Region (40,10) (60,10) (60,290) (40,290)
    Noise O:20%
    //Outline it.
    Line #000000 Region
    
    //Show blur.
    Region (70,10) (90,10) (90,290) (70,290)
    Blur
    //Outline it.
    Line #000000 Region
    
    //Type out what filters are used.
    Text X:14 Y:272 #ffffff "A"
    Text X:44 Y:272 #ffffff "B"
    Text X:74 Y:272 #ffffff "C"
    Text X:140 Y:40 #ffffff "A: Tint cyan 50%"
    Text X:140 Y:60 #ffffff "B: Noise monochrome 20%"
    Text X:140 Y:80 #ffffff "C: Blur"

    This is the result:

  • Doing filters in Monkeybone

    The filters in Monkeybone rely on regions to know what area on the image they apply to. The following lines define a picture 400 pixels wide and 300 pixels with black background. Also, it defines an invisible region.

    Clear 400x300 #000000
    Region (10,10) (200,10) (200,200) (250,250) (60,250) (10,200)

    The Tint filter takes only arguments: The color and the opacity. Opacity can be given as an integer between 0 and 255 where 0 is completely transparent and 255 is completely solid, but it can also be given as a percent value. This adds some purple color to the region with opacity of 100:

    Tint #ff00ff O:100

    These two lines move the region 10 pixels to the right, and fill the region with solid purple color. O:100% gives a solid fill, but O:100 gives an opacity that is less than 50%.

    Region (20,10) (210,10) (210,200) (260,250) (70,250) (20,200)
    Tint #ff00ff O:100%

    Finally, these two lines move the region another 10 pixels to the right, and fill the region with blue color, with 50% opacity. An opacity of 50% can be written as O:127 or O:50%.

    Region (30,10) (220,10) (220,200) (270,250) (80,250) (30,200)
    Tint #0000ff O:50%

    To try this out, create a text file, change the file ending to .mob, and insert these lines:

    Clear 400x300 #000000
    Region (10,10) (200,10) (200,200) (250,250) (60,250) (10,200)
    Tint #ff00ff O:100
    Region (20,10) (210,10) (210,200) (260,250) (70,250) (20,200)
    Tint #ff00ff O:100%
    Region (30,10) (220,10) (220,200) (270,250) (80,250) (30,200)
    Tint #0000ff O:50%

    When you open the file in the Monkeybone viewer, this is the result:

    The Monkeybone viewer is available for download on this page.

  • Using regions

    Regions are used to define a path or an area for later use. The Region instruction takes any number of coordinates (3 or more), and stores them in memory. The region can then be used for drawing. The following example is done in Notepad. I have created a text-file, changed the file ending from .txt to .mob. In the file, I have added these three lines of text:

    Clear #ffffff 70x70
    Region (10,10) (60,10) (60,60) (10,60)
    Line Region #ff00ff

    When loaded in the Monkeybone viewer, this is the result:

    When regions are created using the MonkeyboneWriter class, they are much easier to manipulate. This example defines a shape, writes it, manipulates it, and writes it again.

    Module Module1
    
        Sub Main()
    
            'Create a Monkeybone stream.
            Using W As New Monkeybone.MonkeyboneWriter("C:\regions.mob", 130, 130,
                System.Drawing.Color.Black)
    
                'Define a region.
                Dim R As New Monkeybone.Instructions.Region()
                R.AddPoint(10, 110)
                R.AddPoint(60, 10)
                R.AddPoint(110, 110)
    
                'Write the region to the stream.
                W.WriteLine(R)
    
                'Write an instruction to draw the region outline in green.
                Dim L As New Monkeybone.Instructions.Line()
                L.Color = Drawing.Color.Lime
                L.UseRegion = True
                W.WriteLine(L)
    
                'Modify the region (move it 10 pixels to the
                   left and 10 pixels down) and write it again.
                R.Move(10, 10)
                W.WriteLine(R)
    
                'Write an instruction to draw the region outline in yellow.
                L.Color = Drawing.Color.Yellow
                W.Write(L)
    
                'Flush and close the stream.
                W.Flush()
                W.Close()
            End Using
    
        End Sub
    
    End Module

    The code produces the following mob file:

    Clear #000000 130x130
    Region (10,110) (60,10) (110,110)
    Line Region #00FF00
    Region (20,120) (70,20) (120,120)
    Line Region #FFFF00

    This is the result when it is loaded into the Monkeybone viewer:

  • Some changes made to the viewer

    Some changes are made to the Monkeybone viewer, that is not related to the Monkeybone format (*.mob files). These changes are made just to make the viewer more decent.

    Not only Monkeybone images can be opened. Now, you can open PNG and JPG files as well. Features such as viewing the error log, viewing the source or saving, is only available when a Monkeybone image is loaded.

    When an image is loaded, no matter if it is a Monekybone image or not, the viewer checks the directory for other images. You can use the file menu to load the next or previous image in the folder, or just press F11 for the previous image and F12 for the next.

    Again, these changes are made just to make viewing easier. The Monkeybone viewer is designed to display Monkeybone images. If you are in to serious image viewing, I recommend IrfanView instead. But if you are looking for a viewer of the powerful and editable Monkeybone fomat, the Monkeybone viewer is it.

  • The Monkeybone writer

    The Monkeybone Viewer takes a mob file and displays its content on screen. The file stores instructions, such as Bar and Line, as Unicode text. These files can be created by hand using any text editor, such as Notepad (shown here, here, here and here).

    To automate the generation of the Monkeybone file, you can write a program that creates a file with instructions (with mob as file ending), and writes the instructions to that file. If you do this using the .NET Framework, you might create a StreamWriter and write lines of text to that writer.

    To ensure that the output file is formatted the correct way, and to make this process easier, you can download and use the Monkeybone library that contains the MonkeyboneWriter class. The MonkeyboneWriter class inherits from the StreamWriter class, and it provides overloads of the WriteLine function that takes objects that represent Monkeybone instructions. To make a Bar instruction appear in the file, create a Monkeybone.MonkeyboneWriter object, create a Monkeybone.Bar object and set the properties of the object. Pass the Monkeybone.Bar object to the WriteLine function of the Monkeybone.MonkeyboneWriter object. To make another Bar instruction appear in the file, you can create a new Bar object or modify the Bar object you already have, and pass it to the WriteLine function again, like so:

    Module Module1
    
        Sub Main()
    
            'Create a Monkeybone stream.
            Using W As New Monkeybone.MonkeyboneWriter("C:\mypicture.mob", _
                200, 170, System.Drawing.Color.Black)
    
                'Create a vertical Monkeybone bar.
                Dim B As New Monkeybone.Instructions.Bar(10, 10, 20, 100)
                B.Orientation = Monkeybone.Instructions.Bar.BarOrientation.Vertical
                B.Color = Drawing.Color.Red
    
                'Write the bar to the stream.
                W.WriteLine(B)
    
                'Modify it, and write it again.
                B.X += 10
                B.Y += 20
                B.Color = Drawing.Color.Yellow
                W.WriteLine(B)
    
                'Modify it, and write it again.
                B.X += 10
                B.Y += 20
                B.Color = Drawing.Color.Green
                W.WriteLine(B)
    
                'A nice sine effect on top of everything!
                Dim SineBar As New Monkeybone.Instructions.Bar(0, 5, 1, 160, Drawing.Color.White)
                SineBar.Orientation = Monkeybone.Instructions.Bar.BarOrientation.Vertical
                For I As Integer = 0 To 31
                    SineBar.X += 6
                    SineBar.BarFillPercent = 60 + CType((Math.Sin(I / 5) * 40), Integer)
                    W.WriteLine(SineBar)
                Next
    
                'Flush and close the stream.
                W.Flush()
                W.Close()
            End Using
    
        End Sub
    
    End Module

    (The code requires a reference to the Monkeybone library.)

    Monkeybone pictures can created using Notepad, from any program that creates a Unicode text file with the mob file ending, or from a .NET application using the MonkeyboneWriter class of the Monkeybone library.

    This is the output from the example program (the contents of the mypicture.mob file):

    Clear #000000 200x170
    Bar #FF0000 X:10 Y:10 W:20 H:100
    Bar #FFFF00 X:20 Y:30 W:20 H:100
    Bar #008000 X:30 Y:50 W:20 H:100
    Bar #FFFFFF X:46 Y:5 W:5 H:160 VFill:60%
    Bar #FFFFFF X:52 Y:5 W:5 H:160 VFill:68%
    Bar #FFFFFF X:58 Y:5 W:5 H:160 VFill:76%
    Bar #FFFFFF X:64 Y:5 W:5 H:160 VFill:83%
    Bar #FFFFFF X:70 Y:5 W:5 H:160 VFill:89%
    Bar #FFFFFF X:76 Y:5 W:5 H:160 VFill:94%
    Bar #FFFFFF X:82 Y:5 W:5 H:160 VFill:97%
    Bar #FFFFFF X:88 Y:5 W:5 H:160 VFill:99%
    Bar #FFFFFF X:94 Y:5 W:5 H:160
    Bar #FFFFFF X:100 Y:5 W:5 H:160 VFill:99%
    Bar #FFFFFF X:106 Y:5 W:5 H:160 VFill:96%
    Bar #FFFFFF X:112 Y:5 W:5 H:160 VFill:92%
    Bar #FFFFFF X:118 Y:5 W:5 H:160 VFill:87%
    Bar #FFFFFF X:124 Y:5 W:5 H:160 VFill:81%
    Bar #FFFFFF X:130 Y:5 W:5 H:160 VFill:73%
    Bar #FFFFFF X:136 Y:5 W:5 H:160 VFill:66%
    Bar #FFFFFF X:142 Y:5 W:5 H:160 VFill:58%
    Bar #FFFFFF X:148 Y:5 W:5 H:160 VFill:50%
    Bar #FFFFFF X:154 Y:5 W:5 H:160 VFill:42%
    Bar #FFFFFF X:160 Y:5 W:5 H:160 VFill:36%
    Bar #FFFFFF X:166 Y:5 W:5 H:160 VFill:30%
    Bar #FFFFFF X:172 Y:5 W:5 H:160 VFill:25%
    Bar #FFFFFF X:178 Y:5 W:5 H:160 VFill:22%
    Bar #FFFFFF X:184 Y:5 W:5 H:160 VFill:20%
    Bar #FFFFFF X:190 Y:5 W:5 H:160 VFill:20%
    Bar #FFFFFF X:196 Y:5 W:5 H:160 VFill:22%
    Bar #FFFFFF X:202 Y:5 W:5 H:160 VFill:25%
    Bar #FFFFFF X:208 Y:5 W:5 H:160 VFill:29%
    Bar #FFFFFF X:214 Y:5 W:5 H:160 VFill:35%
    Bar #FFFFFF X:220 Y:5 W:5 H:160 VFill:41%
    Bar #FFFFFF X:226 Y:5 W:5 H:160 VFill:49%

    If you load the mypicture.mob file in the Monkeybone viewer, this would be the result:

  • Dual coordinate systems

    This picture illustrates the different coordinate systems that Monkeybone is using. Both lines are drawn from 0, 0 to 30, 30. The yellow line is drawn using the coordinate system of the image itself, and the green line is drawn using the coordinate system of the diagram.

    The syntax is the same for DiagramLine and Line, the coordinate system is the only difference. This means that you can choose to use named arguments or points encapsulated by parenthesis. This is the source for the above image:

    //Set size and background color.
    Clear 320x200 #667788
    
    //Just to make it more visible, set line thikness to 3 pixels.
    Set Line Thikness To 3
    
    //Create a diagram.
    Diagram #8899aa X:20 Y:20 W:280 H:160
    
    //Draw a yellow line on the image from 0,0 to 30,30.
    Line #ffff00 (0,0) (30,30)
    
    //Draw a green line on the diagram from 0,0 to 30,30.
    DiagramLine #00ff00 (0,0) (30,30)

    Note: A line can be anything from one to 1000 pixels wide.

  • Installation

    The installation program can be downloaded from here or from the Monkeybone page. If you have a previous version of Monkeybone Viewer installed, don’t forget to uninstall that (from the Control Panel) before installing a new version. The installation program registers the MOB file ending with the viewer, so if you double click a Monkeybone picture (*.mob-file), it will open in Monkeybone Viewer.

    Check the Monkeybone tag for news on Monkeybone.

  • Drawing lines

    The basic syntax for drawing lines is this: Use the Line instruction, pass a start coordinate (X1 and Y1) and an end coordinate (X2 and Y2) and a color. This example draws a line across the picture:

    //Set image size and background color.
    Clear 400x300 #ffffff
    
    //Simple line.
    Line #000000 X1:0 Y1:0 X2:400 Y2:300

    The coordinates can be given in an alternative nameless format. This is useful when drawing multiple lines with one single line instruction. This code draws a red U-shape.

    //Set image size and background color.
    Clear 400x300 #ffffff
    
    //Polyline
    Line #ff0000 (10,10) (10,290) (390,290) (390,10)

    To close this shape,  you can add the (10,10) coordinate to the end of this line, telling Monkeybone to draw a line from (390,10) to the startpoint at (10,10), or you can add the AutoClose argument. This code draws a red rectangle:

    //Set image size and background color.
    Clear 400x300 #ffffff
    
    //Polyline
    Line #ff0000 (10,10) (10,290) (390,290) (390,10) AutoClose

    To draw a filled rectangle instead of a rectangle contour, use the Filled argument instead of the AutoClose argument. This code draws a yellow box with black outline:

    //Set image size and background color.
    Clear 400x300 #ffffff
    
    //Polyline
    Line #ffff00 (10,10) (10,290) (390,290) (390,10) Filled
    Line #000000 (10,10) (10,290) (390,290) (390,10) AutoClose
  • Monkeybone: Creating a bar diagram using Notepad part 4/4

    Continued from here.

    To finish this, I want to add some effects, and save it as a png file.

    Adding shadows
    To add shadows behind each bar, just add the Shadowed argument to each bar. Example:

    DiagramBar #ff0000 X:25  Y:0 W:20 H:200 Label="Apples"  Value="1" Shadowed

    Adding gradient background
    To give the image a gradient background, replace the color argument with a VGrad or HGrad. VGrad does a vertical gradient and HGrad does a horizontal. Example:

    The changes I have made is marked with bold font.

    //Set image size and background color.
    Clear 400x300 VGrad:#d0d0d0-#f0f0f0
    
    //Create a white diagram.
    Diagram #ffffff X:25 Y:40 W:350 H:230 "Some fruit"
    
    //Create 5 bars.
    DiagramBar #ff0000 X:25  Y:0 W:20 H:200 Label="Apples"  Value="1" Shadowed
    DiagramBar #00ff00 X:95  Y:0 W:20 H:50  Label="Pears"   Value="2" Shadowed
    DiagramBar #0000ff X:165 Y:0 W:20 H:150 Label="Oranges" Value="3" Shadowed
    DiagramBar #ff00ff X:235 Y:0 W:20 H:180 Label="Peaches" Value="4" Shadowed
    DiagramBar #f2f200 X:305 Y:0 W:20 H:100 Label="Grapes"  Value="5" Shadowed

    This is the result:

    If your pictures didn’t come out as expected, you can check the error log in the View window. This video shows these steps. Also, the png export feature is shown.

  • Monkeybone: Creating a bar diagram using Notepad part 3/4

    Continued from here.

    Text can be added below and above each bar. To add text below, use the Label argument. To add text above, use the Value argument. I show the complete file content below; the latest additions are highlighted with bold font. The text below each bar is a fruit name, and the text above are numbers. As diagram title, I have chosen Some fruit. The diagram title is a nameless argument. The code so far:

    //Set image size and background color.
    Clear 400x300 #e0e0e0
    
    //Create a white diagram.
    Diagram #ffffff X:25 Y:40 W:350 H:230 "Some fruit"
    
    //Create 5 bars.
    DiagramBar #ff0000 X:25  Y:0 W:20 H:200 Label="Apples"  Value="1"
    DiagramBar #00ff00 X:95  Y:0 W:20 H:50  Label="Pears"   Value="2"
    DiagramBar #0000ff X:165 Y:0 W:20 H:150 Label="Oranges" Value="3"
    DiagramBar #ff00ff X:235 Y:0 W:20 H:180 Label="Peaches" Value="4"
    DiagramBar #f2f200 X:305 Y:0 W:20 H:100 Label="Grapes"  Value="5"

    This is the result:

    To be concluded.

  • Monkeybone: Creating a bar diagram using Notepad part 2/4

    Continued from here.

    Bars can be added to a diagram using the DiagramBar instruction. DiagramBar differs from the Bar instruction in that it use a virtual coordinate system (from a previous Diagram instruction) with its zero position in the left bottom corner, as opposed to the image itself that has its zero position in the top left corner. Like the Bar instruction, the DiagramBar instruction takes a color, position and size. Adding these lines (bold) will create five bars on the diagram.

    //Set image size and background color.
    Clear 400x300 #e0e0e0
    
    //Create a white diagram.
    Diagram #ffffff X:25 Y:40 W:350 H:230
    
    //Create 5 bars.
    DiagramBar #ff0000 X:25  Y:0 W:20 H:200
    DiagramBar #00ff00 X:95  Y:0 W:20 H:50
    DiagramBar #0000ff X:165 Y:0 W:20 H:150
    DiagramBar #ff00ff X:235 Y:0 W:20 H:180
    DiagramBar #f2f200 X:305 Y:0 W:20 H:100

    Your picture should now look like this.

    Unlike the Bar instruction, the DiagramBar instruction does not understand the HFill or the VFill argument.

    If you are doing this in notepad, you might want to make use of automatic X positioning. By changing the X position to X:Auto/5, Monkeybone calculates the X position for you, assuming that 5 bars will be added. I don’t recommend that you use this feature when you are automating the diagram creation, but it is a time saver when you are working with notepad. Just enter X:Auto/n where n is the total number of bars. Example:

    DiagramBar #334455 X:Auto/2 Y:0 W:30 H:120
    DiagramBar #556677 X:Auto/2 Y:0 W:30 H:130

    Continued here.

  • Monkeybone: Creating a bar diagram using Notepad part 1/4

    To make a diagram by hand using Notepad, start Notepad, click File and Save as. Change the filter from txt to All files. Provide a filename that ends with .mob (I will use bardiagram.mob in my example) and change the encoding to UTF-8. Then, click save. Keep Notepad open and write your instructions there.

    Open the Monkeybone Viewer and open the bardiagram.mob file (you can use Open in the file Menu or just drag and drop bardiagram.mob onto the Monkeybone Viewer window). Note that the filename of your mob file is now showing in the title bar of Monkeybone viewer.

    First, we specify the size and background color of the image using the Clear instruction. This will make a light gray image 400 pixels wide and 300 pixels high.

    Clear 400x300 #e0e0e0

    This video shows these steps.

    To position the diagram on the picture, use the Diagram instruction. The arguments are it’s position, size and background color. This line create a white diagram.

    Diagram #ffffff X:25 Y:40 W:350 H:230

    The result of this, might look very much like a light gray image with a white Bar on it, but unlike a Bar, a Diagram has a coordinate system on it’s own. The image has it’s 0,0 at the top left and higher values are located to the right (X) and below (Y). Anything that is drawn on a Diagram, will be drawn using the Diagrams coordinate system. 0,0 is at the bottom left and higher values are located to the right (X) and above (Y). Adding a Bar and a DiagramBar with the same arguments, will not place them on top of each other, because the Bar will be drawn on the image using the images coordinate system, and the DiagramBar will be drawn on the Diagram, using the diagrams coordinate system.

    Part 2.

  • Drawing bars

    To do bars, the Bar instruction is used. It takes the color, position and size as arguments. This code…

    //Set image size and background color.
    Clear 100x100 #003366
    
    //Draw a dark blue bar that covers most of the image.
    Bar #225599 X:10 Y:10 W:80 H:80

    …produces this blue rectangle:

    To do a bar that is only party filled; you can specify the percentage of the filling as an additional argument. In this example, I draw a white rectangle over the blue rectangle, on the exact same place as it. Also, I use the VFill argument to specify that the height will be only 75% of the full rectangle. This code…

    //Set image size and background color.
    Clear 100x100 #003366
    
    //Draw a dark blue bar that covers most of the image.
    Bar #225599 X:10 Y:10 W:80 H:80
    
    //Draw a white bar on over the dark blue bar.
    //Let it be a horizontal bar, 75% filled.
    Bar #ffffff X:10 Y:10 W:80 H:80 VFill:75%

    …produces this white bar over the blue rectangle:

    The argument used for doing a bar that is partly filled horizontally, use HFill instead of VFill.

  • Short introduction to Monkeybone

    The posts that I am doing on Monkeybone might only be interesting if you are develop programs that do charting or if you want to be able to produce nice looking charts. Monkeybone is a vector image format, mainly designed for producing bar charts and line charts. Monkeybone images are text files (UTF-8) that are interpretated using Regular Expressions. Each line is a drawing instruction (linefeed, \n, terminates each instruction) and arguments are separated using space. The first part of each line is the name of the drawing instruction, but arguments has no order. The format of the argument determines what the argument is. I have given the Monkeybone format an own section on the site, and I will post some examples in the blog. The image shows a simple Monkeybone image (exportet to PNG for display on this site).