Simple Sine Table Generator lazarus / 39-Graphics ---------------------------------------------------------------------- Gigatron · 2025-05-12 22:52 Hi, Sometimes if we need to optimise code we need precalculated data table; One of my tool based on various sintable generator around www  doing that. It can generate signed integer value sine table like on amiga to move logo or image or text on the screen; Copy the generated code on your project from memo1Text and move your image x or y position taken from sin_data: like move(sin_data[index],100) index is the value from sin_data table. Let me share this code with you, be carefull to play with spinedit values you can encounter data access error ... hope no ! ---------------------------------------------------------------------- Gigatron · 2025-05-13 19:11 A simple demo using sine data table. Beginner version code : Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i unit Unit1;{$mode objfpc}{$H+} interface uses  Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, Spin,  ExtCtrls, BGRAVirtualScreen, BGRABitmap, BGRABitmapTypes, Math; constsin_data :Array[0..179] of Integer =(0,2,5,7,10,12,15,17,19,22,24,27,29,31,34,3 6,39,41,43,46,48,50,52,55,57,59,61,64,66,68,70,72,74,76,78,80,82,84,86 ,88,90,92,94,95,97,99,101,102,104,106,107,109,110,112,113,115,116,117, 119,120,121,122,124,125,126,127,128,129,130,131,132,132,133,134,135,13 5,136,136,137,137,138,138,139,139,139,139,140,140,140,140,140,140,140, 140,140,139,139,139,139,138,138,137,137,136,136,135,135,134,133,132,13 2,131,130,129,128,127,126,125,124,122,121,120,119,117,116,115,113,112, 110,109,107,106,104,102,101,99,97,95,94,92,90,88,86,84,82,80,78,76,74, 72,70,68,66,64,61,59,57,55,52,50,48,46,43,41,39,36,34,31,29,27,24,22,1 9,17,15,12,10,7,5,2); type  { TForm1 }  TForm1 = class(TForm)    BGRAVirtualScreen1: TBGRAVirtualScreen;    Timer1: TTimer;    procedure BGRAVirtualScreen1Redraw(Sender: TObject; Bitmap: TBGRABitmap);    procedure FormCreate(Sender: TObject);    procedure Timer1Timer(Sender: TObject);   private   public  end; var  Form1: TForm1;  txt : Array of Pchar;  s1,s2,s3,s4,s5,s6,s7 : Integer; implementation {$R *.lfm} { TForm1 } procedure TForm1.FormCreate(Sender: TObject);begin   SetLength(txt, 1);  txt[0] := 'LAZARUS';  SetLength(txt ,Length(txt));  s7 := 0;  s6 := 4;  s5 := 8;  s4 := 12;  s3 := 16;  s2 := 20;  s1 := 24; end; procedure TForm1.BGRAVirtualScreen1Redraw(Sender: TObject; Bitmap: TBGRABitmap);begin          Bitmap.FontName := 'Arial';         Bitmap.FontHeight := 72;         Bitmap.FontStyle:=[fsBold];        Bitmap.FillRect(0,0,BGRAVirtualScreen1.Width,BGRAVirtualScreen1.Height ,BGRA(0,0,0));           Bitmap.TextOut(140+60,460 -   sin_data[s1]*3,    txt[0][0], BGRA(255,255,255));          Bitmap.TextOut(140+120,460 -  sin_data[s2]*3,    txt[0][1], BGRA(255,255,255));          Bitmap.TextOut(140+180,460 -  sin_data[s3]*3,    txt[0][2], BGRA(255,255,255));          Bitmap.TextOut(140+240,460 -  sin_data[s4]*3,    txt[0][3], BGRA(255,255,255));          Bitmap.TextOut(140+300,460 -  sin_data[s5]*3,    txt[0][4], BGRA(255,255,255));          Bitmap.TextOut(140+360,460 -  sin_data[s6]*3,    txt[0][5], BGRA(255,255,255));          Bitmap.TextOut(140+420,460 -  sin_data[s7]*3,    txt[0][6], BGRA(255,255,255));           inc(s1,2);inc(s2,2);inc(s3,2);inc(s4,2); inc(s5,2);inc(s6,2);inc(s7,2);            s1 := s1 mod Length(sin_data);           s2 := s2 mod Length(sin_data);           s3 := s3 mod Length(sin_data);           s4 := s4 mod Length(sin_data);           s5 := s5 mod Length(sin_data);           s6 := s6 mod Length(sin_data);           s7 := s7 mod Length(sin_data); end; procedure TForm1.Timer1Timer(Sender: TObject);begin    BGRAVirtualScreen1.RedrawBitmap;end; end. Optimized Version code in project ; Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i unit Unit1;{$mode objfpc}{$H+}interfaceuses  Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls,  ExtCtrls, BGRAVirtualScreen, BGRABitmap, BGRABitmapTypes; const  // Sinus table  sin_data: array[0..179] of Integer = (0,2,5,7,10,12,15,17,19,22,24,27,29,31,34,36,39                                     ,41,43,46,48,50,52,55,57,59,61,64,66,68,70,72,74                                     ,76,78,80,82,84,86,88,90,92,94,95,97,99,101,102,104                                     ,106,107,109,110,112,113,115,116,117,119,120,121,122,124,125,126                                     ,127,128,129,130,131,132,132,133,134,135,135,136,136,137,137,138                                     ,138,139,139,139,139,140,140,140,140,140,140,140,140,140,139,139                                     ,139,139,138,138,137,137,136,136,135,135,134,133,132,132,131,130                                     ,129,128,127,126,125,124,122,121,120,119,117,116,115,113,112,110                                     ,109,107,106,104,102,101,99,97,95,94,92,90,88,86,84,82                                     ,80,78,76,74,72,70,68,66,64,61,59,57,55,52,50,48                                     ,46,43,41,39,36,34,31,29,27,24,22,19,17,15,12,10,7,5,2);   TEXT_TO_DISPLAY = 'LAZARUS 4.0';  pos_X = 0;  pos_Y = 430;  amp   = 3;  phase = 4;  anim_speed = 2; type  { TForm1 }  TForm1 = class(TForm)    BGRAVirtualScreen1: TBGRAVirtualScreen;    Timer1: TTimer;    procedure BGRAVirtualScreen1Redraw(Sender: TObject; Bitmap: TBGRABitmap);    procedure FormCreate(Sender: TObject);    procedure Timer1Timer(Sender: TObject);  private    FPhases: array of Integer;  public  end; var  Form1: TForm1;  X_Space : Integer; implementation{$R *.lfm} { TForm1 } procedure TForm1.FormCreate(Sender: TObject);var  i: Integer;begin   X_Space := 60;  SetLength(FPhases, Length(TEXT_TO_DISPLAY)); // num letters   for i := 0 to High(FPhases) do     // downto ?    FPhases[i] := i * phase;  // each letter y pos pointer in sin tableend; procedure TForm1.BGRAVirtualScreen1Redraw(Sender: TObject; Bitmap: TBGRABitmap);var  i: Integer;  x, y: Integer;  s: string;begin   Bitmap.FontName := 'Courier New';  Bitmap.FontHeight := 90;  Bitmap.FontStyle := [fsBold];   for i := 0 to Length(TEXT_TO_DISPLAY) - 1 do  begin    x := pos_X + (i + 1) * X_Space;    y := pos_Y - sin_data[FPhases[i]] * amp;    s := TEXT_TO_DISPLAY[i+1]; // +1    Bitmap.TextOut(x, y, s, BGRA(255, 255, 255));    Bitmap.TextOut(x-4, y-4, s, BGRA(255, 0,0));    FPhases[i] := (FPhases[i] + anim_speed) mod Length(sin_data);  end; end; procedure TForm1.Timer1Timer(Sender: TObject);begin  BGRAVirtualScreen1.RedrawBitmap;end; end. ---------------------------------------------------------------------- TRon · 2025-05-17 08:28 Quote from: d2010 on May 17, 2025, 06:19:04 amInside my source, my SinTable have more precision a,at least 4digits. I'm afraid that somehow there is a misunderstanding about the purpose of the program made by Gigatron. It is not about precision but about speed and memory-usage. Perhaps not that interesting anymore these days but as a comparison how exactly would you calculate 4 digit-precision on a 8-bit CPU or a CPU that does not contain an FPU ? And perhaps as equal important, how does one use that in practice on such CPU ? It serves hardly any purpose and complicate matters. If wanted you could use fixed point integers or scaling but that is not the purpose of the demonstration. Precalculating an algorithm allows for example to use absolute coordinates (which saves another addition/shift), allows to pre-apply ratios and other useful otherwise costly calculations beforehand which saves cpu-cycles not only because of the calculation already been done but because that way you only have to take care of indices and/or move around memory of the pre-calculated data. On the other hand using this technique also has a turning-point where pre-calculation has no use anymore as it either will take too much time to render (all) the values, lost too much precision and/or requires too much storage space. Newer techniques were developed and combined in order to improve on these limitations. As said, the technique as demonstrated does probably not serve much purpose anymore on modern CPU's but it is nice to see these old techniques put to use. Though, all that buzz stuff of today is also just all about some random iteration on some random pre-calculated data  fwiw: SinusMaker(tm) is a well-known and perfect example of such tool that belong(s/ed) to every developers toolkit (back) in the 8-bit era. The used techniques are still valid though applied on/to/for other matters these days. ---------------------------------------------------------------------- Gigatron · 2025-05-17 09:21 Quote from: d2010 on May 17, 2025, 06:19:04 amInside my source, my SinTable have more precision a,at least 4digits. Can you use myTableCos and myTableSin? iF you other CircleRounded equations, then use  AcDbEllipse[pc] Quote from: Gigatron on May 13, 2025, 12:52:48 amHi, Sometimes if we need to optimise code we need precalculated data table; One of my tool based on various sintable generator around www  doing that. It can generate signed integer value sine table like on amiga to move logo or image or text on the screen; Copy the generated code on your project from memo1Text and move your image x or y position taken from sin_data: like move(sin_data[index],100) index is the value from sin_data table. Let me share this code with you, be carefull to play with spinedit values you can encounter data access error ... hope no ! Hi, If I had wanted to get out of floating-point values, i would have done it here, the purpose is explained by @Tron is sufficient. Don't forget my programs aim for simplicity for those who are new to Pascal and the Amiga 68000 spirit which has no FPU When you disassemble a demo on the Amiga 68000, the sine tables are often signed integers if there is no 3D.  @Tron thank you for your clarification on the subject; Regars Gigatron ---------------------------------------------------------------------- d2010 · 2025-05-17 17:16 I am sorry , at previous message on this Topic, I got many error/s at Online-broken as Opera.exe. I am sorry, Please, you here is .. You search "function CorrectAngleIfNotReadable(Angle:ads_real):ads_real;" Can you replace "sin_data" with my-sin-table"? Please, You quick-watch, and you respond, You got , what you got? Thanks/thank you/ Best Regards. ---------------------------------------------------------------------- cdbc · 2025-05-17 17:48 Hi @d2010: STOP TROLLING and wasting peoples time! Regards Benny