How to resolve the algorithm Pythagoras tree step by step in the PureBasic programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Pythagoras tree step by step in the PureBasic 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 PureBasic programming language
Source code in the purebasic programming language
EnableExplicit
DisableDebugger
Procedure.d maxXY(a.d,b.d,c.d,d.d)
If a<b : Swap a,b : EndIf
If a<c : Swap a,c : EndIf
If a<d : Swap a,d : EndIf
ProcedureReturn a
EndProcedure
Procedure.d minXY(a.d,b.d,c.d,d.d)
If a>b : Swap a,b : EndIf
If a>c : Swap a,c : EndIf
If a>d : Swap a,d : EndIf
ProcedureReturn a
EndProcedure
Procedure Ptree(x1.d, y1.d, x2.d, y2.d, d.i=0)
If d>10 : ProcedureReturn : EndIf
Define dx.d=x2-x1,
dy.d=y1-y2,
x3.d=x2-dy,
y3.d=y2-dx,
x4.d=x1-dy,
y4.d=y1-dx,
x5.d=x4+(dx-dy)/2.0,
y5.d=y4-(dx+dy)/2.0,
p1.d=(maxXY(x1,x2,x3,x4)+minXY(x1,x2,x3,x4))/2.0,
p2.d=(maxXY(y1,y2,y3,y4)+minXY(y1,y2,y3,y4))/2.0,
p3.d=(maxXY(x1,x2,x3,x4)-minXY(x1,x2,x3,x4))
FrontColor(RGB(Random(125,1),Random(255,125),Random(125,1)))
LineXY(x1,y1,x2,y2)
LineXY(x2,y2,x3,y3)
LineXY(x3,y3,x4,y4)
LineXY(x4,y4,x1,y1)
BoxedGradient(minXY(x1,x2,x3,x4),minXY(y1,y2,y3,y4),p3,p3)
FillArea(p1,p2,-1)
Ptree(x4,y4,x5,y5,d+1)
Ptree(x5,y5,x3,y3,d+1)
EndProcedure
Define w1.i=800,
h1.i=w1*11/16,
w2.i=w1/2,
di.i=w1/12
If OpenWindow(0,#PB_Ignore,#PB_Ignore,w1,h1,"Pythagoras tree")
If CreateImage(0,w1,h1,24,0) And StartDrawing(ImageOutput(0))
DrawingMode(#PB_2DDrawing_Gradient)
BackColor($000000)
Ptree(w2-di,h1-10,w2+di,h1-10)
StopDrawing()
EndIf
ImageGadget(0,0,0,0,0,ImageID(0))
Repeat : Until WaitWindowEvent(50)=#PB_Event_CloseWindow
EndIf
End
You may also check:How to resolve the algorithm Kernighans large earthquake problem step by step in the 8080 Assembly programming language
You may also check:How to resolve the algorithm Sequence: smallest number greater than previous term with exactly n divisors step by step in the Nim programming language
You may also check:How to resolve the algorithm Include a file step by step in the Rust programming language
You may also check:How to resolve the algorithm Interactive programming (repl) step by step in the Perl programming language
You may also check:How to resolve the algorithm Binary digits step by step in the BQN programming language