RosettaCodeData/Task/Fractal-tree/Frink/fractal-tree.frink
2020-02-17 23:21:07 -08:00

27 lines
934 B
Text

// Draw Fractal Tree in Frink
// Define the tree function
FractalTree[x1, y1, angleval, lengthval, graphicsobject] :=
{
if lengthval > 1
{
// Define current line end points (x2 and y2)
x2 = x1 + ((cos[angleval degrees]) * lengthval)
y2 = y1 + ((sin[angleval degrees]) * lengthval)
// Draw line - notice that graphicsobject is the graphics object passed into the function.
graphicsobject.line[x1,y1,x2,y2]
// Calculate branches. You can change the lengthval multiplier factor and angleval summand to create different trees
FractalTree[x2, y2, angleval - 20, lengthval * 0.7, graphicsobject]
FractalTree[x2, y2, angleval + 20, lengthval * 0.7, graphicsobject]
}
}
// Create graphics object
g = new graphics
// Start the recursive function. In Frink, a -90° angle moves from the bottom of the screen to the top.
FractalTree[0, 0, -90, 30, g]
// Show the final tree
g.show[]