#------------fractal trees with default values------------ #the function below draws every branch block by block (at location given in first argument) #it can also generate simple leaves (block sphere) around that location #generateLeaves = determines if the leaves will be generated or not #leavesChance = is the chance of leaves appearing in the current block #radius = size of the block sphere options: branchBlock: spruce log leavesBlock: oak leaves function drawTree(branch: location, generateLeaves: boolean=false, leavesChance: number=0, radius: number=1.4): #just a statistic add 1 to {count} set block at {_branch} to {@branchBlock} where [block at {_branch} != {@branchBlock}] {_generateLeaves} = true chance of {_leavesChance}: loop blocks in radius {_radius} around {_branch}: set loop-block to {@leavesBlock} where [loop-block = air] #and here is the main function - it repeats itself until the given number of levels (generations) is generated #branchLoc = starting location for our tree (also a starting locations for every branch in every repeat) #currentLevel = is a current level (generation) - do not change - when calling a funcion always set that argument to 1 #baseLength = is a starting length of our tree - the first branch will be its length #lengthMultiplier = every single branch will be multiplied by that number, so every next branch will be shorter than the previous one - set this to 1 if you want all of them to be the same length #levelsAmount = amount of generations (branches growing out of branches) - how many times the function should be called function fractalTree(branchLoc: locations, currentLevel: integer=1, baseLength: number=10, lengthMultiplier: number=0.90, levelsAmount: number=5): #offset declares how dense our branch will be - in this case its set to 1 set {_offset} to {_baseLength} / {_baseLength} #just a statistic to tell how many locations function has generated broadcast "&4&l%{count}%" if {_currentLevel} = {_levelsAmount} #check if args are correct {_currentLevel} < {_levelsAmount} #lets loop all the locations from which we will start generating new branches (it will contain the starting location given by us or ends of previous branches) loop {_branchLoc::*}: #FIRST CUSTOMIZABLE OPION #we can define here how many branches will be generated from previous branch set {_random} to random integer between 1 and 2 loop {_random} times: set {_newLoc} to loop-value-1 #SECOND CUSTOMIZABLE OPTION #yaw - horizontall rotation of every new branch (in degrees from 0 to 360) #in this case - circle (360 degrees) is divided by amount of new branches ({_random}) and its yaw is chosen only from that range #so there shouldn't be a case where two branches collide with each other set {_yaw1} to (360 / {_random}) set {_yaw} to (random number between ({_yaw} * ({_random} - 1)) and ({_yaw} * ({_random} + 1))) #THIRD CUSTOMIZABLE OPTION #pitch - vertical rotation of every new branch (in degrees from -90 to +90 where -90 = zenit; 0 = horizon; +90 = nadir) #in this case its just a random value from 0 to -90 set {_pitch} to (random number between 0 and -90) #then we create a new vector from that yaw and pitch values #and we set its length to that offset we defined in the first line set {_vector} to vector from yaw {_yaw} and pitch {_pitch} set standard length of {_vector} to {_offset} #then we create a loop that repeats 'density' times #and inside we add our vector to end location of prevuous branch loop {_baseLength} times: set {_newLoc} to {_newLoc} ~ {_vector} #and then we call the function to place a block at that location drawTree({_newLoc}) #optional #we can set a chance of leaves to appear #in this case it depends on current level (generation) - do ther higher we are the bigger the chance for leaves is set {_leavesChance} to ({_currentLevel} / {_levelsAmount} / 3) #at this point a single branch was generated and {_newLoc} is the last block of that branch #so we can generate some leaves around it as its the end of that branch #the last argument is a radius - also depends on current level; the higher we are - the bigger the leaves sphere is drawTree({_newLoc}, true, {_leavesChance}, (({_currentLevel} * 0.4) + 1.7)) #here we add last location of every branch to a list which will be used to generate next level of branches set {_newBranches::%loop-value-1%.%loop-value-2%} to {_newLoc} #the length of next branches is being multiplied #and we set level to higher set {_newLength} to {_baseLength} * {_lengthMultiplier} add 1 to {_currentLevel} #in the end we call the function again with new args (newBranches, newLength, currentLevel) fractalTree({_newBranches::*}, {_currentLevel}, {_newLength}, {_lengthMultiplier}, {_levelsAmount}) #an example of how to call that function command fractal: trigger: fractalTree(targeted block)