-
Notifications
You must be signed in to change notification settings - Fork 522
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
33 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// Fractal trees by Maggie, Claire and Belle | ||
|
||
const t = createTurtle(); | ||
|
||
const MAX_ITERATION = randInRange(7, 10) | ||
const START_ANGLE = 90 | ||
const ANGLE_CHANGE = randInRange(10, 20) | ||
const BRANCH_LEN = randInRange(20, 30) | ||
const START_POS = [62.5, 30] | ||
|
||
function recurse(prevBranchEnd, angle, branchLen, iteration) { | ||
if (iteration > MAX_ITERATION) { | ||
return | ||
} | ||
|
||
// Left branch from a node | ||
t.jump(prevBranchEnd) | ||
t.setAngle(angle + ANGLE_CHANGE) | ||
t.forward(branchLen) | ||
|
||
recurse(t.end, angle + ANGLE_CHANGE, branchLen * 2/3, iteration + 1) | ||
|
||
// Right branch from a node | ||
t.jump(prevBranchEnd) | ||
t.setAngle(angle - ANGLE_CHANGE) | ||
t.forward(branchLen) | ||
|
||
recurse(t.end, angle - ANGLE_CHANGE, branchLen * 2/3, iteration + 1) | ||
} | ||
|
||
recurse(START_POS, START_ANGLE, BRANCH_LEN, 1) | ||
|
||
drawTurtles([t]) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.