How to resolve the algorithm Fractal tree step by step in the Prolog programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Fractal tree step by step in the Prolog programming language
Table of Contents
Problem Statement
Generate and draw a fractal tree.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Fractal tree step by step in the Prolog programming language
Source code in the prolog programming language
fractal :-
new(D, window('Fractal')),
send(D, size, size(800, 600)),
drawTree(D, 400, 500, -90, 9),
send(D, open).
drawTree(_D, _X, _Y, _Angle, 0).
drawTree(D, X1, Y1, Angle, Depth) :-
X2 is X1 + cos(Angle * pi / 180.0) * Depth * 10.0,
Y2 is Y1 + sin(Angle * pi / 180.0) * Depth * 10.0,
new(Line, line(X1, Y1, X2, Y2, none)),
send(D, display, Line),
A1 is Angle - 30,
A2 is Angle + 30,
De is Depth - 1,
drawTree(D, X2, Y2, A1, De),
drawTree(D, X2, Y2, A2, De).
You may also check:How to resolve the algorithm Dice game probabilities step by step in the C programming language
You may also check:How to resolve the algorithm Multifactorial step by step in the Python programming language
You may also check:How to resolve the algorithm Statistics/Normal distribution step by step in the Rust programming language
You may also check:How to resolve the algorithm Null object step by step in the 6502 Assembly programming language
You may also check:How to resolve the algorithm Functional coverage tree step by step in the J programming language