1

I build an application which part is also drawing into video frames. For this I am using Graphics library from System.Drawing. Drawing is working fine and is already implemented. But I also need to be able to draw straight lines with for example this kind of curvy pattern:

Picture for better understanding.

Could somebody help me how this could be achievable?

Scourrge
  • 83
  • 7
  • If you don't find anything already implemented, I guess you could chain some `DrawCurve` or `DrawBezier` together yourself? – Corentin Pane May 31 '20 at 12:45
  • Yes, I was thinking about it too. I just wanted to ask first if there is not some easier way or something already implemented. – Scourrge May 31 '20 at 12:50
  • There's nothing specific. If you already have the points that define the spline, you can add them to a GraphicsPath object (with `GraphicsPath.AddCurve()`, for example). It will generate the bezier curve for you. You can then just use `Graphics.DrawPath()` to draw it. Mind the `Tension` argument value. – Jimi May 31 '20 at 12:54
  • 1
    You can use a [Sine wave](https://en.wikipedia.org/wiki/Sine_wave) (`sinusoid`) to generate those points, for example. – Jimi May 31 '20 at 13:02
  • No, such a wiggly or shaped Pen doesn't exist. Sounds like a nice exercise to create one. Jimi's advice is probably the way to go: Calculate the turning points and the add a series of arcs to a GrphicsPath.. – TaW May 31 '20 at 13:10
  • On 2nd thought I think you can get away by using a regular Pen and DrawCurves. You need to calculate a List the go along the length of the line and vyray to both sides be some distance (half the width of the curves).. – TaW May 31 '20 at 13:20
  • `public void Draw(Graphics g, Point a, Point b) { float lx = b.X - a.X; float ly = b.Y - a.Y; float dx = 0; float dy = 0; float ll = (float)Math.Sqrt(lx * lx + ly * ly); float scale = WiggleLength / ll; if (lx != 0) dy = ly * scale; if (ly != 0) dx = lx * scale; int c = 0;` – TaW Jun 01 '20 at 14:30
  • ..`List points = new List(); while (c < 1f / scale) { float oo = (c % 2 == 0 ? 1 : 0) * (c % 4 == 0 ? 1 : -1) * WiggleWidth / 10f; PointF n = new PointF(a.X + c * dx - oo * dy, a.Y + c * dy + oo * dx); points.Add(n); c++; } g.DrawCurve(pen, points.ToArray(), WiggleTension); }` – TaW Jun 01 '20 at 14:30

0 Answers0