From 9bfe4f3559cc8f811c495558b5f77e74ef0d665d Mon Sep 17 00:00:00 2001 From: Freeman Date: Fri, 8 Jan 2021 03:02:22 +0300 Subject: [PATCH] FractalTree example application added --- Examples/Examples.bpg | 7 ++- Examples/GUI/FractalTree/FractalTree.dpr | 79 ++++++++++++++++++++++++ Examples/GUI/FractalTree/build.bat | 1 + 3 files changed, 85 insertions(+), 2 deletions(-) create mode 100644 Examples/GUI/FractalTree/FractalTree.dpr create mode 100644 Examples/GUI/FractalTree/build.bat diff --git a/Examples/Examples.bpg b/Examples/Examples.bpg index bec33b2..7a669af 100644 --- a/Examples/Examples.bpg +++ b/Examples/Examples.bpg @@ -10,8 +10,8 @@ DCC = $(ROOT)\bin\dcc32.exe $** BRCC = $(ROOT)\bin\brcc32.exe $** #------------------------------------------------------------------------------ PROJECTS = CharMap.exe ColorButtons.exe ConBoard.exe ConsoleColors.exe DateTime.exe DrawImage.exe DrawImageEx.exe \ - DrawText.exe Echo.exe GetCurrentDirectory.exe GetPixel.exe GetPointOwner.exe Hello.exe HelloGUI.exe LoadFile.exe \ - ReadFolder.exe Screenshot.exe SetCursor.exe SetPixel.exe SetWindowPos.exe + DrawText.exe Echo.exe FractalTree.exe GetCurrentDirectory.exe GetPixel.exe GetPointOwner.exe Hello.exe HelloGUI.exe \ + LoadFile.exe ReadFolder.exe Screenshot.exe SetCursor.exe SetPixel.exe SetWindowPos.exe #------------------------------------------------------------------------------ default: $(PROJECTS) #------------------------------------------------------------------------------ @@ -43,6 +43,9 @@ DrawText.exe: GUI\DrawText\DrawText.dpr Echo.exe: Console\Echo\Echo.dpr $(DCC) +FractalTree.exe: GUI\FractalTree\FractalTree.dpr + $(DCC) + GetCurrentDirectory.exe: Console\GetCurrentDir\GetCurrentDir.dpr $(DCC) diff --git a/Examples/GUI/FractalTree/FractalTree.dpr b/Examples/GUI/FractalTree/FractalTree.dpr new file mode 100644 index 0000000..55a6d52 --- /dev/null +++ b/Examples/GUI/FractalTree/FractalTree.dpr @@ -0,0 +1,79 @@ +program FractalTree; + +uses + KolibriOS; + +var + WndLeft, WndTop: LongInt; + WndHeight, WndWidth: LongWord; + +procedure BoldLine(X1, Y1, X2, Y2: LongInt; Color: LongWord); +begin + DrawLine(X1, Y1, X2, Y2, Color); + DrawLine(X1 + 1, Y1, X2 + 1, Y2, Color); + DrawLine(X1 - 1, Y1, X2 - 1, Y2, Color); + DrawLine(X1, Y1 + 1, X2, Y2 + 1, Color); + DrawLine(X1, Y1 - 1, X2, Y2 - 1, Color); +end; + +procedure Tree(X, Y, Size: LongInt; Angle: Extended); +var + X2, Y2: Integer; + Color: LongWord; +begin + case Size of + 0..2: Color := $FFFF00; + 3..4: Color := $00FF00; + 5..8: Color := $808000; + 9..16: Color := $008000; + 17..32: Color := $2C5400; + else + Color := $562A00; + end; + + X2 := Round(X + Size * Sin(Angle)); + Y2 := Round(Y + Size * Cos(Angle)); + + if Size < 8 then + DrawLine(X, Y, X2, Y2, Color) + else + BoldLine(X, Y, X2, Y2, Color); + + if Size > 0 then + begin + Tree(X2, Y2, Size * 3 div 4, Angle + Pi / 5 / (Random + 1)); + Tree(X2, Y2, Size * 3 div 4, Angle - Pi / 5 / (Random + 1)); + end +end; + +procedure Redraw; +begin + BeginDraw; + DrawWindow(WndLeft, WndTop, WndWidth, WndHeight, 'Press ENTER to generate new tree', $00A0A0A0, + WS_SKINNED_FIXED + WS_CLIENT_COORDS + WS_CAPTION, CAPTION_MOVABLE); + Tree(WndWidth div 2, WndHeight - WINDOW_BORDER_SIZE - GetSkinHeight, WndHeight div 4, Pi); + EndDraw; +end; + +begin + Randomize; + + with GetScreenSize do + begin + WndHeight := Height - Height div 4; + WndWidth := Width - Width div 4; + WndLeft := (Width - WndWidth) div 2; + WndTop := (Height - WndHeight) div 2; + end; + + while True do + case WaitEvent of + REDRAW_EVENT: + Redraw; + KEY_EVENT: + if GetKey.Code = #13 then + Redraw; + BUTTON_EVENT: + Break; + end; +end. diff --git a/Examples/GUI/FractalTree/build.bat b/Examples/GUI/FractalTree/build.bat new file mode 100644 index 0000000..8ea67bc --- /dev/null +++ b/Examples/GUI/FractalTree/build.bat @@ -0,0 +1 @@ +@call "%~dp0..\..\..\Tools\build.bat" "%~dp0FractalTree" \ No newline at end of file