Beispiel #1
0
 def random_location(self, provoke_collision=False):
     if provoke_collision and self.entities:
         entity = choice(self.entities)
         angle = Point.from_angle(angle=random())
         return entity.center + angle * entity.shape.size * (self.__class__.COLLISION_MIN_DISTANCE + random())
     else:
         return Point.random_instance(Point.zero, Point.one)
 def sample_entity(self, world, last_entity, combinations=None):
     if last_entity == -1:
         while True:
             self.clusters = list()
             for _ in range(self.num_clusters * self.__class__.MAX_ATTEMPTS):
                 r = random()
                 if r < 0.25:
                     cluster_center = Point(0.125 + r * 3.0, 0.15)
                 elif r < 0.5:
                     cluster_center = Point(0.125 + (r - 0.25) * 3.0, 0.85)
                 elif r < 0.75:
                     cluster_center = Point(0.15, 0.125 + (r - 0.5) * 3.0)
                 else:
                     cluster_center = Point(0.85, 0.125 + (r - 0.75) * 3.0)
                 # cluster_center = world.random_location()
                 if all(cluster_center.distance(cluster) > self.__class__.MIN_CLUSTERS_DISTANCE for cluster in self.clusters):
                     self.clusters.append(cluster_center)
                     if len(self.clusters) == self.num_clusters:
                         break
             else:
                 print(self.clusters)
                 continue
             break
     elif last_entity is not None:
         pass
     self.selected_cluster = choice(self.clusters)
     angle = Point.from_angle(angle=random())
     center = self.selected_cluster + angle * random() * self.__class__.MAX_CLUSTER_CENTER_DISTANCE
     if combinations is None:
         return Entity.random_instance(center=center, rotation=self.rotation, size_range=self.size_range, distortion_range=self.distortion_range, shade_range=self.shade_range, shapes=self.shapes, colors=self.colors, textures=self.textures)
     else:
         return Entity.random_instance(center=center, rotation=self.rotation, size_range=self.size_range, distortion_range=self.distortion_range, shade_range=self.shade_range, combinations=combinations)