Startsidan  ▸  Texter  ▸  Teknikblogg

Anders Hesselbom

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

The Monkeybone writer

2009-12-23

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:

Categories: General

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!

Om...

Kontaktuppgifter, med mera, finns här.

Följ mig

Twitter Instagram
GitHub RSS

Public Service

Folkbildning om public service.

Hem   |   linktr.ee/hesselbom   |   winsoft.se   |   80tal.se   |   Filmtips