Recent

Author Topic: Fast Canvas Library V1.052  (Read 5222 times)

Gigatron

  • Sr. Member
  • ****
  • Posts: 294
  • Amiga Rulez !!
Re: Fast Canvas Library V1.0
« Reply #15 on: June 14, 2025, 12:05:36 pm »
Hi

Are you really need this image flip ? I think i have this effect in Javascript on my Storage HD;
Maybe in future i can include this effect.

Regards
« Last Edit: June 14, 2025, 02:19:28 pm by Gigatron »
Sub Quantum Technology ! Pascal - C - C# - GD  Script - Java - Javascript - Glsl - Lua - Html5 - CSS - Amiga Rules !

TBMan

  • Full Member
  • ***
  • Posts: 200
Re: Fast Canvas Library V1.0
« Reply #16 on: June 14, 2025, 06:29:51 pm »
Hi

Are you really need this image flip ? I think i have this effect in Javascript on my Storage HD;
Maybe in future i can include this effect.

Regards

I use page flipping often with PTCGraph when doing games with constant animation going on. It does away with any flickering.

Here's a demo of one of my games that uses page flipping.
https://www.youtube.com/watch?v=q_EOf4jKW0c
« Last Edit: June 14, 2025, 06:36:19 pm by TBMan »

Gigatron

  • Sr. Member
  • ****
  • Posts: 294
  • Amiga Rulez !!
Re: Fast Canvas Library V1.0
« Reply #17 on: June 15, 2025, 03:29:27 am »
Ok

Here is the FastCanvas Library 1.04 optimised with precalculated sin/cos tables.

This library contain drawing pixels, and others effects to make some nice Amiga like demo
intro.
The included demo to show some functions in one line of code. So test it and send me
feedback and bugs !
I will try to make doc of all functions in next days.

Sometimes i have false positive virus alert in executable with functions.

nfclibrary.zip include all you need to run the example. nfc=nativeFastCanvas

Have Fun
 
Gtr

The minimal code to start projet with this library :
Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, Forms, Controls, Graphics, Dialogs, NativeFastCanvas,Windows, ExtCtrls;
  9.  
  10. type
  11.   { TForm1 }
  12.   TForm1 = class(TForm)
  13.     Timer1: TTimer;
  14.     procedure FormCreate(Sender: TObject);
  15.     procedure FormDestroy(Sender: TObject);
  16.     procedure Timer1Timer(Sender: TObject);
  17.   private
  18.     FNativeFastCanvas: TNativeFastCanvas;
  19.  
  20.   public
  21.     procedure NativeFastCanvas1NativePaint(Sender: TObject; DC: HDC; Pixels: PFastPixel; Ww, Hh: Integer);
  22.  
  23.   end;
  24.  
  25. var
  26.   Form1: TForm1;
  27.  
  28. implementation
  29.  
  30. {$R *.lfm}
  31.  
  32. { TForm1 }
  33.  
  34. procedure TForm1.FormCreate(Sender: TObject);
  35. begin
  36.  
  37.   FNativeFastCanvas := TNativeFastCanvas.Create(Self);
  38.   with FNativeFastCanvas do
  39.   begin
  40.     Parent := Self;
  41.     Align := alClient;
  42.     BackgroundColor := RGB(0, 0, 32);
  43.     OnNativePaint := @NativeFastCanvas1NativePaint;
  44.   end;
  45.  
  46. end;
  47.  
  48. procedure TForm1.NativeFastCanvas1NativePaint(Sender: TObject; DC: HDC;Pixels: PFastPixel; Ww, Hh: Integer);
  49. var
  50.   FastCanvas: TNativeFastCanvas;
  51. begin
  52.   FastCanvas := TNativeFastCanvas(Sender);
  53.   FastCanvas.DC := DC;
  54.   FastCanvas.DrawVectorText(80, 100, 'HELLO LAZARUS 4.0', 35, RGB(255, 255, 0));
  55. end;
  56.  
  57. procedure TForm1.Timer1Timer(Sender: TObject);
  58. begin
  59.   FNativeFastCanvas.Invalidate;
  60. end;
  61.  
  62. procedure TForm1.FormDestroy(Sender: TObject);
  63. begin
  64.   if Assigned(FNativeFastCanvas) then FNativeFastCanvas.Free;
  65. end;
  66.  
  67. end.
« Last Edit: July 05, 2025, 07:16:23 am by Gigatron »
Sub Quantum Technology ! Pascal - C - C# - GD  Script - Java - Javascript - Glsl - Lua - Html5 - CSS - Amiga Rules !

440bx

  • Hero Member
  • *****
  • Posts: 5596
Re: Fast Canvas Library V1.0
« Reply #18 on: June 15, 2025, 04:00:56 am »
The included demo to show some functions in one line of code. So test it and send me
feedback and bugs !
Very nice! 

I just looked at the demo and, it is impressive. 

I will spend some time studying your code as soon as I can (as usual, I'm in the middle of some code I need to "finish" someday).

Thank you for sharing.  It will be very educational to study your code.
(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v4.0rc3) on Windows 7 SP1 64bit.

Gigatron

  • Sr. Member
  • ****
  • Posts: 294
  • Amiga Rulez !!
Re: Fast Canvas Library V1.0
« Reply #19 on: June 17, 2025, 02:30:36 am »
Hi,

For the next release V1.05  added some nice Fx; CopperBitmapScroller, Text fx, image reflection and more. Text from Megabyte inc Sinbad Cracktro.. talking about Amiga at 7.09MHZ !!

Regards
Gtr

List of all commands of the FastCanvas Library V1.06 here :

Code: Pascal  [Select][+][-]
  1.  
  2. **  Graphic Primitives
  3.  
  4. *** Pixels and Buffer
  5. procedure SetPixel(x, y: Integer; Col: TColor);
  6. function  GetPixel(x, y: Integer): TColor;
  7. procedure ClearBuffer(Col: TColor);
  8. procedure FastBlendPixel(x, y: Integer; Col: TColor; Alpha: Byte);
  9.  
  10. *** Lines
  11. procedure Line(x1, y1, x2, y2: Integer; Col: TColor);
  12. procedure HorizontalLine(x1, x2, y: Integer; Col: TColor);
  13. procedure VerticalLine(x, y1, y2: Integer; Col: TColor);
  14.  
  15. *** Rectangles
  16. procedure Rectangle(x1, y1, x2, y2: Integer; Col: TColor);
  17. procedure FillRect(x1, y1, x2, y2: Integer; Col: TColor);
  18.  
  19. *** Circles and Ellipses
  20. procedure Circle(CenterX, CenterY, Radius: Integer; Col: TColor);
  21. procedure FillCircle(CenterX, CenterY, Radius: Integer; Col: TColor);
  22. procedure CircleGradient(CenterX, CenterY, Radius: Integer; CenterCol, EdgeCol: TColor);
  23.  
  24. procedure Ellipse(CenterX, CenterY, RadiusX, RadiusY: Integer; Col: TColor);
  25. procedure FillEllipse(CenterX, CenterY, RadiusX, RadiusY: Integer; Col: TColor);
  26. procedure EllipseGradient(CenterX, CenterY, RadiusX, RadiusY: Integer; CenterCol, EdgeCol: TColor);
  27.  
  28. *** Triangles
  29. procedure Triangle(x1, y1, x2, y2, x3, y3: Integer; Col: TColor);
  30. procedure FillTriangle(x1, y1, x2, y2, x3, y3: Integer; Col: TColor);
  31.  
  32. *** Stars
  33. procedure Star(CenterX, CenterY, OuterRadius, InnerRadius: Integer;
  34.                Points: Integer; RotationAngle: Single; Col: TColor);
  35. procedure FillStar(CenterX, CenterY, OuterRadius, InnerRadius: Integer;
  36.                    Points: Integer; RotationAngle: Single; Col: TColor);
  37. procedure FillStarB(CenterX, CenterY, OuterRadius, InnerRadius: Integer;
  38.                     Points: Integer; RotationAngle: Single;
  39.                     FillCol: TColor; BorderCol: TColor; size: Integer);
  40.  
  41. ** Vector Text
  42.  
  43. *** 2D Text
  44. procedure DrawVectorChar(x, y: Integer; Ch: Char; Size: Integer; Col: TColor);
  45. procedure DrawVectorText(x, y: Integer; const Txt: string; Size: Integer; Col: TColor);
  46.  
  47. *** 3D Text
  48. procedure DrawVectorChar3D(x, y: Integer; Ch: Char; Size: Integer;
  49.                           RotX, RotY, RotZ: Single; Col: TColor);
  50. procedure DrawVectorText3D(x, y: Integer; const Txt: string; Size: Integer;
  51.                           RotX, RotY, RotZ: Single; Col: TColor);
  52. procedure RotateVectorText3D(GlobalX, GlobalY: Integer; Txt: string; Size: Integer;
  53.                             RotX, RotY, RotZ: Single; Col: TColor);
  54.  
  55. *** Scrolling Text
  56. procedure VectorScrollingText(baseX, baseY: Integer; const txt: string;
  57.                              size: Integer; offset: Integer; col: TColor);
  58. procedure ScrollingText(baseX, baseY: Integer; const txt: string;
  59.                        FName: string; FSize: Integer; FStyle: TFontStyles;
  60.                        offset: Integer; col: TColor; charSpacing: Integer);
  61. procedure ScrollingTextSine(baseX, baseY: Integer; const txt: string;
  62.                            FName: string; FSize: Integer; FStyle: TFontStyles;
  63.                            offset: Integer; col: TColor; charSpacing: Integer;
  64.                            sineAmplitude: Integer; sineFrequency: Single; sinePhase: Single);
  65.  
  66. **  Demoscene Effects
  67.  
  68. *** Copper Bars and Raster Bars
  69. procedure CopperBar(x1, y1, x2, y2: Integer; col1, col2, col3: TColor; vertical: Boolean);
  70. procedure CopperBarFill(x1, y1, x2, y2: Integer; col1, col2, col3: TColor;
  71.                        CopYsize, Offset: Integer);
  72. procedure RasterBar(x1, y1, x2, y2: Integer; col1, col2, col3: TColor);
  73. procedure AnimatedRasterBar(x1, y1, x2, y2: Integer; col1, col2, col3: TColor;
  74.                            offset: Integer);
  75.  
  76. *** 2D Starfield
  77. procedure Init2DStarfield(starcount, direction: Integer; speed: Single;
  78.                          basecolor: TColor; screenWidth, screenHeight: Integer);
  79. procedure Update2DStarfield;
  80. procedure Render2DStarfield;
  81.  
  82. *** 3D Starfield
  83. procedure Create3DStarfield(starCount: Integer; baseColor: TColor = clWhite;
  84.                            speed: Single = 1.0; rotationSpeed: Single = 0.01);
  85. procedure Update3DStarfield;
  86. procedure Render3DStarfield;
  87. procedure Set3DStarfieldColor(newColor: TColor);
  88. procedure Set3DStarfieldSpeed(NewSpeed: Single);
  89. procedure Set3DStarfieldRotation(NewRotationSpeed: Single);
  90. function Get3DStarfieldTotalCount: Integer;
  91.  
  92. *** 2D BobField
  93. procedure Create2DBobField(zoneX, zoneY, zoneX2, zoneY2, bobCount: Integer;
  94.                           imageFilename: string; direction: Integer;
  95.                           speed: Single; planeCount: Integer);
  96. procedure Update2DBobField;
  97. procedure Render2DBobField;
  98.  
  99. *** 3D BobField
  100. procedure Create3DBobField(bobCount: Integer; imageFilename: string;
  101.                           rotationSpeed: Single; speed: Single;
  102.                           minZ: Single = 10; maxZ: Single = 1000);
  103. procedure Update3DBobField;
  104. procedure Render3DBobField;
  105.  
  106. *** Plasma
  107. procedure Plasma(x, y, ww, hh: Integer; time: Single);
  108. procedure PlasmaCustom(x, y, ww, hh: Integer; time: Single; col1, col2, col3: TColor);
  109.  
  110. *** Chunky Copper
  111. procedure ChunkyCopper(x, y, ww, hh, cellSize: Integer; angle, zoom: Single;
  112.                       const filename: string);
  113.  
  114. ** Image Handling
  115.  
  116. *** Loading and Cache
  117. function LoadImageToCache(const filename: string): Boolean;
  118. procedure FreeAllImages;
  119. procedure FreeOldestImage;
  120.  
  121. *** Basic Display
  122. procedure DisplayImage(x, y: Integer; const filename: string;
  123.                       alpha: Byte = 255; scaleX: Single = 1.0; scaleY: Single = 1.0);
  124.  
  125. *** Bitmap Font Scroller
  126. function CreateBitmapFontScroller(fontFilename: string; scroll_Text: String;
  127.                                  charWidth, charHeight: Integer; offsetChar: Char;
  128.                                  sineHeight, scrollSpeed, startY, StartScrollPos: Integer): TBitmapFontScroller;
  129.  
  130. **  Image Effects
  131.  
  132. *** Wave Effects
  133. procedure DisplayImageWave(x, y: Integer; const filename: string;
  134.                           amplitude: Integer = 10; frequency: Single = 0.1;
  135.                           phase: Single = 0; transparency: TTransparencyMode = tmNone;
  136.                           transparentColor: TColor = clBlack);
  137.  
  138. procedure DisplayImageWaveVertical(x, y: Integer; const filename: string;
  139.                                   amplitude: Integer = 10; frequency: Single = 0.1;
  140.                                   phase: Single = 0; transparency: TTransparencyMode = tmNone;
  141.                                   transparentColor: TColor = clBlack);
  142.  
  143. procedure DisplayImageWaveXY(x, y: Integer; const filename: string;
  144.                             amplitudeX: Integer = 10; frequencyX: Single = 0.1; phaseX: Single = 0;
  145.                             amplitudeY: Integer = 5; frequencyY: Single = 0.15; phaseY: Single = 0;
  146.                             transparency: TTransparencyMode = tmNone; transparentColor: TColor = clBlack);
  147.  
  148. procedure DisplayImageWaveInterleaved(x, y: Integer; const filename: string;
  149.                                      amplitude: Integer = 10; frequency: Single = 0.1;
  150.                                      phase: Single = 0; transparency: TTransparencyMode = tmNone;
  151.                                      transparentColor: TColor = clBlack);
  152.  
  153. *** Movement and Rotation
  154. procedure ImageSineMove(const filename: string; baseX, baseY, amplitude: Integer;
  155.                        direction: Integer; phase: Single; scale: Single = 1.0; alpha: Byte = 255);
  156.  
  157. procedure ImageSpinner(const filename: string; centerX, centerY: Integer;
  158.                       scale: Single; spinX, spinY: Single);
  159.  
  160. *** Water Reflection
  161. procedure WaterReflection(x, y: Integer; const filename: string;
  162.                          waveAmplitude: Integer = 8; waveFrequency: Single = 0.15;
  163.                          time: Single = 0; reflectionAlpha: Byte = 180;
  164.                          reflectionHeight: Integer = -1);
  165.  
  166. procedure WaterReflectionAdvanced(x, y: Integer; const filename: string;
  167.                                  time: Single = 0; reflectionAlpha: Byte = 160);
  168.  
  169. **  Bitmap Text Effects
  170.  
  171. *** Copper Bitmap Scroll
  172. procedure CopperBitmapScroll(const fontFile: string; const txt: string;
  173.                             startX, y: Integer; charWidth, charHeight: Integer;
  174.                             offsetChar: Char; scrollSpeed: Integer; copperSpeed: Single;
  175.                             col1, col2, col3: TColor);
  176.  
  177. procedure CopperBitmapScrollOptimized(const fontFile: string; const txt: string;
  178.                                      startX, y: Integer; charWidth, charHeight: Integer;
  179.                                      offsetChar: Char; scrollSpeed: Integer; copperSpeed: Single;
  180.                                      col1, col2, col3: TColor);
  181.  
  182. *** Wave Text Effects
  183. procedure BitmapTextWave(
  184.   const fontFile: string;
  185.   const fullText: string;
  186.   baseX, baseY: Integer;
  187.   charWidth, charHeight: Integer;
  188.   offsetChar: Char;
  189.   charsPerLine: Integer;
  190.   time: Single;
  191.   waveAmplitude: Integer;
  192.   waveSpeed: Single = 1.0;
  193.   verticalWave: Boolean = True;
  194.   colorTint: Cardinal = $FFFFFF;
  195.   fadeAlpha: Byte = 255
  196. );
  197.  
  198. procedure BitmapTextWaveCopper(
  199.   const fontFile: string;
  200.   const fullText: string;
  201.   baseX, baseY: Integer;
  202.   charWidth, charHeight: Integer;
  203.   offsetChar: Char;
  204.   charsPerLine: Integer;
  205.   time: Single;
  206.   waveAmplitude: Integer;
  207.   copperColor1, copperColor2, copperColor3: TColor;
  208.   copperSpeed: Single = 1.0;
  209.   copperDirection: Integer = 0;
  210.   copperHeight: Integer = 64;
  211.   waveSpeed: Single = 1.0;
  212.   verticalWave: Boolean = True;
  213.   lineSpacing: Integer = 0;
  214.   fadeAlpha: Byte = 255
  215. );
  216.  
  217. *** Copper Scroll Controls
  218. procedure ResetCopperScroll;
  219. procedure SetCopperScrollPosition(position: Single);
  220. function GetCopperScrollPosition: Single;
  221.  
  222. **  Typewriter System Create
  223.  
  224. procedure CreateTypewriter(const txt: string; x, y, textSize: Integer;
  225.                           col: TColor; fontType: Integer; charDelayMs: Integer = 100;
  226.                           charsPerLine: Integer = 40; lineSpacing: Integer = 0;
  227.                           lineDelayMs: Integer = 300;
  228.                           const fontName: string = 'Arial'; fontStyle: TFontStyles = [];
  229.                           const bitmapFontFile: string = ''; offsetChar: Char = '0';
  230.                           bitmapCharWidth: Integer = 16; bitmapCharHeight: Integer = 16);
  231.  



« Last Edit: June 17, 2025, 06:07:05 pm by Gigatron »
Sub Quantum Technology ! Pascal - C - C# - GD  Script - Java - Javascript - Glsl - Lua - Html5 - CSS - Amiga Rules !

Gigatron

  • Sr. Member
  • ****
  • Posts: 294
  • Amiga Rulez !!
Re: Fast Canvas Library V1.0
« Reply #20 on: June 20, 2025, 01:47:10 am »
Hi

The Blitter Chip on Amiga was used memory block transfert faster than cpu 68000,

Source, x,y,x1,y1 to x2,y2

The next version of native fast canvas include this chip simulator + all modern blend ops mode ,
exemple in attached picture !

Regards

Code: Pascal  [Select][+][-]
  1. //=============================================================================
  2. //             AMIGA BLITTER IMAGE-SOURCE,x1,y1,x2,y2,x3,y3,blitterMod
  3. //=============================================================================
  4.     procedure BlitCopy(const imageFile: string;
  5.                      srcX, srcY, srcW, srcH, destX, destY: Integer;
  6.                      mode: TBlitMode = bmCopy); overload;
  7.     procedure BlitCopy(const imageFile: string;
  8.                      srcRect: TBlitRect; destX, destY: Integer;
  9.                      mode: TBlitMode = bmCopy); overload;
  10.     procedure BlitCopyMasked(const imageFile, maskFile: string;
  11.                         srcX, srcY, srcW, srcH, destX, destY: Integer;
  12.                         mode: TBlitMode = bmCopy);

Sub Quantum Technology ! Pascal - C - C# - GD  Script - Java - Javascript - Glsl - Lua - Html5 - CSS - Amiga Rules !

Gigatron

  • Sr. Member
  • ****
  • Posts: 294
  • Amiga Rulez !!
Re: Fast Canvas Library V1.0
« Reply #21 on: June 21, 2025, 07:07:54 pm »
Hi,

I made a video of the upcoming version v1.05 of the FastCanvas library, including some cool Amiga style effects, I will release this version in a few days. Debugging takes a lot of time and it's not 100% stable. Precalculated Sintable extended to 36000 elements !

https://www.youtube.com/watch?v=w_Pj74K1jdk

TypeWriter Demo :

https://www.youtube.com/watch?v=w5E9ajtlm_0

1 line code for each writer :

Code: Pascal  [Select][+][-]
  1. 1: begin
  2.     FastCanvas.ImageReflection('tex/girl.png',50,200,RotZ,100,50.0);
  3.  
  4.     FastCanvas.RotateBitmapText3D(CenterX,100,'TYPEWRITER','tex/038_64.png',64,64,' ',0,RotX,0,Rgb(0,200,255),64+4);
  5.  
  6.     DrawStars(FastCanvas);
  7.  
  8.    if (FAnimTimer mod (20*60)) = 0 then
  9.      begin
  10.           CurrentWriter := (CurrentWriter + 1) mod 3;
  11.            FastCanvas.FreeTypewriter;
  12.      end;
  13.  
  14.        case CurrentWriter of
  15.         0: FastCanvas.TypewriterText(txt1, 700, 300, 50, RGB(100,200,255), tmVectorText,
  16.                                       60, 21, 60, 1000, '', [], '', ' ', 0, 0, True, 2);
  17.  
  18.         1: FastCanvas.TypewriterText(txt2, 900, 300, 60, RGB(55,100,255), tmSystemText,
  19.                                       60, 21, 65, 1000, 'Arial', [fsBold], '', ' ', 0, 0, True, 2);
  20.  
  21.         2: FastCanvas.TypewriterText(txt3, 900, 300, 40, RGB(0,255,0), tmBitmapText,
  22.                                       60, 21, 40, 1000, '', [], 'tex/040_32.png', ' ', 32, 32, True, 2);
  23.        end;
  24.  
  25.      end;      


Regards

Gtr
« Last Edit: June 22, 2025, 06:16:09 pm by Gigatron »
Sub Quantum Technology ! Pascal - C - C# - GD  Script - Java - Javascript - Glsl - Lua - Html5 - CSS - Amiga Rules !

Gigatron

  • Sr. Member
  • ****
  • Posts: 294
  • Amiga Rulez !!
Re: Fast Canvas Library V1.051
« Reply #22 on: June 25, 2025, 02:21:59 am »
Ok

This is the update release of nativefastCanvas of V1.051.. Removed some bugs and fixed stability,
added some fx. Some parameters are changed in many commands then this version is not
compatible with the old projects made with  v1.050

Send feedback and try it and good luck.

Regards Gtr

« Last Edit: June 25, 2025, 09:57:50 am by Gigatron »
Sub Quantum Technology ! Pascal - C - C# - GD  Script - Java - Javascript - Glsl - Lua - Html5 - CSS - Amiga Rules !

440bx

  • Hero Member
  • *****
  • Posts: 5596
Re: Fast Canvas Library V1.051
« Reply #23 on: June 25, 2025, 03:57:32 am »
Some parameters are changed in many commands then this version is not
compatible with the old projects made with  v1.5

Send feedback and try it and good luck.

Regards Gtr
Do you mean version 1.05

Since you mention some parameters have changed causing incompatibilities with old projects, do you have plans to post 1 or 2 updated demos that use this new version ?

Thank you!
(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v4.0rc3) on Windows 7 SP1 64bit.

Gigatron

  • Sr. Member
  • ****
  • Posts: 294
  • Amiga Rulez !!
Re: Fast Canvas Library V1.051
« Reply #24 on: June 25, 2025, 10:03:24 am »
Some parameters are changed in many commands then this version is not
compatible with the old projects made with  v1.5

Send feedback and try it and good luck.

Regards Gtr
Do you mean version 1.05

Since you mention some parameters have changed causing incompatibilities with old projects, do you have plans to post 1 or 2 updated demos that use this new version ?

Thank you!
Yes
Sorry, I mean V1.050, and the next version will be 1.052 (maximum optimization for .png images
for better management) and sure bug corrections !!

Regards
« Last Edit: June 25, 2025, 10:17:55 am by Gigatron »
Sub Quantum Technology ! Pascal - C - C# - GD  Script - Java - Javascript - Glsl - Lua - Html5 - CSS - Amiga Rules !

440bx

  • Hero Member
  • *****
  • Posts: 5596
Re: Fast Canvas Library V1.051
« Reply #25 on: June 25, 2025, 12:11:08 pm »
Yes
Sorry, I mean V1.050, and the next version will be 1.052 (maximum optimization for .png images
for better management) and sure bug corrections !!

Regards
Thank you for clarifying that.  I thought it was most likely a typo but, wanted to be sure.
(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v4.0rc3) on Windows 7 SP1 64bit.

Gigatron

  • Sr. Member
  • ****
  • Posts: 294
  • Amiga Rulez !!
Re: Fast Canvas Library V1.051
« Reply #26 on: June 26, 2025, 02:35:07 am »
Hi

Quick made of Manic miner rooms (10) with this library;
Project.zip and 2 sprite Sheet are included, sprites by Andy Nobles old manic miner remake on pc.

code example :

** Edit Level 1 to 10 + Robot at Level1 , you can improve it :)

Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, Forms, Controls, Graphics, Dialogs, NativeFastCanvas,
  9.   Windows, ExtCtrls, StdCtrls;
  10.  
  11. type
  12.   { TForm1 }
  13.   TForm1 = class(TForm)
  14.     Button1: TButton;
  15.     Button2: TButton;
  16.     Timer1: TTimer;
  17.  
  18.     procedure FormCreate(Sender: TObject);
  19.     procedure FormDestroy(Sender: TObject);
  20.     procedure Timer1Timer(Sender: TObject);
  21.     procedure ButtonPrevRoomClick(Sender: TObject);
  22.     procedure ButtonNextRoomClick(Sender: TObject);
  23.   private
  24.     FNativeFastCanvas: TNativeFastCanvas;
  25.  
  26.   public
  27.     procedure NativeFastCanvas1NativePaint(Sender: TObject; DC: HDC; Pixels: PFastPixel; Ww, Hh: Integer);
  28.  
  29.   end;
  30.  
  31. var
  32.   Form1: TForm1;
  33.   robotX : integer = 555;
  34.   robotY: integer = 255;  // Position actuelle
  35.   robotDirection: integer = 1;    // 1 = droite, -1 = gauche
  36.   robotSpeed: integer = 5;        // Vitesse
  37.   robotMinX: integer = 312;        // Distance limite gauche
  38.   robotMaxX: integer = 540;       // Distance limite droite
  39.  
  40.  
  41.   currentRoom: integer = 1;
  42.   roomNames: array[1..20] of String = (
  43.     'CENTRAL CAVERN','THE COLD ROOM','THE MENAGERIE','ABANDONED URANIUM WORKINGS',
  44.     'EUGENES LAIR','PROCESSING PLANT', 'THE VAT', 'MINER WILLY MEETS THE KONG BEAST',
  45.     'WACKY AMOEBATRONS','THE ENDORIAN FOREST','ATTACK OF THE MUTANT TELEPHONES',
  46.     'RETURN OF THE ALIEN KONG BEAST', 'ORE REFINERY','SKYLAB LANDING BAY',
  47.     'THE BANK','THE SIXTEENTH CAVERN','THE WAREHOUSE','AMOEBATRONS REVENGE',
  48.     'SOLAR POWER GENERATOR','THE FINAL BARRIER'
  49.   );
  50.   allRooms: array[1..10] of array[0..15] of string = (
  51.     // Room 1
  52.     (
  53.       '30000000090600006000000000000903',
  54.       '30000000000000009000000000000003',
  55.       '30000000000000000000000000000003',
  56.       '30000000000000000000000000000003',
  57.       '30000000000000000000000590050003',
  58.       '31111111111111444414444111111113',
  59.       '30000000000000000000000000000093',
  60.       '31110000000000000000000000000003',
  61.       '30000000000000000333050000000003',
  62.       '31111000777777777777777777770003',
  63.       '30000000000000000000000000000113',
  64.       '30000000000000000000000000000003',
  65.       '30000000000050000000333444441113',
  66.       '30000111111111111111000000000AB3',
  67.       '30000000000000000000000000000BB3',
  68.       '31111111111111111111111111111113'),
  69.     // Room 2
  70.     (
  71.       '30000000000000000003333333333333',
  72.       '30000000900000000000000090000063',
  73.       '30000000000000000000000000000003',
  74.       '30000000000000000000044410000003',
  75.       '30000000000000000000000000000003',
  76.       '31111111111111111111000000003003',
  77.       '30000000000000000000011113443003',
  78.       '31444440000000000000000003903003',
  79.       '30000000000000000000000003443003',
  80.       '30090000011111110000000003443003',
  81.       '30000000000000000004444003443003',
  82.       '300CCCC0000000000000000003443003',
  83.       '30000000000000111109000003443003',
  84.       '30000000444400000000000000000AB3',
  85.       '30000000000000000000000000000BB3',
  86.       '31111111111111111111111111111113'),
  87.       // Room 3
  88.     (
  89.       '30000090006000090020000900060003',
  90.       '30000000000000000060000000000003',
  91.       '30000000000000000000000000000003',
  92.       '30000000000000000000000000000003',
  93.       '30000000000000000000000000000003',
  94.       '31111444444444444444444444444443',
  95.       '30000000000000000000900000000093',
  96.       '31111110000000000000000000011113',
  97.       '32000000000000000000000000000003',
  98.       '32000077777700000000000000000003',
  99.       '32000000000000000000000001111113',
  100.       '36000000000000111110000000000AB3',
  101.       '30000111111000000000000000000BB3',
  102.       '30000000000000000000011111111113',
  103.       '30000000000000000000000000000003',
  104.       '31111111111111111111111111111113'),
  105.       // Room 4
  106.       (
  107.        '39000006000000333333333333333333',
  108.        '30000000000090000000000009000AB3',
  109.        '30000000000000000000000000000BB3',
  110.        '30000000000000000001111110000003',
  111.        '30000000000000000000000000011113',
  112.        '31000001000000000100000000000003',
  113.        '30000000000011009000011100000093',
  114.        '34440000000000000000000000000003',
  115.        '30000001100000000000000000111003',
  116.        '30000000000000000011100000000003',
  117.        '3CCC0000000000000000000000000013',
  118.        '30000000000011100000001110000003',
  119.        '30000011000000000000000600001113',
  120.        '30000000000000000011000000000003',
  121.        '30000000000000000000000000000003',
  122.        '31111111111111111111111111111113'),
  123.        // Room5
  124.        (
  125.        '30000000000000000000600000000003',
  126.        '30000000000000000000000000000093',
  127.        '30000000000000000000000000000003',
  128.        '30000000000000000000000000000003',
  129.        '30000000000000000000000050000003',
  130.        '31111111111111000044441111110003',
  131.        '30000000009000000000000000000113',
  132.        '30000000000000000000050000000903',
  133.        '30000000000000000077777777770003',
  134.        '30001111111111000000000000000003',
  135.        '30000000000000000000000000000003',
  136.        '34411111111111000011111110000013',
  137.        '30000009390000000000000000000003',
  138.        '311000003000003AB300000000000003',
  139.        '300005003000003BB333333355000003',
  140.        '31111111333333333333333311111113'),
  141.        // Room6
  142.        (
  143.        '30000000000000000000000000000AB3',
  144.        '30000000000000000000000000000BB3',
  145.        '30000000000000000000000000000003',
  146.        '30000000000000000000000000000003',
  147.        '30000000000000000000060000000003',
  148.        '30000000111000011000011111000003',
  149.        '30011000000000093900000000001113',
  150.        '30000000000000003000000000000093',
  151.        '30000000000000000000000111110003',
  152.        '31100000000000000000000000000003',
  153.        '39000001111111113111111111000003',
  154.        '30000000000009003600000000000003',
  155.        '30050000000000003000000000001113',
  156.        '30077770000000000000001100000003',
  157.        '30000000000000000000000000000003',
  158.        '31111111111111111111111111111113'),
  159.        // Room7
  160.        (
  161.        '30000000000000333333333333333333',
  162.        '30000000000000000000000000000003',
  163.        '30000000000000000000000000000003',
  164.        '30000000000000011344444444444493',
  165.        '30000000000000000344444444444443',
  166.        '30000007777700111344444444446443',
  167.        '31110000000000000344944444444443',
  168.        '30000000000000000344444444494443',
  169.        '31000000000000000344444644444443',
  170.        '30000000000000111344444444444443',
  171.        '31111111111100000349444444446443',
  172.        '30000000000000000344444444444493',
  173.        '30000000000000333344444644444443',
  174.        '300000000111003AB000000000000003',
  175.        '300000000000003BB000000000000003',
  176.        '31111111111111333333333333333333'),
  177.        // Room 8
  178.        (
  179.        '30600000006000000300300000000003',
  180.        '30000000000000000300300000000003',
  181.        '300000000000090EE300000000000113',
  182.        '30000000000000000300000000000003',
  183.        '30000000000000000300000000000003',
  184.        '31110000011111100311000000000003',
  185.        '30000000000000900300011110000013',
  186.        '30111000000000000300000000010003',
  187.        '30900000111000000300000000000003',
  188.        '30000000000000000311111000000003',
  189.        '31000000000011100300000000011113',
  190.        '30000000011000000D00000000000003',
  191.        '30001100000000000D00001111100003',
  192.        '30000000000CCC3AB311000000000903',
  193.        '300000000000003BB300000500000003',
  194.        '31111111111111111111111111111113'),
  195.        // Room 9
  196.       (
  197.         '3AB30000000000000000000000000003',
  198.         '3BB00000000000090000000000000003',
  199.         '30000000000000000000000000000003',
  200.         '30000000000000000000000000000003',
  201.         '30000000000000000000000000000003',
  202.         '31111001110011111111001110011003',
  203.         '30000000000000000000000000000003',
  204.         '30000000000000000000000000000113',
  205.         '300110011100CCCCCCCC000000000003',
  206.         '30000000000000000000001110011003',
  207.         '31100000000000000000000000000003',
  208.         '30000000000000000000000000000003',
  209.         '30011001110011111111001110011003',
  210.         '30000000000000000000000000000113',
  211.         '30000000000000000000000000000003',
  212.         '31111111111111111111111111111113'
  213.       ),
  214.       // Room 10
  215.       (
  216.       '30000000000601113060611111111113',
  217.       '30000000000000903000060000000093',
  218.       '31111110000000003000090000011113',
  219.       '30060000000000003000000000000003',
  220.       '30000000000000003111100000000003',
  221.       '30000000144444443000000111111113',
  222.       '31111000000900003000000000000003',
  223.       '30000000000000003111111144400003',
  224.       '31111100000000003090000000000003',
  225.       '36000000011111113000000000000113',
  226.       '31111440000000003111111100000063',
  227.       '30000000000000003000000644400003',
  228.       '30000000222222222200000000000003',
  229.       '311100000000AB000000000000001113',
  230.       '300000000000BB000000000000000003',
  231.       '22222222222222222222222222222222')
  232.  
  233.  
  234.  
  235.   );
  236.  
  237.  
  238. implementation
  239.  
  240. function GetTile(x, y: integer): integer;
  241. var
  242.   ch: char;
  243. begin
  244.   if (x >= 0) and (x < 32) and (y >= 0) and (y < 32) and
  245.      (currentRoom >= 1) and (currentRoom <= 10) then    // 7 room
  246.   begin
  247.     ch := allRooms[currentRoom][y][x + 1];
  248.     case ch of
  249.       '0': Result := 0;
  250.       '1': Result := 1;
  251.       '2': Result := 2;
  252.       '3': Result := 3;
  253.       '4': Result := 4;
  254.       '5': Result := 5;
  255.       '6': Result := 6;
  256.       '7': Result := 7;
  257.       '9': Result := 9;
  258.       'A': Result := 10;  // case A
  259.       'C': Result := 12;
  260.       else Result := 11;  // empty
  261.     end;
  262.   end else
  263.     Result := 0;
  264. end;
  265.  
  266. procedure UpdateRobot;
  267. begin
  268.   // Déplacer le robot
  269.   robotX := robotX + (robotDirection * robotSpeed);
  270.  
  271.   if robotX <= robotMinX then
  272.     robotDirection := 1   // right walk
  273.   else if robotX >= robotMaxX then
  274.     robotDirection := -1; // left
  275. end;
  276.  
  277. {$R *.lfm}
  278.  
  279. { TForm1 }
  280.  
  281. procedure TForm1.FormCreate(Sender: TObject);
  282. begin
  283.   FNativeFastCanvas := TNativeFastCanvas.Create(Self);
  284.   with FNativeFastCanvas do
  285.   begin
  286.     Parent := Self;
  287.     Align := alClient;
  288.     BackgroundColor := RGB(0, 0, 32);
  289.     OnNativePaint := @NativeFastCanvas1NativePaint;
  290.   end;
  291. end;
  292.  
  293. procedure TForm1.NativeFastCanvas1NativePaint(Sender: TObject; DC: HDC;Pixels: PFastPixel; Ww, Hh: Integer);
  294. var
  295.   FastCanvas: TNativeFastCanvas;
  296.   x, y, tileIndex, tileX, tileY: integer;
  297.   frameIndex: integer;
  298. begin
  299.   FastCanvas := TNativeFastCanvas(Sender);
  300.   FastCanvas.DC := DC;
  301.   FastCanvas.DrawVectorText(300, 560, roomNames[currentRoom], 25, RGB(255, 255, 255));
  302.  
  303.   for y := 0 to 15 do
  304.   begin
  305.     for x := 0 to 31 do
  306.     begin
  307.       tileIndex := GetTile(x, y);
  308.  
  309.       case tileIndex of
  310.           0..6: begin
  311.             // static sprites 32×32
  312.             tileX := (tileIndex mod 16) * 32;
  313.             tileY := ((currentRoom - 1) * 32) + (tileIndex div 16) * 32;
  314.            // if tileIndex > 0 then
  315.               Fastcanvas.BlitCopy('blocks.png', tileX, tileY, 32, 32, 60+x*32, 30+y*32, bmCopy);
  316.           end;
  317.  
  318.           7: begin // tapis
  319.             frameIndex := (GetTickCount div 150) mod 4; // 4 frames anim
  320.             tileX := 7*32 + frameIndex * 32;
  321.             tileY := ((currentRoom - 1) * 32);
  322.             Fastcanvas.BlitCopy('blocks.png', tileX, tileY, 32, 32, 60+x*32, 30+y*32, bmCopy);
  323.           end;
  324.           12: begin // tapis
  325.             frameIndex := (GetTickCount div 150) mod 4; // 4 frames anim
  326.             tileX := 7*32 + frameIndex * 32;
  327.             tileY := ((currentRoom - 1) * 32);
  328.             Fastcanvas.BlitCopy('blocks.png', tileX, tileY, 32, 32, 60+x*32, 30+y*32, bmCopy);
  329.           end;
  330.  
  331.           9: begin // keys
  332.             frameIndex := (GetTickCount div 200) mod 4;
  333.             tileX := 352 + frameIndex * 32;
  334.             tileY := ((currentRoom - 1) * 32);
  335.             Fastcanvas.BlitCopy('blocks.png', tileX, tileY, 32, 32, 60+x*32, 30+y*32, bmCopy);
  336.           end;
  337.  
  338.          10: begin  // Case A - door 64×64 occupant 2×2 tiles
  339.            frameIndex := (GetTickCount div 500) mod 2;
  340.            tileX :=  ((currentRoom - 1) * 64);
  341.            tileY := 1344+(frameIndex * 64);
  342.            Fastcanvas.BlitCopy('64x64.png', tileX, tileY, 64, 64, 60+ x*32, 30+y*32, bmCopy);
  343.           end;
  344.        end;
  345.       end;
  346.    end;
  347.  
  348.  
  349.  
  350.   frameIndex := (robotX div 16) mod 4;
  351.  
  352.   if (currentRoom = 1) then
  353.   begin
  354.     if robotDirection = 1 then
  355.     begin
  356.       // right
  357.       tileX := 1024 + frameIndex * 72;
  358.       tileY := 0;
  359.     end
  360.     else
  361.     begin
  362.       // left
  363.       tileX := -22 + frameIndex * 72;
  364.       tileY := 64;
  365.     end;
  366.  
  367.     Fastcanvas.BlitCopy('64x64.png', tileX, tileY, 64, 64, robotX, robotY, bmCopy);
  368.   end;
  369.  
  370. end;
  371.  
  372. procedure TForm1.Timer1Timer(Sender: TObject);
  373. begin
  374.   UpdateRobot;
  375.   FNativeFastCanvas.Invalidate;
  376. end;
  377.  
  378. procedure TForm1.ButtonPrevRoomClick(Sender: TObject);
  379. begin
  380.   if currentRoom > 1 then
  381.   begin
  382.     currentRoom := currentRoom - 1;
  383.   end
  384.   else
  385.   begin
  386.     currentRoom := 10; // To room 10
  387.   end;
  388.   FNativeFastCanvas.Invalidate; // Redraw
  389. end;
  390.  
  391. procedure TForm1.ButtonNextRoomClick(Sender: TObject);
  392. begin
  393.   if currentRoom < 10 then
  394.   begin
  395.     currentRoom := currentRoom + 1;
  396.   end
  397.   else
  398.   begin
  399.     currentRoom := 1; // To room 1
  400.   end;
  401.   FNativeFastCanvas.Invalidate; // Redraw
  402. end;
  403.  
  404. procedure TForm1.FormDestroy(Sender: TObject);
  405. begin
  406.   if Assigned(FNativeFastCanvas) then FNativeFastCanvas.Free;
  407. end;
  408.  
  409. end.
« Last Edit: June 26, 2025, 06:11:02 pm by Gigatron »
Sub Quantum Technology ! Pascal - C - C# - GD  Script - Java - Javascript - Glsl - Lua - Html5 - CSS - Amiga Rules !

Gigatron

  • Sr. Member
  • ****
  • Posts: 294
  • Amiga Rulez !!
Re: Fast Canvas Library V1.051
« Reply #27 on: June 26, 2025, 06:56:11 pm »
Hi

For manic miner if you want to go faster than light and see 1-20 level with less code use this
code : load rooms.txt external data ; Replace the code above with this one.

room.txt included
Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, Forms, Controls, Graphics, Dialogs, NativeFastCanvas,
  9.   Windows, ExtCtrls, StdCtrls;
  10.  
  11. type
  12.   { TForm1 }
  13.   TForm1 = class(TForm)
  14.     Button1: TButton;
  15.     Button2: TButton;
  16.     Timer1: TTimer;
  17.  
  18.     procedure FormCreate(Sender: TObject);
  19.     procedure FormDestroy(Sender: TObject);
  20.     procedure Timer1Timer(Sender: TObject);
  21.     procedure ButtonPrevRoomClick(Sender: TObject);
  22.     procedure ButtonNextRoomClick(Sender: TObject);
  23.   private
  24.     FNativeFastCanvas: TNativeFastCanvas;
  25.  
  26.   public
  27.     procedure NativeFastCanvas1NativePaint(Sender: TObject; DC: HDC; Pixels: PFastPixel; Ww, Hh: Integer);
  28.  
  29.   end;
  30.  
  31. var
  32.   Form1: TForm1;
  33.   robotX : integer = 555;
  34.   robotY: integer = 255;          // Position actuelle
  35.   robotDirection: integer = 1;    // 1 = droite, -1 = gauche
  36.   robotSpeed: integer = 5;        // Vitesse
  37.   robotMinX: integer = 312;       // Distance limite gauche
  38.   robotMaxX: integer = 540;       // Distance limite droite
  39.  
  40.   currentRoom: integer = 1;
  41.   maxRooms: integer = 0;
  42.  
  43.   // Dynamique array for rooms and roomsNames
  44.   allRooms: array[1..20] of array[0..15] of string;
  45.   roomNames: array[1..20] of string;
  46.  
  47.  
  48. implementation
  49.  
  50. procedure LoadRoomsFromFile(const filename: string);
  51. var
  52.   fileLines: TStringList;
  53.   i, roomNum, lineNum: integer;
  54.   line: string;
  55. begin
  56.   fileLines := TStringList.Create;
  57.   try
  58.     fileLines.LoadFromFile(filename);
  59.  
  60.     roomNum := 0;
  61.     lineNum := 0;
  62.  
  63.     for i := 0 to fileLines.Count - 1 do
  64.     begin
  65.       line := Trim(fileLines[i]);
  66.  
  67.       if (line = '') or (line[1] = '#') or (line[1] = '/') then
  68.         Continue;
  69.  
  70.       if (Copy(line, 1, 4) = 'ROOM') or (Copy(line, 1, 4) = 'Room') then
  71.       begin
  72.         Inc(roomNum);
  73.         lineNum := 0;
  74.         if Pos(':', line) > 0 then
  75.           roomNames[roomNum] := Copy(line, Pos(':', line) + 1, Length(line))
  76.         else
  77.           roomNames[roomNum] := 'ROOM ' + IntToStr(roomNum);
  78.         Continue;
  79.       end;
  80.  
  81.       if (roomNum > 0) and (lineNum < 16) and (Length(line) = 32) then
  82.       begin
  83.         allRooms[roomNum][lineNum] := line;
  84.         Inc(lineNum);
  85.       end;
  86.     end;
  87.  
  88.     maxRooms := roomNum;
  89.  
  90.   finally
  91.     fileLines.Free;
  92.   end;
  93. end;
  94.  
  95. function GetTile(x, y: integer): integer;
  96. var
  97.   ch: char;
  98. begin
  99.   if (x >= 0) and (x < 32) and (y >= 0) and (y < 32) and
  100.      (currentRoom >= 1) and (currentRoom <= maxRooms) then
  101.   begin
  102.     ch := allRooms[currentRoom][y][x + 1];
  103.     case ch of
  104.       '0': Result := 0;
  105.       '1': Result := 1;
  106.       '2': Result := 2;
  107.       '3': Result := 3;
  108.       '4': Result := 4;
  109.       '5': Result := 5;
  110.       '6': Result := 6;
  111.       '7': Result := 7;
  112.       '9': Result := 9;
  113.       'A': Result := 10;
  114.       'C': Result := 12;
  115.       'D': Result := 13;
  116.       'E': Result := 14;
  117.       else Result := 20; // empty !!
  118.     end;
  119.   end else
  120.     Result := 20;
  121. end;
  122.  
  123.  
  124. procedure UpdateRobot;
  125. begin
  126.   // Déplacer le robot
  127.   robotX := robotX + (robotDirection * robotSpeed);
  128.  
  129.   if robotX <= robotMinX then
  130.     robotDirection := 1   // right walk
  131.   else if robotX >= robotMaxX then
  132.     robotDirection := -1; // left
  133. end;
  134.  
  135. {$R *.lfm}
  136.  
  137. { TForm1 }
  138.  
  139. procedure TForm1.FormCreate(Sender: TObject);
  140. begin
  141.   FNativeFastCanvas := TNativeFastCanvas.Create(Self);
  142.   with FNativeFastCanvas do
  143.   begin
  144.     Parent := Self;
  145.     Align := alClient;
  146.     BackgroundColor := RGB(0, 0, 32);
  147.     OnNativePaint := @NativeFastCanvas1NativePaint;
  148.   end;
  149.  
  150.   try
  151.     LoadRoomsFromFile('rooms.txt');
  152.   except
  153.     on E: Exception do
  154.     begin
  155.       ShowMessage('Erreur lors du chargement: ' + E.Message);
  156.       maxRooms := 1;
  157.       allRooms[1][0] := '31111111111111111111111111111113';
  158.     end;
  159.   end;
  160.  
  161.  
  162. end;
  163.  
  164. procedure TForm1.NativeFastCanvas1NativePaint(Sender: TObject; DC: HDC;Pixels: PFastPixel; Ww, Hh: Integer);
  165. var
  166.   FastCanvas: TNativeFastCanvas;
  167.   x, y, tileIndex, tileX, tileY: integer;
  168.   frameIndex: integer;
  169. begin
  170.   FastCanvas := TNativeFastCanvas(Sender);
  171.   FastCanvas.DC := DC;
  172.   FastCanvas.DrawVectorText(100, 550, roomNames[currentRoom], 25, RGB(255, 255, 255));
  173.  
  174.   for y := 0 to 15 do
  175.   begin
  176.     for x := 0 to 31 do
  177.     begin
  178.       tileIndex := GetTile(x, y);
  179.  
  180.       case tileIndex of
  181.           0..6: begin
  182.             // static sprites 32×32
  183.             tileX := (tileIndex mod 16) * 32;
  184.             tileY := ((currentRoom - 1) * 32) + (tileIndex div 16) * 32;
  185.            // if tileIndex > 0 then
  186.               Fastcanvas.BlitCopy('blocks.png', tileX, tileY, 32, 32, 60+x*32, 30+y*32, bmCopy);
  187.           end;
  188.  
  189.           7: begin // tapis
  190.             frameIndex := (GetTickCount div 150) mod 4; // 4 frames anim
  191.             tileX := 7*32 + frameIndex * 32;
  192.             tileY := ((currentRoom - 1) * 32);
  193.             Fastcanvas.BlitCopy('blocks.png', tileX, tileY, 32, 32, 60+x*32, 30+y*32, bmCopy);
  194.           end;
  195.           12: begin // tapis
  196.             frameIndex := (GetTickCount div 150) mod 4; // 4 frames anim
  197.             tileX := 7*32 + frameIndex * 32;
  198.             tileY := ((currentRoom - 1) * 32);
  199.             Fastcanvas.BlitCopy('blocks.png', tileX, tileY, 32, 32, 60+x*32, 30+y*32, bmCopy);
  200.           end;
  201.  
  202.           9: begin // keys
  203.             frameIndex := (GetTickCount div 200) mod 4;
  204.             tileX := 352 + frameIndex * 32;
  205.             tileY := ((currentRoom - 1) * 32);
  206.             Fastcanvas.BlitCopy('blocks.png', tileX, tileY, 32, 32, 60+x*32, 30+y*32, bmCopy);
  207.           end;
  208.  
  209.          10: begin  // Case A - door 64×64 occupant 2×2 tiles
  210.            frameIndex := (GetTickCount div 500) mod 2;
  211.            tileX :=  ((currentRoom - 1) * 64);
  212.            tileY := 1344+(frameIndex * 64);
  213.            Fastcanvas.BlitCopy('64x64.png', tileX, tileY, 64, 64, 60+ x*32, 30+y*32, bmCopy);
  214.           end;
  215.        end;
  216.       end;
  217.    end;
  218.  
  219.  
  220.  
  221.   frameIndex := (robotX div 16) mod 4;
  222.  
  223.   if (currentRoom = 1) then
  224.   begin
  225.     if robotDirection = 1 then
  226.     begin
  227.       // right
  228.       tileX := 1024 + frameIndex * 72;
  229.       tileY := 0;
  230.     end
  231.     else
  232.     begin
  233.       // left
  234.       tileX := -22 + frameIndex * 72;
  235.       tileY := 64;
  236.     end;
  237.  
  238.     Fastcanvas.BlitCopy('64x64.png', tileX, tileY, 64, 64, robotX, robotY, bmCopy);
  239.   end;
  240.  
  241. end;
  242.  
  243. procedure TForm1.Timer1Timer(Sender: TObject);
  244. begin
  245.   UpdateRobot;
  246.   FNativeFastCanvas.Invalidate;
  247. end;
  248.  
  249. procedure TForm1.ButtonNextRoomClick(Sender: TObject);
  250. begin
  251.   if currentRoom < maxRooms then
  252.     currentRoom := currentRoom + 1
  253.   else
  254.     currentRoom := 1;
  255.   FNativeFastCanvas.Invalidate;
  256. end;
  257.  
  258. procedure TForm1.ButtonPrevRoomClick(Sender: TObject);
  259. begin
  260.   if currentRoom > 1 then
  261.     currentRoom := currentRoom - 1
  262.   else
  263.     currentRoom := maxRooms;
  264.   FNativeFastCanvas.Invalidate;
  265. end;
  266.  
  267. procedure TForm1.FormDestroy(Sender: TObject);
  268. begin
  269.   if Assigned(FNativeFastCanvas) then FNativeFastCanvas.Free;
  270. end;
  271.  
  272. end.
« Last Edit: June 26, 2025, 07:00:00 pm by Gigatron »
Sub Quantum Technology ! Pascal - C - C# - GD  Script - Java - Javascript - Glsl - Lua - Html5 - CSS - Amiga Rules !

Gigatron

  • Sr. Member
  • ****
  • Posts: 294
  • Amiga Rulez !!
Re: Fast Canvas Library V1.051
« Reply #28 on: June 29, 2025, 02:00:21 am »
Hi,
 
Maybe you would like to display more sprites on screen with the maximum performance
if you want to make games or other nice work.

The next version V1.052 include tilebatch to draw fast tiles 8x8,16x16 .. to 128x128 at max speed.

For example the anim_stars.png contain 10 frames this portion of code display all the
10 frames with tiledbatch.

Code: Pascal  [Select][+][-]
  1.   StarsBatch: TTileBatch;
  2.  
  3. implementation
  4.  
  5. {$R *.lfm}
  6.  
  7. procedure UpdateAndBatchStars(FastCanvas: TNativeFastCanvas; AnimTimer: Integer; ScrWidth, ScrHeight: Integer);
  8. var
  9.   i, j: Integer;
  10.   currentFrame: Integer;
  11.   animSpeed: Integer;
  12.   starSize: Integer;
  13.   starsRow, starsCol: Integer;
  14.   x, y: Integer;
  15. begin
  16.  
  17.   StarsBatch.Count := 0;
  18.   animSpeed := 5;
  19.   starSize := 16*2;
  20.   starsRow := (ScrWidth div starSize) + 1;
  21.   starsCol := (ScrHeight div starSize) + 1;
  22.  
  23.   for j := 0 to starsCol - 1 do
  24.   begin
  25.     for i := 0 to starsRow - 1 do
  26.     begin
  27.  
  28.       if StarsBatch.Count >= High(StarsBatch.Tiles) then
  29.         Break;
  30.       x := i * starSize;
  31.       y := j * starSize;
  32.       currentFrame := ((AnimTimer + i * 2 + j * 3) div animSpeed) mod 10;
  33.  
  34.       with StarsBatch.Tiles[StarsBatch.Count] do
  35.       begin
  36.         SrcX := currentFrame * 41;
  37.         SrcY := 0;
  38.         SrcW := 41;
  39.         SrcH := 37;
  40.         DestX := x;
  41.         DestY := y;
  42.         Alpha := 200 + Round(55 * Sin((AnimTimer + i + j) * 0.1));
  43.         Scale := 350 + Round(100 * Sin((i + j) * 0.3));
  44.       end;
  45.       Inc(StarsBatch.Count);
  46.     end;
  47.  
  48.     if StarsBatch.Count >= High(StarsBatch.Tiles) then
  49.       Break;
  50.   end;
  51.  
  52.   if StarsBatch.Count > 0 then FastCanvas.BlitTileBatch(StarsBatch);
  53. end;        


Init on FormCreate the starsBatch counter and Image File

Code: Pascal  [Select][+][-]
  1. procedure TForm1.FormCreate(Sender: TObject);
  2. begin
  3.   FNativeFastCanvas := TNativeFastCanvas.Create(Self);
  4.   with FNativeFastCanvas do
  5.   begin
  6.     Parent := Self;
  7.     Align := alClient;
  8.     BackgroundColor := RGB(0, 0, 32);
  9.     OnNativePaint := @NativeFastCanvasPaint;
  10.   end;
  11.  
  12.   StarsBatch.Count := 0;
  13.   StarsBatch.ImageFile := 'tex/anim_star.png';  

UpdateAndBatchStars on Main loop of nfcpaint proc;

Code: Pascal  [Select][+][-]
  1. procedure TForm1.NativeFastCanvasPaint(Sender: TObject; DC: HDC; Pixels: PFastPixel; Ww, Hh: Integer);  
  2. UpdateAndBatchStars(FastCanvas, FAnimTimer, Ww, Hh);


Sub Quantum Technology ! Pascal - C - C# - GD  Script - Java - Javascript - Glsl - Lua - Html5 - CSS - Amiga Rules !

Gigatron

  • Sr. Member
  • ****
  • Posts: 294
  • Amiga Rulez !!
Re: Fast Canvas Library V1.051
« Reply #29 on: July 07, 2025, 06:45:56 pm »
Hi,

Very busy yet , here is the state of the next versipn V1.052; (Fixed some bugs) Stars, StarsB and
others.

ImageMoveTo(x,y, to x1,to y1) with Easeing ; Tweens; Image Skew X/Y ImagePerspective .. and so.

Here is a little video demonstrate Easing and Tweens system..

This library will released soon .. when bugs fixed.

Regards

https://www.youtube.com/watch?v=RE-YtJdnKYA
Sub Quantum Technology ! Pascal - C - C# - GD  Script - Java - Javascript - Glsl - Lua - Html5 - CSS - Amiga Rules !

 

TinyPortal © 2005-2018