How to resolve the algorithm Fractal tree step by step in the Red programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Fractal tree step by step in the Red 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 Red programming language
Source code in the red programming language
Red [Needs: 'View]
color: brown
width: 9
view/tight/options/flags/no-wait [ ; click image to grow tree
img: image 1097x617 draw [
pen brown line-width 9 line 500x600 500x500] [grow]
] [offset: 0x0] [no-border]
ends: reduce [500x500 pi * 3 / 2] ; list of terminal nodes
da: pi * 30 / 180 ; angle of branches in radians
ea: pi * 5 / 180 ; offset added to angle to break symmetry
l: 200 ; branches initial lenght
scale: 0.7 ; branches scale factor
grow: does [ ; grows branches
l: l * scale
color: 2 * color + leaf / 3
width: width - 1
newends: copy []
foreach [p a] ends [
a1: a + da - ea
p1: p + as-pair l * cos a1 l * sin a1
a2: a - da - ea
p2: p + as-pair l * cos a2 l * sin a2
append img/draw compose/deep [
pen (color) line-width (width) line (p1) (p) (p2)]
append newends reduce [p1 a1 p2 a2]
]
ends: newends
]
You may also check:How to resolve the algorithm Queue/Definition step by step in the Klingphix programming language
You may also check:How to resolve the algorithm Pointers and references step by step in the PicoLisp programming language
You may also check:How to resolve the algorithm Tokenize a string step by step in the XPL0 programming language
You may also check:How to resolve the algorithm One-dimensional cellular automata step by step in the Batch File programming language
You may also check:How to resolve the algorithm Perfect numbers step by step in the AppleScript programming language