How to resolve the algorithm Fractal tree step by step in the Fantom programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Fractal tree step by step in the Fantom 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 Fantom programming language

Source code in the fantom programming language

using fwt
using gfx

class FractalCanvas : Canvas 
{
  new make () : super() {}

  Void drawTree (Graphics g, Int x1, Int y1, Int angle, Int depth)
  {
    if (depth == 0) return
    Int x2 := x1 + (angle.toFloat.toRadians.cos * depth * 10.0).toInt;
    Int y2 := y1 + (angle.toFloat.toRadians.sin * depth * 10.0).toInt;
    g.drawLine(x1, y1, x2, y2);
    drawTree(g, x2, y2, angle - 20, depth - 1);
    drawTree(g, x2, y2, angle + 20, depth - 1);
  }

  override Void onPaint (Graphics g)
  {
    drawTree (g, 400, 500, -90, 9)
  }
}

class FractalTree
{
  public static Void main ()
  {
    Window
    {
      title = "Fractal Tree"
      size = Size(800, 600)
      FractalCanvas(),
    }.open
  }
}

  

You may also check:How to resolve the algorithm Deal cards for FreeCell step by step in the Befunge programming language
You may also check:How to resolve the algorithm Execute Brain step by step in the GAP programming language
You may also check:How to resolve the algorithm Parse an IP Address step by step in the Nim programming language
You may also check:How to resolve the algorithm Remove duplicate elements step by step in the ECL programming language
You may also check:How to resolve the algorithm Perfect numbers step by step in the REXX programming language