// STARTREE - introduction to recursive techniques.

set reduce_factor = 0   // set these here to make them global..
set rotate_factor = 0   
set extra_extend = 0


////////////////////////////////////////////////////////
// STAR - this procedure draws a star, and calls itself once for every point..
// (code copied from the star1 file)
to star :ptlen :rotate_amount :recurs
  set t1 = turtle		
  logo turtledir :rotate_amount
  set sidelen = calc :ptlen * 0.8	
  pu fd :ptlen pd 
  lt 160	

  // do the 5 points..
  repeat 5 [ 
    fd :sidelen 
    rt 68 
    fd :sidelen 
    if :recurs > 0 [ 
       pu; fd (calc :sidelen * :extra_extend) 
       star (calc :ptlen * :reduce_factor) (calc :rotate_amount + :rotate_factor) (calc :recurs - 1)
       pu; bk (calc :sidelen * :extra_extend) 
       pd
       ]
    lt 140
    ]

  // leave pen up and restore turtle position, direction, etc.
  pu					
  logo turtle = :t1			
end


/////////////////////////////////////////
// STARTREE begins executing here..
/////////////////////////////////////////

repeat untilbreak [
  set ngen = buttonchoice "Starting a new star tree. \n How many generations?" "2|3|4|5|Quit"
  if :ngen = "quit" [ break ]

  set firstsize = buttonchoice "First star size:" "75|100|150|200|250"
  set reduce_factor = buttonchoice 
	"Each new generation should be __ the size\nof the current generation:" 
	"0.3|0.4|0.5|0.6"

  set extra_extend = buttonchoice
        "Each new generation should be an extra __\nfurther out:"
	"None|0.5|1|2|3"
  if :extra_extend = "none" [ set extra_extend = 0 ]

  set rotate_factor = buttonchoice 
	"Each new generation should be rotated __ degrees\nmore than the current generation:" 
	"None|5|10|15|20|25|30"
  if :rotate_factor = "none" [ set rotate_factor = 0 ]

  clear
  logo linethick = 0.5

  // start things off by calling star, which will then call itself a number of times..
  star :firstsize 0 :ngen
  ]
