How to resolve the algorithm Pythagoras tree step by step in the QB64 programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Pythagoras tree step by step in the QB64 programming language

Table of Contents

Problem Statement

The Pythagoras tree is a fractal tree constructed from squares. It is named after Pythagoras because each triple of touching squares encloses a right triangle, in a configuration traditionally used to represent the Pythagorean theorem.

Construct a Pythagoras tree of order 7 using only vectors (no rotation or trigonometric functions).

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Pythagoras tree step by step in the QB64 programming language

Source code in the qb64 programming language

_Title "Pythagoras Tree"

Dim As Integer sw, sh
sw = 640
sh = 480

Screen _NewImage(sw, sh, 32)

Call pythTree(sw / 2 - sw / 12, sh - 30, sw / 2 + sw / 12, sh - 30, 0)

Sleep
System

Sub pythTree (ax As Integer, ay As Integer, bx As Integer, by As Integer, depth As Integer)
    Dim As Single cx, cy, dx, dy, ex, ey
    Dim As Integer c

    cx = ax - ay + by
    cy = ax + ay - bx
    dx = bx + by - ay
    dy = ax - bx + by
    ex = (cx - cy + dx + dy) * 0.5
    ey = (cx + cy - dx + dy) * 0.5
    c = depth * 15
    Color _RGB(c Mod 256, Abs((255 - c)) Mod 256, (144 + c) Mod 256)
    Line (cx, cy)-(ax, ay)
    Line (ax, ay)-(bx, by)
    Line (bx, by)-(dx, dy)
    Line (dx, dy)-(cx, cy)
    Line (cx, cy)-(ex, ey)
    Line (ex, ey)-(dx, dy)
    If depth < 12 Then
        Call pythTree(cx, cy, ex, ey, depth + 1)
        Call pythTree(ex, ey, dx, dy, depth + 1)
    End If
End Sub

  

You may also check:How to resolve the algorithm Abelian sandpile model/Identity step by step in the ARM Assembly programming language
You may also check:How to resolve the algorithm Variable declaration reset step by step in the Phix programming language
You may also check:How to resolve the algorithm Named parameters step by step in the OCaml programming language
You may also check:How to resolve the algorithm Vampire number step by step in the Racket programming language
You may also check:How to resolve the algorithm Case-sensitivity of identifiers step by step in the Crystal programming language