コード例 #1
0
        public void addBranchesToLimb(TreePart limb, int limbRemaining)
        {
            int    branchSections = (int)(limbRemaining * species.averageBranchLength + (random.NextDouble() * species.branchLengthVariation - species.branchLengthVariation / 2));
            Branch newBranch      = new Branch(this, species.getRect(species.weightedBranchRects, random));

            limb.addPart(newBranch);
            float initialRot = (float)(random.NextDouble() * (Math.PI * 2f));

            newBranch.rotation = initialRot;
            newBranch.performSetup();
            for (int i = 0; i < branchSections; i++)
            {
                Branch newSection = new Branch(this, species.getRect(species.weightedBranchRects, random));
                newBranch.findAnyEnd().addPart(newSection);
                newSection.rotation = ((float)(random.NextDouble() * 0.5 - 0.25f));
                newSection.performSetup();
            }

            Rectangle   leafSprite  = species.getRect(species.weightedLeafRects, random);
            LeafCluster leafCluster = new LeafCluster(this, leafSprite, species.getColor(species.weightedLeafColors, leafSprite, random));

            newBranch.findAnyEnd().addPart(leafCluster);
            leafCluster.depth -= (float)(random.NextDouble() + 0.5);
            leafCluster.performSetup();
            Logger.log("Leaf cluster is on " + (leafCluster.left ? "left" : "right"));
        }
コード例 #2
0
        public void addLimbToPart(TreePart part, bool left, int sectionsUp, int sectionsDown, float rotationOverride = float.MinValue)
        {
            Logger.log("Limb was on the " + (left ? "left" : "right"));
            Limb newLimb = new Limb(this, species.getRect(species.weightedLimbRects, random));

            float initialRot;

            if (rotationOverride == float.MinValue)
            {
                initialRot = species.limbAngle * (left ? -1 : 1);
            }
            else
            {
                initialRot = rotationOverride;
            }

            float depth = (float)(random.NextDouble() * 2 + 1) * (random.Next(2) == 0 ? -1 : 1);

            newLimb.depth    = depth;
            newLimb.rotation = initialRot;
            part.addPart(newLimb);
            newLimb.left = left;
            newLimb.performSetup();
            int sectionsToGrow = (int)(sectionsDown * species.limbGrowth);

            Logger.log("Growing " + sectionsToGrow + " sections on limb...");
            for (int i = 0; i < sectionsToGrow; i++)
            {
                Limb newSection = new Limb(this, species.getRect(species.weightedLimbRects, random));
                newLimb.findAnyEnd(new Type[] { typeof(Limb) }).addPart(newSection);
                newSection.rotation = ((float)(random.NextDouble() * 0.5 - 0.25f));
                newSection.performSetup();
                if (i >= species.minBranchDistance && random.NextDouble() < species.branchFrequency)
                {
                    Logger.log("Adding branch to limb section " + i);
                    if (species.limbAlternate)
                    {
                        addBranchesToLimb(newSection, sectionsToGrow - i);
                    }
                    else
                    {
                        addBranchesToLimb(newSection, sectionsToGrow - i);
                        addBranchesToLimb(newSection, sectionsToGrow - i);
                    }
                    //sectionsBetweenLimbs = (int)(averageLimbInterval + (random.NextDouble() * limbIntervalVariation) - (limbIntervalVariation / 2));
                }
            }
            //newLimb.addGravity(true);
            addBranchesToLimb(newLimb.findAnyEnd(new Type[] { typeof(Limb) }), sectionsToGrow / 2);
        }