'Using the Japi library
'www.japi.de
$ filename "julia.exe"
'include "$/inc/RTL32.inc"
'include "$/inc/console.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
Dim int r(400*400), g(400*400), b(400*400)
int gc
function julia(double x, y, r, s, int it) as double
double dup
for k=0 to it
gc+=1
dup=x
x=x*x-y*y+r
y=2*dup*y+s
if abs(x*y)>4 then exit for
next
return k*abs(x*y)
end function
int m_p,it_p
double xo_p, yo_P
string color
int col_val=2
sub initState()
m_p=200 : it_p=12 : xo_p=-1.5 : yo_p=-1.5 : color="Green" : col_val=2
end sub
sub main()
double x , y , dz , rc , ic , xo , yo , orb
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)
initState()
toplbl=j_label(frame,"Julia params: m=" m_p ", it=" it_p ", xo=" xo_p ", yo=" yo_p ", color += " color)
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")
options = j_menuitem(calc, "Options")
reset = j_menuitem(calc,"Reset")
'Options Dialog
optdialog = j_dialog(frame,"Options for Julia Sets")
j_setsize(optdialog,300,200)
clr_lbl = j_label(optdialog, " Color:")
j_setpos(clr_lbl, 10,30)
radio =j_radiogroup(optdialog)
Red = j_radiobutton(radio,"Red")
j_setpos(Red,20,60)
Green = j_radiobutton(radio,"Green")
j_setpos(Green,20,80)
Blue = j_radiobutton(radio,"Blue")
j_setpos(Blue,20,100)
p_lbl = j_label(optdialog,"Parameters:")
j_setpos(p_lbl, 150,30)
m_lbl = j_label(optdialog,"m:")
j_setpos(m_lbl, 150,60)
it_lbl = j_label(optdialog,"it:")
j_setpos(it_lbl, 150,80)
xo_lbl = j_label(optdialog,"xo:")
j_setpos(xo_lbl, 150,110)
yo_lbl = j_label(optdialog,"yo:")
j_setpos(yo_lbl, 150,130)
m_field = j_textfield(optdialog,5)
j_setpos(m_field, 180,60)
it_field = j_textfield(optdialog,5)
j_setpos(it_field, 180,80)
xo_field = j_textfield(optdialog,6)
j_setpos(xo_field, 180,110)
yo_field = j_textfield(optdialog,6)
j_setpos(yo_field, 180,130)
close = j_button(optdialog,"Ok")
j_setpos(close, 100,160)
canvas=j_canvas(frame,400,400)
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")
gc=0
for m=m_p to 0 step -1
xo=xo_p
yo=yo_p
rc=0+m/100
ic=-1+m/100
dz=3/400
it=it_p
for i=0 to 399
x=xo+i*dz
for j=0 to 399
y=yo+j*dz
orb=julia(x,y,rc,ic,it)
if color="Red" then r(i+400*j)=int (5*orb)
if color="Green" then g(i+400*j)=int (5*orb)
if color="Blue" then b(i+400*j)=int (5*orb)
next j
next i
j_drawimagesource(canvas,0,0,400,400,r,g,b)
next m
j_settext(lbl,"MAIN ROUTINE CALLED "+str(gc) +" times" )
end if
if obj=reset then
initState()
j_settext(toplbl, "Julia params: m=" m_p ", it=" it_p ", xo=" xo_p ", yo=" yo_p ", color += " color)
j_settext(lbl, "INFO")
j_getimagesource(canvas,0,0,400,400,r,g,b)
for i=0 to <(400*400)
r[i]=0 : g[i]=0 : b[i]=0
next i
j_drawimagesource(canvas,0,0,400,400,r,g,b)
j_setnamedcolorbg(canvas,j_dark_gray)
end if
if obj=jprint then j_print(canvas)
if obj=options then
'place centered in frame
x = j_getxpos(frame)+j_getwidth(frame)/2 - j_getwidth(optdialog)/2
y = j_getypos(frame)+j_getheight(frame)/2 - j_getheight(optdialog)/2
j_setpos(optdialog,x,y)
'values
if col_val=1 then j_setstate(Red, j_true)
if col_val=2 then j_setstate(Green, j_true)
if col_val=3 then j_setstate(Blue, j_true)
j_settext(m_field, m_p)
j_settext(it_field, it_p)
j_settext(xo_field, xo_p)
j_settext(yo_field, yo_p)
j_show(optdialog)
end if
if obj=close or obj = optdialog then
j_hide(optdialog)
'update values
if j_getstate(Red) = j_true then col_val=1 : color="Red"
if j_getstate(Green) = j_true then col_val=2 : color="Green"
if j_getstate(Blue) = j_true then col_val=3 : color="Blue"
string tmp
tmp = j_gettext(m_field, tmp) : m_p=val(rtrim (ltrim (tmp)))
tmp = j_gettext(it_field, tmp) : it_p=val(rtrim (ltrim (tmp)))
tmp = j_gettext(xo_field, tmp) : xo_p=val(rtrim (ltrim (tmp)))
tmp = j_gettext(yo_field, tmp) : yo_p=val(rtrim (ltrim (tmp)))
j_settext(toplbl, "Julia params: m=" m_p ", it=" it_p ", xo=" xo_p ", yo=" yo_p ", color += " color)
end if
if obj=save then
image = j_image(400,400)
j_drawimagesource(image,0,0,400,400,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
j_quit()
end sub
main()