Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 10:39 19 Nov 2025 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : Pythagoras Tree

Author Message
William Leue
Guru

Joined: 03/07/2020
Location: United States
Posts: 405
Posted: 03:23pm 08 Jul 2021
Copy link to clipboard 
Print this post

Here's a very short, simple one.

-Bill






' Pythagoras Tree Fractal
' Based on various published versions on Rosetta
' Rev 1.0.0 William M Leue 7/4/2021

option base 1

limit = 12
w = MM.HRES
h = MM.VRES
w2 = int(w/2)
diff = int(w/12)

cls
PythagTree 350, 500, 450, 500, 0
end

sub PythagTree x1, y1, x2, y2, depth
 local float dx, dy, x3, y3, x4, y4, x5, y5
 local float xv(4), yv(4)
 local integer r, c
 if depth > limit then exit sub
 dx = x2-x1 : dy = y1-y2
 x3 = x2-dy : y3 = y2-dx
 x4 = x1-dy : y4 = y1-dx
 x5 = x4 + 0.5*(dx-dy)
 y5 = y4 - 0.5*(dx+dy)
 r = 255-depth*20
 c = rgb(r, 255, 0)
 xv(1) = x1 : yv(1) = y1
 xv(2) = x2 : yv(2) = y2
 xv(3) = x3 : yv(3) = y3
 xv(4) = x4 : yv(4) = y4
 polygon 4, xv(), yv(), c, c
 PythagTree x4, y4, x5, y5, depth+1
 PythagTree x5, y5, x3, y3, depth+1
end sub


 
William Leue
Guru

Joined: 03/07/2020
Location: United States
Posts: 405
Posted: 04:10pm 09 Jul 2021
Copy link to clipboard 
Print this post

I couldn't resist updating this program to add seasonal colors to the 'tree' for fall and winter as well as the original summer colors.

-Bill





' Pythagoras Tree Fractal
' Based on various published versions on Rosetta
' Rev 1.0.0 William M Leue 7/4/2021
' Rev 1.0.1 7/9/2021 - added fall and winter foliage coloration

option base 1

dim summer(6) = (255, 255, 0, -20,  0,  0)
dim fall(6)   = (87,   43, 0,  14,  8,  0)
dim winter(6) = (87,   39, 0,  14, 18, 21)

limit = 12

cls
print "Enter season 1..3 (summer, fall, winter): ";
input "", season
season = int(season)
if season < 1 then season = 1
if season > 3 then season = 3

select case season
 case 1
   rstart = summer(1) : rinc = summer(4)
   gstart = summer(2) : ginc = summer(5)
   bstart = summer(3) : binc = summer(6)
 case 2
   rstart = fall(1) : rinc = fall(4)
   gstart = fall(2) : ginc = fall(5)
   bstart = fall(3) : binc = fall(6)
 case 3
   rstart = winter(1) : rinc = winter(4)
   gstart = winter(2) : ginc = winter(5)
   bstart = winter(3) : binc = winter(6)
end select

cls
PythagTree 350, 500, 450, 500, 0
save image "PythagTree"
end

sub PythagTree x1, y1, x2, y2, depth
 local float dx, dy, x3, y3, x4, y4, x5, y5
 local float xv(4), yv(4)
 local integer r, c
 if depth > limit then exit sub
 dx = x2-x1 : dy = y1-y2
 x3 = x2-dy : y3 = y2-dx
 x4 = x1-dy : y4 = y1-dx
 x5 = x4 + 0.5*(dx-dy)
 y5 = y4 - 0.5*(dx+dy)
 xv(1) = x1 : yv(1) = y1
 xv(2) = x2 : yv(2) = y2
 xv(3) = x3 : yv(3) = y3
 xv(4) = x4 : yv(4) = y4
 r = rstart + depth*rinc
 g = gstart + depth*ginc
 b = bstart + depth*binc
 c = rgb(r, g, b)
 polygon 4, xv(), yv(), c, c
 PythagTree x4, y4, x5, y5, depth+1
 PythagTree x5, y5, x3, y3, depth+1
end sub

 
lizby
Guru

Joined: 17/05/2016
Location: United States
Posts: 3478
Posted: 04:15pm 09 Jul 2021
Copy link to clipboard 
Print this post

Beautiful. Thanks. Such a small program for such a rich image.
PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed
 
Print this page


To reply to this topic, you need to log in.

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025