Permalink
Browse files

changed leave generator to use circular radius

  • Loading branch information...
GandhiGames committed Dec 19, 2016
1 parent 90e978b commit e17678bf8ca8d4d8d8515dfcf7abbecce8b13bf5
Binary file not shown.
Binary file not shown.
@@ -21,6 +21,8 @@ public class DemoTreeCreator : MonoBehaviour
/// </summary>
public bool showingStationary = true;
public int startIndex = 0;
/// <summary>
/// Gets the active tree or null if there is none.
/// </summary>
@@ -36,6 +38,8 @@ public class DemoTreeCreator : MonoBehaviour
void Start()
{
m_TreeIndex = startIndex;
foreach (var demo in treeBuilders) {
if (leafGenerator != null && demo.stationaryTree.treeType == TreeBuilder.TreeType.Colonization) {
@@ -9,19 +9,21 @@ namespace FractalTree
/// </summary>
public class ColonizationLeafGenerator : MonoBehaviour
{
/// <summary>
/// The bounds within which to spawn the leafs.
/// </summary>
public Rect bounds;
public float radius = 6f;
/// <summary>
/// The number of leaves to spawn.
/// </summary>
public int numToCreate = 100;
public bool buildOnStart = false;
void Awake ()
{
Generate ();
if (buildOnStart) {
Generate ();
}
}
public void Generate()
@@ -30,9 +32,7 @@ public void Generate()
for (int i = 0; i < numToCreate; i++) {
GameObject leaf = new GameObject ("Leaf " + (i + 1));
leaf.transform.position = new Vector2 (
Random.Range (bounds.xMin, bounds.xMax),
Random.Range (bounds.yMin, bounds.yMax));
leaf.transform.position = (Vector2)transform.position + (Random.insideUnitCircle * radius);
leaf.AddComponent<ColonizationLeaf> ();
leaf.transform.SetParent (transform);
@@ -153,7 +153,7 @@ private void CalculateNextStep ()
branchesCreated.Add (branch);
current = next;
} else if (currentChar.Equals ('G')) {
current += (Vector2.up * m_Length).Rotate (rotation);
current += (Vector2.up * m_Length).Rotate (rotation);
} else if (currentChar.Equals ('+')) {
rotation -= m_Angle;
} else if (currentChar.Equals ('-')) {
@@ -187,6 +187,10 @@ private void CalculateNextStep ()
}
}
} else if (currentChar.Equals ('!')) {
m_Angle *= -1f;
} else if (currentChar.Equals ('|')) {
rotation = 180f;
}
}
Binary file not shown.
Binary file not shown.
@@ -1 +1,4 @@
sceneSetups: []
sceneSetups:
- path: Assets/Scenes/Tree Demo.unity
isLoaded: 1
isActive: 1
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 comments on commit e17678b

Please sign in to comment.