Author Topic: Japi Experiments  (Read 4185 times)

0 Members and 2 Guests are viewing this topic.

Mike Lobanovsky

  • Admin Support Member
  • *****
  • Posts: 1768
Re: Japi Experiments
« Reply #15 on: November 25, 2016, 12:30:02 PM »
Regretfully many if not all screenshots of Rob's fractals are now gone from the site (attachments are only kept for about two or three months and then deleted). But I remember that the best coloration attempts were made using Exp() and Log() combinations on the r, g, and b values, which unfortunately also made the calc much, much slower. Linear gradients like in these screenshots above are a little simplistic for this gorgeous fractal.

In fact trying to spectacularly colorize the dull insides of Julia was the very topic that made me acquainted with Rob on the thinBasic forum. :)
Mike
(3.6GHz Intel Core i5 Quad w/ 16GB RAM, 2 x nVidia GTX 650Ti w/ 2GB VRAM, Windows 7 Ultimate Sp1)

Charles Pegge

  • Admin Support Member
  • *****
  • Posts: 3581
    • Oxygen Basic
Re: Japi Experiments
« Reply #16 on: November 26, 2016, 03:40:30 AM »
We could use GLSL pixel shaders for high performance rendering of fractals, subject to the limited precision of floats.

http://n.ethz.ch/~vartokb/gl-shaders.html
-->
glsl fractals
https://www.youtube.com/watch?v=H-3yPXXZUC8
-->
Best fractals zoom ever
https://www.youtube.com/watch?v=BTiZD7p_oTc
-->
**
Mandelbrot Zoom 10^225 1080p - Grand Pianola Music
https://www.youtube.com/watch?v=n9nf5ShnRfk

Mike Lobanovsky

  • Admin Support Member
  • *****
  • Posts: 1768
Re: Japi Experiments
« Reply #17 on: November 26, 2016, 11:15:40 AM »
Charles,

Thanks for the links!

This glossy, silky, shiny coloration is what I was talking about mentioning Exp() and Log():



It's relatively easy to apply to Julia's curves but not so, to its plain insides. The insides are in fact also structured but their variations fall outside the scope of calc in the normally renderable parts of the fractal. The variations aren't however as rich nor as pronounced:

Mike
(3.6GHz Intel Core i5 Quad w/ 16GB RAM, 2 x nVidia GTX 650Ti w/ 2GB VRAM, Windows 7 Ultimate Sp1)

Charles Pegge

  • Admin Support Member
  • *****
  • Posts: 3581
    • Oxygen Basic
Re: Japi Experiments
« Reply #18 on: November 27, 2016, 01:04:48 PM »
I think byte overflow coloration, as in Roland's example here, is quite a good way to increase the sensitivity in the interior.

I've attached most of the Julia variables to the keyboard, and get a wide variety of views:

« Last Edit: November 27, 2016, 01:31:41 PM by Charles Pegge »

Charles Pegge

  • Admin Support Member
  • *****
  • Posts: 3581
    • Oxygen Basic
Re: Japi Experiments
« Reply #19 on: November 27, 2016, 01:10:54 PM »

I wonder why 3d fractals are so spooky:

Trip inside a 3D fractal (Kleinian) GPU realtime rendering
https://www.youtube.com/watch?v=XIzScwydxOE
-->
Like in a dream - 3D fractal trip
https://www.youtube.com/watch?v=S530Vwa33G0
-->
Like in a dream - 3D fractal trip
https://www.youtube.com/watch?v=HCl-7AbyCsY
-->
Amazing 3D Fractal Compilation + 4D with Jazzy Groove House Mix
https://www.youtube.com/watch?v=LbWS79Cxykg

Arnold

  • Hero Member
  • *****
  • Posts: 599
Re: Japi Experiments
« Reply #20 on: November 28, 2016, 03:10:52 AM »
Hi Charles, Mike,

I am lightyears away from your level. The more I learn by / with Oxygenbasic the more I feel like Sokrates (I know that I know nothing). In my earlier life I counted many things but neither pixels nor complex numbers. And now I am sitting here and try to remember about trigonometric functions, differentiation, derivation rules, find out the real and imaginary parts of life. But I learned that I only use 10 percent of my brain so maybe there is still some hope.

Until now I was only aware of some basic geometric shapes and the basic Mandelbrot image. I never had the idea that there is so much possible by applying some sophisticated formulae in a computer program.

Roland


Mike Lobanovsky

  • Admin Support Member
  • *****
  • Posts: 1768
Re: Japi Experiments
« Reply #21 on: November 28, 2016, 09:13:11 AM »
Hi Charles, Roland,


I wonder why 3d fractals are so spooky:

No they aren't for me. They are terrifically awesome, hypnotic, and viral. :)


... byte overflow coloration ...

Your renders are beautiful, Charles. But byte range is too narrow and restrictive to render the entire of a Julia, hence exponents and logarithms.

What I really mean by Julia insides is seen in your bottommost violet snapshot as black areas. The central regions clamped to black (or to white in some other programs) by byte linear coloration are in fact full of life of their own. Here's Rob's best attempt to colorize the black abyss inside a 2D Julia fractal in real time:



... I feel like Sokrates (I know that I know nothing). In my earlier life I counted many things but neither pixels nor complex numbers. And now I am sitting here and try to remember about trigonometric functions, differentiation, derivation rules, find out the real and imaginary parts of life. But I learned that I only use 10 percent of my brain so maybe there is still some hope.

I couldn't put it better than you did, Roland! :D
Mike
(3.6GHz Intel Core i5 Quad w/ 16GB RAM, 2 x nVidia GTX 650Ti w/ 2GB VRAM, Windows 7 Ultimate Sp1)

Charles Pegge

  • Admin Support Member
  • *****
  • Posts: 3581
    • Oxygen Basic
Re: Japi Experiments
« Reply #22 on: November 29, 2016, 01:22:53 AM »

Interiors using sqr(abs(x)) and sqr(sqr(abs(x))) as the output of JuliaCalc:

It is useful to have full control of the iterations, and output multiplier to get the best visual:




Charles Pegge

  • Admin Support Member
  • *****
  • Posts: 3581
    • Oxygen Basic
Re: Japi Experiments
« Reply #23 on: November 29, 2016, 09:09:56 AM »
abs(x) is used to render yellow and  abs(y) renders blue:


Mike Lobanovsky

  • Admin Support Member
  • *****
  • Posts: 1768
Re: Japi Experiments
« Reply #24 on: November 29, 2016, 12:37:01 PM »
WOW!!!

This is all VERY impressive indeed, Charles!

And those Julias remind me strongly of a pair of Italian (Peninsula) boots! :D
Mike
(3.6GHz Intel Core i5 Quad w/ 16GB RAM, 2 x nVidia GTX 650Ti w/ 2GB VRAM, Windows 7 Ultimate Sp1)

Arnold

  • Hero Member
  • *****
  • Posts: 599
Re: Japi Experiments
« Reply #25 on: November 30, 2016, 03:35:07 AM »
Hi Charles,

you changed JuliaCalc and JuliaRender a little bit? I do not know the meaning of sc, and I suddenly see Mandelbrot. I can achieve some effects but they are far away from your results. Your images appear like some kind of artwork - ars mathematice.

Would it be possible to adapt the julia algorithm for different sizes? (no streching). If I change width or height I only get garbage. The best result would be if I use width = 2*height but then I only get the picture twice.

This is my trial with Japi (of course not comparable with Opengl)

Roland

Code: [Select]
'Using the Japi library
'www.japi.de

$ filename "julia2.exe"
'include "$/inc/RTL32.inc"
'include "$/inc/console.inc"
include "$/inc/dynamic.inc"

extern lib "$/projectsC/Japi/japi.dll" cdecl
include once "$/projectsC/Japi/japi.h"
end extern

j_setdebug(0)
if( j_start() = J_FALSE ) then 
   print "can't connect to JAPI server"     
   end 
endif 

indexbase 0

int c_width = 800
int c_height= 400

int mp  = 40
int itp =  2
double xop  = -1.5
double yop  = -1.5
double amp_p = 8.0

double crf = 0.3    'red factor
double cgf = 0.4    'green
double cbf = 0.4    'blue

'sc ?

DynDim int r(c_width*c_height) : DynDim int g(c_width*c_height) : DynDim int b(c_width*c_height)
int gc

function JuliaCalc(double x, y, r, s, int it) as double 
  double mx=4.0

  for k=0 to it
     gc+=1
     xy=x*y
     x=x*x-y*y+r
     y=2*xy+s
     if abs(xy)>mx then exit for
  next
  return k*abs(xy)
end function 

function JuliaRender(int m, canvas,double rf,gf,bf)
==================================================
  'mf        'loop factor
  'rf 0 .. 1 'red
  'gf 0 .. 1 'green
  'bf 0 .. 1 'blue
  double mf=m/100
  sys i , j
  double x , y , dz , rc , ic , xo , yo , orb, amp

  rf*=2.55 : gf*=2.55 : bf*=2.55
   
  gc=0
  xo=xop
  yo=yop
  rc=mf
  ic=mf-1.0
  dz=3/c_width
  amp=amp_p
  it=itp
  for i=0 to <c_height
    y=yo+i*dz 
    for j=0 to <c_width
      x=xo+j*dz
      orb=JuliaCalc(x,y,rc,ic,it)*amp
      idx=i+c_height*j     
      r(idx)=rf*orb
      g(idx)=gf*orb
      b(idx)=bf*orb
    next j
  next i
  j_drawimagesource(canvas,0,0,c_width,c_height,r,g,b)
end function


sub main()

    sys frame, canvas
   
    frame=j_frame("Graphic Win - Julia Sets")
    j_setflowlayout(frame,j_vertical)
    j_setinsets(frame,50,20,20,20)
    j_setnamedcolorbg(frame,j_light_gray)
   
    toplbl=j_label(frame,"Julia params: m=" mp ", it=" itp ", xo=" xop ", yo=" yop)   
    j_setnamedcolor(toplbl,j_blue)

    'Menu
    menubar = j_menubar(frame)
    file    = j_menu(menubar,"File")
    save    = j_menuitem(file, "Save as BMP")
    jprint   = j_menuitem(file,"Print")
    quit    = j_menuitem(file,"Quit")

    calc    = j_menu(menubar,"Calc")
    start   = j_menuitem(calc,"Start")

    canvas=j_canvas(frame,c_width,c_height)
    j_setnamedcolorbg(canvas,j_dark_gray)
    lbl=j_label(frame,"INFO")
    j_setsize(lbl,260,32)
    j_setnamedcolor(lbl,j_blue)

    j_pack(frame)
    j_setpos(frame, 200,100)
    j_show(frame)

    obj=0
    while obj != quit and obj != frame

       obj=j_getaction()
                             
       if obj=start then
         j_settext(lbl,"Calculating - Please wait")

         for m=mp to 0 step -1
            JuliaRender m, canvas, crf, cgf, cbf
         next m
         j_drawimagesource(canvas,0,0,c_width,c_height,r,g,b)           

         j_settext(lbl,"MAIN ROUTINE CALLED "+str(gc) +" times" )
         
       end if

       if obj=jprint then j_print(canvas)

       if obj=save then
          image = j_image(c_width,c_height)
          j_drawimagesource(image,0,0,c_width,c_height,r,g,b)           
          if j_saveimage(image,"Julia.bmp",J_BMP) != 1 then
            mbox "Error saving Bitmap file"
          else
            mbox "Saved as Julia.bmp"
          end if 
       end if

    wend
    DynFree r : DynFree g : DynFree b   
    j_quit()

end sub

main()
« Last Edit: November 30, 2016, 05:17:13 AM by Arnold »

Charles Pegge

  • Admin Support Member
  • *****
  • Posts: 3581
    • Oxygen Basic
Re: Japi Experiments
« Reply #26 on: November 30, 2016, 08:41:45 AM »
Hi Roland, I am using an interactive derivation, JuliaKeyb, which has become a laboratory for testing all sorts of variations.

+/-  increase/decrease
arrow keys to pan
z  to zoom
f   for julia factor
i   for iterations
m  for color multiplier
j   to toggle julia/mandelbrot

r g b for colors

the program is directly altered for all other explorations.

Today's code:

Code: [Select]
  #compact
  % Title "Fractal Demo: keyboard: + - r g b f i j m  Ctrl P for snapshot"
 '% Animated
  % ScaleUp
 '% PlaceCentral
 '% AnchorCentral
 '% NoEscape

  includepath "$\inc\"
  '% filename "t.exe"
  'include "RTL64.inc"
  include "ConsoleG.inc"

  macro limit(v,min,max)
  ======================
  if v>max then
    v=max
  elseif v<min then
    v=min
  end if
  end macro

  indexbase 0
  pixel4 juliapix[512*512]
  int gc
     
  function JuliaCalc(double x, y, r, s,*oc, int it,jm) as double
  ==============================================================
  double xy,mx=4.0
  int k=it
  '
  if jm then
    'SWITCH TO MANDELBROT SET
    r=x
    s=y
    x=0
    y=0
  end if
  '
  '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 x
       fmul st0
       fld qword y
       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
     'if x*x+y*y>mx then exit for
       fld qword mx
       fld qword x
       fmul st0
       fld qword y
       fmul st0
       faddp st1
       fcomip
       fstp st0
       ja exit
  'next
    repeat
  )
 oc={x,y}
 'return sqr(sqr(abs(y)))
 'return sqr(abs(x)+abs(y))
 'return sqr(abs(y))
  return abs(x)
 'return x+y
 'return abs(x)+abs(y)
 'return abs(xy)
 'return hypot(x,y)
  '
  sub k,esi
  'return k*abs(xy)
    'fld qword xy
    'fabs
    'fimul dword k
    'return
  'return abs(xy)
    'fld qword xy
    'fabs
    'return
  'return xy
    'fld qword xy
    'return
  'return xy*xy
    'fld qword xy
    'fmul st0
    'return
  'return k
  end function 
     
     


  function JuliaRender(double mf,it,jm,mp,sc,xo,yo,rf,gf,bf)
  ==========================================================
  indexbase 0
  'mf 2 .. 0 'factor
  'rf 0 .. 1 'red
  'gf 0 .. 1 'green
  'bf 0 .. 1 'blue
  sys i , j
  double x , y , dz , rc , ic , orb, oc[1]
  gc=0
  pixel4 jp at @JuliaPix
  rc=mf
  ic=mf-1.0
  dz=sc*3/512
  for i=0 to <512
    y=yo-1.5*sc+i*dz
    for j=0 to <512
      x=xo-1.5*sc+j*dz
      orb=JuliaCalc(x,y,rc,ic,oc,it,jm)*mp
      '
      'RECIPROCALS
      if oc[0] then oc[0]=1/abs(oc[0])
      if oc[1] then oc[1]=1/abs(oc[1])
      jp.r=abs(oc[0])*mp*rf
      jp.g=abs(oc[0])*abs(oc[1])*mp*gf
      jp.b=abs(oc[1])*mp*bf
     '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,it,jm,mp
  static double rf,gf,bf,jf,jfi,sc,xo,yo
  if not init then
    sc=1
    xo=0
    yo=0
    rf=1.0
    gf=.5
    bf=.2
    jf=0
    jfi=0.002
    it=10
    mp=5
    init=1
    NewTexture JuliaTex
  end if
  if lastkey or lastchar then
    static float kvi=.01, kva=0.05
    static int   kii=1
    int cey=lastchar
    kva=.05*sc
    if cey>0x60 and cey<0x7b then cey-=32 'to uppercase
    '
    if key[189]      then kvi=-.01 : kii=-1 '-'
    if key[187]      then kvi= .01 : kii= 1 '+'
    if key[VK_RIGHT] then xo+=kva           'ARROW RIGHT'
    if key[VK_LEFT]  then xo-=kva           'ARROW LEFT'
    if key[VK_UP]    then yo+=kva           'ARROW UP'
    if key[VK_DOWN]  then yo-=kva           'ARROW DOWN'
    if key[0x5A]     then sc*=(1-kvi*5)     'Z' ZOOM
    if key[0x46]     then jf+=kvi           'F' FACTOR
    if cey=0x49      then it+=kii           'I' ITERATIONS
    if cey=0x4a      then jm=1-jm           'J' JULIA/MANDELBROT MODE
    if cey=0x4d      then mp+=kii           'M' OUTPUT MULTIPLIER
    if key[0x52]     then rf+=kvi           'R' RED
    if key[0x47]     then gf+=kvi           'G' GREEN
    if key[0x42]     then bf+=kvi           'B' BLUE
    '
   'limit sc, .01,100 'Julia Zoom
   'limit jf, 0,2     'Julia factor
    limit it, 1,1000  'JuliaCalc iterations
    limit mp, 1,1000  'Julia output multiplier
    limit rf, 0,1     'red
    limit gf, 0,1     'green
    limit bf, 0,1     'blue
    '
    '
    lastkey=0
    lastchar=0
  end if
  '
  'DISPLAY FACTORS
  def fi "  %1:" str(%1,0)
  def ff "  %1:" str(%1,2)
  def ff3 "  %1:" str(%1,3)
  printl ff jf fi it  fi mp  ff3 sc ff3 xo ff3 yo ff rf  ff gf  ff bf
  '
  JuliaRender jf,it,jm,mp,sc,xo,yo,rf,gf,bf
  '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

« Last Edit: November 30, 2016, 09:25:45 AM by Charles Pegge »

Charles Pegge

  • Admin Support Member
  • *****
  • Posts: 3581
    • Oxygen Basic
Re: Japi Experiments
« Reply #27 on: November 30, 2016, 08:51:36 AM »
Mike,

More interior revelations :)

Using 1/abs(x) and 1/abs(y) and their roots  to colorize:


« Last Edit: November 30, 2016, 08:58:58 AM by Charles Pegge »

Mike Lobanovsky

  • Admin Support Member
  • *****
  • Posts: 1768
Re: Japi Experiments
« Reply #28 on: November 30, 2016, 09:09:22 AM »
OMG Charles!

!!! THIS IS BEAUTIFUL !!!

You simply MUST make the texture twice larger, ensure it renders at a 1:1 scale, and save your renders in a lossless PNG format!

I think you could also use fast integer square root approximations to compensate for the larger texture sizes. It shouldn't affect the coloration quality to any visible extent, I think.



P.S. Your Mandelbrot is simply AWESOME! :)
Mike
(3.6GHz Intel Core i5 Quad w/ 16GB RAM, 2 x nVidia GTX 650Ti w/ 2GB VRAM, Windows 7 Ultimate Sp1)

Arnold

  • Hero Member
  • *****
  • Posts: 599
Re: Japi Experiments
« Reply #29 on: December 01, 2016, 12:58:43 AM »
Hi Charles,

it is impressive to see how you improved and enhanced the basic code. I will not continue to try this with Japi. The use of Japi as a gui framework is limited, the graphical capabilities can not be compared with Opengl and javaw.exe will consume a lot of memory. So I think this would be a waste of time and resources. Maybe I will try to use JuliaCalc and JuliaRender with Freeglut and MinWin. The purpose then would be to learn a bit more about Opengl.

Roland