-
Notifications
You must be signed in to change notification settings - Fork 1
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
1 parent
781979c
commit c2fe78b
Showing
3 changed files
with
41 additions
and
35 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,37 @@ | ||
import { random } from "../../classes/utilities" | ||
import { LSystemCondition } from "./lsystem_rule" | ||
import { VanillaLSystemRule } from "./vanilla_lsystem_rule" | ||
|
||
export const RandomRuleConstructor = { | ||
random(): VanillaLSystemRule { | ||
const alphabets = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".split("") | ||
const conditions = alphabets.slice(0, random(alphabets.length, 1)) | ||
const map = new Map<string, LSystemCondition[]>() | ||
const maxConditions = 10 | ||
|
||
const randomCondition = (): string => { | ||
const index = Math.floor(random(conditions.length)) | ||
|
||
return conditions[index] | ||
} | ||
|
||
conditions.forEach(condition => { | ||
const nextConditions: LSystemCondition[] = [] | ||
for (let i = 0; i < maxConditions; i += 1) { | ||
if (random(1) > 0.5) { | ||
break | ||
} | ||
const angle = Math.floor(random(360, 0)) - 180 | ||
nextConditions.push(angle) | ||
nextConditions.push(randomCondition()) | ||
} | ||
if (nextConditions.length === 0) { | ||
nextConditions.push(VanillaLSystemRule.endOfBranch) | ||
} | ||
|
||
map.set(condition, nextConditions) | ||
}) | ||
|
||
return new VanillaLSystemRule(map) | ||
} | ||
} |
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
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