Latest OxygenBasic.zip at GitHub (Click on the Wizard)
0 Members and 1 Guest are viewing this topic.
'$ filename "ftree.exe"'include "rtl32.inc"include "awinh.inc"#lookahead'Window 500,375,1int win,winstyle = WS_MINMAXSIZE or WS_CLIPCHILDREN int w=800,h=600win = SetWindow("FracTree",0,0,w,h,0,winstyle)INT hdc, hdcMem, hbmMem, oldBmp, oldBrush, oldPen, oldFont, fColorINT textX,textY,hBrushInitDrawing()FillRect ( hdcMem,rc,CreateSolidBrush RGB(0,0,0) )BitBlt(hDC, 0, 0, w, h, hdcMem, 0, 0, SRCCOPY)'============================================================================single Spread_Ang = 35single Scaling_Factor = 0.75sys sizeH = 800sys SizeV = 600sys Init_Size = 150TextColor (win,RGB(0,150,0))DrawTree(SizeH / 2, SizeV, Init_Size, -90, 9)'============================================================================Wait()'============================================================================Function WndProc (sys hwnd,wmsg,wparam,lparam) as sys callbackSELECT hwnd'----------------------------------------CASE win'----------------------------------------Select wmsgCASE WM_CLOSECleanUp()DestroyWindow winPostQuitMessage 0CASE WM_PAINTBitBlt(hDC, 0, 0, w, h, hdcMem, 0, 0, SRCCOPY)End selectEND SELECTRETURN DefaultEND FUNCTION'============================================================================SUB InitDrawing''get current size of window GetSize(win,0,0,w,h)'get window DChdc=GetDC(win)hdcMem = CreateCompatibleDC(0)hbmMem = CreateCompatibleBitmap(hdc, w, h)oldBmp = SelectObject( hdcMem, hbmMem )oldBrush = SelectObject(hdcMem, CreateSolidBrush( RGB(231,223,231)) )oldPen = SelectObject(hdcMem, CreatePen(PS_SOLID,1,RGB(231,223,231)))'fill rectangle memDC with brush colorFillRect ( hdcMem,rc, oldBrush) SetTextColor( hDC,RGB(0,0,0))SetBkColor( hDC, RGB(231,223,231))'blit to memDCBitBlt(hDCmem, 0, 0, w, h, hdc, 0, 0, SRCCOPY)ReleaseDC( win, hdc)End SUB'============================================================================SUB CleanUpDeleteDC(hdcMem)DeleteObject(SelectObject(hdcMem, oldBrush))DeleteObject(SelectObject(hdcMem, oldPen))DeleteObject(SelectObject(hdcMem, oldBmp))END SUB'=================================================SUB TextColor (wID as INT,byval frontColor as sys)hdc = GetDC(wID)sys bColorfColor=frontColorbColor = RGB(231,223,231)SetTextColor( hDC, frontColor)SetBkColor( hDC, bColor)BitBlt(hDCmem, 0, 0, w, h, hdc, 0, 0, SRCCOPY)ReleaseDC( wID, hdc)End SUB '============================================================================SUB LineXY (wID as INT,Lx as INT,Ly as INT,Lx1 as INT,Ly1 as INT)hdc = GetDC(wID)GetSize(wID,0,0,w,h)SelectObject(hdc, CreatePen(PS_SOLID,1,fColor))MoveToEx hdc,Lx,Ly,Byval 0LineTo hdc,Lx1,Ly1BitBlt(hDCmem, 0, 0, w, h, hdc, 0, 0, SRCCOPY)ReleaseDC( wID, hdc)End SUB'===========================================================================Sub DrawTree(single x1, y1, Size, theta, depth) x2 = x1 + cos(rad(theta)) * Size y2 = y1 + sin(rad(theta)) * Size LineXY win,x1, y1, x2, y2 iF depth <= 0 Then Return DrawTree(x2, y2, Size * Scaling_Factor, theta - Spread_Ang, depth - 1) DrawTree(x2, y2, Size * Scaling_Factor, theta + Spread_Ang, depth - 1)End Sub