Exemplo n.º 1
0
    def make_branches(self, world):
        """
        Generate the branches and enter them in world.
        """

        height = self.height
        topy = self.pos[1] + int(self.trunkheight + 0.5)
        # endrad is the base radius of the branches at the trunk
        endrad = max(self.trunkradius * (1 - self.trunkheight / height), 1)
        for coord in self.foliage_cords:
            distance = dist((coord[0], coord[2]), (self.pos[0], self.pos[2]))
            ydist = coord[1] - self.pos[1]
            # value is a magic number that weights the probability
            # of generating branches properly so that
            # you get enough on small trees, but not too many
            # on larger trees.
            # Very difficult to get right... do not touch!
            value = (self.branchdensity * 220 * height) / ((ydist + distance) ** 3)
            if value < random():
                continue

            posy = coord[1]
            slope = self.branchslope + (0.5 - random()) * .16
            if coord[1] - distance * slope > topy:
                # Another random rejection, for branches between
                # the top of the trunk and the crown of the tree
                threshhold = 1 / height
                if random() < threshhold:
                    continue
                branchy = topy
                basesize = endrad
            else:
                branchy = posy - distance * slope
                basesize = (endrad + (self.trunkradius - endrad) *
                         (topy - branchy) / self.trunkheight)
            startsize = (basesize * (1 + random()) * PHI *
                         (distance / height) ** PHI)
            if startsize < 1.0:
                startsize = 1.0
            rndr = sqrt(random()) * basesize * PHI
            rndang = random() * 2 * pi
            rndx = int(rndr * sin(rndang) + 0.5)
            rndz = int(rndr * cos(rndang) + 0.5)
            startcoord = [self.pos[0] + rndx,
                          int(branchy),
                          self.pos[2] + rndz]
            endsize = 1.0
            self.taperedcylinder(startcoord, coord, startsize, endsize, world,
                                 blocks["log"].slot)
Exemplo n.º 2
0
    def make_branches(self, world):
        """
        Generate the branches and enter them in world.
        """

        height = self.height
        topy = self.pos[1] + int(self.trunkheight + 0.5)
        # endrad is the base radius of the branches at the trunk
        endrad = max(self.trunkradius * (1 - self.trunkheight / height), 1)
        for coord in self.foliage_cords:
            distance = dist((coord[0], coord[2]), (self.pos[0], self.pos[2]))
            ydist = coord[1] - self.pos[1]
            # value is a magic number that weights the probability
            # of generating branches properly so that
            # you get enough on small trees, but not too many
            # on larger trees.
            # Very difficult to get right... do not touch!
            value = (self.branchdensity * 220 * height) / (
                (ydist + distance)**3)
            if value < random():
                continue

            posy = coord[1]
            slope = self.branchslope + (0.5 - random()) * .16
            if coord[1] - distance * slope > topy:
                # Another random rejection, for branches between
                # the top of the trunk and the crown of the tree
                threshhold = 1 / height
                if random() < threshhold:
                    continue
                branchy = topy
                basesize = endrad
            else:
                branchy = posy - distance * slope
                basesize = (endrad + (self.trunkradius - endrad) *
                            (topy - branchy) / self.trunkheight)
            startsize = (basesize * (1 + random()) * PHI *
                         (distance / height)**PHI)
            if startsize < 1.0:
                startsize = 1.0
            rndr = sqrt(random()) * basesize * PHI
            rndang = random() * 2 * pi
            rndx = int(rndr * sin(rndang) + 0.5)
            rndz = int(rndr * cos(rndang) + 0.5)
            startcoord = [self.pos[0] + rndx, int(branchy), self.pos[2] + rndz]
            endsize = 1.0
            self.taperedcylinder(startcoord, coord, startsize, endsize, world,
                                 blocks["log"].slot)
Exemplo n.º 3
0
 def shapefunc(self, y):
     twigs = ProceduralTree.shapefunc(self, y)
     if twigs is not None:
         return twigs
     if y < self.height * (.282 + .1 * sqrt(random())):
         return None
     radius = self.height / 2
     adj = self.height / 2 - y
     if adj == 0:
         distance = radius
     elif abs(adj) >= radius:
         distance = 0
     else:
         distance = dist((0, 0), (radius, adj))
     distance *= PHI
     return distance
Exemplo n.º 4
0
 def shapefunc(self, y):
     twigs = ProceduralTree.shapefunc(self, y)
     if twigs is not None:
         return twigs
     if y < self.height * (.282 + .1 * sqrt(random())):
         return None
     radius = self.height / 2
     adj = self.height / 2 - y
     if adj == 0:
         distance = radius
     elif abs(adj) >= radius:
         distance = 0
     else:
         distance = dist((0, 0), (radius, adj))
     distance *= PHI
     return distance
Exemplo n.º 5
0
    def make_roots(self, rootbases, world):
        """generate the roots and enter them in world.

        rootbases = [[x,z,base_radius], ...] and is the list of locations
        the roots can originate from, and the size of that location.
        """

        height = self.height
        for coord in self.foliage_cords:
            # First, set the threshhold for randomly selecting this
            # coordinate for root creation.
            distance = dist((coord[0], coord[2]), (self.pos[0], self.pos[2]))
            ydist = coord[1] - self.pos[1]
            value = ((self.branchdensity * 220 * height) /
                     ((ydist + distance) ** 3))
            # Randomly skip roots, based on the above threshold
            if value < random():
                continue
            # initialize the internal variables from a selection of
            # starting locations.
            rootbase = choice(rootbases)
            rootx = rootbase[0]
            rootz = rootbase[1]
            rootbaseradius = rootbase[2]
            # Offset the root origin location by a random amount
            # (radialy) from the starting location.
            rndr = sqrt(random()) * rootbaseradius * PHI
            rndang = random() * 2 * pi
            rndx = int(rndr * sin(rndang) + 0.5)
            rndz = int(rndr * cos(rndang) + 0.5)
            rndy = int(random() * rootbaseradius * 0.5)
            startcoord = [rootx + rndx, self.pos[1] + rndy, rootz + rndz]
            # offset is the distance from the root base to the root tip.
            offset = [startcoord[i] - coord[i] for i in xrange(3)]
            # If this is a mangrove tree, make the roots longer.
            offset = [int(val * IPHI - 1.5) for val in offset]
            rootstartsize = (rootbaseradius * IPHI * abs(offset[1]) /
                             (height * IPHI))
            rootstartsize = max(rootstartsize, 1.0)
Exemplo n.º 6
0
    def make_roots(self, rootbases, world):
        """generate the roots and enter them in world.

        rootbases = [[x,z,base_radius], ...] and is the list of locations
        the roots can originate from, and the size of that location.
        """

        height = self.height
        for coord in self.foliage_cords:
            # First, set the threshhold for randomly selecting this
            # coordinate for root creation.
            distance = dist((coord[0], coord[2]), (self.pos[0], self.pos[2]))
            ydist = coord[1] - self.pos[1]
            value = ((self.branchdensity * 220 * height) /
                     ((ydist + distance)**3))
            # Randomly skip roots, based on the above threshold
            if value < random():
                continue
            # initialize the internal variables from a selection of
            # starting locations.
            rootbase = choice(rootbases)
            rootx = rootbase[0]
            rootz = rootbase[1]
            rootbaseradius = rootbase[2]
            # Offset the root origin location by a random amount
            # (radialy) from the starting location.
            rndr = sqrt(random()) * rootbaseradius * PHI
            rndang = random() * 2 * pi
            rndx = int(rndr * sin(rndang) + 0.5)
            rndz = int(rndr * cos(rndang) + 0.5)
            rndy = int(random() * rootbaseradius * 0.5)
            startcoord = [rootx + rndx, self.pos[1] + rndy, rootz + rndz]
            # offset is the distance from the root base to the root tip.
            offset = [startcoord[i] - coord[i] for i in xrange(3)]
            # If this is a mangrove tree, make the roots longer.
            offset = [int(val * IPHI - 1.5) for val in offset]
            rootstartsize = (rootbaseradius * IPHI * abs(offset[1]) /
                             (height * IPHI))
            rootstartsize = max(rootstartsize, 1.0)
Exemplo n.º 7
0
 def test_pythagorean_triple(self):
     five = dist((0, 0), (3, 4))
     self.assertAlmostEqual(five, 5)
Exemplo n.º 8
0
 def test_pythagorean_triple(self):
     five = dist((0, 0), (3, 4))
     self.assertAlmostEqual(five, 5)