Author Topic: Fractal Trees  (Read 1803 times)

0 Members and 1 Guest are viewing this topic.

Peter

  • Guest
Fractal Trees
« on: December 12, 2013, 05:51:01 AM »
Deleted
« Last Edit: April 25, 2015, 03:37:12 AM by Peter »

Aurel

  • Guest
Re: Fractal Trees
« Reply #1 on: December 12, 2013, 08:18:22 AM »
tree with much more code ... ;D
Code: [Select]
'$ filename "ftree.exe"
'include "rtl32.inc"
include "awinh.inc"
#lookahead
'Window 500,375,1
int win,winstyle = WS_MINMAXSIZE or WS_CLIPCHILDREN
int w=800,h=600
win = SetWindow("FracTree",0,0,w,h,0,winstyle)
INT hdc, hdcMem, hbmMem,   oldBmp, oldBrush, oldPen, oldFont, fColor
INT textX,textY,hBrush


InitDrawing()
FillRect ( hdcMem,rc,CreateSolidBrush RGB(0,0,0) )
BitBlt(hDC, 0, 0, w, h, hdcMem, 0, 0, SRCCOPY)
'============================================================================
single Spread_Ang     = 35
single Scaling_Factor = 0.75
sys sizeH = 800
sys SizeV = 600
sys Init_Size = 150

TextColor (win,RGB(0,150,0))
DrawTree(SizeH / 2, SizeV, Init_Size, -90, 9)
'============================================================================
Wait()
'============================================================================
Function WndProc (sys hwnd,wmsg,wparam,lparam) as sys callback

SELECT hwnd
'----------------------------------------
CASE win
'----------------------------------------
Select wmsg

CASE WM_CLOSE
CleanUp()
DestroyWindow win
PostQuitMessage 0

CASE WM_PAINT
BitBlt(hDC, 0, 0, w, h, hdcMem, 0, 0, SRCCOPY)

End select

END SELECT

RETURN Default

END FUNCTION
'============================================================================
SUB InitDrawing
''get current size of window
GetSize(win,0,0,w,h)
'get window DC
hdc=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 color
FillRect ( hdcMem,rc, oldBrush)
SetTextColor( hDC,RGB(0,0,0))
SetBkColor( hDC, RGB(231,223,231))
'blit to memDC
BitBlt(hDCmem, 0, 0, w, h, hdc, 0, 0, SRCCOPY)
ReleaseDC( win, hdc)
End SUB
'============================================================================
SUB CleanUp
DeleteDC(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 bColor
fColor=frontColor
bColor = 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 0
LineTo hdc,Lx1,Ly1

BitBlt(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



.