Forum > Graphics

Epitrochoid Curve: Now Drawing correctly

(1/3) > >>

Boleeman:
Made an Epitrochoid Curve.

I was getting an annoying extra line from (0,0).   (as shown in attached png picture)

Now fixed by Circular and Josh

I also changed the minimum A H B selectors to something other than 0 (zero), as Josh was correct about the division by zero bug.

The converted CSharp code originally had scale and translate, which I think BGRABmp may have but I just translated by half the paintbox width and height by doing:

pt0 := Point(Round(X(a, b, h, t) * scale) + Round(PaintBox1.ClientWidth / 2),
                 Round(Y(a, b, h, t) * scale) + Round(PaintBox1.ClientHeight / 2));

Working bug fixed code is now attached below. Also a straight filled pattern using MSPaint.

Also wondered it could be possibly be multi-colored and made to spin/animate?

The coloured attached picture almost looks like stained glass.
Would be nice to alter the opacity of it to make it appear slightly see-through like real glass.

Boleeman:
Just noticed:

Varying the value of H makes a blinking eye effect.

circular:
Sure, check when the first coordinate is supplied and use MoveTo instead of LineTo:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TForm1.DrawEpitrochoid(ACanvas: TCanvas; a, b, h, dt: Double);var  scale, stop_t, t: Double;  pt0, pt1: TPoint;  first: boolean;begin  // Calculate the stop value for t.  stop_t := b * 2 * Pi;   // Scale.  scale := Min(PaintBox1.ClientWidth * 0.45, PaintBox1.ClientHeight * 0.45);   // Find the first point on the curve.  t := 0;  repeat    pt0 := Point(Round(X(a, b, h, t) * scale) + Round(PaintBox1.ClientWidth / 2),                 Round(Y(a, b, h, t) * scale) + Round(PaintBox1.ClientHeight / 2));    t := t + dt;  until (t > stop_t) or ((pt0.X >= 0) and (pt0.Y >= 0) and (pt0.X < PaintBox1.ClientWidth) and (pt0.Y < PaintBox1.ClientHeight));   first := true;  while t <= stop_t do  begin    pt1 := Point(Round(X(a, b, h, t) * scale) + Round(PaintBox1.ClientWidth / 2),                 Round(Y(a, b, h, t) * scale) + Round(PaintBox1.ClientHeight / 2));    if first then    begin      ACanvas.MoveTo(pt1.X, pt1.Y);      first := false    end    else      ACanvas.LineTo(pt1.X, pt1.Y);    pt0 := pt1;    t := t + dt;  end; end;

Josh:
also at end line needs to draw back to start ordinates.

Also you need to change the minimum A H B selectors to something other than 0 (zero), else you will get FLT error when zero as calc are divided by them.


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TForm1.DrawEpitrochoid(ACanvas: TCanvas; a, b, h, dt: Double);var  scale, stop_t, t: Double;  pt0, pt1,fp: TPoint;begin  // Calculate the stop value for t.  stop_t := b * 2 * Pi;   // Scale.  scale := Min(PaintBox1.ClientWidth * 0.45, PaintBox1.ClientHeight * 0.45);   // Find the first point on the curve.  t := 0;  repeat    pt0 := Point(Round(X(a, b, h, t) * scale) + Round(PaintBox1.ClientWidth / 2),                 Round(Y(a, b, h, t) * scale) + Round(PaintBox1.ClientHeight / 2));    t := t + dt;  until (t > stop_t) or ((pt0.X >= 0) and (pt0.Y >= 0) and (pt0.X < PaintBox1.ClientWidth) and (pt0.Y < PaintBox1.ClientHeight));  fp:=pt0;  ACanvas.MoveTo(fp.X, fp.Y);  // move to first point  while t <= stop_t do  begin    pt1 := Point(Round(X(a, b, h, t) * scale) + Round(PaintBox1.ClientWidth / 2),                 Round(Y(a, b, h, t) * scale) + Round(PaintBox1.ClientHeight / 2));    ACanvas.LineTo(pt1.X, pt1.Y);    pt0 := pt1;    t := t + dt;  end;  ACanvas.LineTo(fp.X, fp.Y); // draw line back to originend;                

Boleeman:
Thanks to Circular and Josh for replying with your respective fixes.

With Circular's code there was still a small gap in the center part of the curve, as the at end line needed to draw back to start ordinates. With Josh's code the gap is now gone. I originally tried ACanvas.MoveTo before asking for help, but for some reason could not get it working properly.


As mentioned in 1st post, the original CSharp code had TRANSFORM parts to it like translate and scale, so as to move the curve and to size the curve.

I wanted to do some TRANSFORMS like:
scale := Min(PaintBox1.ClientWidth * 0.45, PaintBox1.ClientHeight * 0.45);
  Canvas.Scale(scale, scale);
  Canvas.Translate(PaintBox1.ClientWidth / 2, PaintBox1.ClientHeight / 2);

which I think BGRABmp can do.
I would still like to know how to perform the transforms in BGRABmp.

I ended up doing:

pt0 := Point(Round(X(a, b, h, t) * scale) + Round(PaintBox1.ClientWidth / 2),
                 Round(Y(a, b, h, t) * scale) + Round(PaintBox1.ClientHeight / 2));

to perform the transformations another way.



Attached is a filled pattern, with a Bulge effect done in Paint.Net (making the central shapes more elongated).
I wonder if something in BGRABmp can be used to achieve a similar shape distortion effect?

I just tried out Josh's Animated Version in the next thread. Nice.
Really like the Animate H with Color Cycle and A=19 and B=15 and linewidth=2 and Speed Adjust.
There is another effect at the circumference, where the colors appear to be rotating, while the pulsating effect is happening.
Actually single color animation also works well (I had Yellow curve with black background, Animating H value).


With the other animation parameters (A and B parameters), it seems you have to start them at certain spots to get differing effects.
Nicely done by Josh.



Navigation

[0] Message Index

[#] Next page

Go to full version