This is a conversion of Graham's Fractal-like Patterns (http://www.ionicwind.com/forums/index.php?topic=4683.0) program. It uses an undocumented trick to draw multiple pixels in a very short time.
To see how it would work at the normal speed, comment out the line with "$define BOOST_ME".
' Mathematical Patterns - GWS Aug 2011
' original post: http://www.ionicwind.com/forums/index.php?topic=4683.0
def w:WINDOW
def i:int
def wW,wH,dots:int
def col[20,4],repeat:int
def a,b,c,x,y,z,j,xfocus,yfocus:float
autodefine "off"
GETSCREENSIZE wW,wH
OPENWINDOW w, 0,0, wW, wH,@NOCAPTION,0 ,"CB Fractal Patterns", &handler
CENTERWINDOW w
SETWINDOWCOLOR w,RGB(0,0,0)
xfocus = wW * 0.47
yfocus = wH * 0.45
CONTROL w,@BUTTON,"Exit",2*(wW - 60)/3,wH * 0.85,60,30,@CTLBTNFLAT, 1
CONTROL w,@BUTTON,"Next",(wW - 60)/3,wH * 0.85,60,30,@CTLBTNFLAT, 2
for i = 1 to 2
SETCONTROLCOLOR w,i,RGB(124,171,255),RGB(0,80,180)
next i
' set up random colors ..
for i = 0 to 15
col[i,1] = RND(255) : col[i,2] = RND(255) : col[i,3] = RND(255)
next i
draw()
WAITUNTIL w.hWnd=0
end
SUB handler(),int
select @CLASS
case @IDCLOSEWINDOW
CLOSEWINDOW w
case @IDCONTROL
select @CONTROLID
' clicking the Exit button ...
case 1
CLOSEWINDOW w
case 2
' clicking the new image button ...
SETWINDOWCOLOR w,RGB(0,0,0)
draw()
endselect
endselect
return 0
endsub
$define BOOST_ME
sub draw
$ifdef BOOST_ME
' PSET and other graphics commands will be much faster if we
' save HDC in m_hPrintDC
int hdcOld = w.m_hPrintDC
w.m_hPrintDC = GETHDC(w)
$endif
for repeat = 1 to RAND(1,5)
' set up some random starting positions ..
a = RND(1.0)
b = 0.9998
c = 2 - 2 * a
dots = 15000 ' dots/1000=15; the last random color index
x = 0 : j = 0
y = RND(1.0)*12 + 0.1
' calculate and draw the points ..
for i = 0 to dots
z = x
x = b * y + j
j = a * x + c * (x^2)/(1 + x^2)
y = j - z
int xpos = x*20 + xfocus
int ypos = y*20 + yfocus
int d = i/1000
PSET w,xpos,ypos,RGB(col[d,1], col[d,2], col[d,3])
next i
next repeat
$ifdef BOOST_ME
int hdc = w.m_hPrintDC
w.m_hPrintDC = hdcOld
RELEASEHDC(w, hdc)
$endif
endsub
Wow!! That's fast.
Remarkable!!
LarryMc
Waah! I shall have to wait 'til I get a non-protected version of IWB to see it .. ::)
My copy doesn't work since I rebuilt my machine.
all the best, :)
Graham
Excellent Sapero :)
Work with EB to....
I got my IWB going - :) so I've tried it out ..
Ten out of ten for the improvements Sapero - very impressive.
Best wishes, :)
Graham
Sapero, what other undocumented tricks are there? :)
That one even works with GDI+ functions. It's going to be used in all my graphics programs.
Thanks for sharing,
Clint
Clint, this trick is responsible for what the GETHDC and RELEASEHDC commands are doing. They are used by all graphics commands, even 2D and 3D, but the boost will be remarkable only for normal GDI graphics. Each normal (gdi mode) call to get/release takes much more than a simple call to GetDC/ReleaseDC apis. If you set printer dc to some value, gethdc does nothing more than returning that value, and releasehdc does nothing, because "printer mode" is active.