MandelBrot Fractal in HMG :)

HMG Samples and Enhancements

Moderator: Rathinagiri

User avatar
Rathinagiri
Posts: 5471
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Contact:

MandelBrot Fractal in HMG :)

Post by Rathinagiri »

Just these 88 lines of code creates a wonderful MandelBrot fractal. Enjoy!

Code: Select all

#include <hmg.ch>

Function Main
   public lStop := .f.
   define window main at 0, 0 width 1000 height 800 title 'MandelBrot' main
      define button b1
         row 10
         col 10
         width 80
         caption "Draw"
         action startcalc()
      end button
      define button stop
         row 10
         col 110
         caption 'Stop'
         action lStop := .t.
      end button 
   end window
   Main.Center
   Main.Activate

Return

function startcalc
   local nWidth := 800
   local nHeight := 600
   local hDC, BTstruct
   local aColors := { ;
   {66, 30, 15},;
    {25, 7, 26},;
    {9, 1, 47},;
    {4, 4, 73},;
    {0, 7, 100},;
    {12, 44, 138},;
    {24, 82, 177},;
    {57, 125, 209},;
    {134, 181, 229},;
    {211, 236, 248},;
    {241, 233, 191},;
    {248, 201, 95},;
    {255, 170, 0},;
    {204, 128, 0},;
    {153, 87, 0},;
    {106, 52, 3};
   }
   BT_ClientAreaInvalidateAll ("main")
   hDC := BT_CreateDC ("main", BT_HDC_INVALIDCLIENTAREA, @BTstruct)
   BT_DrawFillRectangle (hDC, 40, 40, nWidth, nHeight, { 255, 255, 255 }, { 0, 0, 0 }, 1 )
   cx := 0.05
   cy := 0.05
   scale := 0.005
   limit := 40
   for x := -400 to ( nWidth / 2 )
      for y:= -300 to ( nHeight / 2 )
         ax := cx + ( x * scale )
         ay := cy + ( y * scale )
         a1 := ax
         b1 := ay
         lp := 0 
         for lp = 1 to 255
            a2 := ( a1 * a1 ) -  ( b1 * b1 ) + ax 
            b2 := 2*a1*b1+ay
            a1 := a2
            b1 := b2
            if ( a1 * a1 ) + ( b1 * b1 ) > limit
               exit
            endif
         next lp   
         if lp < 255 
            aColor := aColors[ if( int( mod( lp, 16 ) ) > 0, int( mod( lp, 16 ) ), 1 ) ]
         else
            aColor := { 0, 0, 0 }
         endif
         nRow := 40 + 300 + y
         nCol := 40 + 400 + x
         BT_DrawSetPixel ( hDC, nRow, nCol, aColor )
         do events
         if lStop
            exit
         endif
      next y
      if lStop
         exit
      endif
   next x   
   BT_DeleteDC( BTstruct )
return nil   
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.
User avatar
andyglezl
Posts: 1461
Joined: Fri Oct 26, 2012 7:58 pm
Location: Guadalajara Jalisco, MX
Contact:

Re: MandelBrot Fractal in HMG :)

Post by andyglezl »

Fantastico Rathi !!!
Gracias.
Andrés González López
Desde Guadalajara, Jalisco. México.
User avatar
serge_girard
Posts: 3165
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Contact:

Re: MandelBrot Fractal in HMG :)

Post by serge_girard »

Great work!

Serge
There's nothing you can do that can't be done...
chrisjx2002
Posts: 190
Joined: Wed Jan 06, 2010 5:39 pm

Re: MandelBrot Fractal in HMG :)

Post by chrisjx2002 »

Beautiful!
User avatar
gfilatov
Posts: 1066
Joined: Fri Aug 01, 2008 5:42 am
Location: Ukraine
Contact:

Re: MandelBrot Fractal in HMG :)

Post by gfilatov »

Rathinagiri wrote: Wed Oct 31, 2018 1:14 pm Just these 88 lines of code creates a wonderful MandelBrot fractal. Enjoy!
Thanks a lot, Rathi :!:
My result is below
Attachments
screen.png
screen.png (97.99 KiB) Viewed 3300 times
Kind Regards,
Grigory Filatov

"Everything should be made as simple as possible, but no simpler." Albert Einstein
EduardoLuis
Posts: 682
Joined: Tue Jun 04, 2013 6:33 pm
Location: Argentina

Re: MandelBrot Fractal in HMG :)

Post by EduardoLuis »

SUPERB DEMO. Thanks Rathi for share.-
Eduardo
User avatar
andyglezl
Posts: 1461
Joined: Fri Oct 26, 2012 7:58 pm
Location: Guadalajara Jalisco, MX
Contact:

Re: MandelBrot Fractal in HMG :)

Post by andyglezl »

Rathi, tu eres un genio, yo no entendí nada... :oops:
*-----------------------------------------------------------
Rathi, you are a genius, I did not understand anything ... :oops:

https://en.wikipedia.org/wiki/Mandelbrot_set
Andrés González López
Desde Guadalajara, Jalisco. México.
User avatar
luisvasquezcl
Posts: 1258
Joined: Thu Jul 31, 2008 3:23 am
Location: Chile
Contact:

Re: MandelBrot Fractal in HMG :)

Post by luisvasquezcl »

Great rathi. Beauti result
Best regards
User avatar
Steed
Posts: 427
Joined: Sat Dec 12, 2009 3:40 pm

Re: MandelBrot Fractal in HMG :)

Post by Steed »

Congratulations,
User avatar
mustafa
Posts: 1158
Joined: Fri Mar 20, 2009 11:38 am
DBs Used: DBF
Location: Alicante - Spain
Contact:

Re: MandelBrot Fractal in HMG :)

Post by mustafa »

+1
Best regards
Mustafa
Post Reply