  #compact
  % Title "Animated Julia Fractal Demo"
  % Animated
  % ScaleUp
 '% PlaceCentral
 '% AnchorCentral
 '% NoEscape

  '% filename "t.exe"
  'uses rtl64
  uses ConsoleG


  indexbase 0
  pixel4 juliapix[512*512]
  int gc
     
  function JuliaCalc(double x, y, r, s, int it) as double
  =======================================================
  double xy,mx=4.0
  int k=it
  'for k=0 to it
  mov esi,it
  (
    dec esi
    jl exit
     'gc+=1
       inc dword gc
     'xy=x*y
       fld qword x
       fmul qword y
       fstp qword xy
     'x=x*x-y*y+r
       fld qword y
       fmul st0
       fld qword x
       fmul st0
       fsubp st1
       fadd qword r
       fstp qword x
     'y=2*xy+s
       fld qword xy
       fadd st0
       fadd qword s
       fstp qword y
     'if abs(xy)>mx then exit for
       fld qword mx
       fld qword xy
       fabs
       fcomip
       fstp st0
       ja exit
  'next
    repeat
  )
  'return k*abs(xy)
    fld qword xy
    fabs
    sub k,esi
    fimul dword k
    return
  end function  
     
  int m_p,it_p
  double xo_p, yo_P
  string colorstr
  int col_val=2
     

  sub JuliaInitState()
  ====================
  m_p=200 : it_p=5 : xo_p=-1.5 : yo_p=-1.5 : colorstr="Green"  : col_val=2
  end sub

  function JuliaRender(float mf,rf,gf,bf)
  =======================================
  'mf 2 .. 0 'factor
  'rf 0 .. 1 'red
  'gf 0 .. 1 'green
  'bf 0 .. 1 'blue
  int i , j , it
  double x , y , dz , rc , ic , xo , yo , orb, amp
  gc=0
  pixel4 jp at (@JuliaPix) 
  xo=xo_p
  yo=yo_p
  rc=mf
  ic=mf-1.0
  dz=3/512
  amp=5.0
  it=it_p
  for i=0 to <512
    y=yo+i*dz
    for j=0 to <512
      x=xo+j*dz
      orb=JuliaCalc(x,y,rc,ic,it)*amp
      jp.r=orb*rf 'red
      jp.g=orb*gf 'green
      jp.b=orb*bf 'blue
      jp.a=255    'alpha
      @jp+=4      'next pixel
    next j
  next i
  end function


  function main()
  ===============
  '
  indexbase 1
  static int init
  static float jf,jfi
  if not init then
    JuliaInitState()
    jf=0
    jfi=0.002
    init=1
    NewTexture JuliaTex
  end if
  JuliaRender jf,1,1,0
  jf+=jfi
  if jf<0.0 then
    jf=0.0 : jfi=-jfi
  elseif jf>2.0 then
    jf=2.0 : jfi=-jfi
  end if
  pushstate
    move 15,-15.0
    'UserMovement m2,200
    flat : color 1,1,1,1
    texture JuliaTex
    DynSynthTexture JuliaTex,JuliaPix,512*512*4  
    quadnorm 15.0,15.0 'apply image texture to quad
    texture 0
  popstate
  '
  end function



  EndScript
