Example #1
0
    // Start is called before the first frame update
    void Start()
    {
        terrainGenerator = GameObject.Find("Level").GetComponent <TerrainGenerator>();

        float frequency   = 1f;
        float persistence = 1f;
        float lacunarity  = 1f;
        int   octaves     = 1;

        perlin      = new Perlin(frequency, lacunarity, persistence, octaves, TerrainGenerator.Seed, LibNoise.QualityMode.High);
        fractalTree = GetComponent <FractalTree>();
    }
Example #2
0
    Mesh BuildMesh(FractalTree tree)
    {
        var vertices  = new List <Vector3>();
        var triangles = new List <int>();

        AddToMesh(tree.trunk, vertices, triangles);
        var mesh = new Mesh();

        mesh.vertices  = vertices.ToArray();
        mesh.triangles = triangles.ToArray();
        mesh.RecalculateBounds();
        mesh.RecalculateNormals();
        mesh.RecalculateTangents();
        return(mesh);
    }
Example #3
0
    public override void OnInspectorGUI()
    {
        FractalTree tree = (FractalTree)target;

        // If inspector is changed
        if (DrawDefaultInspector())
        {
            tree.GenerateTree();
        }

        if (GUILayout.Button("Generate Tree"))
        {
            tree.GenerateTree();
        }
    }
Example #4
0
 void Draw()
 {
     try
     {
         if (this.tbDepth.Text != String.Empty)
         {
             int depth = Convert.ToInt32(this.tbDepth.Text);
             if (cbType.SelectedItem.ToString() == Constants.Fractals.pyphagorTree)
             {
                 if (txbAngleRight.Text != String.Empty && txbAngleLeft.Text != String.Empty)
                 {
                     int         leftAngle  = Convert.ToInt32(this.txbAngleLeft.Text);
                     int         rightAngle = Convert.ToInt32(this.txbAngleRight.Text);
                     FractalTree tree       = new FractalTree(this.pbFractal.Width / 2, 0, this.size, depth, leftAngle, rightAngle, this.lineColor);
                     tree.Fill(this.pbFractal, this.backgroundColor);
                     tree.Draw(this.pbFractal);
                 }
             }
             if (cbType.SelectedItem.ToString() == Constants.Fractals.windTree)
             {
                 if (txbAngleRight.Text != String.Empty && txbAngleLeft.Text != String.Empty)
                 {
                     int         leftAngle  = Convert.ToInt32(this.txbAngleLeft.Text);
                     int         rightAngle = Convert.ToInt32(this.txbAngleRight.Text);
                     FractalTree tree       = new FractalTree(this.pbFractal.Width / 2, 0, this.size, depth, leftAngle, rightAngle, this.lineColor);
                     tree.Fill(this.pbFractal, this.backgroundColor);
                     tree.Draw(this.pbFractal);
                 }
             }
             if (cbType.SelectedItem.ToString() == Constants.Fractals.triangle)
             {
                 FractalTriangle fractalTriangle = new FractalTriangle(this.pbFractal.Width / 2, 0, this.size, depth, this.lineColor);
                 fractalTriangle.Fill(this.pbFractal, this.backgroundColor);
                 fractalTriangle.Draw(this.pbFractal);
             }
         }
         lblAngleLeft.Visible  = IsTreeChecked();
         lblAngleRight.Visible = IsTreeChecked();
         txbAngleLeft.Visible  = IsTreeChecked();
         txbAngleRight.Visible = IsTreeChecked();
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
Example #5
0
        /// <summary>
        /// Generic event for when the user drags any of the sliders
        /// Renders the whole tree
        /// </summary>
        private async void OnSliderValueChanged(object sender, RoutedPropertyChangedEventArgs <double> e)
        {
            try
            {
                if (!IsInitialized ||
                    _BranchTask != null && !_BranchTask.IsCompleted)
                {
                    return;
                }

                FractalTree.ClearHostChildren();

                _MaxRecursions = (int)BranchesSlider.Value;
                _Length        = LengthSlider.Value;
                _Width         = WidthSlider.Value;
                _ShrinkFactor  = ShrinkFactorSlider.Value;

                double increment = (Math.PI / 180) * AngleSlider.Value;

                double x2 = 0;
                double y2 = _Length;

                FractalTree.AddBranchCoordinate(new Point(0, 0), new Point(x2, y2));

                _BranchTask = Task.Factory.StartNew(async() =>
                {
                    await foreach (PointPair branchPoints in GetBranchesAsync(0, Math.PI / 2, increment, x2, y2, _ShrinkFactor))
                    {
                        FractalTree.AddBranchCoordinate(branchPoints);
                    }

                    await Application.Current.Dispatcher.BeginInvoke((Action)(() => FractalTree.RenderTree(_Width)));
                });

                await _BranchTask;
            }
            catch
            {
            }
        }