Lazarus

Programming => Graphics and Multimedia => Graphics => Topic started by: Boleeman on November 30, 2024, 08:14:46 am

Title: Random SnowFlakes:
Post by: Boleeman on November 30, 2024, 08:14:46 am
Hi All.

I have found a nice random Javascript snowflake generator that uses svg elements to generate random snowflake curves.

It is in a html file and is only one line long.

Code: Pascal  [Select][+][-]
  1. <canvas id=b><svg onload='with(Math)for(I=Y=0;Y++<70;I=random()-1.9&I+1)for(i=12;i--;C=X=>b.getContext`2d`.fillRect(70+X,s*j+c*Y+70,1,1)||X,C(-C((c=cos(a=PI/3*i))*j-(s=sin(a))*Y)))j=i>5&&I'>

I tried to convert to Lazarus using a TBgrabmp, but all I see is dots.

Is it possible to use svg in TBgrabmp to draw the random snowflakes correctly?

Can't seem to work out how to render the curve correctly so that it looks like a snowflake.
Must have something to do with the svg graphics ?
Title: Re: Random SnowFlakes: Javascript conversion to Lazarus needed
Post by: Boleeman on November 30, 2024, 08:37:53 am
Somehow need to work out how to render svg in Lazarus ?
Title: Re: Random SnowFlakes: Better Javascript conversion to Lazarus needed !
Post by: Dzandaa on November 30, 2024, 11:25:02 am
Hi
@Boleeman:

In BGRAControls, there is a TBCSVGViewer

Create your SVG code in a string and put it in TBCSVGViewer.SVGString


B->

Title: Re: Random SnowFlakes: Better Javascript conversion to Lazarus needed !
Post by: Roland57 on December 01, 2024, 04:39:47 pm
Hi. I don't know the answer to your question, but here are my snowflakes using Cairo.  :)

https://forum.lazarus.freepascal.org/index.php/topic,57657.msg428979.html#msg428979
Title: Re: Random SnowFlakes: Better Javascript conversion to Lazarus needed !
Post by: Boleeman on December 02, 2024, 05:08:57 am
Sorry about the late reply: Been a bit crook lately with a bug.

Thanks Dzandaa and Roland57 for your replies about snowflakes.

Roland57: Compiled your Cairo Snowflake Lazarus source after downloading GTK from
http://downloads.sourceforge.net/gladewin32/gtk-2.12.9-win32-2.exe
I tried installing GTK3 runtime but was getting an error after compiling the Cairo snowflake code..

Also remembered seeing a few interesting cpp and CSharp snowflake examples on Codeproject ages ago.
Went to the Codeproject site yesterday and it looks like it has gone by way of the DODO .... Shutdown.

I compiled a CSharp Xmas Snowflakes code, but the flakes seem quite ordinary.
There was another Codeproject example that had some intricate random snowflakes but I can't find where I put it.

Title: Re: Random SnowFlakes: Better Javascript conversion to Lazarus needed !
Post by: Laksen on December 02, 2024, 07:17:25 am
That's some well obfuscated code...

I think, minus the antialiasing and stuff this gets close
Code: Pascal  [Select][+][-]
  1. procedure TForm1.GenerateSnowflake(BgraBitmap: TBGRABitmap);
  2. var
  3.   Y, i, ii: integer;
  4.   j: integer;
  5.   a, c, s: double;
  6.  
  7.   function CC(X: double): double;
  8.   var
  9.     lx, ly: Int64;
  10.   begin
  11.     lx:=round(70+x);
  12.     ly:=round(s*j+c*y+70);
  13.     BgraBitmap.FillRect(lx, ly,lx+1, ly+1, BGRA(0, 0, 0), dmSet);
  14.     result:=X;
  15.   end;
  16. begin
  17.   I := 0;
  18.   for Y := 0 to 69 do
  19.   begin
  20.     for ii := 12 downto 0 do
  21.     begin
  22.       j := ifthen(ii > 5,I,0);
  23.  
  24.       a := PI/3*ii;
  25.       c := Cos(a);
  26.       s := Sin(a);
  27.       CC(-CC(c*j-s*Y));
  28.     end;
  29.  
  30.     I:=(trunc(random()-1.9) and (I+1));
  31.   end;
  32. end;
  33.  
Title: Re: Random SnowFlakes: Better Javascript conversion to Lazarus needed !
Post by: Boleeman on December 02, 2024, 08:46:51 am
Laksen, that's fantastic.

Got the thickness working and Multiple Flakes.

I wonder if we could possibly smooth the flakes a bit ?

Made a small update: Realized that some curves were not that random, so put Randomize in the form's OnCreate.
Title: Re: Random SnowFlakes: Multiple Flakes but Smoothing Required
Post by: Boleeman on December 02, 2024, 09:05:23 am
I tried applying a Blur filter from TBgrabmp. A bit slower on the rendering now.
Would be nice if we could make the lines SVG.

What else could we possibly try to make the lines look smoother?
Title: Re: Random SnowFlakes: Multiple Flakes but Smoothing Required
Post by: Thaddy on December 02, 2024, 10:37:20 am
I had to invert the colours to obtain snowflakes....
Title: Re: Random SnowFlakes: Multiple Flakes but Smoothing Required
Post by: Boleeman on December 02, 2024, 11:26:29 am
Great idea Thaddy.

White Snowflakes on a black background !
Title: Re: Random SnowFlakes: Multiple Flakes but Smoothing Required
Post by: Boleeman on December 02, 2024, 12:24:18 pm
Render to a TBgrabmp control.
Title: Re: Random SnowFlakes:
Post by: Boleeman on December 03, 2024, 09:01:13 am
Sort of feeling like I need to start looking into fpVectorial to create some vector (svg) curves.

Javascript does svg well, but would like to look at Lazarus methods to do vector graphics.
Title: Re: Random SnowFlakes:
Post by: zamtmn on December 03, 2024, 09:23:12 am
On topic of the upcoming holidays - it will be useful https://habr.com/ru/articles/246895/
Title: Re: Random SnowFlakes:
Post by: Boleeman on December 03, 2024, 09:07:14 pm
Thanks zamtmn for that interesting Snowflake Maker information. And with Lazarus source.

I also came across a Snowflake Generator Webpage which does snowflakes as well.
The page saved OK so I can run it on my computer without connecting to the Net.
Might try to make something similar in Lazarus.

Late 2 png attachments: Compiled the program from zamtmn's "snowflaker" site suggestion and tested it out.
It uses Bezier type curves. Takes a bit of getting used to, but has real unique curve potential. COOL !

Thanks zamtmn.

Title: Re: Random SnowFlakes:
Post by: Boleeman on January 10, 2025, 06:34:41 am
Found a nicely rendered Snowflake Maker (but it for paying customers).

The flakes look so realistic.

https://www.incendia.net/wiki/index.php?title=Snowflake_Generator
https://www.incendia.net/snowflake.php

I am drooling looking at the fine details in the rendered flakes.

Would be nice to make something like this in Lazarus.
TinyPortal © 2005-2018