# Formula shapes with adjustable parameters in Flowchart.NET

In this post we’ll show how to create custom formula shapes with adjustable control points. Shape control points are a new feature in version 6.1 of the Flowchart.NET control, which is currently in beta tests. You can download a copy of the beta version from the following link.

http://mindfusion.eu/_beta/DiagWinForms61.zip

A shape formula is defined using a script, which calls one of the following functions to draw the node shape.

 MoveTo (x,y) Moves the current position to the specified point without drawing. LineTo (x,y) Draws a line from the current position to the specified point. BezierTo (x1,y1,x2,y2,x3,y3) Draws a Bezier curve from the current position to (x3,y3) using (x1,y1) and (x2,y2) as control points. ArcTo (x,y,largeArc,clockwiseArc,rx,ry) Draws an arc from the specified point to (x,y) where rx and ry are the ellipse radiuses and the arc flags are boolean values specifying which of the four possible arcs to draw.

For example, the following formula defines a rounded rectangle shape using lines and arcs, and expects to receive a “radius” control point parameter that will control the corner radii:

```// a rounded rectangle shape, with an arc at each corner
string roundRect = @"
r = Min(Width / 2, radius.X);
MoveTo(r, 0);
LineTo(Width - r, 0);
ArcTo(Width, r, false, false, r, r);
LineTo(Width, Height - r);
ArcTo(Width - r, Height, false, false, r, r);
LineTo(r, Height);
ArcTo(0, Height - r, false, false, r, r);
LineTo(0, r);
ArcTo(r, 0, false, false, r, r);
";```

When creating a Shape instance, we must add a ShapeControlPoint object to it that defines the radius parameter and its constraints. The following code specifies that the default radius is 5, the minimum and maximum values allowed are 1 and 15 respectively, and prevents the control point from moving vertically by setting minY and maxY to 0.

```var myRect = new Shape(roundRect, "MyRect");

"radius", 5, 1, 15, UnitType.Fixed, 0, 0, 0, UnitType.Fixed));
```

Here is another example that defines an anchor-like shape with two parameters controlling the tips of the anchor arms.

```// an anchor shape, with two arcs outlining each anchor arm
string anchor = @"
r = Width / 3;
y1 = p1.Y * Height / 100;
y2 = p2.Y * Height / 100;
MoveTo(Width / 2, Height);
MoveTo(Width / 2 + 3, Height - 5);
ArcTo(Width, y2, false, true, r, r);
ArcTo(Width / 2 + 3, Height - 10, false, false, r, r);
LineTo(Width / 2 + 3, 0);
LineTo(Width / 2 - 3, 0);
LineTo(Width / 2 - 3, Height - 10);
ArcTo(0, y1, false, false, r, r);
ArcTo(Width / 2 - 3, Height - 5, false, true, r, r);
LineTo(Width / 2, Height);
";

var myAnchor = new Shape(anchor, "MyAnchor");

// add control points at the tips of anchor arms
"p1", 0, 0, 0, UnitType.Percentage, 55, 50, 80, UnitType.Percentage));