Recent

Author Topic: Epitrochoid Curve: Now Drawing correctly  (Read 1502 times)

Boleeman

  • Hero Member
  • *****
  • Posts: 526
Epitrochoid Curve: Now Drawing correctly
« on: May 21, 2024, 02:14:56 pm »
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.
« Last Edit: May 22, 2024, 10:22:31 am by Boleeman »

Boleeman

  • Hero Member
  • *****
  • Posts: 526
Re: Epitrochoid Curve: Annoying extra line
« Reply #1 on: May 21, 2024, 02:27:32 pm »
Just noticed:

Varying the value of H makes a blinking eye effect.


circular

  • Hero Member
  • *****
  • Posts: 4269
    • Personal webpage
Re: Epitrochoid Curve: Annoying extra line
« Reply #2 on: May 21, 2024, 09:33:58 pm »
Sure, check when the first coordinate is supplied and use MoveTo instead of LineTo:
Code: Pascal  [Select][+][-]
  1. procedure TForm1.DrawEpitrochoid(ACanvas: TCanvas; a, b, h, dt: Double);
  2. var
  3.   scale, stop_t, t: Double;
  4.   pt0, pt1: TPoint;
  5.   first: boolean;
  6. begin
  7.   // Calculate the stop value for t.
  8.   stop_t := b * 2 * Pi;
  9.  
  10.   // Scale.
  11.   scale := Min(PaintBox1.ClientWidth * 0.45, PaintBox1.ClientHeight * 0.45);
  12.  
  13.   // Find the first point on the curve.
  14.   t := 0;
  15.   repeat
  16.     pt0 := Point(Round(X(a, b, h, t) * scale) + Round(PaintBox1.ClientWidth / 2),
  17.                  Round(Y(a, b, h, t) * scale) + Round(PaintBox1.ClientHeight / 2));
  18.     t := t + dt;
  19.   until (t > stop_t) or ((pt0.X >= 0) and (pt0.Y >= 0) and (pt0.X < PaintBox1.ClientWidth) and (pt0.Y < PaintBox1.ClientHeight));
  20.  
  21.   first := true;
  22.   while t <= stop_t do
  23.   begin
  24.     pt1 := Point(Round(X(a, b, h, t) * scale) + Round(PaintBox1.ClientWidth / 2),
  25.                  Round(Y(a, b, h, t) * scale) + Round(PaintBox1.ClientHeight / 2));
  26.     if first then
  27.     begin
  28.       ACanvas.MoveTo(pt1.X, pt1.Y);
  29.       first := false
  30.     end
  31.     else
  32.       ACanvas.LineTo(pt1.X, pt1.Y);
  33.     pt0 := pt1;
  34.     t := t + dt;
  35.   end;
  36.  
  37. end;
Conscience is the debugger of the mind

Josh

  • Hero Member
  • *****
  • Posts: 1310
Re: Epitrochoid Curve: Annoying extra line
« Reply #3 on: May 22, 2024, 01:05:53 am »
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  [Select][+][-]
  1. procedure TForm1.DrawEpitrochoid(ACanvas: TCanvas; a, b, h, dt: Double);
  2. var
  3.   scale, stop_t, t: Double;
  4.   pt0, pt1,fp: TPoint;
  5. begin
  6.   // Calculate the stop value for t.
  7.   stop_t := b * 2 * Pi;
  8.  
  9.   // Scale.
  10.   scale := Min(PaintBox1.ClientWidth * 0.45, PaintBox1.ClientHeight * 0.45);
  11.  
  12.   // Find the first point on the curve.
  13.   t := 0;
  14.   repeat
  15.     pt0 := Point(Round(X(a, b, h, t) * scale) + Round(PaintBox1.ClientWidth / 2),
  16.                  Round(Y(a, b, h, t) * scale) + Round(PaintBox1.ClientHeight / 2));
  17.     t := t + dt;
  18.   until (t > stop_t) or ((pt0.X >= 0) and (pt0.Y >= 0) and (pt0.X < PaintBox1.ClientWidth) and (pt0.Y < PaintBox1.ClientHeight));
  19.   fp:=pt0;
  20.   ACanvas.MoveTo(fp.X, fp.Y);  // move to first point
  21.   while t <= stop_t do
  22.   begin
  23.     pt1 := Point(Round(X(a, b, h, t) * scale) + Round(PaintBox1.ClientWidth / 2),
  24.                  Round(Y(a, b, h, t) * scale) + Round(PaintBox1.ClientHeight / 2));
  25.     ACanvas.LineTo(pt1.X, pt1.Y);
  26.     pt0 := pt1;
  27.     t := t + dt;
  28.   end;
  29.   ACanvas.LineTo(fp.X, fp.Y); // draw line back to origin
  30. end;                
« Last Edit: May 22, 2024, 01:09:38 am by Josh »
The best way to get accurate information on the forum is to post something wrong and wait for corrections.

Boleeman

  • Hero Member
  • *****
  • Posts: 526
Re: Epitrochoid Curve: Now Drawing correctly
« Reply #4 on: May 22, 2024, 07:55:44 am »
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.



« Last Edit: May 22, 2024, 10:20:21 am by Boleeman »

Josh

  • Hero Member
  • *****
  • Posts: 1310
Re: Epitrochoid Curve: Now Drawing correctly
« Reply #5 on: May 22, 2024, 09:32:47 am »
Fixes and extra controls for Anim based on V1

The Attached Project removed from this post, go down thread to get latest
« Last Edit: May 22, 2024, 12:32:28 pm by Josh »
The best way to get accurate information on the forum is to post something wrong and wait for corrections.

Josh

  • Hero Member
  • *****
  • Posts: 1310
Re: Epitrochoid Curve: Now Drawing correctly
« Reply #6 on: May 22, 2024, 10:46:08 am »
and for my 1300th post

added option to turn off/on merge pen
added option to draw a center linewhen line width >10
max line width updated to 100

edit Quick update, tidy up code.
« Last Edit: May 22, 2024, 11:37:55 am by Josh »
The best way to get accurate information on the forum is to post something wrong and wait for corrections.

Boleeman

  • Hero Member
  • *****
  • Posts: 526
Re: Epitrochoid Curve: Now Drawing correctly
« Reply #7 on: May 22, 2024, 12:17:55 pm »
Yeeeee Harrrrrrr, 1300th post.

Congratulations Josh


Nice Going.

Josh

  • Hero Member
  • *****
  • Posts: 1310
Re: Epitrochoid Curve: Now Drawing correctly
« Reply #8 on: May 22, 2024, 12:28:59 pm »
setting the parameters to the pic then click animate..

the reason the colour cycles and gives the rotating effect is becaus i purposely did not reset the color index counter when redrawing.. I found it more effective
The best way to get accurate information on the forum is to post something wrong and wait for corrections.

AlexTP

  • Hero Member
  • *****
  • Posts: 2433
    • UVviewsoft
Re: Epitrochoid Curve: Now Drawing correctly
« Reply #9 on: May 22, 2024, 12:35:31 pm »

Boleeman

  • Hero Member
  • *****
  • Posts: 526
Re: Epitrochoid Curve: Now Drawing correctly
« Reply #10 on: May 22, 2024, 12:47:45 pm »
AlexTP, getting those uploaded to share. Good.


Josh. I set the program to those settings and got that nice Rotation effect.

Then I did an Animate with Value H with those settings and got a TRIPPY Effect. Wow.

Also click Animate Value A or Animate Value B just for a short time and then unclick those, while leaving Animate Value H still selected, and then .... THE MAGIC HAPPENS.  Even more interesting and varying psychedelic effects.

Thanks for the great animation effects and extra features.

That's it for me today. Take care.
« Last Edit: May 22, 2024, 01:06:43 pm by Boleeman »

440bx

  • Hero Member
  • *****
  • Posts: 4216
Re: Epitrochoid Curve: Now Drawing correctly
« Reply #11 on: May 22, 2024, 12:57:40 pm »
Some really interesting curves and associated programs in this thread :)  in addition to being good stuff, it's quite enjoyable.  Thank you to those who are participating and in particular to Boleeman and Josh.

Since there seems to be some people interested in "interesting curves", I thought I'd mention one of my favorites (might actually be my favorite), it is a Loxodrome.  Google has a good number of renderings that range from "sure, that's fine" to Wow!!!.
(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

Josh

  • Hero Member
  • *****
  • Posts: 1310
Re: Epitrochoid Curve: Now Drawing correctly
« Reply #12 on: May 22, 2024, 12:59:09 pm »
if you show it down then turn on merge, you get a psychedelic effect.

Too Many options, but good fun
The best way to get accurate information on the forum is to post something wrong and wait for corrections.

Josh

  • Hero Member
  • *****
  • Posts: 1310
Re: Epitrochoid Curve: Now Drawing correctly
« Reply #13 on: May 23, 2024, 03:56:13 am »
@440bx

Not sure, is this the type of thing

The best way to get accurate information on the forum is to post something wrong and wait for corrections.

440bx

  • Hero Member
  • *****
  • Posts: 4216
Re: Epitrochoid Curve: Now Drawing correctly
« Reply #14 on: May 23, 2024, 06:18:45 am »
@440bx

Not sure, is this the type of thing
Not sure either, I have not played with that curve represented in the complex plane.  I've played with its representation in the real plane.  I attached one of the renditions I made, about 14 years ago, using a free program called "Incendia".
(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

 

TinyPortal © 2005-2018