Fractal map

Post your FreeBASIC source, examples, tips and tricks here. Please don’t post code without including an explanation.
Luxan
Posts: 222
Joined: Feb 18, 2009 12:47
Location: New Zealand

Fractal map

Post by Luxan »

Code: Select all

'
' -----------------------------------------------------------------------------
'
'      (c) Edward . Q . Montague . 
'
'                  [ alias ]
'
'        quintin9g@gmail.com
'
'
'  Modified Euler Heun method for Volterra Lottka
'    differential equations .
'
'     x' =  a x - b x y      = f1(x,y)
'     y' = -g y + c x y    = g1(x,y)
'
' In this instance a=b=c=d = 1 , therefore :
'
'     u = x - x*y            = f1(x,y)
'     w = -y + x*y         = g1(x,y)
'
' -----------------------------------------------------------------------------
'
'
'             Load a 800x600 bitmap into an image
'
'   This is from a fractint iteration .
'
' -----------------------------------------------------------------------------
'
declare function f1(x as single,y as single) as single
declare function g1(x as single,y as single) as single
'
declare function store(Byref a1 as single,Byref b1 as single,Byref c1 as single,Byref d1 as single) as integer
'
declare function EH2a(a1() as single,xfinal as single,steps as integer,x as single,y as single) as integer
'
declare function pal() as integer
declare function scanner2(xImage As Any Ptr ,a2() as single) as integer
declare function attractors(a2() as single) as integer
'
' -----------------------------------------------------------------------------
'
#include "EHStr.bas"
'
' -----------------------------------------------------------------------------
'
dim as integer fg
dim as single a2()
'
' -----------------------------------------------------------------------------
'
ScreenRes 820, 690, 8 ' all fractint image files are 8 bit == 256 colours
Dim myImage As Any Ptr = ImageCreate( 800, 600 )  
'
BLoad "fract005.bmp", myImage
'
'fg=pal()
'sleep
'end
 fg=scanner2(myImage  ,a2() ) 
Put (10,10), myImage
'
window (0,-1)-(128,1)
view (10,612)-(810,688) 
'
'
'   Function attractor will automatically scan for regions of attraction ,
' from the 'blue' coloured map  for  the Euler - Huen iterator.
'
'
'fg=attractors(a2() )

fg = mousey() 

sleep
ImageDestroy( myImage )
'
end
'
' ==============================
'
function EH2a(a1() as single,xfinal as single,steps as integer,x as single,y as single) as integer
'
'
'    Modified Euler Huen method ,
' applied to differential equations defined by f1() and g1() .
'
'  This is similar to a fractint frm file .
'
'
static as integer p2,iter
static as single p,h,u,w,a,b,c,d,z
'
'
for iter=0 to steps
     a1(iter,0)=0
     a1(iter,1)=0
next iter
'
'
    p = 0.739
    h = 0.739/2
  p2 = 256
iter = 0
    u = 0
   w = 0
    a = 0
    b = 0
    c = 0
    d = 0
    z = 0
'
    while(z<=p2 and (iter<256) )       
                     iter = iter+1
                        u = f1(x,y)
                        w = g1(x,y)
                         a = x+p*u
                         b = y+p*w
                         c = x+h*(u+f1(a,b))
                         d = y+h*(w+g1(a,b))
                         x = c
                         y = d
                         a1(iter-1,0)=x 
                         a1(iter-1,1)=y
  '                       z = x + -flip(y)
                         z = mag(x,y) 
                       wend
'
                     return ( iter)
'
'                         
  end function
' 
' --------------------------------------------------------------------------------
'
function pal() as integer
'
'  Examine palette associated with fractint image .
'
'  Choose lower and upper limits for scanner2 function .
'
static as integer i,c
'
line(10,10)-(266,50),0,b
line(10,10)-(266,50),56,b
for i=1 to 255
     line(i+10,10)-(i+10,50),i,bf
next i
line(10,10)-(266,50),56,b
'
line(10,70)-(266,110),0,bf
line(10,70)-(266,110),56,b
for i=1 to 255
      c = point(i+10,20)
     line(i+10,70)-(i+10,110),c,bf
     if (c=86) then line(i+10,70)-(i+10,110),12,bf
     if (c=114) then line(i+10,70)-(i+10,110),12,bf
next i
line(10,70)-(266,110),56,b
'
              return (0)
'
end function
'
' -----------------------------------------------------------------------------
'
function store(Byref a1 as single,Byref b1 as single,Byref c1 as single,Byref d1 as single) as integer
'
'   Store coordinates for this fractal 
'
'
'
'   Top left corner .
'
a1=0
c1=4.5
'
'  Bottom right corner .
'
b1=6
d1=0
'
              return (0)
'
end function
'
' -----------------------------------------------------------------------------
'
function scanner2(xImage As Any Ptr ,a2() as single) as integer
'
'    scan  image , in memory , for stable points ; these
'  are coloured white when using the blue color map. 
'
'  Use lower and upper limits selected from function pal().
'
'
'  The dimensions of the image are :  800x600 , n x m
'
'
static as integer i,j,n,m,c1,k
static as single ax,bx,cy,dy,x,y
'
i= store(ax ,bx ,cy ,dy ) 
'
   n=800
   m=600
' 
      k = 0
  for j=0 to m
    for i=0 to n
        c1=point(i,j,xImage)
      if (c1 > 86) and (c1<114) then   k=k+1
    next i
  next j  
'
redim as single a2(k,1) 
'
      k = 0
  for j=0 to m
    for i=0 to n
        c1=point(i,j,xImage)
      if (c1 > 86) and (c1<114) then   
         a2(k,0)=i
         a2(k,1)=j
          k=k+1
     end if
    next i
  next j  
'
for c1 =0 to k
      i=a2(c1,0)
      j=a2(c1,1)
     x = ax+(bx-ax)*(i)/800
     y = cy+(dy-cy)*(j)/600     
     a2(c1,0) = x
     a2(c1,1) = y
next c1
'
          return (0) 
'
'
end function
'
' --------------------------------------------------------------------------------
'
function attractors(a2() as single) as integer
'
'        Waveforms from results of scanner2
'
'
'
static as integer k ,i,fg
static as single a1(256,1),x,y
'
'
k=ubound(a2)

'print"k====";k

for i = 0 to k-1
     x = a2(i,0)
     y = a2(i,1)
    fg = EH2a(a1() , 12 , 256 ,x,y) 
    fg = plot2d(a1() , 256 )
   sleep 500
next i
'
return (k)
'
'
end function
'
' --------------------------------------------------------------------------------
'
function f1(x as single,y as single) as single
'
'                       x' = x - x*y            = f1(x,y)
'
'
static as single z


                         z = x - x*y
          return (z)

 end function
'
' -----------------------------------------------------------------------------
'
function g1(x as single,y as single) as single
'
'
'                    y' = -y + x*y         = g1(x,y)
'
'
static as single z


                         z =  -y + x*y  
          return (z)

 end function
'
' ------------------------------------------------------------------------------
'
'
'
'
'   Various functions used with the Euler Huen iterator .
'
'
'
Const LEFTBUTTON   = 1
Const MIDDLEBUTTON = 4   ' UNUSED IN THIS DEMO
Const RIGHTBUTTON  = 2   ' UNUSED IN THIS DEMO
Const SHOWMOUSE    = 1
Const HIDEMOUSE    = 0
'
declare function mag(x as single,y as single) as single
declare function mousey() as integer
declare function plot2d(a1() as single, steps as integer ) as integer  
'declare function scanner2(xImage As Any Ptr ,a2() as single) as integer
'declare function attractors(a2() as single) as integer
'
'declare function pal() as integer
'
declare function transi2x(i as integer,a as single,b as single)  as single
declare function transj2y(j as integer,c as single,d as single) as single
'
' =========================================
'
function mousey() as integer
'
'   Use mouse to select a point from the fractal .
'
'
'
Dim CurrentX     As Integer
Dim CurrentY     As Integer
Dim MouseButtons As Integer
Dim CanExit      As Integer
Dim as single  ax,bx,cy,dy,a1(256,1),x,y
dim as integer fg
'
fg= store(ax , bx ,cy,dy) 
'
'
SetMouse 1, 1, SHOWMOUSE

Do
   GetMouse CurrentX, CurrentY, , MouseButtons
   
   If MouseButtons And LEFTBUTTON Then
'    
    If (CurrentX >=10 and CurrentX <=810) and (CurrentY >=10 and CurrentY <= 610 ) then
                      x = ax+(bx-ax)*(CurrentX-10)/800
                      y = cy+(dy-cy)*(CurrentY-10)/600
                     fg = EH2d(a1() , 12 , 256,x,y ) 
                     fg = plot2d(a1() , 256 )
   End If
'
   End If
     
Loop While Inkey$ = ""

return 0

end function
'
' ------------------------------------------------------------------------------
'
function mag(x as single ,y as single) as single
'
'                                        sqrt(x*x+y*y)
'
static as single w

     w=x*x+y*y
     if (w>0) then w=sqr(w)
     
     return (w)
'
end function
'
 '
' ------------------------------------------------------------------------------
'
 function plot2d(a1() as single, steps as integer ) as integer  
 '
 '   Plot sequence generated from EH2a()
 '
 '
 'window (0,-1)-(steps,1)
' view (10,612)-(810,688)
 static as integer i,j
 static as single maxx,maxy,x,y,u,v
 
 line (0,-1)-(steps,1),0,bf
 
    i=2
   maxx = 0 
   maxy = 0
  for i=0 to steps
        x = a1(i,0)
        y = a1(i,1)
        x = abs(x)
        y= abs(y)
   if (x>maxx) then maxx=x
   if(y>maxy) then maxy=y
  next i
'  
if (maxx=0) then maxx=1
if (maxy=0) then maxy=1
'
        x = a1(0,0)/maxx
        y = a1(0,1)/maxy
        j=0
' 
 for i=1 to steps
        u = a1(i,0)/maxx
        v = a1(i,1)/maxy
        line(j,x)-(i,u), 96
        line(j,y)-(i,v), 53
         j = i
       x = u
       y = v
  next i
'     
    return (i) 

 end function
'
' ------------------------------------------------------------------------------
'
 function transi2x(i as integer,a as single,b as single)  as single
'
'  translate from screen coordinate to map coordinate
'
static as single x
'
                  x = a+(b-a)*i/800
'
     return (x)
'
end function
'
' -----------------------------------------------------------------------------
'
function transj2y(j as integer,c as single,d as single) as single
'
'  translate from screen coordinate to map coordinate
'
static as single y
'
                              y = c+(d-c)*(j)/600
'
                return (y)
'
end function
'
Path: unixg.ubc.ca!news.mic.ucla.edu!library.ucla.edu!europa.eng.gtefsd.com!darwin.sura.net!paladin.american.edu!auvm!VAXB.MIDDLESEX.AC.UK!DAVID1
Comments: Gated by NETNEWS@AUVM.AMERICAN.EDU
Newsgroups: bit.listserv.frac-l
Via: uk.ac.mdx.vaxa; Mon, 27 Jun 1994 00:09:14 +0100
Message-ID: <FRAC-L%94062619112203@GITVM1.GATECH.EDU>
Date: Mon, 27 Jun 1994 00:10:00 GMT
Sender: "\"FRACTAL\" discussion list" <FRAC-L@GITVM1.BITNET>
From: DAVID1@VAXB.MIDDLESEX.AC.UK
Subject: Ramiro Perez Volterra .FRM
Lines: 33

These are the Volterra-Lotka Formulas p 125 BOF received from Ramiro Perez:

comment={received from Ramiro Perez <RPEREZ@EARN.UTPVM1> 18 Aug 93
}
V-Euler{
x=real(pixel),
y=imag(pixel),
h=real(p1)/2:
u=x-x*y,
w=-y+x*y,
c=x+h*(u+u),
d=y+h*(w+w),
x=c,
y=d,
z=x+flip(y),
|z|<=p2
}
V-Heun{
x=real(pixel),
y=imag(pixel),
p=real(p1),
h=imag(p1)/2:
u=x-x*y,
w=-y+x*y,
a=x+p*u,
b=y+p*w,
c=x+h*(u+(a-a*b)),
d=y+h*(w+(-b+a*b)),
x=c,
y=d,
z=x+flip(y),
|z|<=p2
}
Regards David Walter London england.

VHeun { ; Volterra-Lottka
reset=2004 type=formula formulafile=fractint.frm formulaname=V-Heun
corners=0.000150015/6.00015/0/4.5
params=0.73899999999999999/0.73899999999999999/64/0 float=y
maxiter=2048 inside=bof60 logmap=yes colors=@blues.map
}
fxm
Moderator
Posts: 12110
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Fractal map

Post by fxm »

Please when editing or reediting of your post, by using the button "Code", put your code inside two tags:
[code].....your code.....[/code]
(Verify that the field "Disable BBCode" is unchecked)
integer
Posts: 408
Joined: Feb 01, 2007 16:54
Location: usa

Re: Fractal map

Post by integer »

Where is:

Code: Select all

 #include "EHStr.bas"
Compiler output:
...(47) error 23: File not found, "EHStr.bas" in '#include "EHStr.bas"'

Results:
Compilation failed
Luxan
Posts: 222
Joined: Feb 18, 2009 12:47
Location: New Zealand

Re: Fractal map

Post by Luxan »

EHStr.bas is within the code listed and beyond the first code , which has
an END statement .

Look for the relevant function names , this just consists of declarations and functions.

If you omit #include "EHStr.bas" and just enter all of the BASIC code with all declarations at the begining then the code should work ; I shall attempt to send again
using the code option .

Also note that fract005.bmp is generated by fractint using the function , Volterra-Lotka
selection , I was unable to include the image.
Luxan
Posts: 222
Joined: Feb 18, 2009 12:47
Location: New Zealand

Re: Fractal map

Post by Luxan »

Code: Select all

'
' -----------------------------------------------------------------------------
'
'      (c) Edward . Q . Montague . 
'
'                  [ alias ]
'
'        quintin9g@gmail.com
'
'
'  Modified Euler Heun method for Volterra Lottka
'    differential equations .
'
'     x' =  a x - b x y      = f1(x,y)
'     y' = -g y + c x y    = g1(x,y)
'
' In this instance a=b=c=d = 1 , therefore :
'
'     u = x - x*y            = f1(x,y)
'     w = -y + x*y         = g1(x,y)
'
' -----------------------------------------------------------------------------
'
'
'             Load a 800x600 bitmap into an image
'
'   This is from a fractint iteration .
'
' -----------------------------------------------------------------------------
'
declare function f1(x as single,y as single) as single
declare function g1(x as single,y as single) as single
'
declare function store(Byref a1 as single,Byref b1 as single,Byref c1 as single,Byref d1 as single) as integer
'
declare function EH2a(a1() as single,xfinal as single,steps as integer,x as single,y as single) as integer
'
declare function pal() as integer
declare function scanner2(xImage As Any Ptr ,a2() as single) as integer
declare function attractors(a2() as single) as integer
'
' -----------------------------------------------------------------------------
'
#include "EHStr.bas"
'
' -----------------------------------------------------------------------------
'
dim as integer fg
dim as single a2()
'
' -----------------------------------------------------------------------------
'
ScreenRes 820, 690, 8 ' all fractint image files are 8 bit == 256 colours
Dim myImage As Any Ptr = ImageCreate( 800, 600 )  
'
BLoad "fract005.bmp", myImage
'
'fg=pal()
'sleep
'end
 fg=scanner2(myImage  ,a2() ) 
Put (10,10), myImage
'
window (0,-1)-(128,1)
view (10,612)-(810,688) 
'
'
'   Function attractor will automatically scan for regions of attraction ,
' from the 'blue' coloured map  for  the Euler - Huen iterator.
'
'
'fg=attractors(a2() )

fg = mousey() 

sleep
ImageDestroy( myImage )
'
end
'
' ==============================
'
function EH2a(a1() as single,xfinal as single,steps as integer,x as single,y as single) as integer
'
'
'    Modified Euler Huen method ,
' applied to differential equations defined by f1() and g1() .
'
'  This is similar to a fractint frm file .
'
'
static as integer p2,iter
static as single p,h,u,w,a,b,c,d,z
'
'
for iter=0 to steps
     a1(iter,0)=0
     a1(iter,1)=0
next iter
'
'
    p = 0.739
    h = 0.739/2
  p2 = 256
iter = 0
    u = 0
   w = 0
    a = 0
    b = 0
    c = 0
    d = 0
    z = 0
'
    while(z<=p2 and (iter<256) )       
                     iter = iter+1
                        u = f1(x,y)
                        w = g1(x,y)
                         a = x+p*u
                         b = y+p*w
                         c = x+h*(u+f1(a,b))
                         d = y+h*(w+g1(a,b))
                         x = c
                         y = d
                         a1(iter-1,0)=x 
                         a1(iter-1,1)=y
  '                       z = x + -flip(y)
                         z = mag(x,y) 
                       wend
'
                     return ( iter)
'
'                         
  end function
' 
' --------------------------------------------------------------------------------
'
function pal() as integer
'
'  Examine palette associated with fractint image .
'
'  Choose lower and upper limits for scanner2 function .
'
static as integer i,c
'
line(10,10)-(266,50),0,b
line(10,10)-(266,50),56,b
for i=1 to 255
     line(i+10,10)-(i+10,50),i,bf
next i
line(10,10)-(266,50),56,b
'
line(10,70)-(266,110),0,bf
line(10,70)-(266,110),56,b
for i=1 to 255
      c = point(i+10,20)
     line(i+10,70)-(i+10,110),c,bf
     if (c=86) then line(i+10,70)-(i+10,110),12,bf
     if (c=114) then line(i+10,70)-(i+10,110),12,bf
next i
line(10,70)-(266,110),56,b
'
              return (0)
'
end function
'
' -----------------------------------------------------------------------------
'
function store(Byref a1 as single,Byref b1 as single,Byref c1 as single,Byref d1 as single) as integer
'
'   Store coordinates for this fractal 
'
'
'
'   Top left corner .
'
a1=0
c1=4.5
'
'  Bottom right corner .
'
b1=6
d1=0
'
              return (0)
'
end function
'
' -----------------------------------------------------------------------------
'
function scanner2(xImage As Any Ptr ,a2() as single) as integer
'
'    scan  image , in memory , for stable points ; these
'  are coloured white when using the blue color map. 
'
'  Use lower and upper limits selected from function pal().
'
'
'  The dimensions of the image are :  800x600 , n x m
'
'
static as integer i,j,n,m,c1,k
static as single ax,bx,cy,dy,x,y
'
i= store(ax ,bx ,cy ,dy ) 
'
   n=800
   m=600
' 
      k = 0
  for j=0 to m
    for i=0 to n
        c1=point(i,j,xImage)
      if (c1 > 86) and (c1<114) then   k=k+1
    next i
  next j  
'
redim as single a2(k,1) 
'
      k = 0
  for j=0 to m
    for i=0 to n
        c1=point(i,j,xImage)
      if (c1 > 86) and (c1<114) then   
         a2(k,0)=i
         a2(k,1)=j
          k=k+1
     end if
    next i
  next j  
'
for c1 =0 to k
      i=a2(c1,0)
      j=a2(c1,1)
     x = ax+(bx-ax)*(i)/800
     y = cy+(dy-cy)*(j)/600     
     a2(c1,0) = x
     a2(c1,1) = y
next c1
'
          return (0) 
'
'
end function
'
' --------------------------------------------------------------------------------
'
function attractors(a2() as single) as integer
'
'        Waveforms from results of scanner2
'
'
'
static as integer k ,i,fg
static as single a1(256,1),x,y
'
'
k=ubound(a2)

'print"k====";k

for i = 0 to k-1
     x = a2(i,0)
     y = a2(i,1)
    fg = EH2a(a1() , 12 , 256 ,x,y) 
    fg = plot2d(a1() , 256 )
   sleep 500
next i
'
return (k)
'
'
end function
'
' --------------------------------------------------------------------------------
'
function f1(x as single,y as single) as single
'
'                       x' = x - x*y            = f1(x,y)
'
'
static as single z


                         z = x - x*y
          return (z)

 end function
'
' -----------------------------------------------------------------------------
'
function g1(x as single,y as single) as single
'
'
'                    y' = -y + x*y         = g1(x,y)
'
'
static as single z


                         z =  -y + x*y  
          return (z)

 end function
'
' ------------------------------------------------------------------------------
'

Code: Select all

'
'   This is  EHStr.bas
'
'   Various functions used with the Euler Huen iterator .
'
'
'
Const LEFTBUTTON   = 1
Const MIDDLEBUTTON = 4   ' UNUSED IN THIS DEMO
Const RIGHTBUTTON  = 2   ' UNUSED IN THIS DEMO
Const SHOWMOUSE    = 1
Const HIDEMOUSE    = 0
'
declare function mag(x as single,y as single) as single
declare function mousey() as integer
declare function plot2d(a1() as single, steps as integer ) as integer  
'declare function scanner2(xImage As Any Ptr ,a2() as single) as integer
'declare function attractors(a2() as single) as integer
'
'declare function pal() as integer
'
declare function transi2x(i as integer,a as single,b as single)  as single
declare function transj2y(j as integer,c as single,d as single) as single
'
' =========================================
'
function mousey() as integer
'
'   Use mouse to select a point from the fractal .
'
'
'
Dim CurrentX     As Integer
Dim CurrentY     As Integer
Dim MouseButtons As Integer
Dim CanExit      As Integer
Dim as single  ax,bx,cy,dy,a1(256,1),x,y
dim as integer fg
'
fg= store(ax , bx ,cy,dy) 
'
'
SetMouse 1, 1, SHOWMOUSE

Do
   GetMouse CurrentX, CurrentY, , MouseButtons
   
   If MouseButtons And LEFTBUTTON Then
'    
    If (CurrentX >=10 and CurrentX <=810) and (CurrentY >=10 and CurrentY <= 610 ) then
                      x = ax+(bx-ax)*(CurrentX-10)/800
                      y = cy+(dy-cy)*(CurrentY-10)/600
                     fg = EH2d(a1() , 12 , 256,x,y ) 
                     fg = plot2d(a1() , 256 )
   End If
'
   End If
     
Loop While Inkey$ = ""

return 0

end function
'
' ------------------------------------------------------------------------------
'
function mag(x as single ,y as single) as single
'
'                                        sqrt(x*x+y*y)
'
static as single w

     w=x*x+y*y
     if (w>0) then w=sqr(w)
     
     return (w)
'
end function
'
 '
' ------------------------------------------------------------------------------
'
 function plot2d(a1() as single, steps as integer ) as integer  
 '
 '   Plot sequence generated from EH2a()
 '
 '
 'window (0,-1)-(steps,1)
' view (10,612)-(810,688)
 static as integer i,j
 static as single maxx,maxy,x,y,u,v
 
 line (0,-1)-(steps,1),0,bf
 
    i=2
   maxx = 0 
   maxy = 0
  for i=0 to steps
        x = a1(i,0)
        y = a1(i,1)
        x = abs(x)
        y= abs(y)
   if (x>maxx) then maxx=x
   if(y>maxy) then maxy=y
  next i
'  
if (maxx=0) then maxx=1
if (maxy=0) then maxy=1
'
        x = a1(0,0)/maxx
        y = a1(0,1)/maxy
        j=0
' 
 for i=1 to steps
        u = a1(i,0)/maxx
        v = a1(i,1)/maxy
        line(j,x)-(i,u), 96
        line(j,y)-(i,v), 53
         j = i
       x = u
       y = v
  next i
'     
    return (i) 

 end function
'
' ------------------------------------------------------------------------------
'
 function transi2x(i as integer,a as single,b as single)  as single
'
'  translate from screen coordinate to map coordinate
'
static as single x
'
                  x = a+(b-a)*i/800
'
     return (x)
'
end function
'
' -----------------------------------------------------------------------------
'
function transj2y(j as integer,c as single,d as single) as single
'
'  translate from screen coordinate to map coordinate
'
static as single y
'
                              y = c+(d-c)*(j)/600
'
                return (y)
'
end function
'

Luxan
Posts: 222
Joined: Feb 18, 2009 12:47
Location: New Zealand

Re: Fractal map

Post by Luxan »


test {
reset=2004 type=formula formulafile=fractint.frm
formulaname=V-HeunPH center-mag=0/0/0.6666667 float=y inside=0
colors=@blues.map
}

comment{Volterra Lotka , p , h variable .

V-HeunPH.frm
Top left corner [ -2.0 , 1.5 ]
Bottom right corner . [ 2 , -1.5 ]

initial condition [ x = 0.8 , y=0.8 ],
this initial condition might be
determined from the V-Heun map .

[ p , h ] varied over plane .

x' = x - x*y
y' = -y + x*y

}
V-HeunPH {
x=0.8
y=0.8
p=real(pixel)
h=imag(pixel):
u=x-x*y
w=-y+x*y
a=x+p*u
b=y+p*w
c=x+h*(u+(a-a*b))
d=y+h*(w+(-b+a*b))
x=c
y=d
z=x+flip(y)
|z|<=256
}




Code: Select all

'
' -------------------------------------------------------------------------------
'
'  Modified Euler Heun method for Volterra Lottka
'    differential equations .
'
'     x' =  a*x  -  b*x*y      = f1(x,y)
'     y' = -g*y + c*x*y    = g1(x,y)
'
' In this instance a=b=c=d = 1 , therefore :
'
'     u = x - x*y            = f1(x,y)
'     w = -y + x*y         = g1(x,y)
'
' ---------------------------------------------------------------------------------
'
'   The par[ameter] file uses bof60 , outside colour 1 ,
'  or whatever that produces black .
'
'
'  --------------------------------------------------------------------------------
'             Load a 800x600 bitmap into an image
'
'
Const LEFTBUTTON   = 1
Const MIDDLEBUTTON = 4   ' UNUSED IN THIS DEMO
Const RIGHTBUTTON  = 2   ' UNUSED IN THIS DEMO
Const SHOWMOUSE    = 1
Const HIDEMOUSE    = 0
dim as integer fg
'
declare function store(Byref a1 as single,Byref b1 as single,Byref c1 as single,Byref d1 as single) as integer
'
declare function EH2a(a1() as single,xfinal as single,steps as integer,px as single,py as single) as integer
'
declare function mag(x as single,y as single) as single
declare function mousey() as integer
declare function plot2d(a1() as single, steps as integer ) as integer  
declare function f1(x as single,y as single) as single
declare function g1(x as single,y as single) as single
declare function scanner2(xImage As Any Ptr ,a2() as single) as integer
declare function attractors(a2() as single) as integer
'
declare function pal() as integer
'
declare function transi2x(i as integer,a as single,b as single)  as single
declare function transj2y(j as integer,c as single,d as single) as single
'
' -----------------------------------------------------------------------------
'
ScreenRes 820, 690, 8 ' all fractint image files are 8 bit == 256 colours
Dim myImage As Any Ptr = ImageCreate( 800, 600 )  
dim as single a2()
'
BLoad "fract006.bmp", myImage
'
'fg=pal()
'sleep
'end
 'fg=scanner2(myImage  ,a2() ) 
Put (10,10), myImage
'
window (0,-1)-(128,1)
view (10,612)-(810,688) 
'
'fg=attractors(a2() )

fg = mousey() 

sleep
ImageDestroy( myImage )
'
end
'
' ==============================
'
function mousey() as integer
'
'   Use mouse to select a point from the fractal .
'
'
'
Dim CurrentX     As Integer
Dim CurrentY     As Integer
Dim MouseButtons As Integer
Dim CanExit      As Integer
Dim as single  ax,bx,cy,dy,a1(256,1),x,y
dim as integer fg
'
fg= store(ax , bx ,cy,dy) 
'
'
SetMouse 1, 1, SHOWMOUSE

Do
   GetMouse CurrentX, CurrentY, , MouseButtons
   
   If MouseButtons And LEFTBUTTON Then
'    
    If (CurrentX >=10 and CurrentX <=810) and (CurrentY >=10 and CurrentY <= 610 ) then
                      x = ax+(bx-ax)*(CurrentX-10)/800
                      y = cy+(dy-cy)*(CurrentY-10)/600
                     fg = EH2a(a1() , 12 , 256,x,y ) 
                     fg = plot2d(a1() , 256 )
   End If
'
   End If
     
Loop While Inkey$ = ""

return 0

end function
'
' ------------------------------------------------------------------------------
'
function mag(x as single ,y as single) as single
'
'                                        sqrt(x*x+y*y)
'
static as single w

     w=x*x+y*y
     if (w>0) then w=sqr(w)
     
     return (w)
'
end function
'
' ------------------------------------------------------------------------------
'
function EH2a(a1() as single,xfinal as single,steps as integer,px as single,py as single) as integer
'
'
'    Modified Euler Huen method ,
' applied to differential equations defined by f1() and g1() .
'
'   In this instance [ x , y ]  are set to an initial condition
' and [ p , h ] are varied  across the plane .
'
'
'
static as integer p2,iter
static as single p,h,u,w,a,b,c,d,z,x,y
'
'
for iter=0 to steps
     a1(iter,0)=0
     a1(iter,1)=0
next iter
'
   x = 0.8
   y = 0.8
'
    p = px
    h = py
'    
  p2 = 256
iter = 0
    u = 0
   w = 0
    a = 0
    b = 0
    c = 0
    d = 0
    z = 0
'
    while(z<=p2 and (iter<256) )    
                       
                     iter = iter+1
                        u = f1(x,y)
                        w = g1(x,y)
                         a = x+p*u
                         b = y+p*w
                         c = x+h*(u+f1(a,b))
                         d = y+h*(w+g1(a,b))
                         x = c
                         y = d
                         a1(iter-1,0)=x 
                         a1(iter-1,1)=y
  '                       z = x + -flip(y)
                         z = mag(x,y) 
                       wend
'
                     return ( iter)
'
'                         
  end function
'
' ------------------------------------------------------------------------------
'
 function plot2d(a1() as single, steps as integer ) as integer  
 '
 '   Plot sequence generated from EH2a()
 '
 '
 'window (0,-1)-(steps,1)
' view (10,612)-(810,688)
 static as integer i,j
 static as single maxx,maxy,x,y,u,v
 
 line (0,-1)-(steps,1),0,bf
 
    i=2
   maxx = 0 
   maxy = 0
  for i=0 to steps
        x = a1(i,0)
        y = a1(i,1)
        x = abs(x)
        y= abs(y)
   if (x>maxx) then maxx=x
   if(y>maxy) then maxy=y
  next i
'  
if (maxx=0) then maxx=1
if (maxy=0) then maxy=1
'
        x = a1(0,0)/maxx
        y = a1(0,1)/maxy
        j=0
' 
 for i=1 to steps
        u = a1(i,0)/maxx
        v = a1(i,1)/maxy
        line(j,x)-(i,u), 96
        line(j,y)-(i,v), 53
         j = i
       x = u
       y = v
  next i
'     
    return (i) 

 end function
'
' --------------------------------------------------------------------------------
'
function pal() as integer
'
'  Examine palette associated with fractint image .
'
'  Choose lower and upper limits for scanner2 function .
'
static as integer i,c
'
line(10,10)-(266,50),0,b
line(10,10)-(266,50),56,b
for i=1 to 255
     line(i+10,10)-(i+10,50),i,bf
next i
line(10,10)-(266,50),56,b
'
line(10,70)-(266,110),0,bf
line(10,70)-(266,110),56,b
for i=1 to 255
      c = point(i+10,20)
     line(i+10,70)-(i+10,110),c,bf
     if (c=86) then line(i+10,70)-(i+10,110),12,bf
     if (c=114) then line(i+10,70)-(i+10,110),12,bf
next i
line(10,70)-(266,110),56,b
'
              return (0)
'
end function
'
' ------------------------------------------------------------------------------
'
 function transi2x(i as integer,a as single,b as single)  as single
'
'  translate from screen coordinate to map coordinate
'
static as single x
'
                  x = a+(b-a)*i/800
'
     return (x)
'
end function
'
' -----------------------------------------------------------------------------
'
function transj2y(j as integer,c as single,d as single) as single
'
'  translate from screen coordinate to map coordinate
'
static as single y
'
                              y = c+(d-c)*(j)/600
'
                return (y)
'
end function
'
' -----------------------------------------------------------------------------
'
function store(Byref a1 as single,Byref b1 as single,Byref c1 as single,Byref d1 as single) as integer
'
'   Store coordinates for this fractal 
'
'
'
'   Top left corner .
'
a1=-2.0
c1=1.5
'
'  Bottom right corner .
'
b1=2
d1=-1.5
'
              return (0)
'
end function
'
' -----------------------------------------------------------------------------
'
function scanner2(xImage As Any Ptr ,a2() as single) as integer
'
'    scan  image , in memory , for stable points ; these
'  are coloured white when using the blue color map. 
'
'  Use lower and upper limits selected from function pal().
'
'
'  The dimensions of the image are :  800x600 , n x m
'
'
static as integer i,j,n,m,c1,k
static as single ax,bx,cy,dy,x,y
'
i= store(ax ,bx ,cy ,dy ) 
'
   n=800
   m=600
' 
      k = 0
  for j=0 to m
    for i=0 to n
        c1=point(i,j,xImage)
      if (c1 > 86) and (c1<114) then   k=k+1
    next i
  next j  
'
redim as single a2(k,1) 
'
      k = 0
  for j=0 to m
    for i=0 to n
        c1=point(i,j,xImage)
      if (c1 > 86) and (c1<114) then   
         a2(k,0)=i
         a2(k,1)=j
          k=k+1
     end if
    next i
  next j  
'
for c1 =0 to k
      i=a2(c1,0)
      j=a2(c1,1)
     x = ax+(bx-ax)*(i)/800
     y = cy+(dy-cy)*(j)/600     
     a2(c1,0) = x
     a2(c1,1) = y
next c1
'
          return (0) 
'
'
end function
'
' --------------------------------------------------------------------------------
'
function attractors(a2() as single) as integer
'
'        Waveforms from results of scanner2
'
'
'
static as integer k ,i,fg
static as single a1(256,1),x,y
'
'
k=ubound(a2)

'print"k====";k

for i = 0 to k-1
     x = a2(i,0)
     y = a2(i,1)
    fg = EH2a(a1() , 12 , 256 ,x,y) 
    fg = plot2d(a1() , 256 )
   sleep 500
next i
'
return (k)
'
'
end function
'
' --------------------------------------------------------------------------------
'
function f1(x as single,y as single) as single
'
'                       x' = x - x*y            = f1(x,y)
'
'
static as single z


                         z = x - x*y
          return (z)

 end function
'
' -----------------------------------------------------------------------------
'
function g1(x as single,y as single) as single
'
'
'                    y' = -y + x*y         = g1(x,y)
'
'
static as single z


                         z =  -y + x*y  
          return (z)

 end function
'
' ------------------------------------------------------------------------------
'










dafhi
Posts: 1641
Joined: Jun 04, 2005 9:51

Re: Fractal map

Post by dafhi »

Code: Select all

sub sub_with_static
  static as integer i
  print "static "; i
  i += 1
end sub

sub sub_with_normal
  dim as integer i
  print "normal "; i
  i += 1
end sub

for j as integer = 1 to 3
  sub_with_static
  sub_with_normal
  print
next

sleep
Luxan
Posts: 222
Joined: Feb 18, 2009 12:47
Location: New Zealand

Re: Fractal map

Post by Luxan »

Your code is somewhat informative.

Presently I'm just trying a few ideas and will eventually
tidy up all of the code.

I find that FreeBASIC helps me to construct various,
at times , vague notions .
A little bit of code might represent a lot of information.
Fractint is a very good example of this.
Luxan
Posts: 222
Joined: Feb 18, 2009 12:47
Location: New Zealand

Re: Fractal map

Post by Luxan »

This is just a minor update of the two FreeBASIC
examples uploaded previously.

In this instance I've included the ability to print
the location of the point selected from the map;
[px,py].
Also the magnitude of the two sequences
generated ; [maxx,maxy].

Large values of [maxx,maxy] tend to indicate
overflow in the calculations and are of little
interest.

For FracMap1.bas the color scheme , blues.map,
retains some validity.
For FracMap1a.bas the color scheme, blues.map,
may require revision.

Code: Select all

'
' -------------------------------------------------------------------------------
'
'      FracMap1.bas
'
'  Modified Euler Heun method for Volterra Lottka
'    differential equations .
'
'     x' =  a x - b x y      = f1(x,y)
'     y' = -g y + c x y    = g1(x,y)
'
' In this instance a=b=c=d = 1 , therefore :
'
'     u = x - x*y            = f1(x,y)
'     w = -y + x*y         = g1(x,y)
'
' ---------------------------------------------------------------------------------
'
'
'             Load a 800x600 bitmap into an image
'
'
Const LEFTBUTTON   = 1
Const MIDDLEBUTTON = 4   ' UNUSED IN THIS DEMO
Const RIGHTBUTTON  = 2   ' UNUSED IN THIS DEMO
Const SHOWMOUSE    = 1
Const HIDEMOUSE    = 0
dim as integer fg
'
declare function store(Byref a1 as single,Byref b1 as single,Byref c1 as single,Byref d1 as single) as integer
'
declare function EH2a(a1() as single,xfinal as single,steps as integer,x as single,y as single) as integer
'
declare function mag(x as single,y as single) as single
declare function mousey() as integer
declare function plot2d(a1() as single, steps as integer ) as integer  
declare function f1(x as single,y as single) as single
declare function g1(x as single,y as single) as single
declare function scanner2(xImage As Any Ptr ,a2() as single) as integer
declare function attractors(a2() as single) as integer
'
declare function pal() as integer
'
declare function transi2x(i as integer,a as single,b as single)  as single
declare function transj2y(j as integer,c as single,d as single) as single
'
' -----------------------------------------------------------------------------
'
' ScreenRes 820, 690, 8 ' all fractint image files are 8 bit == 256 colours
'
Const W1 = 820, H1 = 690
ScreenRes W1, H1,8
Dim myImage As Any Ptr = ImageCreate( 800, 600 )  
BLoad "fract005.bmp", myImage

dim as single a2()
Dim As Integer twid, tw, th
Width W1\8, H1\16 '' Use 8*16 font
'
twid = Width()
tw = LoWord(twid): th = HiWord(twid)
'
'fg=pal()
'sleep
'end
 'fg=scanner2(myImage  ,a2() ) 
Put (10,10), myImage
'
window (0,-1)-(128,1)
view (10,612)-(810,688) 
'
'fg=attractors(a2() )

fg = mousey() 

sleep
ImageDestroy( myImage )
'
end
'
' ==============================
'
function mousey() as integer
'
'   Use mouse to select a point from the fractal .
'
'
'
Dim CurrentX     As Integer
Dim CurrentY     As Integer
Dim MouseButtons As Integer
Dim CanExit      As Integer
Dim as single  ax,bx,cy,dy,a1(256,1),x,y
dim as integer fg
'
fg= store(ax , bx ,cy,dy) 
'
'
SetMouse 1, 1, SHOWMOUSE

Do
   GetMouse CurrentX, CurrentY, , MouseButtons
   
   If MouseButtons And LEFTBUTTON Then
'    
    If (CurrentX >=10 and CurrentX <=810) and (CurrentY >=10 and CurrentY <= 610 ) then
                      x = ax+(bx-ax)*(CurrentX-10)/800
                      y = cy+(dy-cy)*(CurrentY-10)/600
                     fg = EH2a(a1() , 12 , 256,x,y ) 
                     fg = plot2d(a1() , 256 )
                     color 150,0
                     locate 42,2
                     print "                        ";
                     locate 42,2
                     print "px  ";x;
                     locate 43,2
                     print "                        ";
                     locate 43,2
                     print "py  ";y;
   End If
'
   End If
     
Loop While Inkey$ = ""

return 0

end function
'
' ------------------------------------------------------------------------------
'
function mag(x as single ,y as single) as single
'
'                                        sqrt(x*x+y*y)
'
static as single w

     w=x*x+y*y
     if (w>0) then w=sqr(w)
     
     return (w)
'
end function
'
' ------------------------------------------------------------------------------
'
function EH2a(a1() as single,xfinal as single,steps as integer,x as single,y as single) as integer
'
'
'    Modified Euler Huen method ,
' applied to differential equations defined by f1() and g1() .
'
static as integer p2,iter
static as single p,h,u,w,a,b,c,d,z
'
'
for iter=0 to steps
     a1(iter,0)=0
     a1(iter,1)=0
next iter
'
'
    p = 0.739
    h = 0.739/2
  p2 = 256
iter = 0
    u = 0
   w = 0
    a = 0
    b = 0
    c = 0
    d = 0
    z = 0
'
    while(z<=p2 and (iter<256) )       
                     iter = iter+1
                        u = f1(x,y)
                        w = g1(x,y)
                         a = x+p*u
                         b = y+p*w
                         c = x+h*(u+f1(a,b))
                         d = y+h*(w+g1(a,b))
                         x = c
                         y = d
                         a1(iter-1,0)=x 
                         a1(iter-1,1)=y
  '                       z = x + -flip(y)
                         z = mag(x,y) 
                       wend
'
                     return ( iter)
'
'                         
  end function
 '
' ------------------------------------------------------------------------------
'
 function plot2d(a1() as single, steps as integer ) as integer  
 '
 '   Plot sequence generated from EH2a()
 '
 '
 'window (0,-1)-(steps,1)
' view (10,612)-(810,688)
 static as integer i,j
 static as single maxx,maxy,x,y,u,v
 
 line (0,-1)-(steps,1),0,bf
 
    i=2
   maxx = 0 
   maxy = 0
  for i=0 to steps
        x = a1(i,0)
        y = a1(i,1)
        x = abs(x)
        y= abs(y)
   if (x>maxx) then maxx=x
   if(y>maxy) then maxy=y
  next i
'  
                    color 160,0
                    locate 42,32
                     print "                        ";
                     locate 42,32
                     print "maxx  ";maxx;
                     color 110,0
                     locate 43,32
                     print "                        ";
                     locate 43,32
                     print "maxy  ";maxy;

'
if (maxx=0) then maxx=1
if (maxy=0) then maxy=1
'
        x = a1(0,0)/maxx
        y = a1(0,1)/maxy
        j=0
' 
 for i=1 to steps
        u = a1(i,0)/maxx
        v = a1(i,1)/maxy
        line(j,x)-(i,u), 96
        line(j,y)-(i,v), 53
         j = i
       x = u
       y = v
  next i
'     
    return (i) 

 end function
'
' --------------------------------------------------------------------------------
'
function pal() as integer
'
'  Examine palette associated with fractint image .
'
'  Choose lower and upper limits for scanner2 function .
'
static as integer i,c
'
line(10,10)-(266,50),0,b
line(10,10)-(266,50),56,b
for i=1 to 255
     line(i+10,10)-(i+10,50),i,bf
next i
line(10,10)-(266,50),56,b
'
line(10,70)-(266,110),0,bf
line(10,70)-(266,110),56,b
for i=1 to 255
      c = point(i+10,20)
     line(i+10,70)-(i+10,110),c,bf
     if (c=86) then line(i+10,70)-(i+10,110),12,bf
     if (c=114) then line(i+10,70)-(i+10,110),12,bf
next i
line(10,70)-(266,110),56,b
'
              return (0)
'
end function
'
' ------------------------------------------------------------------------------
'
 function transi2x(i as integer,a as single,b as single)  as single
'
'  translate from screen coordinate to map coordinate
'
static as single x
'
                  x = a+(b-a)*i/800
'
     return (x)
'
end function
'
' -----------------------------------------------------------------------------
'
function transj2y(j as integer,c as single,d as single) as single
'
'  translate from screen coordinate to map coordinate
'
static as single y
'
                              y = c+(d-c)*(j)/600
'
                return (y)
'
end function
'
' -----------------------------------------------------------------------------
'
function store(Byref a1 as single,Byref b1 as single,Byref c1 as single,Byref d1 as single) as integer
'
'   Store coordinates for this fractal 
'
'
'
'   Top left corner .
'
a1=0
c1=4.5
'
'  Bottom right corner .
'
b1=6
d1=0
'
              return (0)
'
end function
'
' -----------------------------------------------------------------------------
'
function scanner2(xImage As Any Ptr ,a2() as single) as integer
'
'    scan  image , in memory , for stable points ; these
'  are coloured white when using the blue color map. 
'
'  Use lower and upper limits selected from function pal().
'
'
'  The dimensions of the image are :  800x600 , n x m
'
'
static as integer i,j,n,m,c1,k
static as single ax,bx,cy,dy,x,y
'
i= store(ax ,bx ,cy ,dy ) 
'
   n=800
   m=600
' 
      k = 0
  for j=0 to m
    for i=0 to n
        c1=point(i,j,xImage)
      if (c1 > 86) and (c1<114) then   k=k+1
    next i
  next j  
'
redim as single a2(k,1) 
'
      k = 0
  for j=0 to m
    for i=0 to n
        c1=point(i,j,xImage)
      if (c1 > 86) and (c1<114) then   
         a2(k,0)=i
         a2(k,1)=j
          k=k+1
     end if
    next i
  next j  
'
for c1 =0 to k
      i=a2(c1,0)
      j=a2(c1,1)
     x = ax+(bx-ax)*(i)/800
     y = cy+(dy-cy)*(j)/600     
     a2(c1,0) = x
     a2(c1,1) = y
next c1
'
          return (0) 
'
'
end function
'
' --------------------------------------------------------------------------------
'
function attractors(a2() as single) as integer
'
'        Waveforms from results of scanner2
'
'
'
static as integer k ,i,fg
static as single a1(256,1),x,y
'
'
k=ubound(a2)

'print"k====";k

for i = 0 to k-1
     x = a2(i,0)
     y = a2(i,1)
    fg = EH2a(a1() , 12 , 256 ,x,y) 
    fg = plot2d(a1() , 256 )
   sleep 500
next i
'
return (k)
'
'
end function
'
' --------------------------------------------------------------------------------
'
function f1(x as single,y as single) as single
'
'                       x' = x - x*y            = f1(x,y)
'
'
static as single z


                         z = x - x*y
          return (z)

 end function
'
' -----------------------------------------------------------------------------
'
function g1(x as single,y as single) as single
'
'
'                    y' = -y + x*y         = g1(x,y)
'
'
static as single z


                         z =  -y + x*y  
          return (z)

 end function
'
' ------------------------------------------------------------------------------
'

Code: Select all

'
' -------------------------------------------------------------------------------
'
'   FracMap1a.bas
'
'
'  Modified Euler Heun method for Volterra Lotka
'    differential equations .
'
'    Variation of parameters [ p , h ] with initial
'  condition for [ x , y ] = [ 0.8 , 0.8 ] .
'    There's more to sort out here , therefore one
'  must consider this as being preliminary .
'
'     x' =  a*x - b*x*y      = f1(x,y)
'     y' = -g*y + c*x*y    = g1(x,y)
'
' In this instance a=b=c=d = 1 , therefore :
'
'     u = x - x*y            = f1(x,y)
'     w = -y + x*y         = g1(x,y)
'
' ---------------------------------------------------------------------------------
'
'
'             Load a 800x600 bitmap into an image
'
'
Const LEFTBUTTON   = 1
Const MIDDLEBUTTON = 4   ' UNUSED IN THIS DEMO
Const RIGHTBUTTON  = 2   ' UNUSED IN THIS DEMO
Const SHOWMOUSE    = 1
Const HIDEMOUSE    = 0
dim as integer fg
'
declare function store(Byref a1 as single,Byref b1 as single,Byref c1 as single,Byref d1 as single) as integer
'
declare function EH2a(a1() as single,xfinal as single,steps as integer,px as single,py as single) as integer
'
declare function mag(x as single,y as single) as single
declare function mousey() as integer
declare function plot2d(a1() as single, steps as integer ) as integer  
declare function f1(x as single,y as single) as single
declare function g1(x as single,y as single) as single
declare function scanner2(xImage As Any Ptr ,a2() as single) as integer
declare function attractors(a2() as single) as integer
'
declare function pal() as integer
'
declare function transi2x(i as integer,a as single,b as single)  as single
declare function transj2y(j as integer,c as single,d as single) as single
'
' -----------------------------------------------------------------------------
'
'
' ScreenRes 820, 690, 8 ' all fractint image files are 8 bit == 256 colours
'
Const W1 = 820, H1 = 690
ScreenRes W1, H1,8
Dim myImage As Any Ptr = ImageCreate( 800, 600 )  
BLoad "fract006.bmp", myImage

dim as single a2()
Dim As Integer twid, tw, th
Width W1\8, H1\16 '' Use 8*16 font
'
twid = Width()
tw = LoWord(twid): th = HiWord(twid)
'
'fg=pal()
'sleep
'end
 'fg=scanner2(myImage  ,a2() ) 
Put (10,10), myImage
'
window (0,-1)-(128,1)
view (10,612)-(810,688) 
'
'fg=attractors(a2() )

fg = mousey() 

sleep
ImageDestroy( myImage )
'
end
'
' ==============================
'
function mousey() as integer
'
'   Use mouse to select a point from the fractal .
'
'
'
Dim CurrentX     As Integer
Dim CurrentY     As Integer
Dim MouseButtons As Integer
Dim CanExit      As Integer
Dim as single  ax,bx,cy,dy,a1(256,1),x,y
dim as integer fg
'
fg= store(ax , bx ,cy,dy) 
'
'
SetMouse 1, 1, SHOWMOUSE

Do
   GetMouse CurrentX, CurrentY, , MouseButtons
   
   If MouseButtons And LEFTBUTTON Then
'    
    If (CurrentX >=10 and CurrentX <=810) and (CurrentY >=10 and CurrentY <= 610 ) then
                      x = ax+(bx-ax)*(CurrentX-10)/800
                      y = cy+(dy-cy)*(CurrentY-10)/600
                     fg = EH2a(a1() , 12 , 256,x,y ) 
                     fg = plot2d(a1() , 256 )
                     color 150,0
                     locate 42,2
                     print "                        ";
                     locate 42,2
                     print "px  ";x;
                     locate 43,2
                     print "                        ";
                     locate 43,2
                     print "py  ";y;
   End If
'
   End If
     
Loop While Inkey$ = ""

return 0

end function
'
' ------------------------------------------------------------------------------
'
function mag(x as single ,y as single) as single
'
'                                        sqrt(x*x+y*y)
'
static as single w

     w=x*x+y*y
     if (w>0) then w=sqr(w)
     
     return (w)
'
end function
'
' ------------------------------------------------------------------------------
'
function EH2a(a1() as single,xfinal as single,steps as integer,px as single,py as single) as integer
'
'
'    Modified Euler Huen method ,
' applied to differential equations defined by f1() and g1() .
'
'   In this instance [ x , y ]  are set to an initial condition
' and [ p , h ] are varied  across the plane .
'
'
'
static as integer p2,iter
static as single p,h,u,w,a,b,c,d,z,x,y
'
'
for iter=0 to steps
     a1(iter,0)=0
     a1(iter,1)=0
next iter
'
   x = 0.8
   y = 0.8
'
    p = px
    h = py
'    
  p2 = 256
iter = 0
    u = 0
   w = 0
    a = 0
    b = 0
    c = 0
    d = 0
    z = 0
'
    while(z<=p2 and (iter<256) )    
                       
                     iter = iter+1
                        u = f1(x,y)
                        w = g1(x,y)
                         a = x+p*u
                         b = y+p*w
                         c = x+h*(u+f1(a,b))
                         d = y+h*(w+g1(a,b))
                         x = c
                         y = d
                         a1(iter-1,0)=x 
                         a1(iter-1,1)=y
  '                       z = x + -flip(y)
                         z = mag(x,y) 
                       wend
'
                     return ( iter)
'
'                         
  end function
'
' ------------------------------------------------------------------------------
'
 function plot2d(a1() as single, steps as integer ) as integer  
 '
 '   Plot sequence generated from EH2a()
 '
 '
 'window (0,-1)-(steps,1)
' view (10,612)-(810,688)
 static as integer i,j
 static as single maxx,maxy,x,y,u,v
 
 line (0,-1)-(steps,1),0,bf
 
    i=2
   maxx = 0 
   maxy = 0
  for i=0 to steps
        x = a1(i,0)
        y = a1(i,1)
        x = abs(x)
        y= abs(y)
   if (x>maxx) then maxx=x
   if(y>maxy) then maxy=y
  next i
'  
                    color 160,0
                     locate 42,32
                     print "                        ";
                     locate 42,32
                     print "maxx  ";maxx;
                     color 110,0
                     locate 43,32
                     print "                        ";
                     locate 43,32
                     print "maxy  ";maxy;
'
if (maxx=0) then maxx=1
if (maxy=0) then maxy=1
'
        x = a1(0,0)/maxx
        y = a1(0,1)/maxy
        j=0
' 
 for i=1 to steps
        u = a1(i,0)/maxx
        v = a1(i,1)/maxy
        line(j,x)-(i,u), 96
        line(j,y)-(i,v), 53
         j = i
       x = u
       y = v
  next i
'    
'line (0,-1)-(steps,1),110,b
' 
    return (i) 

 end function
'
' --------------------------------------------------------------------------------
'
function pal() as integer
'
'  Examine palette associated with fractint image .
'
'  Choose lower and upper limits for scanner2 function .
'
static as integer i,c
'
line(10,10)-(266,50),0,b
line(10,10)-(266,50),56,b
for i=1 to 255
     line(i+10,10)-(i+10,50),i,bf
next i
line(10,10)-(266,50),56,b
'
line(10,70)-(266,110),0,bf
line(10,70)-(266,110),56,b
for i=1 to 255
      c = point(i+10,20)
     line(i+10,70)-(i+10,110),c,bf
     if (c=86) then line(i+10,70)-(i+10,110),12,bf
     if (c=114) then line(i+10,70)-(i+10,110),12,bf
next i
line(10,70)-(266,110),56,b
'
              return (0)
'
end function
'
' ------------------------------------------------------------------------------
'
 function transi2x(i as integer,a as single,b as single)  as single
'
'  translate from screen coordinate to map coordinate
'
static as single x
'
                  x = a+(b-a)*i/800
'
     return (x)
'
end function
'
' -----------------------------------------------------------------------------
'
function transj2y(j as integer,c as single,d as single) as single
'
'  translate from screen coordinate to map coordinate
'
static as single y
'
                              y = c+(d-c)*(j)/600
'
                return (y)
'
end function
'
' -----------------------------------------------------------------------------
'
function store(Byref a1 as single,Byref b1 as single,Byref c1 as single,Byref d1 as single) as integer
'
'   Store coordinates for this fractal 
'
'
'
'   Top left corner .
'
a1=-2.0
c1=1.5
'
'  Bottom right corner .
'
b1=2
d1=-1.5
'
              return (0)
'
end function
'
' -----------------------------------------------------------------------------
'
function scanner2(xImage As Any Ptr ,a2() as single) as integer
'
'    scan  image , in memory , for stable points ; these
'  are coloured white when using the blue color map. 
'
'  Use lower and upper limits selected from function pal().
'
'
'  The dimensions of the image are :  800x600 , n x m
'
'
static as integer i,j,n,m,c1,k
static as single ax,bx,cy,dy,x,y
'
i= store(ax ,bx ,cy ,dy ) 
'
   n=800
   m=600
' 
      k = 0
  for j=0 to m
    for i=0 to n
        c1=point(i,j,xImage)
      if (c1 > 86) and (c1<114) then   k=k+1
    next i
  next j  
'
redim as single a2(k,1) 
'
      k = 0
  for j=0 to m
    for i=0 to n
        c1=point(i,j,xImage)
      if (c1 > 86) and (c1<114) then   
         a2(k,0)=i
         a2(k,1)=j
          k=k+1
     end if
    next i
  next j  
'
for c1 =0 to k
      i=a2(c1,0)
      j=a2(c1,1)
     x = ax+(bx-ax)*(i)/800
     y = cy+(dy-cy)*(j)/600     
     a2(c1,0) = x
     a2(c1,1) = y
next c1
'
          return (0) 
'
'
end function
'
' --------------------------------------------------------------------------------
'
function attractors(a2() as single) as integer
'
'        Waveforms from results of scanner2
'
'
'
static as integer k ,i,fg
static as single a1(256,1),x,y
'
'
k=ubound(a2)

'print"k====";k

for i = 0 to k-1
     x = a2(i,0)
     y = a2(i,1)
    fg = EH2a(a1() , 12 , 256 ,x,y) 
    fg = plot2d(a1() , 256 )
   sleep 500
next i
'
return (k)
'
'
end function
'
' --------------------------------------------------------------------------------
'
function f1(x as single,y as single) as single
'
'                       x' = x - x*y            = f1(x,y)
'
'
static as single z


                         z = x - x*y
          return (z)

 end function
'
' -----------------------------------------------------------------------------
'
function g1(x as single,y as single) as single
'
'
'                    y' = -y + x*y         = g1(x,y)
'
'
static as single z


                         z =  -y + x*y  
          return (z)

 end function
'
' ------------------------------------------------------------------------------
'

Luxan
Posts: 222
Joined: Feb 18, 2009 12:47
Location: New Zealand

Re: Fractal map

Post by Luxan »

Time for another update , the fractal map , sequence , explorer
now shows the results of the automatic scan ; done by scanner2.
These appear as a circle around the selected point , press Enter
to move to the next point , the associated sequence and point
data is also displayed in the lower part of the screen.
I've named this fracmap3.bas.

(c) Copyright 2015 sciwise@ihug.co.nz , Luxan .
Just so that at least I can continue to use this code.

You can download and examine this code and do other things ,

Code: Select all

'
' -------------------------------------------------------------------------------
'
'  Modified Euler Heun method for Volterra Lottka
'    differential equations .
'
'     x' =  a x - b x y      = f1(x,y)
'     y' = -g y + c x y    = g1(x,y)
'
' In this instance a=b=c=d = 1 , therefore :
'
'     u = x - x*y            = f1(x,y)
'     w = -y + x*y         = g1(x,y)
'
' ---------------------------------------------------------------------------------
'
'
'             Load a 800x600 bitmap into an image
'
'
Const LEFTBUTTON   = 1
Const MIDDLEBUTTON = 4   ' UNUSED IN THIS DEMO
Const RIGHTBUTTON  = 2   ' UNUSED IN THIS DEMO
Const SHOWMOUSE    = 1
Const HIDEMOUSE    = 0
dim as integer fg
'
declare function store(Byref a1 as single,Byref b1 as single,Byref c1 as single,Byref d1 as single) as integer
'
declare function EH2a(a1() as single,xfinal as single,steps as integer,x as single,y as single) as integer
'
declare function mag(x as single,y as single) as single
declare function mousey() as integer
declare function plot2d(a1() as single, steps as integer ) as integer  
declare function f1(x as single,y as single) as single
declare function g1(x as single,y as single) as single
declare function scanner2(xImage As Any Ptr ,a2() as single,a3() as integer ) as integer
declare function attractors(a2() as single,a3() as integer,Image As Any Ptr ) as integer
'
'
declare function pal() as integer
declare function getputxy(i as integer,j as integer , Image As Any Ptr , flag as integer) as integer
'
declare function transi2x(i as integer,a as single,b as single)  as single
declare function transj2y(j as integer,c as single,d as single) as single
'
declare function transx2i(x as single , a as single , b as single) as integer 
declare function transy2j(y as single,c as single,d as single) as integer
'
' -----------------------------------------------------------------------------
'
' ScreenRes 820, 690, 8 ' all fractint image files are 8 bit == 256 colours
'
Const W1 = 820, H1 = 690
ScreenRes W1, H1,8
'
dim as single a2()
dim as integer a3()
Dim As Integer twid, tw, th
'
dim Image As Any Ptr = ImageCreate( 21, 21 ) 
Dim myImage As Any Ptr = ImageCreate( 800, 600 )  
'
BLoad "fract008.bmp", myImage
'
' -----------------------------------------------------------------------------
'
Width W1\8, H1\16 '' Use 8*16 font
'
twid = Width()
tw = LoWord(twid): th = HiWord(twid)
'
'fg=pal()
'sleep  
'end

fg= scanner2(myImage ,a2(),a3())

window screen  (0,0)-(W1,H1)
Put (10,10), myImage
'
fg=attractors(a2() ,a3(),Image)
'fg = mousey() 

sleep
ImageDestroy( Image )
ImageDestroy( myImage )
'
end
'
' ==============================
'
function mousey() as integer
'
'   Use mouse to select a point from the fractal .
'
'
'
Dim CurrentX     As Integer
Dim CurrentY     As Integer
Dim MouseButtons As Integer
Dim CanExit      As Integer
Dim as single  ax,bx,cy,dy,a1(256,1),x,y
dim as integer fg
'

fg= store(ax , bx ,cy,dy) 
'
'
SetMouse 1, 1, SHOWMOUSE

Do

  window screen (0,0)-( W1, H1)
   view (0,0)-(W1,H1)

  
   GetMouse CurrentX, CurrentY, , MouseButtons
   
   If MouseButtons And LEFTBUTTON Then
'    
    If (CurrentX >=10 and CurrentX <=810) and (CurrentY >=10 and CurrentY <= 610 ) then

 '                      circle(CurrentX,CurrentY), 10,20

  
                      x = ax+(bx-ax)*(CurrentX-10)/800
                      y = cy+(dy-cy)*(CurrentY-10)/600
                     fg = EH2a(a1() , 12 , 256,x,y ) 
                     fg = plot2d(a1() , 256 )
                     color 150,0
                     locate 42,2
                     print "                        ";
                     locate 42,2
                     print "px  ";x;
                     locate 43,2
                     print "                        ";
                     locate 43,2
                     print "py  ";y;
                     
                     
   End If
'
   End If
     
Loop While Inkey$ = ""

return 0

end function
'
' ------------------------------------------------------------------------------
'
function mag(x as single ,y as single) as single
'
'                                        sqrt(x*x+y*y)
'
static as single w

     w=x*x+y*y
     if (w>0) then w=sqr(w)
     
     return (w)
'
end function
'
' ------------------------------------------------------------------------------
'
function EH2a(a1() as single,xfinal as single,steps as integer,x as single,y as single) as integer
'
'
'    Modified Euler Huen method ,
' applied to differential equations defined by f1() and g1() .
'
static as integer p2,iter
static as single p,h,u,w,a,b,c,d,z
'
'
for iter=0 to steps
     a1(iter,0)=0
     a1(iter,1)=0
next iter
'
'
    p = 0.739
    h = 0.739/2
  p2 = 256
iter = 0
    u = 0
   w = 0
    a = 0
    b = 0
    c = 0
    d = 0
    z = 0
'
    while(z<=p2 and (iter<256) )       
                     iter = iter+1
                        u = f1(x,y)
                        w = g1(x,y)
                         a = x+p*u
                         b = y+p*w
                         c = x+h*(u+f1(a,b))
                         d = y+h*(w+g1(a,b))
                         x = c
                         y = d
                         a1(iter-1,0)=x 
                         a1(iter-1,1)=y
  '                       z = x + -flip(y)
                         z = mag(x,y) 
                       wend
'
                     return ( iter)
'
'                         
  end function
 '
' ------------------------------------------------------------------------------
'
 function plot2d(a1() as single, steps as integer ) as integer  
 '
 '   Plot sequence generated from EH2a()
 '
 '
 static as integer i,j
 static as single maxx,maxy,x,y,u,v
 '
 window  (0,1)-(steps,-1)
 view (10,612)-(810,688)
 line (0,1)-(steps,-1),0,bf
 
    i=2
   maxx = 0 
   maxy = 0
  for i=0 to steps
        x = a1(i,0)
        y = a1(i,1)
        x = abs(x)
        y= abs(y)
   if (x>maxx) then maxx=x
   if(y>maxy) then maxy=y
  next i
'  
                    color 160,0
                    locate 42,32
                     print "                        ";
                     locate 42,32
                     print "maxx  ";maxx;
                     color 110,0
                     locate 43,32
                     print "                        ";
                     locate 43,32
                     print "maxy  ";maxy;

'
if (maxx=0) then maxx=1
if (maxy=0) then maxy=1
'
        x = -a1(0,0)/maxx
        y = -a1(0,1)/maxy
        j=0
' 
 for i=1 to steps
        u = -a1(i,0)/maxx
        v = -a1(i,1)/maxy
        line(j,x)-(i,u), 96
        line(j,y)-(i,v), 53
         j = i
       x = u
       y = v
  next i
'    
  window screen (0,0)-( W1, H1)
   view (0,0)-(W1,H1)
'
    return (i) 

 end function
'
' --------------------------------------------------------------------------------
'
function pal() as integer
'
'  Examine palette associated with fractint image .
'
'  Choose lower and upper limits for scanner2 function .
'
static as integer i,c
'
line(10,10)-(266,50),0,b
line(10,10)-(266,50),56,b
for i=1 to 255
     line(i+10,10)-(i+10,50),i,bf
next i
line(10,10)-(266,50),56,b
'
line(10,70)-(266,110),0,bf
line(10,70)-(266,110),56,b
for i=1 to 255
      c = point(i+10,20)
     line(i+10,70)-(i+10,110),c,bf
     if (c=90) then line(i+10,70)-(i+10,110),12,bf
     if (c=102) then line(i+10,70)-(i+10,110),12,bf
next i
line(10,70)-(266,110),56,b
'
              return (0)
'
end function
'
' -----------------------------------------------------------------------------
'
function transx2i(x as single , a as single , b as single) as integer 
'
'    Translate from map coordinate to screen coordinate.
'
static as single i
'
                    i = (800*x-800*a)/(b-a)
'
               return i
'
end function
'
' ------------------------------------------------------------------------------
'
function transy2j(y as single,c as single,d as single) as integer
'
'   Translate from map coordinates to screen coordinates.
'
static as integer j

                j = (600*y-600*c)/(d-c)
'
                 return j
'
end function
'
'  ----------------------------------------------------------------------------
'
 function transi2x(i as integer,a as single,b as single)  as single
'
'  translate from screen coordinate to map coordinate
'
static as single x
'
                  x = a+(b-a)*i/800
'
     return (x)
'
end function
'
' -----------------------------------------------------------------------------
'
function transj2y(j as integer,c as single,d as single) as single
'
'  translate from screen coordinate to map coordinate
'
static as single y
'
                              y = c+(d-c)*(j)/600
'
                return (y)
'
end function
'
' -----------------------------------------------------------------------------
'
function store(Byref a1 as single,Byref b1 as single,Byref c1 as single,Byref d1 as single) as integer
'
'   Store coordinates for this fractal 
'
'
'
'   Top left corner .
'
a1=0
c1=4.5
'
'  Bottom right corner .
'
b1=6
d1=0
'
              return (0)
'
end function
'
' -----------------------------------------------------------------------------
'
function scanner2(xImage As Any Ptr ,a2() as single,a3() as integer ) as integer
'
'    scan  image , in memory , for stable points ; these
'  are coloured white when using the blue color map. 
'
'  Use lower and upper limits selected from function pal().
'
'
'  The dimensions of the image are :  800x600 , n x m
'
'
static as integer i,j,n,m,c1,k
static as single ax,bx,cy,dy,x,y
'
i= store(ax ,bx ,cy ,dy ) 
'
   n=800
   m=600
' 
      k = 0
  for j=0 to m
    for i=0 to n
        c1=point(i,j,xImage)
 '     if (c1 > 86) and (c1<114) then   k=k+1
       if (c1 > 86) and (c1<106) then   k=k+1
     
    next i
  next j  
'
redim as single a2(k,1) 
redim as integer a3(k,1) 
'
      k = 0
  for j=0 to m
    for i=0 to n
        c1=point(i,j,xImage)
'      if (c1 > 86) and (c1<114) then   
      if (c1 > 86) and (c1<106) then      
         a2(k,0)=i
         a2(k,1)=j
          k=k+1
     end if
    next i
  next j  
'
for c1 =0 to k 
      i=a2(c1,0)
      j=a2(c1,1)
      a3(c1,0)=i
      a3(c1,1)=j
     x = ax+((bx-ax)*i)/800
     y = cy+((dy-cy)*j)/600    
     a2(c1,0) = x
     a2(c1,1) = y
next c1
'
          return (0) 
'
'
end function
'
' --------------------------------------------------------------------------------
'
function attractors(a2() as single,a3() as integer,Image As Any Ptr ) as integer
'
'        Waveforms from results of scanner2
'
'   Note :  a2() holds [x,y] values , a1() holds sequence values.
'
static as integer k ,i,j,g,fg
static as single a1(256,1),x,y
'
'
k=ubound(a2)

'print"k====";k

for g = 0 to k-1
     x = a2(g,0)
     y = a2(g,1)
   
    fg = EH2a(a1() , 12 , 256 ,x,y) 
    fg = plot2d(a1() , 256 )
 '     
                     color 150,0
                     locate 42,2
                     print "                        ";
                     locate 42,2
                     print "px  ";x;
                     locate 43,2
                     print "                        ";
                     locate 43,2
                     print "py  ";y;    
 ' 
     i = a3(g,0)
     j = a3(g,1)

   fg = getputxy(i ,j  , Image  , 1 ) 
   sleep  ' 800
    fg = getputxy(i ,j  , Image  , 0 ) 
next g
'
return (k)
'
'
end function
'
' ------------------------------------------------------------------------------
'
function getputxy(i as integer,j as integer , Image As Any Ptr , flag as integer) as integer
'
'                   Selectively ,
'
'                   Draw circle around a chosen point .
'                   Return image to original instance .
'
'       i == x
'       j == y
'
'
select case flag
           case 0
if (i>=0) and (j>=0) and (i<=780) and (j<=580) then            
           Put (i,j),image,pset
end if
'           
           case 1
'
if (i>=0) and (j>=0) and (i<=780) and (j<=580) then   
           Get (i,j)-(i+20,j+20), image   
           circle(i+10,j+10), 8,20
end if
'
          
           case else
           
end select           
'
'
    return 0
'
end function
'
' --------------------------------------------------------------------------------
'
function f1(x as single,y as single) as single
'
'                       x' = x - x*y            = f1(x,y)
'
'
static as single z


                         z = x - x*y
          return (z)

 end function
'
' -----------------------------------------------------------------------------
'
function g1(x as single,y as single) as single
'
'
'                    y' = -y + x*y         = g1(x,y)
'
'
static as single z


                         z =  -y + x*y  
          return (z)

 end function
'
' ------------------------------------------------------------------------------
'
I'm including the parameter file that I used with xfractint 20.04.10
to generate fract008.gif .
I call this frac08.par .


test {
reset=2004 type=volterra-lotka passes=1 center-mag=3/2.25/0.4444444
params=0.73899999999999999/0.73899999999999999 float=y maxiter=2048
inside=bof60 outside=0 logmap=yes
colors=000000<25>00d00f00h00i00k00m<26>0ew0fx0hx0iy0ky0mz<25>nwzpwzrxz<3\
>zzz<42>7zz6zz4zz3zz2zz0zz<42>07z06z04z03z02z00z<60>002000000
}
Luxan
Posts: 222
Joined: Feb 18, 2009 12:47
Location: New Zealand

Re: Fractal map

Post by Luxan »

This is an update for the V-HeunPH fractal explorer.

After preferentially setting element 102 of the
palette to a pink - red colour I obtained a map
that I scanned and displayed with associated
waveforms via fracmap3a.bas.

As in FracMap3.bas , the selected point [ p ,h ]
is within a red circle and the waveform appears
in the lower portion of the screen.

Code: Select all

'
' -------------------------------------------------------------------------------
'
'   FracMap3a.bas
'
'             Copyright (c) 2015 sciwise@ihug.co.nz , Luxan
'
'  Modified Euler Heun method for Volterra Lotka
'    differential equations .
'
'    Variation of parameters [ p , h ] with initial
'  condition for [ x , y ] = [ 0.8 , 0.8 ] .
'    There's more to sort out here , therefore one
'  must consider this as being preliminary .
'
'     x' =  a*x - b*x*y      = f1(x,y)
'     y' = -g*y + c*x*y    = g1(x,y)
'
' In this instance a=b=c=d = 1 , therefore :
'
'     u = x - x*y            = f1(x,y)
'     w = -y + x*y         = g1(x,y)
'
' ---------------------------------------------------------------------------------
'
'             Load a 800x600 bitmap into an image
'
Const LEFTBUTTON   = 1
Const MIDDLEBUTTON = 4   ' UNUSED IN THIS DEMO
Const RIGHTBUTTON  = 2   ' UNUSED IN THIS DEMO
Const SHOWMOUSE    = 1
Const HIDEMOUSE    = 0
dim as integer fg
'
declare function store(Byref a1 as single,Byref b1 as single,Byref c1 as single,Byref d1 as single) as integer
'
declare function EH2a(a1() as single,xfinal as single,steps as integer,x as single,y as single) as integer
'
declare function mag(x as single,y as single) as single
declare function mousey() as integer
declare function plot2d(a1() as single, steps as integer ) as integer  
declare function f1(x as single,y as single) as single
declare function g1(x as single,y as single) as single
declare function scanner2(xImage As Any Ptr ,a2() as single,a3() as integer ) as integer
declare function attractors(a2() as single,a3() as integer,Image As Any Ptr ) as integer
'
'
declare function pal() as integer
declare function getputxy(i as integer,j as integer , Image As Any Ptr , flag as integer) as integer
'
declare function transi2x(i as integer,a as single,b as single)  as single
declare function transj2y(j as integer,c as single,d as single) as single
'
declare function transx2i(x as single , a as single , b as single) as integer 
declare function transy2j(y as single,c as single,d as single) as integer
'
' -----------------------------------------------------------------------------
'
' ScreenRes 820, 690, 8 ' all fractint image files are 8 bit == 256 colours
'
Const W1 = 820, H1 = 690
ScreenRes W1, H1,8
'
dim as single a2()
dim as integer a3()
Dim As Integer twid, tw, th
'
dim Image As Any Ptr = ImageCreate( 21, 21 ) 
Dim myImage As Any Ptr = ImageCreate( 800, 600 )  
'
BLoad "fract013.bmp", myImage
'
' -----------------------------------------------------------------------------
'
Width W1\8, H1\16 '' Use 8*16 font
'
twid = Width()
tw = LoWord(twid): th = HiWord(twid)
'
fg=pal()
'sleep  
'end

fg= scanner2(myImage ,a2(),a3())

window screen  (0,0)-(W1,H1)
Put (10,10), myImage
'
 fg=attractors(a2() ,a3(),Image)
'fg = mousey() 

sleep
ImageDestroy( Image )
ImageDestroy( myImage )
'
end
'
' ==============================
'
function mousey() as integer
'
'   Use mouse to select a point from the fractal .
'
'
'
Dim CurrentX     As Integer
Dim CurrentY     As Integer
Dim MouseButtons As Integer
Dim CanExit      As Integer
Dim as single  ax,bx,cy,dy,a1(256,1),x,y
dim as integer fg
'

fg= store(ax , bx ,cy,dy) 
'
'
SetMouse 1, 1, SHOWMOUSE

Do

  window screen (0,0)-( W1, H1)
   view (0,0)-(W1,H1)

  
   GetMouse CurrentX, CurrentY, , MouseButtons
   
   If MouseButtons And LEFTBUTTON Then
'    
    If (CurrentX >=10 and CurrentX <=810) and (CurrentY >=10 and CurrentY <= 610 ) then

 '                      circle(CurrentX,CurrentY), 10,20

  
                      x = ax+(bx-ax)*(CurrentX-10)/800
                      y = cy+(dy-cy)*(CurrentY-10)/600
                     fg = EH2a(a1() , 12 , 256,x,y ) 
                     fg = plot2d(a1() , 256 )
                     color 150,0
                     locate 42,2
                     print "                        ";
                     locate 42,2
                     print "p  ";x;
                     locate 43,2
                     print "                        ";
                     locate 43,2
                     print "h  ";y;
                     
                     
   End If
'
   End If
     
Loop While Inkey$ = ""

return 0

end function
'
' ------------------------------------------------------------------------------
'
function mag(x as single ,y as single) as single
'
'                                        sqrt(x*x+y*y)
'
static as single w

     w=x*x+y*y
     if (w>0) then w=sqr(w)
     
     return (w)
'
end function
'
' ------------------------------------------------------------------------------
'
function EH2a(a1() as single,xfinal as single,steps as integer,px as single,py as single) as integer
'
'
'    Modified Euler Huen method ,
' applied to differential equations defined by f1() and g1() .
'
'   In this instance [ x , y ]  are set to an initial condition
' and [ p , h ] are varied  across the plane .
'
'
'
static as integer p2,iter
static as single p,h,u,w,a,b,c,d,z,x,y
'
'
for iter=0 to steps
     a1(iter,0)=0
     a1(iter,1)=0
next iter
'
   x = 0.8 
   y = 0.8
'
    p = px
    h = py
'    
  p2 = 256
iter = 0
    u = 0
   w = 0
    a = 0
    b = 0
    c = 0
    d = 0
    z = 0
'
    while(z<=p2 and (iter<256) )    
                       
                     iter = iter+1
                        u = f1(x,y)
                        w = g1(x,y)
                         a = x+p*u
                         b = y+p*w
                         c = x+h*(u+f1(a,b))
                         d = y+h*(w+g1(a,b))
                         x = c
                         y = d
                         a1(iter-1,0)=x 
                         a1(iter-1,1)=y
  '                       z = x + -flip(y)
                         z = mag(x,y) 
                       wend
'
                     return ( iter)
'
'                         
  end function
'
'
' ------------------------------------------------------------------------------
'
 function plot2d(a1() as single, steps as integer ) as integer  
 '
 '   Plot sequence generated from EH2a()
 '
 '
 static as integer i,j
 static as single maxx,maxy,x,y,u,v
 '
 window  (0,1)-(steps,-1)
 view (10,612)-(810,688)
 line (0,1)-(steps,-1),0,bf
 
    i=2
   maxx = 0 
   maxy = 0
  for i=0 to steps
        x = a1(i,0)
        y = a1(i,1)
        x = abs(x)
        y= abs(y)
   if (x>maxx) then maxx=x
   if(y>maxy) then maxy=y
  next i
'  
                    color 160,0
                    locate 42,32
                     print "                        ";
                     locate 42,32
                     print "maxx  ";maxx;
                     color 110,0
                     locate 43,32
                     print "                        ";
                     locate 43,32
                     print "maxy  ";maxy;

'
if (maxx=0) then maxx=1
if (maxy=0) then maxy=1
'
        x = -a1(0,0)/maxx
        y = -a1(0,1)/maxy
        j=0
' 
 for i=1 to steps
        u = -a1(i,0)/maxx
        v = -a1(i,1)/maxy
        line(j,x)-(i,u), 96
        line(j,y)-(i,v), 53
         j = i
       x = u
       y = v
  next i
'    
  window screen (0,0)-( W1, H1)
   view (0,0)-(W1,H1)
'
    return (i) 

 end function
'
' --------------------------------------------------------------------------------
'
function pal() as integer
'
'  Examine palette associated with fractint image .
'
'  Choose lower and upper limits for scanner2 function .
'
static as integer i,c
'
line(10,10)-(266,50),0,b
line(10,10)-(266,50),56,b
for i=1 to 255
     line(i+10,10)-(i+10,50),i,bf
next i
line(10,10)-(266,50),56,b
'
line(10,70)-(266,110),0,bf
line(10,70)-(266,110),56,b
for i=1 to 255
      c = point(i+10,20)
     line(i+10,70)-(i+10,110),c,bf
'     if (c=90) then line(i+10,70)-(i+10,110),12,bf
'     if (c=102) then line(i+10,70)-(i+10,110),12,bf
next i
'
i=100
line(i+10,70)-(i+10,110),56

'
line(10,70)-(266,110),56,b
'
              return (0)
'
end function
'
' -----------------------------------------------------------------------------
'
function transx2i(x as single , a as single , b as single) as integer 
'
'    Translate from map coordinate to screen coordinate.
'
static as single i
'
                    i = (800*x-800*a)/(b-a)
'
               return i
'
end function
'
' ------------------------------------------------------------------------------
'
function transy2j(y as single,c as single,d as single) as integer
'
'   Translate from map coordinates to screen coordinates.
'
static as integer j

                j = (600*y-600*c)/(d-c)
'
                 return j
'
end function
'
'  ----------------------------------------------------------------------------
'
 function transi2x(i as integer,a as single,b as single)  as single
'
'  translate from screen coordinate to map coordinate
'
static as single x
'
                  x = a+(b-a)*i/800
'
     return (x)
'
end function
'
' -----------------------------------------------------------------------------
'
function transj2y(j as integer,c as single,d as single) as single
'
'  translate from screen coordinate to map coordinate
'
static as single y
'
                              y = c+(d-c)*(j)/600
'
                return (y)
'
end function
'
' -----------------------------------------------------------------------------
'
function store(Byref a1 as single,Byref b1 as single,Byref c1 as single,Byref d1 as single) as integer
'
'   Store coordinates for this fractal 
'
'
'
'   Top left corner .
'
a1=0.0275344180225283
c1=0.9390651085141903

a1=0.0826
c1=0.909


a1=0.0
c1=1

'
'  Bottom right corner .
'
b1=6
d1=0


b1=1.9949937421777224
d1=-0.5365293846022053

b1=2.025
d1=-0.5478

b1=1.0
d1=0
'
              return (0)
'
end function
'
' -----------------------------------------------------------------------------
'
function scanner2(xImage As Any Ptr ,a2() as single,a3() as integer ) as integer
'
'    scan  image , in memory , for stable points ; these
'  are coloured white when using the blue color map. 
'
'  Use lower and upper limits selected from function pal().
'
'
'  The dimensions of the image are :  800x600 , n x m
'
'
static as integer i,j,n,m,c1,k
static as single ax,bx,cy,dy,x,y
'
i= store(ax ,bx ,cy ,dy ) 
'
   n=800
   m=600
' 
      k = 0
  for j=0 to m
    for i=0 to n
        c1=point(i,j,xImage)
 '     if (c1 > 86) and (c1<114) then   k=k+1
'       if (c1 > 86) and (c1<106) then   k=k+1

       if (c1 =100)  then   k=k+1    
    next i
  next j  
'
redim as single a2(k,1) 
redim as integer a3(k,1) 
'
      k = 0
  for j=0 to m
    for i=0 to n
        c1=point(i,j,xImage)
'      if (c1 > 86) and (c1<114) then   
'      if (c1 > 86) and (c1<106) then      
    if (c1 =100)  then     
         a2(k,0)=i
         a2(k,1)=j
          k=k+1
     end if
    next i
  next j  
'
for c1 =0 to k 
      i=a2(c1,0)
      j=a2(c1,1)
      a3(c1,0)=i
      a3(c1,1)=j
     x = ax+((bx-ax)*i)/800
     y = cy+((dy-cy)*j)/600    
     a2(c1,0) = x
     a2(c1,1) = y
next c1
'
          return (0) 
'
'
end function
'
' --------------------------------------------------------------------------------
'
function attractors(a2() as single,a3() as integer,Image As Any Ptr ) as integer
'
'        Waveforms from results of scanner2
'
'   Note :  a2() holds [x,y] values , a1() holds sequence values.
'
static as integer k ,i,j,g,fg
static as single a1(256,1),x,y
'
'
k=ubound(a2)

'print"k====";k

for g = 0 to k-1
     x = a2(g,0)
     y = a2(g,1)
   
    fg = EH2a(a1() , 12 , 256 ,x,y) 
    fg = plot2d(a1() , 256 )
 '     
                     color 150,0
                     locate 42,2
                     print "                        ";
                     locate 42,2
                     print "px  ";x;
                     locate 43,2
                     print "                        ";
                     locate 43,2
                     print "py  ";y;    
 ' 
     i = a3(g,0)
     j = a3(g,1)

   fg = getputxy(i ,j  , Image  , 1 ) 
   sleep   800
    fg = getputxy(i ,j  , Image  , 0 ) 
next g
'
return (k)
'
'
end function
'
' ------------------------------------------------------------------------------
'
function getputxy(i as integer,j as integer , Image As Any Ptr , flag as integer) as integer
'
'                   Selectively ,
'
'                   Draw circle around a chosen point .
'                   Return image to original instance .
'
'       i == x
'       j == y
'
'
select case flag
           case 0
if (i>=0) and (j>=0) and (i<=780) and (j<=580) then            
           Put (i,j),image,pset
end if
'           
           case 1
'
if (i>=0) and (j>=0) and (i<=780) and (j<=580) then   
           Get (i,j)-(i+20,j+20), image   
           circle(i+10,j+10), 8,100
end if
'
          
           case else
           
end select           
'
'
    return 0
'
end function
'
' --------------------------------------------------------------------------------
'
function f1(x as single,y as single) as single
'
'                       x' = x - x*y            = f1(x,y)
'
'
static as single z


                         z = x - x*y
          return (z)

 end function
'
' -----------------------------------------------------------------------------
'
function g1(x as single,y as single) as single
'
'
'                    y' = -y + x*y         = g1(x,y)
'
'
static as single z


                         z =  -y + x*y  
          return (z)

 end function
'
' ------------------------------------------------------------------------------
'
The parameter file I used for fractint :

[quote]
test               {
  reset=2004 type=formula formulafile=fractint.frm
  formulaname=V-HeunPH passes=1 center-mag=0.5/0.5/2/1.3333 float=y
  maxiter=1024 inside=bof61 outside=0 logmap=yes periodicity=0
  colors=000000<25>00d00f00h00i00k00m<26>0ew0fx0hx0iy0ky0mz<24>lwznwzpwz<3\
  >xyzzuzyzzxzzwzzz0ztzz<37>7zz6zz4zz3zz2zz0zz<42>07z06z04z03z02z00z<60>00\
  2000000
  }

[/quote]





Luxan
Posts: 222
Joined: Feb 18, 2009 12:47
Location: New Zealand

Re: Fractal map

Post by Luxan »

I've setup cloud storage for the two bitmap files
used with FracMap3.bas and FracMap3a.bas.

These are , fract008.bmp at :

http://ovh.to/BXW9QFS

and

fract013.bmp at :

http://ovh.to/CTQ9kp3


Click on the link .
Then click on the image file , this should open
as an image in a new tab , or perhaps browser
instance.
Use right click on image , then save image as;
save the image in the same directory where
you have the FracMap3.bas and FracMap3a.bas
files.
The images should now load and display within
these FreeBASIC programs.
Luxan
Posts: 222
Joined: Feb 18, 2009 12:47
Location: New Zealand

Re: Fractal map

Post by Luxan »

That was somewhat unexpected , the fract008 and fract013
image files download with the png image extension.

You'll require image viewer software to convert both to the
bitmap format , with the bmp extension.
Luxan
Posts: 222
Joined: Feb 18, 2009 12:47
Location: New Zealand

Re: Fractal map

Post by Luxan »

Apparently , if you click on the image links detailed in
the previous post you will arrive at a webpage containing
an image file. If you then check the box to the left of
the file icon , a direct download option will appear above
the file icon. Clicking this will prompt you to select a
directory where you want to save the image file.
The image file will then download and the file format
is as expected ; in this instance a bitmap file , with
file extension bmp.

The gif file , generated from fractint , might also be
transfered in a similar way ; this is useful if you
want to further explore the fractal.
Luxan
Posts: 222
Joined: Feb 18, 2009 12:47
Location: New Zealand

Re: Fractal map

Post by Luxan »

For completeness I'm providing links to the gif image files generated
from Fractint. These can be loaded into Fractint and provide all of
the parameters necessary to examine the fractals .

To explore the V-HeunPH fractal you'll require the formula , this I'm also
providing . Use an editor to load fractint.frm and copy V-HeunPH code to
the end of the text , save to same location and close text editor.
V-HeunPH is now available and will be found by the appropriate gif
image file.

fract008.gif
http://ovh.to/BhC6xE

fract013.gif
http://ovh.to/6ovUcd

To download in the appropriate format left click the box
on the left of the image icon , then left click the download
tab that appears above the image icon.



comment{Volterra Lotka , p , h variable .

V-HeunPH.frm
(c) Copyright 2015 sciwise@ihug.co.nz , Edward . Q . Montague

initial condition [ x = 0.8 , y=0.8 ],
this initial condition might be
determined from the V-Heun map .

[ p , h ] varied over plane .

x' = x - x*y
y' = -y + x*y

}
V-HeunPH {
x=0.8
y=0.8
p=real(pixel)
h=imag(pixel):
u=x-x*y
w=-y+x*y
a=x+p*u
b=y+p*w
c=x+h*(u+(a-a*b))
d=y+h*(w+(-b+a*b))
x=c
y=d
z=x+flip(y)
|z|<=256
}
Post Reply