Recent

Author Topic: Peter de Jong Attractor: Bgrabmp Colouring Help Needed ?  (Read 479 times)

Boleeman

  • Hero Member
  • *****
  • Posts: 910
Peter de Jong Attractor: Bgrabmp Colouring Help Needed ?
« on: April 16, 2025, 10:19:59 am »
I made a Lazarus program that creates Peter de Jong Attractors.

I am trying to get a smooth high coloured rainbow effect like at
https://richardrosenman.com/shop/peter-de-jong-attractor/


I used a TBgrabmap for the rendering but have been struggling to get a high coloured rendering."

Up to version 4, after making a basic rendering and then extending it.

Thaddy

  • Hero Member
  • *****
  • Posts: 16982
  • Ceterum censeo Trump esse delendam
Re: Peter de Jong Attractor: Bgrabmp Colouring Help Needed ?
« Reply #1 on: April 16, 2025, 02:14:43 pm »
Wow. Made me think to apply it to audio:
Code: Pascal  [Select][+][-]
  1. unit PeterDeJongAttractor;
  2. {$mode objfpc}
  3. interface
  4.  
  5. uses
  6.   Math, Types;
  7. type
  8.   TDoublePoint = record
  9.     X, Y: Double;
  10.     constructor Create(AX, AY: Double);
  11.   end;
  12.  
  13. constructor TDoublePoint.Create(AX, AY: Double);
  14. begin
  15.   X := AX;
  16.   Y := AY;
  17. end;
  18.  
  19.   TPDJAttractor = class
  20.   private
  21.     Fx, Fy: Double;
  22.     FParamA, FParamB, FParamC, FParamD: Double;
  23.   public
  24.     constructor Create(a, b, c, d: Double);
  25.     /// Returns the next point in the attractor sequence
  26.     function Iterate: TDoublePoint;inline;
  27.     /// Reset to initial state (optional)
  28.     procedure Reset;inline;
  29.   end;
  30.  
  31. implementation
  32.  
  33. constructor TPDJAttractor.Create(a, b, c, d: Double);
  34. begin
  35.   FParamA := a;
  36.   FParamB := b;
  37.   FParamC := c;
  38.   FParamD := d;
  39.   Fx := 0;
  40.   Fy := 0;
  41. end;
  42.  
  43. function TPDJAttractor.Iterate: TDoublePoint;
  44. var
  45.   newX, newY: Double;
  46. begin
  47.   newX := Sin(FParamA * Fy) - Cos(FParamB * Fx);
  48.   newY := Sin(FParamC * Fx) - Cos(FParamD * Fy);
  49.   Fx := newX;
  50.   Fy := newY;
  51.   Result := TDoublePoint.Create(newX, newY);
  52. end;
  53.  
  54. procedure TPDJAttractor.Reset;
  55. begin
  56.   Fx := 0;
  57.   Fy := 0;
  58. end;
  59.  
  60. end.
Then:
Code: Pascal  [Select][+][-]
  1. procedure TMyVSTModule.ProcessAudioBlock(Buffer: PSingle; SampleCount: Integer);
  2. var
  3.   i: Integer;
  4.   AttractorPoint: TDoublePoint;
  5.   ModulationValue: Single;
  6. begin
  7.   for i := 0 to SampleCount - 1 do
  8.   begin
  9.     // Retrieve the current attractor values (could be at a slower modulation rate)
  10.     AttractorPoint := FMyAttractor.Iterate;
  11.     // Map the output to a useful modulation range. For example, normalize and scale:
  12.     ModulationValue := (CSng(AttractorPoint.X) + 2) / 4; // maps from [-2,2] to [0,1]
  13.    
  14.     // Use ModulationValue to influence a parameter in your DSP code:
  15.     // For example, adjust oscillator frequency, filter cutoff, etc.
  16.     ApplyModulationToYourDSP(ModulationValue);
  17.  
  18.     // Continue processing audio...
  19.     Buffer[i] := ProcessSample(Buffer[i]);
  20.   end;
  21. end;
I think I have a VST to write....This is just a scetch.
You can probably also use this simple unit for your graphics purpose.

« Last Edit: April 16, 2025, 02:55:37 pm by Thaddy »
Due to censorship, I changed this to "Nelly the Elephant". Keeps the message clear.

Boleeman

  • Hero Member
  • *****
  • Posts: 910
Re: Peter de Jong Attractor: Bgrabmp Colouring Help Needed ?
« Reply #2 on: April 17, 2025, 01:44:08 am »
Wondered how that audio version would sound ?


There are lots of graphic versions about , written in other languages but never thought of audio versions.

 

TinyPortal © 2005-2018