Beispiel #1
0
 public Node(NodeDNA dna, Vector3 pos)
 {
     this.dna       = dna;
     this.position  = pos;
     this.baseAngle = this.angle = -MathHelper.PiOver2;
     this.radius    = (10f * dna.BaseRadius) + NodeDNA.NextFloat() + 4f;
     this.idColor   = makeIDColor(this.dna, this.depth);
 }
Beispiel #2
0
        static HSBColor makeIDColor(NodeDNA dna, float depth)
        {
            float h = (3 + dna.HueStart + .1f * dna.HueDiff * depth);
            float s = (.7f + .3f * dna.Saturation * MathF.Sin(depth)) -
                      (dna.Saturation * depth * .08f);
            float b = .3f + .1f * depth;

            return(new HSBColor(h % 1f, MathF.Unit(s), MathF.Unit(b)));
        }
Beispiel #3
0
        protected override void Update(GameTime gameTime)
        {
            KeyboardState keyboard = Keyboard.GetState();

            if (
                lastKeyboard.IsKeyDown(Keys.Enter) &&
                keyboard.IsKeyUp(Keys.Enter)
                )
            {
                nodes = null;
            }

            if (keyboard.IsKeyDown(Keys.Escape))
            {
                Exit();
            }

            lastKeyboard = keyboard;

            if (nodes == null)
            {
                nodes = new List <TrunkNode>();
                float halfWidth  = (float)(GraphicsDevice.Viewport.Width) / 2.0f;
                float halfHeight = (float)(GraphicsDevice.Viewport.Height) /
                                   2.0f;
                float spaceY = (float)(GraphicsDevice.Viewport.Height) /
                               (float)NodeGridHeight;
                float spaceX = (float)(GraphicsDevice.Viewport.Width) /
                               (float)NodeGridWidth;
                for (int y = 0; y < NodeGridHeight; y++)
                {
                    for (int x = 0; x < NodeGridWidth; x++)
                    {
                        Vector3 origin = new Vector3(
                            (x * spaceX) + (spaceX / 2.0f) - halfWidth,
                            (y * spaceY) + (spaceY / 2.0f) - halfHeight,
                            0.0f
                            );

                        var dna  = new NodeDNA();
                        var node = new TrunkNode(dna, origin);
                        for (int i = 0; i < IterationCount; i++)
                        {
                            node.Iterate();
                        }

                        nodes.Add(node);
                    }
                }
            }

            foreach (var node in this.nodes)
            {
                node.Update(gameTime);
            }
        }
Beispiel #4
0
 public TrunkNode(NodeDNA dna, Vector3 origin)
     : this(
         dna : dna,
         origin : origin,
         depth : 1,
         angle : 0,
         width : MathHelper.Lerp(
             MinTrunkWidth,
             MaxTrunkWidth,
             dna.BaseRadius
             )
         )
 {
 }
Beispiel #5
0
        public TrunkNode(
            NodeDNA dna,
            Vector3 origin,
            int depth,
            float angle,
            float width)
        {
            this.dna    = dna;
            this.origin = origin;
            this.color  = HSBColors.Brown; //makeIDColor(dna, 0);
            this.angle  = angle;
            this.depth  = depth;

            this.width  = width;
            this.length =
                this.width *
                MathHelper.Lerp(
                    MinTrunkLengthScale,
                    MaxTrunkLengthScale,
                    dna.Bushiness
                    );
        }
Beispiel #6
0
        public Node(Node parent, float childPct)
        {
            this.id     = NextID++;
            this.parent = parent;

            if (parent != null)
            {
                this.depth = parent.depth + 1;
                this.dna   = parent.dna;

                // As a child, offset the child index
                var skew   = (float)Math.Pow(this.dna.AngleSkew - .5f, 3);
                var spread = (2f * this.dna.Bushiness);
                this.baseAngle  = parent.angle + spread * (childPct - .5f) + skew;
                this.baseAngle +=
                    this.dna.Wiggle * .1f * MathF.Sin(this.depth) * this.depth;

                // Set the position relative to the parent
                var mult = 15 - 12 * this.dna.Bushiness;
                this.branchLength = .7f * mult * parent.radius;

                this.branchLength *=
                    (1 + 1 * this.dna.Variation * (NodeDNA.NextFloat() - .5f));
                this.radius = parent.radius * (.6f + .3f * this.dna.Shrinkage);

                this.position =
                    MathF.PolarOffset(
                        parent.position,
                        this.branchLength,
                        this.baseAngle
                        );
            }

            this.angle   = this.baseAngle;
            this.idColor = makeIDColor(this.dna, this.depth);
        }