Recent

Author Topic: Seeing CLOUDS: But outside the sky is clear. How?  (Read 352 times)

Boleeman

  • Hero Member
  • *****
  • Posts: 910
Seeing CLOUDS: But outside the sky is clear. How?
« on: April 25, 2025, 05:25:31 am »
Ah ........ that's because the clouds are in digital form.


A Lazarus program to make clouds.

SHARPNESS  --->  Lower is fluffier. Higher is sharper.
DENSITY       --->  0.7=Nearly clear sky, 0.2=Nearly full of clouds.


Enjoy.


Lulu

  • Sr. Member
  • ****
  • Posts: 295
Re: Seeing CLOUDS: But outside the sky is clear. How?
« Reply #1 on: April 25, 2025, 07:57:46 pm »
Hi Boleeman, thank you for all your graphic demos!

I compiled the clouds demo in debug mode and an exception occurs on the line:
Code: Pascal  [Select][+][-]
  1. procedure TForm1.Timer1Timer(Sender: TObject);
  2. ...
  3. col := RGBToColor(R + Round(z * (256 - R)), G + Round(z * (256 - G)), B + Round(z * (256 - B)));
  4. ...

if I replace this line by this one, no more exception:
Code: Pascal  [Select][+][-]
  1. col := RGBToColor(R + Round(z * (255 - R)), G + Round(z * (255 - G)), B + Round(z * (255 - B)));

Heaptrc report 102 unfreed memory block at the termination of the program.
If we add:
Code: Pascal  [Select][+][-]
  1. procedure TForm1.FormDestroy(Sender: TObject);
  2. var
  3.   i: Integer;
  4. begin
  5.   SkyBmp.Free;
  6.   for i := 0 to 3 do
  7.   begin
  8.     OctavesA[i].Free;
  9.     OctavesB[i].Free;
  10.   end;
  11.   Clouds.Free;
  12. end;
  13.  
its not enough, there still remain 70 unfreed blocks.
Nothing serious, but it's better when the code ends cleanly.
wishing you a nice life!
GitHub repositories https://github.com/Lulu04

Boleeman

  • Hero Member
  • *****
  • Posts: 910
Re: Seeing CLOUDS: But outside the sky is clear. How?
« Reply #2 on: April 26, 2025, 06:12:15 am »
Thanks Lulu. for finding those errors. For some reason they did not happen on my Dell AMD Cpu laptop.
I was in a hurry to upload yesterday, as I made quite a number of other programs.

For the clouds program I also forgot the destructor:

type
  TArray2D = class
  private
    FWidth, FHeight: Integer;
    FData: array of Double;
  public
    constructor Create(AWidth, AHeight: Integer);
    destructor Destroy; override;

and under implementation

{$R *.lfm} 

Add this:

destructor TArray2D.Destroy;
begin
  SetLength(FData, 0); // Or use Finalize(FData);
  inherited Destroy;
end;   




Thank you Lulu for letting me know.

TRon:  Yes it is confusing, but I like the clouds produced and thought it would be cool to share what I had to others.
« Last Edit: April 26, 2025, 03:27:19 pm by Boleeman »

TRon

  • Hero Member
  • *****
  • Posts: 4371
Re: Seeing CLOUDS: But outside the sky is clear. How?
« Reply #3 on: April 26, 2025, 06:20:14 am »
Funny that when added (though right decision) it makes matters worse  :)

The 'problem' is that T2darray is a class and in the code it gets created, stored into a variable and that variable is used to for example smooth the data, which returns a new instance of T2darray and assigning to that same variable.

At quick glance there is not an easy fix. E.g. I dunno if it is possible to for instance apply the effect to the existing instance of the t2array that will achieve the same results.
Today is tomorrow's yesterday.

 

TinyPortal © 2005-2018