Fibonacci Word Fractal lazarus / 39-Graphics ---------------------------------------------------------------------- Boleeman · 2024-06-07 10:04 A Fibonacci Word Fractal. When the N value is low you will need to increase the step size, otherwise the curve is drawn too small to be seen correctly. Wondered how to make the canvas oversized to be able to see the fractal at larger recursion levels? (Possibly a Zoom control, BgraVirtualScreen ?) As shown in the 2nd attached picture, the fractal curve is only partly seen. How to see that whole curve? ---------------------------------------------------------------------- Handoko · 2024-06-16 21:08 Quote from: Boleeman on June 07, 2024, 12:04:35 pm(Possibly a Zoom control, BgraVirtualScreen ?) Done. I quickly rewrite your code tested on Linux only, it may contain bugs. 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, ExtCtrls, Spin,  StdCtrls, ComCtrls, OpenGLContext, GL, Math; type   { TForm1 }   TForm1 = class(TForm)    cbBackcolor: TColorButton;    cbLinecolor: TColorButton;    Label1: TLabel;    Label2: TLabel;    Label3: TLabel;    Label4: TLabel;    Label5: TLabel;    OpenGLControl1: TOpenGLControl;    Panel1: TPanel;    seLinewidth: TSpinEdit;    seNvalue: TSpinEdit;    seStepSize: TSpinEdit;    TrackBar1: TTrackBar;    procedure FormCreate(Sender: TObject);    procedure ControlChange(Sender: TObject);    procedure OpenGLControl1Resize(Sender: TObject);  private    glTextureID: array[0..0] of GLuint; // OpenGL texture    procedure DoDraw;    procedure DrawWordFractal(n: Integer; g: TCanvas; x, y, dx, dy: integer);    function GetWordFractal(n: Integer): string;  public   end; var  Form1: TForm1; implementation {$R *.lfm} { TForm1 } procedure TForm1.FormCreate(Sender: TObject);begin   Panel1.Align                    := alLeft;  OpenGLControl1.Align              := alClient;  OpenGLControl1.AutoResizeViewport := True;   seNvalue.MinValue                 := 1;  seNvalue.MaxValue               := 30;  seNvalue.Value                    := 20;   seStepSize.MinValue               := 1;  seStepSize.MaxValue             := 20;  seStepSize.Value                  := 3;   seLinewidth.MinValue              := 1;  seLinewidth.MaxValue            := 10;  seLinewidth.Value                 := 2;   cbLinecolor.ButtonColor           := clBlack;  cbBackcolor.ButtonColor           := clWhite; end; procedure TForm1.ControlChange(Sender: TObject);begin  DoDraw;end; procedure TForm1.OpenGLControl1Resize(Sender: TObject);const  ZNear = 0.1;  ZFar  = 100;var  X, Y: GLdouble;begin  glViewport(0, 0, OpenGLControl1.Width, OpenGLControl1.Height);  glMatrixMode(GL_PROJECTION);  glLoadIdentity;  Y := Tan(40 * Pi / 360) * ZNear;  X := Y * OpenGLControl1.Width / OpenGLControl1.Height;  glFrustum(-X, X, -Y, Y, ZNear, ZFar);  glMatrixMode(GL_MODELVIEW);  glLoadIdentity;  DoDraw;end; procedure TForm1.DoDraw;const  PictureSize = 1000;var  Bitmap: TBitmap;begin   Bitmap        := TBitmap.Create;  Bitmap.Height := PictureSize;  Bitmap.Width  := PictureSize;  Bitmap.Clear;  DrawWordFractal(seNvalue.Value, Bitmap.Canvas, 20, Bitmap.Height - 20, seStepSize.Value, 0);   OpenGLControl1.MakeCurrent;  glGenTextures(1, glTextureID);  glBindTexture(GL_TEXTURE_2D, glTextureID[0]);  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);  glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, PictureSize, PictureSize, 0, GL_RGBA,    GL_UNSIGNED_BYTE, Bitmap.RawImage.Data);  glBindTexture(GL_TEXTURE_2D, glTextureID[0]);  Bitmap.Free;   glEnable(GL_TEXTURE_2D);  glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT);  glLoadIdentity;  glTranslatef(0, 0, -TrackBar1.Position/2);  glBegin(GL_QUADS);    glTexCoord2f(0, 1); glVertex3f(-1, -1, 0);    glTexCoord2f(1, 1); glVertex3f( 1, -1, 0);  glTexCoord2f(1, 0); glVertex3f( 1,  1, 0);    glTexCoord2f(0, 0); glVertex3f(-1,  1, 0);  glEnd;  OpenGLControl1.SwapBuffers;  glDeleteTextures(1, glTextureID); end; function TForm1.GetWordFractal(n: Integer): string;var  f1, f2, tmp: string;  i: Integer;begin  case n of    0: Result := '';    1: Result := '1';  else    begin      f1 := '1';      f2 := '0';      for i := n - 2 downto 1 do      begin        tmp := f2;        f2 := f2 + f1;        f1 := tmp;      end;      Result := f2;    end;  end;end; procedure TForm1.DrawWordFractal(n: Integer; g: TCanvas; x, y, dx, dy: integer);var  i, tx: Integer;  wordFractal: string;begin  wordFractal := GetWordFractal(n);  with g do  begin    Brush.Color := cbBackcolor.ButtonColor;    FillRect(ClipRect);    Pen.Color := cbLinecolor.ButtonColor;    Pen.Width := seLinewidth.Value;    MoveTo(x, y);  end;  for i := 1 to wordFractal.Length do  begin    g.LineTo(x + dx, y + dy);    Inc(x, dx);    Inc(y, dy);    if wordFractal[i] = '0' then    begin      tx := dx;      if Odd(i) then      begin        dx := dy;        dy := -tx;      end      else      begin        dx := -dy;        dy := tx;      end;    end;  end;end; end. Because I used TOpenGLContext, you need to enable LazOpenGLContext package in your Lazarus by doing: Lazarus main menu > Package > Install/Uninstall Packages > right panel, select: LazOpenGLContext 0.0.1 > Install selection > Save and rebuild IDE Make sure your computer has VGA driver installed properly. For Linux users, you need to have libgl1-mesa-dev installed. In the uses clause I added OpenGLContext, GL, Math (see line #9).  In Form.OnCreate event I added some lines, see line #53..55. For the OpenGL control to be able to do proportional resizing, I added the code for OpenGLControl1Resize event, see line #79. If you want to change the picture size, see line #99. To change the zoom increment value, see line #125. All the repaints now are handled by DoDraw, see line #97. It is done by doing the fractal drawing to a bitmap and then draw to bitmap's texture in the OpenGL control. ---------------------------------------------------------------------- Boleeman · 2024-06-17 06:15 Thanks Handoko for your Linux version. I wanted to do an install of Linux. Wondered what type of Linux and version I should install that works reliably with Lazarus? ---------------------------------------------------------------------- TRon · 2024-06-17 06:50 Quote from: Boleeman on June 17, 2024, 08:15:18 amWondered what type of Linux and version I should install that works reliably with Lazarus? Go with what looks like you are most comfortable with. If you come from f.e. windows then there are special Linux distro's tailored for windows users (these attempt to try and make you feel at home). I would personally advise to go with something debian based and for your dear life please stay away from wayland. And whatever you do do not install Lazarus from your distro's package manager: do it manually or use fpcupdeluxe. BTW: be advised that such question could potentially end up as a topic of its own so perhaps worth considering spending a separate thread for it. ---------------------------------------------------------------------- cdbc · 2024-06-17 07:08 Hi QuoteWondered what type of Linux and version I should install that works reliably with Lazarus? You should try and have a look at PCLinuxOS: https://www.pclinuxos.com/?page_id=180 It's an easy transit, when you come from windows. Even though it's a 'rolling release', it's a bit conservative e.g.: the distro will wait with Wayland, till it's matured a bit/lot and we've even got a Debian flavour, if you so wish. In the repo, we've got the latest release versions of software and e.g.: I'm running fpc trunk & laz 3.0, installed from "FpcUpDeluxe", in paralel  It's definately worth a try. Regards Benny ---------------------------------------------------------------------- TRon · 2024-06-17 07:16 I forgot to mention something that Boleeman might be interested in and it is named ventoy which, after initial setup, allows you to copy- paste iso's to a flash-drive and which you can then pop into a USB port, boot and select which ISO you wish to run. Most Linux distribution provide a live mode CD/DVD iso so that you can test-drive a distribution. ---------------------------------------------------------------------- Boleeman · 2024-06-17 07:22 Thanks for the advice guys. Going to have a 2 week (teacher) break coming up soon so will start the install process then.