ProcessingFS is a user friendly library created to simplify the drawing of 2d graphics to a window. It also makes it simple to extend your application and give it to other people. To use ProcessingFS library download the dlls from the Downloads page. The libraries will require .net 4 and F# to run correctly.

You can also download the source code and it should compile if you have the most recent version of F# installed and .net 4

Basic Structure

All ProcessingFS programs will have a class that inherits from PApp. This is a class that contains the basic wpf code and orchestrates all of the method calls. The class has 3 virtual methods as of yet that are useful: Setup, Draw, and MouseLeft.


Setup is used to initialize all of the variables in the program and is executed first and only once.


Draw is the most important method in the whole program. It is called every 60th of a second and is the workhorse behind most animations. Some programs can be created that only display a static image, but the interesting apps will mostly all use the Draw methods. Draw will not be called if setup has not been called first.


MouseLeft is called immediately before the draw method if the left mouse button has been pressed since the last draw call. In general it is not a good idea to do many actions here because it will delay the draw method if to many calculations are performed.

Draw Methods

As of yet there are four main drawing methods that can be called on the PApp class: Point, Line, Rect, and Ellipse


Point is used to draw a point at the given x and y coordinates


Line draws a line between


Rect is where it gets weird. There are 3 types of rectangle draw systems: Corner,Corners, and Center.

Corner is the default and draws the top corner as x and y and draws the rectangle with a as the width and b as the height

Corners is drawn with x,y as the top corner and a,b as the bottom corner

Center uses x,y as the center of the rectangle and a as the width and b as the height

Rectangle draw modes can be set with the RectMode method on the PApp class


Ellipse uses the same systems as the rectangle for drawing but draws an ellipse in the center of the rectangle specified instead of a rectangle

Color Modes

There are also 3 colors of importance.


Background is set through the background method and clears the bitmap to the specified color


Stroke is set through the stroke method and sets the outline for all drawing methods


Fill is set through the, you guessed it, fill method and sets the fill for 2d shapes like rect and ellipse

Each of these three methods have three overloads: color, gray, and rgb. Color takes a System.Media.Color color and uses that, Gray takes an int bellow 255 and creates a grayscale shade from it, and RGB takes 3 ints for Red, Green, and Blue in that order bellow 255.

Both Stroke and Fill have correlating methods NoFill and NoStroke which remove the drawing of those parts of shapes. The color can be returned by calling an overload of stroke and fill respectively.


There are the MouseX and MouseY properties on the PApp object or derived object that return the last recorded mouse coordinates relative to the bitmap.

Width and Height give the current dimensions of the drawable region of the window.

Util Methods


Size changes the size of the window  and updates the width and height properties.

RectMode and EllipseMode

Both Ellipse mode and Rect mode take an instance of the DrawMode discriminated union. This is consumed in f# by typing the name of the mode you want: Corner Corners or Center. In C# however it is required to use the type as though it was an enum, which is less nice but required.



To use ProcessingFS you need to create a class that inherits from PApp and overrides the methods that you wants to use. Then you need to create a new instance of the application and call show on it. In F# interactive this is all that is required and will be sufficient, but in console applications, you need to add the [<STAThread()>] to ensure that the app is run in a SingleThreadAppartment.


open ProcessingFS
open System

type test () =
    inherit PApp()
    override this.Setup () = ()
    override this.Draw () =
        let wOver2 = this.Width / 2
        let hOver2 = this.Height / 2
        this.Ellipse wOver2 hOver2 this.Width this.Height

    let pApp = new test()

When run this produces this:

Sample Example

As you can see this is a very simple and rewarding library. I hope you enjoy it as much as I enjoyed making it. Please contribute or ask if you have any features or suggestions.

Last edited Sep 25, 2011 at 12:26 AM by Oragamster, version 2


No comments yet.