'BARNSLEY FERN

sys imgHnd, imgHdc

imgHnd = CreateCompatibleBitmap sys_hdc, 420,600
imgHdc = CreateCompatibleDC sys_hdc
SelectObject imgHdc, imgHnd


Sub PutPixel(sys x,y, r,g,b)
    SetpixelV imgHdc, x, 450-y, ColorRGB(r,g,b)
End Sub    

Sub FernCopy(sys x, y, width, height, iwidth, iheight)
    TransparentBlt bHdc,x,y,width,height,imgHdc,0,0,iwidth,iheight,0 
End Sub

Sub FernParticle
static single a, b, c, d, e, f, newx, newy
static sys r
static xy(2) as single
r = Rand(0,100)
if r <= 10 
   a = 0
   b = 0
   c = 0
   d = 0.16
   e = 0
   f = 0
elseif r > 1 and r <= 86 
   a = 0.85
   b = 0.04
   c = -.04
   d = 0.85
   e = 0
   f = 1.60
elseif r > 86 and r <= 93 
   a = 0.2
   b = -.26
   c = 0.23
   d = 0.22
   e = 0
   f = 0.16
else
   a = -.15
   b = 0.28
   c = 0.26
   d = 0.24
   e = 0
   f = 0.44
end if

newx = ((a * xy(1)) + (b * xy(2)) + e)
newy = ((c * xy(1)) + (d * xy(2)) + f)
xy(1) = newx
xy(2) = newy 
PutPixel xy(1)*40+275,xy(2)*40+50, 0,210,0
End Sub

sub CreateFern()
sys i
for i=1 to 64000
   FernParticle
next
end sub

sub DeleteFern()
DeleteObject imgHnd
DeleteDC     imgHdc
end sub
